Commit 90e0d8965bc9b2d8886a6a9dbc87269dae4b02a0

Authored by hagaic
1 parent 4976a532

install hybrid db schema (simplified)

@@ -24,9 +24,10 @@ import org.springframework.context.annotation.Profile; @@ -24,9 +24,10 @@ import org.springframework.context.annotation.Profile;
24 import org.springframework.stereotype.Service; 24 import org.springframework.stereotype.Service;
25 import org.thingsboard.server.service.component.ComponentDiscoveryService; 25 import org.thingsboard.server.service.component.ComponentDiscoveryService;
26 import org.thingsboard.server.service.install.DataUpdateService; 26 import org.thingsboard.server.service.install.DataUpdateService;
27 -import org.thingsboard.server.service.install.DatabaseSchemaService;  
28 import org.thingsboard.server.service.install.DatabaseUpgradeService; 27 import org.thingsboard.server.service.install.DatabaseUpgradeService;
  28 +import org.thingsboard.server.service.install.EntityDatabaseSchemaService;
29 import org.thingsboard.server.service.install.SystemDataLoaderService; 29 import org.thingsboard.server.service.install.SystemDataLoaderService;
  30 +import org.thingsboard.server.service.install.TsDatabaseSchemaService;
30 31
31 @Service 32 @Service
32 @Profile("install") 33 @Profile("install")
@@ -43,7 +44,10 @@ public class ThingsboardInstallService { @@ -43,7 +44,10 @@ public class ThingsboardInstallService {
43 private Boolean loadDemo; 44 private Boolean loadDemo;
44 45
45 @Autowired 46 @Autowired
46 - private DatabaseSchemaService databaseSchemaService; 47 + private EntityDatabaseSchemaService entityDatabaseSchemaService;
  48 +
  49 + @Autowired
  50 + private TsDatabaseSchemaService tsDatabaseSchemaService;
47 51
48 @Autowired 52 @Autowired
49 private DatabaseUpgradeService databaseUpgradeService; 53 private DatabaseUpgradeService databaseUpgradeService;
@@ -114,9 +118,13 @@ public class ThingsboardInstallService { @@ -114,9 +118,13 @@ public class ThingsboardInstallService {
114 118
115 log.info("Starting ThingsBoard Installation..."); 119 log.info("Starting ThingsBoard Installation...");
116 120
117 - log.info("Installing DataBase schema..."); 121 + log.info("Installing DataBase schema for entities...");
  122 +
  123 + entityDatabaseSchemaService.createDatabaseSchema();
  124 +
  125 + log.info("Installing DataBase schema for timeseries...");
118 126
119 - databaseSchemaService.createDatabaseSchema(); 127 + tsDatabaseSchemaService.createDatabaseSchema();
120 128
121 log.info("Loading system data..."); 129 log.info("Loading system data...");
122 130
@@ -25,7 +25,7 @@ import java.nio.file.Paths; @@ -25,7 +25,7 @@ import java.nio.file.Paths;
25 import java.util.List; 25 import java.util.List;
26 26
27 @Slf4j 27 @Slf4j
28 -public abstract class CassandraAbstractDatabaseSchemaService /*implements DatabaseSchemaService*/ { 28 +public abstract class CassandraAbstractDatabaseSchemaService implements DatabaseSchemaService {
29 29
30 private static final String CASSANDRA_DIR = "cassandra"; 30 private static final String CASSANDRA_DIR = "cassandra";
31 31
@@ -41,7 +41,7 @@ public abstract class CassandraAbstractDatabaseSchemaService /*implements Databa @@ -41,7 +41,7 @@ public abstract class CassandraAbstractDatabaseSchemaService /*implements Databa
41 this.schemaCql = schemaCql; 41 this.schemaCql = schemaCql;
42 } 42 }
43 43
44 - //@Override 44 + @Override
45 public void createDatabaseSchema() throws Exception { 45 public void createDatabaseSchema() throws Exception {
46 log.info("Installing Cassandra DataBase schema part: " + schemaCql); 46 log.info("Installing Cassandra DataBase schema part: " + schemaCql);
47 Path schemaFile = Paths.get(installScripts.getDataDir(), CASSANDRA_DIR, schemaCql); 47 Path schemaFile = Paths.get(installScripts.getDataDir(), CASSANDRA_DIR, schemaCql);
1 -/**  
2 - * Copyright © 2016-2018 The Thingsboard Authors  
3 - *  
4 - * Licensed under the Apache License, Version 2.0 (the "License");  
5 - * you may not use this file except in compliance with the License.  
6 - * You may obtain a copy of the License at  
7 - *  
8 - * http://www.apache.org/licenses/LICENSE-2.0  
9 - *  
10 - * Unless required by applicable law or agreed to in writing, software  
11 - * distributed under the License is distributed on an "AS IS" BASIS,  
12 - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  
13 - * See the License for the specific language governing permissions and  
14 - * limitations under the License.  
15 - */  
16 -package org.thingsboard.server.service.install;  
17 -  
18 -import lombok.extern.slf4j.Slf4j;  
19 -import org.springframework.beans.factory.annotation.Autowired;  
20 -import org.springframework.context.annotation.Profile;  
21 -import org.springframework.stereotype.Service;  
22 -import org.thingsboard.server.dao.util.NoSqlDao;  
23 -  
24 -@Service  
25 -@NoSqlDao  
26 -@Profile("install")  
27 -@Slf4j  
28 -public class CassandraDatabaseSchemaService implements DatabaseSchemaService {  
29 -  
30 - @Autowired  
31 - private CassandraEntityDatabaseSchemaService cassandraEntityDatabaseSchemaService;  
32 -  
33 - @Autowired  
34 - private CassandraTsDatabaseSchemaService cassandraTsDatabaseSchemaService;  
35 -  
36 -  
37 - @Override  
38 - public void createDatabaseSchema() throws Exception {  
39 - log.info("Installing Cassandra DataBase schema...");  
40 - cassandraEntityDatabaseSchemaService.createDatabaseSchema();  
41 - cassandraTsDatabaseSchemaService.createDatabaseSchema();  
42 - }  
43 -}  
@@ -16,9 +16,12 @@ @@ -16,9 +16,12 @@
16 package org.thingsboard.server.service.install; 16 package org.thingsboard.server.service.install;
17 17
18 import org.springframework.stereotype.Service; 18 import org.springframework.stereotype.Service;
  19 +import org.thingsboard.server.dao.util.NoSqlDao;
19 20
20 @Service 21 @Service
21 -public class CassandraEntityDatabaseSchemaService extends CassandraAbstractDatabaseSchemaService { 22 +@NoSqlDao
  23 +public class CassandraEntityDatabaseSchemaService extends CassandraAbstractDatabaseSchemaService
  24 + implements EntityDatabaseSchemaService {
22 public CassandraEntityDatabaseSchemaService() { 25 public CassandraEntityDatabaseSchemaService() {
23 super("schema-entities.cql"); 26 super("schema-entities.cql");
24 } 27 }
@@ -16,9 +16,12 @@ @@ -16,9 +16,12 @@
16 package org.thingsboard.server.service.install; 16 package org.thingsboard.server.service.install;
17 17
18 import org.springframework.stereotype.Service; 18 import org.springframework.stereotype.Service;
  19 +import org.thingsboard.server.dao.util.NoSqlTsDao;
19 20
20 @Service 21 @Service
21 -public class CassandraTsDatabaseSchemaService extends CassandraAbstractDatabaseSchemaService { 22 +@NoSqlTsDao
  23 +public class CassandraTsDatabaseSchemaService extends CassandraAbstractDatabaseSchemaService
  24 + implements TsDatabaseSchemaService {
22 public CassandraTsDatabaseSchemaService() { 25 public CassandraTsDatabaseSchemaService() {
23 super("schema-ts.cql"); 26 super("schema-ts.cql");
24 } 27 }
  1 +package org.thingsboard.server.service.install;
  2 +
  3 +public interface EntityDatabaseSchemaService extends DatabaseSchemaService {
  4 +}
1 -/**  
2 - * Copyright © 2016-2018 The Thingsboard Authors  
3 - *  
4 - * Licensed under the Apache License, Version 2.0 (the "License");  
5 - * you may not use this file except in compliance with the License.  
6 - * You may obtain a copy of the License at  
7 - *  
8 - * http://www.apache.org/licenses/LICENSE-2.0  
9 - *  
10 - * Unless required by applicable law or agreed to in writing, software  
11 - * distributed under the License is distributed on an "AS IS" BASIS,  
12 - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  
13 - * See the License for the specific language governing permissions and  
14 - * limitations under the License.  
15 - */  
16 -package org.thingsboard.server.service.install;  
17 -  
18 -import lombok.extern.slf4j.Slf4j;  
19 -import org.springframework.beans.factory.annotation.Autowired;  
20 -import org.springframework.context.annotation.Profile;  
21 -import org.springframework.stereotype.Service;  
22 -import org.thingsboard.server.dao.util.HybridDao;  
23 -  
24 -@Service  
25 -@Profile("install")  
26 -@Slf4j  
27 -@HybridDao  
28 -public class HybridDatabaseSchemaService implements DatabaseSchemaService {  
29 -  
30 - @Autowired  
31 - private SqlEntityDatabaseSchemaService sqlEntityDatabaseSchemaService;  
32 -  
33 - @Autowired  
34 - private CassandraTsDatabaseSchemaService cassandraTsDatabaseSchemaService;  
35 -  
36 -  
37 - @Override  
38 - public void createDatabaseSchema() throws Exception {  
39 - log.info("Installing Hybrid SQL/Cassandra DataBase schema...");  
40 - sqlEntityDatabaseSchemaService.createDatabaseSchema();  
41 - cassandraTsDatabaseSchemaService.createDatabaseSchema();  
42 - }  
43 -  
44 -}  
@@ -27,7 +27,7 @@ import java.sql.Connection; @@ -27,7 +27,7 @@ import java.sql.Connection;
27 import java.sql.DriverManager; 27 import java.sql.DriverManager;
28 28
29 @Slf4j 29 @Slf4j
30 -public abstract class SqlAbstractDatabaseSchemaService /*implements DatabaseSchemaService*/ { 30 +public abstract class SqlAbstractDatabaseSchemaService implements DatabaseSchemaService {
31 31
32 private static final String SQL_DIR = "sql"; 32 private static final String SQL_DIR = "sql";
33 33
@@ -49,7 +49,7 @@ public abstract class SqlAbstractDatabaseSchemaService /*implements DatabaseSche @@ -49,7 +49,7 @@ public abstract class SqlAbstractDatabaseSchemaService /*implements DatabaseSche
49 this.schemaSql = schemaSql; 49 this.schemaSql = schemaSql;
50 } 50 }
51 51
52 - //@Override 52 + @Override
53 public void createDatabaseSchema() throws Exception { 53 public void createDatabaseSchema() throws Exception {
54 54
55 log.info("Installing SQL DataBase schema part: " + schemaSql); 55 log.info("Installing SQL DataBase schema part: " + schemaSql);
1 -/**  
2 - * Copyright © 2016-2018 The Thingsboard Authors  
3 - *  
4 - * Licensed under the Apache License, Version 2.0 (the "License");  
5 - * you may not use this file except in compliance with the License.  
6 - * You may obtain a copy of the License at  
7 - *  
8 - * http://www.apache.org/licenses/LICENSE-2.0  
9 - *  
10 - * Unless required by applicable law or agreed to in writing, software  
11 - * distributed under the License is distributed on an "AS IS" BASIS,  
12 - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  
13 - * See the License for the specific language governing permissions and  
14 - * limitations under the License.  
15 - */  
16 -package org.thingsboard.server.service.install;  
17 -  
18 -import lombok.extern.slf4j.Slf4j;  
19 -import org.springframework.beans.factory.annotation.Autowired;  
20 -import org.springframework.context.annotation.Profile;  
21 -import org.springframework.stereotype.Service;  
22 -import org.thingsboard.server.dao.util.SqlDao;  
23 -  
24 -@Service  
25 -@Profile("install")  
26 -@Slf4j  
27 -@SqlDao  
28 -public class SqlDatabaseSchemaService implements DatabaseSchemaService {  
29 -  
30 - @Autowired  
31 - private SqlEntityDatabaseSchemaService sqlEntityDatabaseSchemaService;  
32 -  
33 - @Autowired  
34 - private SqlTsDatabaseSchemaService sqlTsDatabaseSchemaService;  
35 -  
36 -  
37 - @Override  
38 - public void createDatabaseSchema() throws Exception {  
39 - log.info("Installing SQL DataBase schema...");  
40 - sqlEntityDatabaseSchemaService.createDatabaseSchema();  
41 - sqlTsDatabaseSchemaService.createDatabaseSchema();  
42 - }  
43 -  
44 -}  
@@ -16,9 +16,12 @@ @@ -16,9 +16,12 @@
16 package org.thingsboard.server.service.install; 16 package org.thingsboard.server.service.install;
17 17
18 import org.springframework.stereotype.Service; 18 import org.springframework.stereotype.Service;
  19 +import org.thingsboard.server.dao.util.SqlDao;
19 20
20 @Service 21 @Service
21 -public class SqlEntityDatabaseSchemaService extends SqlAbstractDatabaseSchemaService { 22 +@SqlDao
  23 +public class SqlEntityDatabaseSchemaService extends SqlAbstractDatabaseSchemaService
  24 + implements EntityDatabaseSchemaService {
22 public SqlEntityDatabaseSchemaService() { 25 public SqlEntityDatabaseSchemaService() {
23 super("schema-entities.sql"); 26 super("schema-entities.sql");
24 } 27 }
@@ -16,9 +16,12 @@ @@ -16,9 +16,12 @@
16 package org.thingsboard.server.service.install; 16 package org.thingsboard.server.service.install;
17 17
18 import org.springframework.stereotype.Service; 18 import org.springframework.stereotype.Service;
  19 +import org.thingsboard.server.dao.util.SqlTsDao;
19 20
20 @Service 21 @Service
21 -public class SqlTsDatabaseSchemaService extends SqlAbstractDatabaseSchemaService { 22 +@SqlTsDao
  23 +public class SqlTsDatabaseSchemaService extends SqlAbstractDatabaseSchemaService
  24 + implements TsDatabaseSchemaService {
22 public SqlTsDatabaseSchemaService() { 25 public SqlTsDatabaseSchemaService() {
23 super("schema-ts.sql"); 26 super("schema-ts.sql");
24 } 27 }
  1 +package org.thingsboard.server.service.install;
  2 +
  3 +public interface TsDatabaseSchemaService extends DatabaseSchemaService {
  4 +}