Search in sources :

Example 6 with IDdlBuilder

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();
}
Also used : ChannelMap(org.jumpmind.symmetric.model.ChannelMap) OutgoingBatchWithPayload(org.jumpmind.symmetric.model.OutgoingBatchWithPayload) IDdlBuilder(org.jumpmind.db.platform.IDdlBuilder) ArrayList(java.util.ArrayList) OutgoingBatches(org.jumpmind.symmetric.model.OutgoingBatches) OutgoingBatch(org.jumpmind.symmetric.model.OutgoingBatch) StructureDataWriter(org.jumpmind.symmetric.io.data.writer.StructureDataWriter)

Example 7 with IDdlBuilder

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();
        }
    }
}
Also used : IDdlBuilder(org.jumpmind.db.platform.IDdlBuilder) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement)

Example 8 with IDdlBuilder

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;
}
Also used : ISymmetricDialect(org.jumpmind.symmetric.db.ISymmetricDialect) IDdlBuilder(org.jumpmind.db.platform.IDdlBuilder) Database(org.jumpmind.db.model.Database) SqlScript(org.jumpmind.db.sql.SqlScript) AbstractJdbcDatabasePlatform(org.jumpmind.db.platform.AbstractJdbcDatabasePlatform)

Example 9 with IDdlBuilder

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);
}
Also used : IDdlBuilder(org.jumpmind.db.platform.IDdlBuilder) Database(org.jumpmind.db.model.Database)

Example 10 with IDdlBuilder

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);
    }
}
Also used : IDdlBuilder(org.jumpmind.db.platform.IDdlBuilder)

Aggregations

IDdlBuilder (org.jumpmind.db.platform.IDdlBuilder)10 Database (org.jumpmind.db.model.Database)4 SqlScript (org.jumpmind.db.sql.SqlScript)4 PreparedStatement (java.sql.PreparedStatement)3 ResultSet (java.sql.ResultSet)3 LogSqlResultsListener (org.jumpmind.db.sql.LogSqlResultsListener)2 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Column (org.jumpmind.db.model.Column)1 Table (org.jumpmind.db.model.Table)1 AbstractJdbcDatabasePlatform (org.jumpmind.db.platform.AbstractJdbcDatabasePlatform)1 IAlterDatabaseInterceptor (org.jumpmind.db.platform.IAlterDatabaseInterceptor)1 ISqlResultsListener (org.jumpmind.db.sql.ISqlResultsListener)1 SqlException (org.jumpmind.db.sql.SqlException)1 IoException (org.jumpmind.exception.IoException)1 ISymmetricDialect (org.jumpmind.symmetric.db.ISymmetricDialect)1 IDatabaseUpgradeListener (org.jumpmind.symmetric.ext.IDatabaseUpgradeListener)1 StructureDataWriter (org.jumpmind.symmetric.io.data.writer.StructureDataWriter)1 ChannelMap (org.jumpmind.symmetric.model.ChannelMap)1 OutgoingBatch (org.jumpmind.symmetric.model.OutgoingBatch)1