Commit db904c69637b4a6d716b8551943728a695f912d8

Authored by Igor Kulikov
1 parent dc9960a5

Fix HSQLDB support

@@ -15,11 +15,20 @@ @@ -15,11 +15,20 @@
15 */ 15 */
16 package org.thingsboard.server.service.install; 16 package org.thingsboard.server.service.install;
17 17
  18 +import lombok.extern.slf4j.Slf4j;
18 import org.springframework.context.annotation.Profile; 19 import org.springframework.context.annotation.Profile;
19 import org.springframework.stereotype.Service; 20 import org.springframework.stereotype.Service;
20 import org.thingsboard.server.dao.util.HsqlDao; 21 import org.thingsboard.server.dao.util.HsqlDao;
21 22
  23 +import java.nio.charset.Charset;
  24 +import java.nio.file.Files;
  25 +import java.nio.file.Path;
  26 +import java.nio.file.Paths;
  27 +import java.sql.Connection;
  28 +import java.sql.DriverManager;
  29 +
22 @Service 30 @Service
  31 +@Slf4j
23 @HsqlDao 32 @HsqlDao
24 @Profile("install") 33 @Profile("install")
25 public class HsqlEntityDatabaseSchemaService extends SqlAbstractDatabaseSchemaService 34 public class HsqlEntityDatabaseSchemaService extends SqlAbstractDatabaseSchemaService
@@ -27,5 +36,21 @@ public class HsqlEntityDatabaseSchemaService extends SqlAbstractDatabaseSchemaSe @@ -27,5 +36,21 @@ public class HsqlEntityDatabaseSchemaService extends SqlAbstractDatabaseSchemaSe
27 protected HsqlEntityDatabaseSchemaService() { 36 protected HsqlEntityDatabaseSchemaService() {
28 super("schema-entities-hsql.sql", "schema-entities-idx.sql"); 37 super("schema-entities-hsql.sql", "schema-entities-idx.sql");
29 } 38 }
  39 +
  40 + private final String schemaTypesSql = "schema-types-hsql.sql";
  41 +
  42 + @Override
  43 + public void createDatabaseSchema(boolean createIndexes) throws Exception {
  44 +
  45 + log.info("Installing SQL DataBase types part: " + schemaTypesSql);
  46 +
  47 + Path schemaFile = Paths.get(installScripts.getDataDir(), SQL_DIR, schemaTypesSql);
  48 + try (Connection conn = DriverManager.getConnection(dbUrl, dbUserName, dbPassword)) {
  49 + String sql = new String(Files.readAllBytes(schemaFile), Charset.forName("UTF-8"));
  50 + conn.createStatement().execute(sql); //NOSONAR, ignoring because method used to load initial thingsboard database schema
  51 + }
  52 +
  53 + super.createDatabaseSchema(createIndexes);
  54 + }
30 } 55 }
31 56
@@ -30,7 +30,7 @@ import java.sql.SQLException; @@ -30,7 +30,7 @@ import java.sql.SQLException;
30 @Slf4j 30 @Slf4j
31 public abstract class SqlAbstractDatabaseSchemaService implements DatabaseSchemaService { 31 public abstract class SqlAbstractDatabaseSchemaService implements DatabaseSchemaService {
32 32
33 - private static final String SQL_DIR = "sql"; 33 + protected static final String SQL_DIR = "sql";
34 34
35 @Value("${spring.datasource.url}") 35 @Value("${spring.datasource.url}")
36 protected String dbUrl; 36 protected String dbUrl;
@@ -42,7 +42,7 @@ public abstract class SqlAbstractDatabaseSchemaService implements DatabaseSchema @@ -42,7 +42,7 @@ public abstract class SqlAbstractDatabaseSchemaService implements DatabaseSchema
42 protected String dbPassword; 42 protected String dbPassword;
43 43
44 @Autowired 44 @Autowired
45 - private InstallScripts installScripts; 45 + protected InstallScripts installScripts;
46 46
47 private final String schemaSql; 47 private final String schemaSql;
48 private final String schemaIdxSql; 48 private final String schemaIdxSql;
@@ -83,7 +83,7 @@ public class EntityDataAdapter { @@ -83,7 +83,7 @@ public class EntityDataAdapter {
83 if (value != null) { 83 if (value != null) {
84 String strVal = value.toString(); 84 String strVal = value.toString();
85 // check number 85 // check number
86 - if (strVal.length() > 0 && NumberUtils.isParsable(strVal)) { 86 + if (NumberUtils.isNumber(strVal)) {
87 try { 87 try {
88 long longVal = Long.parseLong(strVal); 88 long longVal = Long.parseLong(strVal);
89 return Long.toString(longVal); 89 return Long.toString(longVal);
@@ -114,7 +114,7 @@ CREATE TABLE IF NOT EXISTS customer ( @@ -114,7 +114,7 @@ CREATE TABLE IF NOT EXISTS customer (
114 CREATE TABLE IF NOT EXISTS dashboard ( 114 CREATE TABLE IF NOT EXISTS dashboard (
115 id uuid NOT NULL CONSTRAINT dashboard_pkey PRIMARY KEY, 115 id uuid NOT NULL CONSTRAINT dashboard_pkey PRIMARY KEY,
116 created_time bigint NOT NULL, 116 created_time bigint NOT NULL,
117 - configuration varchar, 117 + configuration varchar(10000000),
118 assigned_customers varchar(1000000), 118 assigned_customers varchar(1000000),
119 search_text varchar(255), 119 search_text varchar(255),
120 tenant_id uuid, 120 tenant_id uuid,