use of org.jumpmind.db.platform.IDdlBuilder in project symmetric-ds by JumpMind.
the class DataExtractorService method extractToPayload.
public List<OutgoingBatchWithPayload> extractToPayload(ProcessInfo processInfo, Node targetNode, PayloadType payloadType, boolean useJdbcTimestampFormat, boolean useUpsertStatements, boolean useDelimiterIdentifiers) {
OutgoingBatches batches = outgoingBatchService.getOutgoingBatches(targetNode.getNodeId(), false);
if (batches.containsBatches()) {
ChannelMap channelMap = configurationService.getSuspendIgnoreChannelLists(targetNode.getNodeId());
List<OutgoingBatch> activeBatches = filterBatchesForExtraction(batches, channelMap);
if (activeBatches.size() > 0) {
IDdlBuilder builder = DdlBuilderFactory.createDdlBuilder(targetNode.getDatabaseType());
if (builder == null) {
throw new IllegalStateException("Could not find a ddl builder registered for the database type of " + targetNode.getDatabaseType() + ". Please check the database type setting for node '" + targetNode.getNodeId() + "'");
}
StructureDataWriter writer = new StructureDataWriter(symmetricDialect.getPlatform(), targetNode.getDatabaseType(), payloadType, useDelimiterIdentifiers, symmetricDialect.getBinaryEncoding(), useJdbcTimestampFormat, useUpsertStatements);
List<OutgoingBatch> extractedBatches = extract(processInfo, targetNode, activeBatches, writer, ExtractMode.FOR_PAYLOAD_CLIENT);
List<OutgoingBatchWithPayload> batchesWithPayload = new ArrayList<OutgoingBatchWithPayload>();
for (OutgoingBatch batch : extractedBatches) {
OutgoingBatchWithPayload batchWithPayload = new OutgoingBatchWithPayload(batch, payloadType);
batchWithPayload.setPayload(writer.getPayloadMap().get(batch.getBatchId()));
batchWithPayload.setPayloadType(payloadType);
batchesWithPayload.add(batchWithPayload);
}
return batchesWithPayload;
}
}
return Collections.emptyList();
}
use of org.jumpmind.db.platform.IDdlBuilder in project symmetric-ds by JumpMind.
the class FirebirdDdlReader method isInternalPrimaryKeyIndex.
@Override
protected boolean isInternalPrimaryKeyIndex(Connection connection, DatabaseMetaDataWrapper metaData, Table table, IIndex index) throws SQLException {
IDdlBuilder builder = getPlatform().getDdlBuilder();
String tableName = builder.getTableName(table.getName());
String indexName = builder.getIndexName(index);
StringBuilder query = new StringBuilder();
query.append("SELECT RDB$CONSTRAINT_NAME FROM RDB$RELATION_CONSTRAINTS where RDB$RELATION_NAME=? AND RDB$CONSTRAINT_TYPE=? AND RDB$INDEX_NAME=?");
PreparedStatement stmt = connection.prepareStatement(query.toString());
try {
stmt.setString(1, getPlatform().getDdlBuilder().isDelimitedIdentifierModeOn() ? tableName : tableName.toUpperCase());
stmt.setString(2, "PRIMARY KEY");
stmt.setString(3, indexName);
ResultSet resultSet = stmt.executeQuery();
return resultSet.next();
} finally {
if (stmt != null) {
stmt.close();
}
}
}
use of org.jumpmind.db.platform.IDdlBuilder in project symmetric-ds by JumpMind.
the class TestSetupUtil method dropDatabaseTables.
public static IDatabasePlatform dropDatabaseTables(String databaseType, ISymmetricEngine engine) {
ISymmetricDialect dialect = engine.getSymmetricDialect();
AbstractJdbcDatabasePlatform platform = (AbstractJdbcDatabasePlatform) dialect.getPlatform();
engine.uninstall();
platform.resetDataSource();
IDdlBuilder builder = platform.getDdlBuilder();
Database db2drop = platform.readDatabase(platform.getDefaultCatalog(), platform.getDefaultSchema(), new String[] { "TABLE" });
platform.resetDataSource();
String sql = builder.dropTables(db2drop);
SqlScript dropScript = new SqlScript(sql, platform.getSqlTemplate(), false, platform.getSqlScriptReplacementTokens());
dropScript.execute(true);
platform.resetDataSource();
dialect.cleanDatabase();
platform.resetCachedTableModel();
return platform;
}
use of org.jumpmind.db.platform.IDdlBuilder in project symmetric-ds by JumpMind.
the class AbstractSymmetricDialect method getCreateSymmetricDDL.
public String getCreateSymmetricDDL() {
Database database = readSymmetricSchemaFromXml();
prefixConfigDatabase(database);
IDdlBuilder builder = platform.getDdlBuilder();
return builder.createTables(database, true);
}
use of org.jumpmind.db.platform.IDdlBuilder in project symmetric-ds by JumpMind.
the class StructureDataWriter method write.
public void write(CsvData data) {
String sql = null;
switch(data.getDataEventType()) {
case UPDATE:
sql = buildSql(useUpsertStatements ? DmlType.UPSERT : DmlType.UPDATE, data.getParsedData(CsvData.ROW_DATA), currentTable.getColumns());
break;
case INSERT:
sql = buildSql(useUpsertStatements ? DmlType.UPSERT : DmlType.INSERT, data.getParsedData(CsvData.ROW_DATA), currentTable.getColumns());
break;
case DELETE:
sql = buildSql(DmlType.DELETE, data.getParsedData(CsvData.PK_DATA), currentTable.getPrimaryKeyColumns());
break;
case SQL:
sql = data.getParsedData(CsvData.ROW_DATA)[0];
break;
case CREATE:
IDdlBuilder builder = DdlBuilderFactory.createDdlBuilder(targetDatabaseName);
sql = builder.createTable(currentTable);
break;
default:
break;
}
if (sql != null) {
this.payloadMap.get(this.currentBatch).add(sql);
}
}
Aggregations