Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Small refactoring project structure and added data definition utils
- Loading branch information
Showing
12 changed files
with
339 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
...ration-0.9.0-0.10.0/src/main/java/org/kaaproject/data_migration/UpdateUuidsMigration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
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; | ||
import org.codehaus.jackson.JsonNode; | ||
import org.codehaus.jackson.map.ObjectMapper; | ||
import org.kaaproject.data_migration.model.Configuration; | ||
|
||
import java.io.IOException; | ||
import java.sql.Connection; | ||
import java.sql.SQLException; | ||
import java.util.List; | ||
|
||
import static org.kaaproject.data_migration.utils.Utils.encodeUuids; | ||
|
||
public class UpdateUuidsMigration { | ||
private Connection connection; | ||
|
||
public UpdateUuidsMigration(Connection connection) { | ||
this.connection = connection; | ||
} | ||
|
||
public void transform() throws IOException { | ||
try { | ||
QueryRunner run = new QueryRunner(); | ||
ResultSetHandler<List<Configuration>> rsHandler = new BeanListHandler<Configuration>(Configuration.class); | ||
List<Configuration> configs = run.query(connection, "SELECT * FROM configuration", rsHandler); | ||
for (Configuration config : configs) { | ||
JsonNode json = new ObjectMapper().readTree(config.getConfiguration_body()); | ||
JsonNode jsonEncoded = encodeUuids(json); | ||
byte[] encodedConfigurationBody = jsonEncoded.toString().getBytes(); | ||
|
||
int updates = run.update(connection, "UPDATE configuration SET configuration_body=? WHERE id=?", encodedConfigurationBody, config.getId()); | ||
if (updates == 1) { | ||
//TODO | ||
} | ||
} | ||
|
||
} catch (SQLException e) { | ||
System.err.println("Error: " + e.getMessage()); | ||
} finally { | ||
DbUtils.closeQuietly(connection); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
....0/src/main/java/org/kaaproject/data_migration/utils/datadefinition/BuilderException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package org.kaaproject.data_migration.utils.datadefinition; | ||
|
||
|
||
public class BuilderException extends RuntimeException { | ||
|
||
|
||
public BuilderException(String s) { | ||
super(s); | ||
} | ||
} |
Oops, something went wrong.