Search in sources :

Example 21 with IDatabasePlatform

use of org.jumpmind.db.platform.IDatabasePlatform in project symmetric-ds by JumpMind.

the class AbstractRouterServiceTest method execute.

protected void execute(final String sql, final String node2disable) {
    ISymmetricDialect dialect = getDbDialect();
    IDatabasePlatform platform = dialect.getPlatform();
    ISqlTransaction transaction = null;
    try {
        transaction = platform.getSqlTemplate().startSqlTransaction();
        if (node2disable != null) {
            dialect.disableSyncTriggers(transaction, node2disable);
        }
        transaction.prepareAndExecute(sql);
        if (node2disable != null) {
            dialect.enableSyncTriggers(transaction);
        }
        transaction.commit();
    } finally {
        if (transaction != null) {
            transaction.close();
        }
    }
}
Also used : ISymmetricDialect(org.jumpmind.symmetric.db.ISymmetricDialect) IDatabasePlatform(org.jumpmind.db.platform.IDatabasePlatform) ISqlTransaction(org.jumpmind.db.sql.ISqlTransaction)

Example 22 with IDatabasePlatform

use of org.jumpmind.db.platform.IDatabasePlatform in project symmetric-ds by JumpMind.

the class AbstractRouterServiceTest method update.

protected void update(String tableName, String value) {
    IDatabasePlatform platform = getDbDialect().getPlatform();
    String columnName = platform.alterCaseToMatchDatabaseDefaultCase("ROUTING_VARCHAR");
    getSqlTemplate().update(String.format("insert into %s (%s) values(?)", tableName, columnName), value);
}
Also used : IDatabasePlatform(org.jumpmind.db.platform.IDatabasePlatform)

Example 23 with IDatabasePlatform

use of org.jumpmind.db.platform.IDatabasePlatform in project symmetric-ds by JumpMind.

the class DataServiceTest method setUp.

@Before
public void setUp() throws Exception {
    sqlTemplate = mock(ISqlTemplate.class);
    sqlTransaction = mock(ISqlTransaction.class);
    when(sqlTemplate.startSqlTransaction()).thenReturn(sqlTransaction);
    IDatabasePlatform platform = mock(IDatabasePlatform.class);
    when(platform.getDatabaseInfo()).thenReturn(new DatabaseInfo());
    when(platform.getSqlTemplate()).thenReturn(sqlTemplate);
    symmetricDialect = mock(AbstractSymmetricDialect.class);
    when(symmetricDialect.getPlatform()).thenReturn(platform);
    parameterService = mock(ParameterService.class);
    when(parameterService.getLong(ParameterConstants.ROUTING_LARGEST_GAP_SIZE)).thenReturn(50000000L);
    IExtensionService extensionService = mock(ExtensionService.class);
    ISymmetricEngine engine = mock(AbstractSymmetricEngine.class);
    when(engine.getParameterService()).thenReturn(parameterService);
    when(engine.getSymmetricDialect()).thenReturn(symmetricDialect);
    dataService = new DataService(engine, extensionService);
}
Also used : ISqlTemplate(org.jumpmind.db.sql.ISqlTemplate) ISqlTransaction(org.jumpmind.db.sql.ISqlTransaction) IDatabasePlatform(org.jumpmind.db.platform.IDatabasePlatform) DatabaseInfo(org.jumpmind.db.platform.DatabaseInfo) IParameterService(org.jumpmind.symmetric.service.IParameterService) IExtensionService(org.jumpmind.symmetric.service.IExtensionService) ISymmetricEngine(org.jumpmind.symmetric.ISymmetricEngine) AbstractSymmetricDialect(org.jumpmind.symmetric.db.AbstractSymmetricDialect) IDataService(org.jumpmind.symmetric.service.IDataService) Before(org.junit.Before)

Example 24 with IDatabasePlatform

use of org.jumpmind.db.platform.IDatabasePlatform in project symmetric-ds by JumpMind.

the class JavaColumnTransformTest method setUp.

@Before
public void setUp() throws Exception {
    ISqlTransaction sqlTransaction = mock(ISqlTransaction.class);
    platform = mock(IDatabasePlatform.class);
    ISymmetricEngine engine = mock(ISymmetricEngine.class);
    IParameterService parameterService = mock(IParameterService.class);
    IDatabasePlatform platform = mock(IDatabasePlatform.class);
    ISymmetricDialect dialect = mock(ISymmetricDialect.class);
    when(dialect.getPlatform()).thenReturn(platform);
    when(platform.getDatabaseInfo()).thenReturn(new DatabaseInfo());
    when(engine.getParameterService()).thenReturn(parameterService);
    when(engine.getSymmetricDialect()).thenReturn(dialect);
    extensionService = new ExtensionService(engine);
    when(engine.getExtensionService()).thenReturn(extensionService);
    context = mock(DataContext.class);
    when(context.findTransaction()).thenReturn(sqlTransaction);
}
Also used : ISymmetricDialect(org.jumpmind.symmetric.db.ISymmetricDialect) IExtensionService(org.jumpmind.symmetric.service.IExtensionService) ExtensionService(org.jumpmind.symmetric.service.impl.ExtensionService) ISqlTransaction(org.jumpmind.db.sql.ISqlTransaction) IDatabasePlatform(org.jumpmind.db.platform.IDatabasePlatform) DataContext(org.jumpmind.symmetric.io.data.DataContext) DatabaseInfo(org.jumpmind.db.platform.DatabaseInfo) ISymmetricEngine(org.jumpmind.symmetric.ISymmetricEngine) IParameterService(org.jumpmind.symmetric.service.IParameterService) Before(org.junit.Before)

