From 67964c34c8f38c7cb0c24f9399d67c5af12c3ce1 Mon Sep 17 00:00:00 2001 From: Sasha Didukh Date: Fri, 12 Aug 2016 18:13:10 +0300 Subject: [PATCH] KAA-1297: Add log schema migration support --- .../data_migration/AbstractCTLMigration.java | 32 +++++++++++----- .../BaseSchemaRecordsCreation.java | 17 ++++++++- .../data_migration/CTLAggregation.java | 25 ++++++++++-- .../CTLConfigurationMigration.java | 38 +++++++++---------- .../data_migration/CTLEventsMigration.java | 18 ++++++++- .../data_migration/CtlLogMigration.java | 33 ++++++++++++++++ .../data_migration/MigrateData.java | 17 +++++++++ .../data_migration/MigrationException.java | 17 ++++++++- .../data_migration/UpdateUuidsMigration.java | 18 ++++++++- .../data_migration/model/Configuration.java | 16 ++++++++ .../kaaproject/data_migration/model/Ctl.java | 17 ++++++++- .../data_migration/model/CtlMetaInfo.java | 16 ++++++++ .../data_migration/model/EventClass.java | 16 ++++++++ .../model/EventSchemaVersion.java | 16 ++++++++ .../data_migration/model/Schema.java | 16 ++++++++ .../utils/BaseSchemaIdCounter.java | 23 ++++++++--- .../data_migration/utils/Constants.java | 19 +++++++++- .../data_migration/utils/DataSources.java | 27 ++++++++++--- .../data_migration/utils/Utils.java | 31 ++++++++------- .../datadefinition/BuilderException.java | 18 ++++++++- .../utils/datadefinition/Constraint.java | 17 ++++++++- .../utils/datadefinition/ConstraintType.java | 17 ++++++++- .../utils/datadefinition/DataDefinition.java | 37 ++++++++++++------ .../datadefinition/ReferenceOptions.java | 17 ++++++++- 24 files changed, 437 insertions(+), 81 deletions(-) create mode 100644 server/upgrade/data-migration-0.9.0-0.10.0/src/main/java/org/kaaproject/data_migration/CtlLogMigration.java diff --git a/server/upgrade/data-migration-0.9.0-0.10.0/src/main/java/org/kaaproject/data_migration/AbstractCTLMigration.java b/server/upgrade/data-migration-0.9.0-0.10.0/src/main/java/org/kaaproject/data_migration/AbstractCTLMigration.java index e58891e005..9c138435c3 100644 --- a/server/upgrade/data-migration-0.9.0-0.10.0/src/main/java/org/kaaproject/data_migration/AbstractCTLMigration.java +++ b/server/upgrade/data-migration-0.9.0-0.10.0/src/main/java/org/kaaproject/data_migration/AbstractCTLMigration.java @@ -1,7 +1,21 @@ -package org.kaaproject.data_migration; +/* + * Copyright 2014-2016 CyberVision, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.kaaproject.data_migration; -import org.apache.commons.dbutils.DbUtils; import org.apache.commons.dbutils.QueryRunner; import org.apache.commons.dbutils.handlers.BeanListHandler; import org.kaaproject.data_migration.model.Schema; @@ -29,7 +43,7 @@ public AbstractCTLMigration(Connection connection) { public void beforeTransform() throws SQLException { // delete relation between _schems to schems - dd.dropUnnamedFK(getName() + "_schems", "schems"); + dd.dropUnnamedFK(getPrefixTableName() + "_schems", "schems"); } @@ -38,16 +52,16 @@ protected List transform() throws SQLException { List schemas = runner.query(connection, "select " + "f.id as id, created_time as createdTime, created_username as createdUsername, " + "description, name, schems, version, application_id as appId " + - "from " + getName() + "_schems f join schems s on f.id = s.id", new BeanListHandler<>(Schema.class)); + "from " + getPrefixTableName() + "_schems f join schems s on f.id = s.id", new BeanListHandler<>(Schema.class)); // delete the fetched ids from schema table String toDelete = schemas.stream().map(s -> s.getId().toString()).collect(joining(", ")); runner.update(connection, "delete from schems where id in (" + toDelete + ")"); // shift ids in order to avoid PK constraint violation during adding record to base_schema - Long shift = runner.query(connection, "select max(id) as max_id from "+ getName() + "_schems", rs -> rs.next() ? rs.getLong("max_id") : null); + Long shift = runner.query(connection, "select max(id) as max_id from "+ getPrefixTableName() + "_schems", rs -> rs.next() ? rs.getLong("max_id") : null); Long idShift = BaseSchemaIdCounter.getInstance().getAndShift(shift); - runner.update(connection, "update " + getName() + "_schems set id = id + " + idShift + " order by id desc"); + runner.update(connection, "update " + getPrefixTableName() + "_schems set id = id + " + idShift + " order by id desc"); schemas.forEach(s -> s.setId(s.getId() + idShift)); return schemas; @@ -55,8 +69,8 @@ protected List transform() throws SQLException { public void afterTransform() throws SQLException { - dd.alterTable(getName() + "_schems") - .add(constraint("FK_" + getName() + "_base_schems_id") + dd.alterTable(getPrefixTableName() + "_schems") + .add(constraint("FK_" + getPrefixTableName() + "_base_schems_id") .foreignKey("id") .references("base_schems", "id") .onDelete(CASCADE) @@ -65,6 +79,6 @@ public void afterTransform() throws SQLException { .execute(); } - protected abstract String getName(); + protected abstract String getPrefixTableName(); } diff --git a/server/upgrade/data-migration-0.9.0-0.10.0/src/main/java/org/kaaproject/data_migration/BaseSchemaRecordsCreation.java b/server/upgrade/data-migration-0.9.0-0.10.0/src/main/java/org/kaaproject/data_migration/BaseSchemaRecordsCreation.java index 2af9bafc1f..452e97576a 100644 --- a/server/upgrade/data-migration-0.9.0-0.10.0/src/main/java/org/kaaproject/data_migration/BaseSchemaRecordsCreation.java +++ b/server/upgrade/data-migration-0.9.0-0.10.0/src/main/java/org/kaaproject/data_migration/BaseSchemaRecordsCreation.java @@ -1,5 +1,20 @@ -package org.kaaproject.data_migration; +/* + * Copyright 2014-2016 CyberVision, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.kaaproject.data_migration; import org.apache.commons.dbutils.QueryRunner; import org.kaaproject.data_migration.model.Ctl; diff --git a/server/upgrade/data-migration-0.9.0-0.10.0/src/main/java/org/kaaproject/data_migration/CTLAggregation.java b/server/upgrade/data-migration-0.9.0-0.10.0/src/main/java/org/kaaproject/data_migration/CTLAggregation.java index 9b8b56fb07..213e9a7edd 100644 --- a/server/upgrade/data-migration-0.9.0-0.10.0/src/main/java/org/kaaproject/data_migration/CTLAggregation.java +++ b/server/upgrade/data-migration-0.9.0-0.10.0/src/main/java/org/kaaproject/data_migration/CTLAggregation.java @@ -1,5 +1,20 @@ -package org.kaaproject.data_migration; +/* + * Copyright 2014-2016 CyberVision, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.kaaproject.data_migration; import org.apache.commons.dbutils.QueryRunner; import org.apache.commons.dbutils.handlers.ScalarHandler; @@ -19,11 +34,15 @@ import java.io.IOException; import java.sql.Connection; import java.sql.SQLException; -import java.util.*; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; import static java.lang.String.format; import static java.util.Arrays.asList; -import static java.util.Arrays.binarySearch; public class CTLAggregation { private Connection connection; diff --git a/server/upgrade/data-migration-0.9.0-0.10.0/src/main/java/org/kaaproject/data_migration/CTLConfigurationMigration.java b/server/upgrade/data-migration-0.9.0-0.10.0/src/main/java/org/kaaproject/data_migration/CTLConfigurationMigration.java index c6842efa7a..c57de5713e 100644 --- a/server/upgrade/data-migration-0.9.0-0.10.0/src/main/java/org/kaaproject/data_migration/CTLConfigurationMigration.java +++ b/server/upgrade/data-migration-0.9.0-0.10.0/src/main/java/org/kaaproject/data_migration/CTLConfigurationMigration.java @@ -1,26 +1,24 @@ +/* + * Copyright 2014-2016 CyberVision, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package org.kaaproject.data_migration; -import org.apache.commons.dbutils.DbUtils; -import org.apache.commons.dbutils.QueryRunner; -import org.apache.commons.dbutils.handlers.BeanListHandler; -import org.apache.commons.dbutils.handlers.ScalarHandler; -import org.kaaproject.data_migration.model.Schema; -import org.kaaproject.data_migration.model.Ctl; -import org.kaaproject.data_migration.model.CtlMetaInfo; -import org.kaaproject.data_migration.utils.datadefinition.DataDefinition; -import org.kaaproject.kaa.server.common.core.algorithms.generation.ConfigurationGenerationException; -import org.kaaproject.kaa.server.common.core.algorithms.generation.DefaultRecordGenerationAlgorithm; -import org.kaaproject.kaa.server.common.core.algorithms.generation.DefaultRecordGenerationAlgorithmImpl; -import org.kaaproject.kaa.server.common.core.configuration.RawData; -import org.kaaproject.kaa.server.common.core.configuration.RawDataFactory; -import org.kaaproject.kaa.server.common.core.schema.RawSchema; - -import java.io.IOException; import java.sql.Connection; import java.sql.SQLException; -import java.util.*; -import static java.util.stream.Collectors.joining; import static org.kaaproject.data_migration.utils.datadefinition.Constraint.constraint; import static org.kaaproject.data_migration.utils.datadefinition.ReferenceOptions.CASCADE; @@ -37,7 +35,7 @@ public void beforeTransform() throws SQLException { // change FK constraint between table that contains data and appropriate _schems table dd.dropUnnamedFK("configuration", "configuration_schems"); - dd.alterTable(getName()) + dd.alterTable(getPrefixTableName()) .add(constraint("FK_configuration_schems_id") .foreignKey("configuration_schems_id") .references("configuration_schems", "id") @@ -48,7 +46,7 @@ public void beforeTransform() throws SQLException { } @Override - protected String getName() { + protected String getPrefixTableName() { return "configuration"; } diff --git a/server/upgrade/data-migration-0.9.0-0.10.0/src/main/java/org/kaaproject/data_migration/CTLEventsMigration.java b/server/upgrade/data-migration-0.9.0-0.10.0/src/main/java/org/kaaproject/data_migration/CTLEventsMigration.java index d1ecb85075..e8823b8adc 100644 --- a/server/upgrade/data-migration-0.9.0-0.10.0/src/main/java/org/kaaproject/data_migration/CTLEventsMigration.java +++ b/server/upgrade/data-migration-0.9.0-0.10.0/src/main/java/org/kaaproject/data_migration/CTLEventsMigration.java @@ -1,3 +1,19 @@ +/* + * Copyright 2014-2016 CyberVision, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package org.kaaproject.data_migration; import com.fasterxml.jackson.databind.JsonNode; @@ -32,7 +48,7 @@ public CTLEventsMigration(Connection connection) { //actually not needed here @Override - protected String getName() { + protected String getPrefixTableName() { return null; } diff --git a/server/upgrade/data-migration-0.9.0-0.10.0/src/main/java/org/kaaproject/data_migration/CtlLogMigration.java b/server/upgrade/data-migration-0.9.0-0.10.0/src/main/java/org/kaaproject/data_migration/CtlLogMigration.java new file mode 100644 index 0000000000..91ba48a62e --- /dev/null +++ b/server/upgrade/data-migration-0.9.0-0.10.0/src/main/java/org/kaaproject/data_migration/CtlLogMigration.java @@ -0,0 +1,33 @@ +/* + * Copyright 2014-2016 CyberVision, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.kaaproject.data_migration; + +import java.sql.Connection; + +public class CtlLogMigration extends AbstractCTLMigration { + + public static final String LOG_SCHEMA_PREFIX_TABLE_NAME = "log"; + + public CtlLogMigration(Connection connection) { + super(connection); + } + + @Override + protected String getPrefixTableName() { + return LOG_SCHEMA_PREFIX_TABLE_NAME; + } +} diff --git a/server/upgrade/data-migration-0.9.0-0.10.0/src/main/java/org/kaaproject/data_migration/MigrateData.java b/server/upgrade/data-migration-0.9.0-0.10.0/src/main/java/org/kaaproject/data_migration/MigrateData.java index e822d8bc60..3170df2c8f 100644 --- a/server/upgrade/data-migration-0.9.0-0.10.0/src/main/java/org/kaaproject/data_migration/MigrateData.java +++ b/server/upgrade/data-migration-0.9.0-0.10.0/src/main/java/org/kaaproject/data_migration/MigrateData.java @@ -1,3 +1,19 @@ +/* + * Copyright 2014-2016 CyberVision, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package org.kaaproject.data_migration; import org.apache.commons.dbutils.DbUtils; @@ -31,6 +47,7 @@ public static void main(String[] args) { List migrationList = new ArrayList<>(); migrationList.add(new CTLConfigurationMigration(conn)); migrationList.add(new CTLEventsMigration(conn)); + migrationList.add(new CtlLogMigration(conn)); CTLAggregation aggregation = new CTLAggregation(conn); BaseSchemaRecordsCreation recordsCreation = new BaseSchemaRecordsCreation(conn); diff --git a/server/upgrade/data-migration-0.9.0-0.10.0/src/main/java/org/kaaproject/data_migration/MigrationException.java b/server/upgrade/data-migration-0.9.0-0.10.0/src/main/java/org/kaaproject/data_migration/MigrationException.java index 5c1bfca478..3902eb57c3 100644 --- a/server/upgrade/data-migration-0.9.0-0.10.0/src/main/java/org/kaaproject/data_migration/MigrationException.java +++ b/server/upgrade/data-migration-0.9.0-0.10.0/src/main/java/org/kaaproject/data_migration/MigrationException.java @@ -1,5 +1,20 @@ -package org.kaaproject.data_migration; +/* + * Copyright 2014-2016 CyberVision, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.kaaproject.data_migration; public class MigrationException extends RuntimeException { diff --git a/server/upgrade/data-migration-0.9.0-0.10.0/src/main/java/org/kaaproject/data_migration/UpdateUuidsMigration.java b/server/upgrade/data-migration-0.9.0-0.10.0/src/main/java/org/kaaproject/data_migration/UpdateUuidsMigration.java index c07ed4163f..5538c587af 100644 --- a/server/upgrade/data-migration-0.9.0-0.10.0/src/main/java/org/kaaproject/data_migration/UpdateUuidsMigration.java +++ b/server/upgrade/data-migration-0.9.0-0.10.0/src/main/java/org/kaaproject/data_migration/UpdateUuidsMigration.java @@ -1,7 +1,21 @@ -package org.kaaproject.data_migration; +/* + * Copyright 2014-2016 CyberVision, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.kaaproject.data_migration; -import org.apache.commons.dbutils.DbUtils; import org.apache.commons.dbutils.QueryRunner; import org.apache.commons.dbutils.ResultSetHandler; import org.apache.commons.dbutils.handlers.BeanListHandler; diff --git a/server/upgrade/data-migration-0.9.0-0.10.0/src/main/java/org/kaaproject/data_migration/model/Configuration.java b/server/upgrade/data-migration-0.9.0-0.10.0/src/main/java/org/kaaproject/data_migration/model/Configuration.java index 3e01f7b81d..b2b2c66413 100644 --- a/server/upgrade/data-migration-0.9.0-0.10.0/src/main/java/org/kaaproject/data_migration/model/Configuration.java +++ b/server/upgrade/data-migration-0.9.0-0.10.0/src/main/java/org/kaaproject/data_migration/model/Configuration.java @@ -1,3 +1,19 @@ +/* + * Copyright 2014-2016 CyberVision, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package org.kaaproject.data_migration.model; import java.io.Serializable; diff --git a/server/upgrade/data-migration-0.9.0-0.10.0/src/main/java/org/kaaproject/data_migration/model/Ctl.java b/server/upgrade/data-migration-0.9.0-0.10.0/src/main/java/org/kaaproject/data_migration/model/Ctl.java index 5b410f97a3..6c62d0858c 100644 --- a/server/upgrade/data-migration-0.9.0-0.10.0/src/main/java/org/kaaproject/data_migration/model/Ctl.java +++ b/server/upgrade/data-migration-0.9.0-0.10.0/src/main/java/org/kaaproject/data_migration/model/Ctl.java @@ -1,5 +1,20 @@ -package org.kaaproject.data_migration.model; +/* + * Copyright 2014-2016 CyberVision, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.kaaproject.data_migration.model; public class Ctl { private final Long id; diff --git a/server/upgrade/data-migration-0.9.0-0.10.0/src/main/java/org/kaaproject/data_migration/model/CtlMetaInfo.java b/server/upgrade/data-migration-0.9.0-0.10.0/src/main/java/org/kaaproject/data_migration/model/CtlMetaInfo.java index 17708edb07..c979970234 100644 --- a/server/upgrade/data-migration-0.9.0-0.10.0/src/main/java/org/kaaproject/data_migration/model/CtlMetaInfo.java +++ b/server/upgrade/data-migration-0.9.0-0.10.0/src/main/java/org/kaaproject/data_migration/model/CtlMetaInfo.java @@ -1,3 +1,19 @@ +/* + * Copyright 2014-2016 CyberVision, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package org.kaaproject.data_migration.model; public class CtlMetaInfo { diff --git a/server/upgrade/data-migration-0.9.0-0.10.0/src/main/java/org/kaaproject/data_migration/model/EventClass.java b/server/upgrade/data-migration-0.9.0-0.10.0/src/main/java/org/kaaproject/data_migration/model/EventClass.java index 13e3d4c0bc..a71629aa5b 100644 --- a/server/upgrade/data-migration-0.9.0-0.10.0/src/main/java/org/kaaproject/data_migration/model/EventClass.java +++ b/server/upgrade/data-migration-0.9.0-0.10.0/src/main/java/org/kaaproject/data_migration/model/EventClass.java @@ -1,3 +1,19 @@ +/* + * Copyright 2014-2016 CyberVision, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package org.kaaproject.data_migration.model; public class EventClass { diff --git a/server/upgrade/data-migration-0.9.0-0.10.0/src/main/java/org/kaaproject/data_migration/model/EventSchemaVersion.java b/server/upgrade/data-migration-0.9.0-0.10.0/src/main/java/org/kaaproject/data_migration/model/EventSchemaVersion.java index 52bb64dbc4..cb7e518722 100644 --- a/server/upgrade/data-migration-0.9.0-0.10.0/src/main/java/org/kaaproject/data_migration/model/EventSchemaVersion.java +++ b/server/upgrade/data-migration-0.9.0-0.10.0/src/main/java/org/kaaproject/data_migration/model/EventSchemaVersion.java @@ -1,3 +1,19 @@ +/* + * Copyright 2014-2016 CyberVision, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package org.kaaproject.data_migration.model; public class EventSchemaVersion { diff --git a/server/upgrade/data-migration-0.9.0-0.10.0/src/main/java/org/kaaproject/data_migration/model/Schema.java b/server/upgrade/data-migration-0.9.0-0.10.0/src/main/java/org/kaaproject/data_migration/model/Schema.java index 34b523dbb3..62962dc694 100644 --- a/server/upgrade/data-migration-0.9.0-0.10.0/src/main/java/org/kaaproject/data_migration/model/Schema.java +++ b/server/upgrade/data-migration-0.9.0-0.10.0/src/main/java/org/kaaproject/data_migration/model/Schema.java @@ -1,3 +1,19 @@ +/* + * Copyright 2014-2016 CyberVision, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package org.kaaproject.data_migration.model; public class Schema { diff --git a/server/upgrade/data-migration-0.9.0-0.10.0/src/main/java/org/kaaproject/data_migration/utils/BaseSchemaIdCounter.java b/server/upgrade/data-migration-0.9.0-0.10.0/src/main/java/org/kaaproject/data_migration/utils/BaseSchemaIdCounter.java index 8be237a3c5..e8358d5522 100644 --- a/server/upgrade/data-migration-0.9.0-0.10.0/src/main/java/org/kaaproject/data_migration/utils/BaseSchemaIdCounter.java +++ b/server/upgrade/data-migration-0.9.0-0.10.0/src/main/java/org/kaaproject/data_migration/utils/BaseSchemaIdCounter.java @@ -1,5 +1,20 @@ -package org.kaaproject.data_migration.utils; +/* + * Copyright 2014-2016 CyberVision, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.kaaproject.data_migration.utils; public class BaseSchemaIdCounter { private static BaseSchemaIdCounter instance; @@ -9,7 +24,7 @@ public class BaseSchemaIdCounter { // can be called only once public static void setInitValue(Long value) { getInstance(); - if(isInitMethodCalled) { + if (isInitMethodCalled) { return; } isInitMethodCalled = true; @@ -27,12 +42,10 @@ private BaseSchemaIdCounter() { } public static BaseSchemaIdCounter getInstance() { - if(instance == null) { + if (instance == null) { instance = new BaseSchemaIdCounter(); } return instance; } - - } diff --git a/server/upgrade/data-migration-0.9.0-0.10.0/src/main/java/org/kaaproject/data_migration/utils/Constants.java b/server/upgrade/data-migration-0.9.0-0.10.0/src/main/java/org/kaaproject/data_migration/utils/Constants.java index be7859ee90..cb06889f5f 100644 --- a/server/upgrade/data-migration-0.9.0-0.10.0/src/main/java/org/kaaproject/data_migration/utils/Constants.java +++ b/server/upgrade/data-migration-0.9.0-0.10.0/src/main/java/org/kaaproject/data_migration/utils/Constants.java @@ -1,10 +1,25 @@ -package org.kaaproject.data_migration.utils; +/* + * Copyright 2014-2016 CyberVision, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.kaaproject.data_migration.utils; final public class Constants { public static final String USER_NAME = "sqladmin"; public static final String PASSWORD = "admin"; public static final String DB_NAME = "kaa"; - public static final String HOST = "10.2.1.130"; + public static final String HOST = "localhost"; public static final Integer PORT = 8080; } diff --git a/server/upgrade/data-migration-0.9.0-0.10.0/src/main/java/org/kaaproject/data_migration/utils/DataSources.java b/server/upgrade/data-migration-0.9.0-0.10.0/src/main/java/org/kaaproject/data_migration/utils/DataSources.java index 737bec7b07..efe0bffec1 100644 --- a/server/upgrade/data-migration-0.9.0-0.10.0/src/main/java/org/kaaproject/data_migration/utils/DataSources.java +++ b/server/upgrade/data-migration-0.9.0-0.10.0/src/main/java/org/kaaproject/data_migration/utils/DataSources.java @@ -1,11 +1,28 @@ -package org.kaaproject.data_migration.utils; +/* + * Copyright 2014-2016 CyberVision, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.kaaproject.data_migration.utils; import org.apache.commons.dbcp.BasicDataSource; import javax.sql.DataSource; -import static org.kaaproject.data_migration.utils.Constants.*; +import static org.kaaproject.data_migration.utils.Constants.HOST; +import static org.kaaproject.data_migration.utils.Constants.PASSWORD; +import static org.kaaproject.data_migration.utils.Constants.USER_NAME; public enum DataSources { @@ -15,7 +32,7 @@ public enum DataSources { private static final String DB_NAME = "kaa"; - DataSources(DataSource ds) { + DataSources(DataSource ds) { this.ds = ds; } @@ -26,7 +43,7 @@ public DataSource getDs() { private static DataSource getPostgreSQL() { BasicDataSource bds = new BasicDataSource(); bds.setDriverClassName("org.postgresql.Driver"); - bds.setUrl("jdbc:postgresql://" + HOST +":5432/" + DB_NAME); + bds.setUrl("jdbc:postgresql://" + HOST + ":5432/" + DB_NAME); bds.setUsername(USER_NAME); bds.setPassword(PASSWORD); return bds; @@ -36,7 +53,7 @@ private static DataSource getPostgreSQL() { private static DataSource getMariaDB() { BasicDataSource bds = new BasicDataSource(); bds.setDriverClassName("org.mariadb.jdbc.Driver"); - bds.setUrl("jdbc:mysql://" + HOST +":3306/" + DB_NAME); + bds.setUrl("jdbc:mysql://" + HOST + ":3306/" + DB_NAME); bds.setUsername(USER_NAME); bds.setPassword(PASSWORD); // bds.setDefaultAutoCommit(false); diff --git a/server/upgrade/data-migration-0.9.0-0.10.0/src/main/java/org/kaaproject/data_migration/utils/Utils.java b/server/upgrade/data-migration-0.9.0-0.10.0/src/main/java/org/kaaproject/data_migration/utils/Utils.java index b8b736d4b0..8a8304b670 100644 --- a/server/upgrade/data-migration-0.9.0-0.10.0/src/main/java/org/kaaproject/data_migration/utils/Utils.java +++ b/server/upgrade/data-migration-0.9.0-0.10.0/src/main/java/org/kaaproject/data_migration/utils/Utils.java @@ -1,14 +1,25 @@ -package org.kaaproject.data_migration.utils; +/* + * Copyright 2014-2016 CyberVision, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.kaaproject.data_migration.utils; -import org.apache.commons.dbutils.QueryRunner; -import org.apache.commons.io.IOUtils; import org.codehaus.jackson.JsonNode; import org.codehaus.jackson.node.ObjectNode; import java.io.IOException; -import java.sql.Connection; -import java.sql.SQLException; import java.util.Base64; final public class Utils { @@ -17,16 +28,13 @@ final public class Utils { private static final String UUID_VALUE = "org.kaaproject.configuration.uuidT"; - - - public static JsonNode encodeUuids(JsonNode json) throws IOException { if (json.has(UUID_FIELD)) { JsonNode j = json.get(UUID_FIELD); if (j.has(UUID_VALUE)) { String value = j.get(UUID_VALUE).asText(); String encodedValue = Base64.getEncoder().encodeToString(value.getBytes("ISO-8859-1")); - ((ObjectNode)j).put(UUID_VALUE, encodedValue); + ((ObjectNode) j).put(UUID_VALUE, encodedValue); } } @@ -37,9 +45,4 @@ public static JsonNode encodeUuids(JsonNode json) throws IOException { return json; } - - - - - } diff --git a/server/upgrade/data-migration-0.9.0-0.10.0/src/main/java/org/kaaproject/data_migration/utils/datadefinition/BuilderException.java b/server/upgrade/data-migration-0.9.0-0.10.0/src/main/java/org/kaaproject/data_migration/utils/datadefinition/BuilderException.java index 898a43054b..f6a9be297f 100644 --- a/server/upgrade/data-migration-0.9.0-0.10.0/src/main/java/org/kaaproject/data_migration/utils/datadefinition/BuilderException.java +++ b/server/upgrade/data-migration-0.9.0-0.10.0/src/main/java/org/kaaproject/data_migration/utils/datadefinition/BuilderException.java @@ -1,9 +1,23 @@ -package org.kaaproject.data_migration.utils.datadefinition; +/* + * Copyright 2014-2016 CyberVision, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.kaaproject.data_migration.utils.datadefinition; public class BuilderException extends RuntimeException { - public BuilderException(String s) { super(s); } diff --git a/server/upgrade/data-migration-0.9.0-0.10.0/src/main/java/org/kaaproject/data_migration/utils/datadefinition/Constraint.java b/server/upgrade/data-migration-0.9.0-0.10.0/src/main/java/org/kaaproject/data_migration/utils/datadefinition/Constraint.java index 4667bf8265..3495d28066 100644 --- a/server/upgrade/data-migration-0.9.0-0.10.0/src/main/java/org/kaaproject/data_migration/utils/datadefinition/Constraint.java +++ b/server/upgrade/data-migration-0.9.0-0.10.0/src/main/java/org/kaaproject/data_migration/utils/datadefinition/Constraint.java @@ -1,5 +1,20 @@ -package org.kaaproject.data_migration.utils.datadefinition; +/* + * Copyright 2014-2016 CyberVision, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.kaaproject.data_migration.utils.datadefinition; public class Constraint { private String constraintName; diff --git a/server/upgrade/data-migration-0.9.0-0.10.0/src/main/java/org/kaaproject/data_migration/utils/datadefinition/ConstraintType.java b/server/upgrade/data-migration-0.9.0-0.10.0/src/main/java/org/kaaproject/data_migration/utils/datadefinition/ConstraintType.java index fa588cbf46..82948eb337 100644 --- a/server/upgrade/data-migration-0.9.0-0.10.0/src/main/java/org/kaaproject/data_migration/utils/datadefinition/ConstraintType.java +++ b/server/upgrade/data-migration-0.9.0-0.10.0/src/main/java/org/kaaproject/data_migration/utils/datadefinition/ConstraintType.java @@ -1,5 +1,20 @@ -package org.kaaproject.data_migration.utils.datadefinition; +/* + * Copyright 2014-2016 CyberVision, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.kaaproject.data_migration.utils.datadefinition; enum ConstraintType { FK, PK, UNIQUE, CHECK diff --git a/server/upgrade/data-migration-0.9.0-0.10.0/src/main/java/org/kaaproject/data_migration/utils/datadefinition/DataDefinition.java b/server/upgrade/data-migration-0.9.0-0.10.0/src/main/java/org/kaaproject/data_migration/utils/datadefinition/DataDefinition.java index d302d1f2e3..ec339aaefb 100644 --- a/server/upgrade/data-migration-0.9.0-0.10.0/src/main/java/org/kaaproject/data_migration/utils/datadefinition/DataDefinition.java +++ b/server/upgrade/data-migration-0.9.0-0.10.0/src/main/java/org/kaaproject/data_migration/utils/datadefinition/DataDefinition.java @@ -1,5 +1,20 @@ -package org.kaaproject.data_migration.utils.datadefinition; +/* + * Copyright 2014-2016 CyberVision, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.kaaproject.data_migration.utils.datadefinition; import org.apache.commons.dbutils.QueryRunner; @@ -24,7 +39,7 @@ public AlterBuilder alterTable(String tableName) { /** * Drop foreign key with autogenerated name based on the table where constrain declared and referenced table name - * */ + */ public void dropUnnamedFK(String tableName, String referencedTableName) throws SQLException { QueryRunner runner = new QueryRunner(); String query = String.format(QUERY_FIND_FK_NAME, tableName, referencedTableName); @@ -32,8 +47,7 @@ public void dropUnnamedFK(String tableName, String referencedTableName) throws S runner.update(connection, "ALTER TABLE " + tableName + " DROP FOREIGN KEY " + fkName); } - - public class AlterBuilder { + public class AlterBuilder { private String tableName; private List addConstrains = new ArrayList<>(); @@ -53,17 +67,17 @@ public void execute() throws SQLException { switch (c.getType()) { case FK: sql.append(format("ADD CONSTRAINT %s FOREIGN KEY (%s) REFERENCES %s(%s) \n", - c.getConstraintName(), - c.getField(), - c.getReferencedTable(), - c.getReferencedField()) + c.getConstraintName(), + c.getField(), + c.getReferencedTable(), + c.getReferencedField()) ); - if(c.getOnDeleteOpt() != null) { + if (c.getOnDeleteOpt() != null) { sql.append("ON DELETE " + c.getOnDeleteOpt() + "\n"); } - if(c.getOnUpdateOpt() != null) { + if (c.getOnUpdateOpt() != null) { sql.append("ON UPDATE " + c.getOnUpdateOpt() + "\n"); } break; @@ -75,7 +89,7 @@ public void execute() throws SQLException { break; } - if(i < addConstrains.size() - 1) { + if (i < addConstrains.size() - 1) { sql.append(", \n"); } else { sql.append(";"); @@ -87,5 +101,4 @@ public void execute() throws SQLException { } } - } diff --git a/server/upgrade/data-migration-0.9.0-0.10.0/src/main/java/org/kaaproject/data_migration/utils/datadefinition/ReferenceOptions.java b/server/upgrade/data-migration-0.9.0-0.10.0/src/main/java/org/kaaproject/data_migration/utils/datadefinition/ReferenceOptions.java index 401ad9f9f8..2e4eedc917 100644 --- a/server/upgrade/data-migration-0.9.0-0.10.0/src/main/java/org/kaaproject/data_migration/utils/datadefinition/ReferenceOptions.java +++ b/server/upgrade/data-migration-0.9.0-0.10.0/src/main/java/org/kaaproject/data_migration/utils/datadefinition/ReferenceOptions.java @@ -1,5 +1,20 @@ -package org.kaaproject.data_migration.utils.datadefinition; +/* + * Copyright 2014-2016 CyberVision, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.kaaproject.data_migration.utils.datadefinition; public enum ReferenceOptions { RESTRICT, CASCADE