Example 25 with IDatabasePlatform

use of org.jumpmind.db.platform.IDatabasePlatform in project symmetric-ds by JumpMind.

the class AbstractXmlPublisherExtensionPoint method resend.

@ManagedOperation(description = "Looks up rows in the database and resends them to the publisher")
@ManagedOperationParameters({ @ManagedOperationParameter(name = "args", description = "A pipe deliminated list of key values to use to look up the tables to resend") })
public boolean resend(String args) {
    try {
        String[] argArray = args != null ? args.split("\\|") : new String[0];
        DataContext context = new DataContext();
        IDatabasePlatform platform = engine.getDatabasePlatform();
        for (String tableName : tableNamesToPublishAsGroup) {
            Table table = platform.getTableFromCache(tableName, false);
            List<String[]> dataRowsForTable = readData(table, argArray);
            for (String[] values : dataRowsForTable) {
                Batch batch = new Batch();
                batch.setBinaryEncoding(engine.getSymmetricDialect().getBinaryEncoding());
                batch.setSourceNodeId("republish");
                context.setBatch(batch);
                CsvData data = new CsvData(DataEventType.INSERT);
                data.putParsedData(CsvData.ROW_DATA, values);
                Element xml = getXmlFromCache(context, context.getBatch().getBinaryEncoding(), table.getColumnNames(), data.getParsedData(CsvData.ROW_DATA), table.getPrimaryKeyColumnNames(), data.getParsedData(CsvData.PK_DATA));
                if (xml != null) {
                    toXmlElement(data.getDataEventType(), xml, table.getCatalog(), table.getSchema(), table.getName(), table.getColumnNames(), data.getParsedData(CsvData.ROW_DATA), table.getPrimaryKeyColumnNames(), data.getParsedData(CsvData.PK_DATA));
                }
            }
        }
        if (doesXmlExistToPublish(context)) {
            finalizeXmlAndPublish(context);
            return true;
        } else {
            log.warn(String.format("Failed to resend message for tables %s, columns %s, and args %s", tableNamesToPublishAsGroup, groupByColumnNames, args));
        }
    } catch (RuntimeException ex) {
        log.error(String.format("Failed to resend message for tables %s, columns %s, and args %s", tableNamesToPublishAsGroup, groupByColumnNames, args), ex);
    }
    return false;
}
Also used : DataContext(org.jumpmind.symmetric.io.data.DataContext) IDatabasePlatform(org.jumpmind.db.platform.IDatabasePlatform) Table(org.jumpmind.db.model.Table) Batch(org.jumpmind.symmetric.io.data.Batch) Element(org.jdom.Element) CsvData(org.jumpmind.symmetric.io.data.CsvData) ManagedOperationParameters(org.springframework.jmx.export.annotation.ManagedOperationParameters) ManagedOperation(org.springframework.jmx.export.annotation.ManagedOperation)

Aggregations

IDatabasePlatform (org.jumpmind.db.platform.IDatabasePlatform)27 Table (org.jumpmind.db.model.Table)13 Database (org.jumpmind.db.model.Database)9 Test (org.junit.Test)9 AbstractServiceTest (org.jumpmind.symmetric.service.impl.AbstractServiceTest)8 ISqlTemplate (org.jumpmind.db.sql.ISqlTemplate)7 DatabaseInfo (org.jumpmind.db.platform.DatabaseInfo)6 ISqlTransaction (org.jumpmind.db.sql.ISqlTransaction)6 ISymmetricEngine (org.jumpmind.symmetric.ISymmetricEngine)6 DbExport (org.jumpmind.symmetric.io.data.DbExport)6 DbImport (org.jumpmind.symmetric.io.data.DbImport)6 ISymmetricDialect (org.jumpmind.symmetric.db.ISymmetricDialect)5 IExtensionService (org.jumpmind.symmetric.service.IExtensionService)5 IParameterService (org.jumpmind.symmetric.service.IParameterService)5 Column (org.jumpmind.db.model.Column)4 Before (org.junit.Before)4 File (java.io.File)3 DmlStatement (org.jumpmind.db.sql.DmlStatement)3 Row (org.jumpmind.db.sql.Row)3 SqlException (org.jumpmind.db.sql.SqlException)3