Search in sources :

Example 16 with IDatabasePlatform

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

the class DbExportImportTest method testInsertBigIntIntoOracleIntField.

@Test
public void testInsertBigIntIntoOracleIntField() {
    if (getPlatform().getName().equals(DatabaseNamesConstants.ORACLE)) {
        ISymmetricEngine engine = getSymmetricEngine();
        IDatabasePlatform platform = engine.getDatabasePlatform();
        Table table = new Table("TEST_ORACLE_INTEGER");
        table.addColumn(new Column("A", false, Types.INTEGER, -1, -1));
        platform.alterCaseToMatchDatabaseDefaultCase(table);
        platform.createTables(true, false, table);
        DbImport importer = new DbImport(platform);
        importer.setFormat(DbImport.Format.CSV);
        importer.importTables("\"A\"\n1149140000100490", table.getName());
        Assert.assertEquals(1149140000100490l, platform.getSqlTemplate().queryForLong("select A from TEST_ORACLE_INTEGER"));
    }
}
Also used : IDatabasePlatform(org.jumpmind.db.platform.IDatabasePlatform) Table(org.jumpmind.db.model.Table) Column(org.jumpmind.db.model.Column) DbImport(org.jumpmind.symmetric.io.data.DbImport) AbstractServiceTest(org.jumpmind.symmetric.service.impl.AbstractServiceTest) Test(org.junit.Test)

Example 17 with IDatabasePlatform

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

the class TestSetupUtil method dropAndCreateDatabaseTables.

public static void dropAndCreateDatabaseTables(String databaseType, ISymmetricEngine engine) {
    IDatabasePlatform platform = dropDatabaseTables(databaseType, engine);
    Database testDb = platform.readDatabaseFromXml("/test-schema.xml", true);
    platform.createDatabase(testDb, false, true);
}
Also used : IDatabasePlatform(org.jumpmind.db.platform.IDatabasePlatform) Database(org.jumpmind.db.model.Database)

Example 18 with IDatabasePlatform

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

the class DbExportImportTest method testExportCsvToDirectory.

@Test
public void testExportCsvToDirectory() throws Exception {
    ISymmetricEngine engine = getSymmetricEngine();
    IDatabasePlatform platform = engine.getSymmetricDialect().getPlatform();
    DbImport importXml = new DbImport(platform);
    importXml.setFormat(DbImport.Format.XML);
    importXml.importTables(getClass().getResourceAsStream("/test-dbexportimport-3-tables.xml"));
    File dir = new File("target/test");
    FileUtils.deleteDirectory(dir);
    Assert.assertFalse(dir.exists());
    DbExport exportCsv = new DbExport(platform);
    exportCsv.setComments(true);
    exportCsv.setFormat(Format.CSV);
    exportCsv.setDir(dir.getAbsolutePath());
    exportCsv.exportTables(new String[] { "a", "b", "c" });
    Assert.assertTrue(dir.exists());
    Assert.assertTrue(dir.isDirectory());
    File a = new File(dir, platform.getTableFromCache("a", false).getName() + ".csv");
    Assert.assertTrue(a.exists());
    Assert.assertTrue(a.isFile());
    List<String> lines = FileUtils.readLines(a);
    Assert.assertEquals(9, lines.size());
    Assert.assertEquals("\"id\",\"string_value\"", lines.get(5));
    Assert.assertEquals("\"1\",\"This is a test of a\"", lines.get(6));
    Assert.assertEquals("\"2\",\"This is a test of a\"", lines.get(7));
    File b = new File(dir, platform.getTableFromCache("b", false).getName() + ".csv");
    Assert.assertTrue(b.exists());
    Assert.assertTrue(b.isFile());
    lines = FileUtils.readLines(b);
    Assert.assertEquals(10, lines.size());
    Assert.assertEquals("\"id\",\"string_value\"", lines.get(5));
    Assert.assertEquals("\"1\",\"This is a test of b\"", lines.get(6));
    Assert.assertEquals("\"2\",\"This is a test of b\"", lines.get(7));
    Assert.assertEquals("\"3\",\"This is line 3 of b\"", lines.get(8));
    File c = new File(dir, platform.getTableFromCache("c", false).getName() + ".csv");
    Assert.assertTrue(c.exists());
    Assert.assertTrue(c.isFile());
    lines = FileUtils.readLines(c);
    Assert.assertEquals(9, lines.size());
    Assert.assertEquals("\"id\",\"string_value\"", lines.get(5));
    Assert.assertEquals("\"1\",\"This is a test of c\"", lines.get(6));
    Assert.assertEquals("\"2\",\"This is a test of c\"", lines.get(7));
}
Also used : IDatabasePlatform(org.jumpmind.db.platform.IDatabasePlatform) DbExport(org.jumpmind.symmetric.io.data.DbExport) DbImport(org.jumpmind.symmetric.io.data.DbImport) File(java.io.File) AbstractServiceTest(org.jumpmind.symmetric.service.impl.AbstractServiceTest) Test(org.junit.Test)

Example 19 with IDatabasePlatform

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

the class AuditTableDataRouter method routeToNodes.

public Set<String> routeToNodes(SimpleRouterContext context, DataMetaData dataMetaData, Set<Node> nodes, boolean initialLoad, boolean initialLoadSelectUsed, TriggerRouter triggerRouter) {
    DataEventType eventType = dataMetaData.getData().getDataEventType();
    if (eventType == DataEventType.INSERT || eventType == DataEventType.UPDATE || eventType == DataEventType.DELETE) {
        IParameterService parameterService = engine.getParameterService();
        IDatabasePlatform platform = engine.getDatabasePlatform();
        TriggerHistory triggerHistory = dataMetaData.getTriggerHistory();
        Table table = dataMetaData.getTable().copyAndFilterColumns(triggerHistory.getParsedColumnNames(), triggerHistory.getParsedPkColumnNames(), true);
        String tableName = table.getFullyQualifiedTableName();
        Table auditTable = auditTables.get(tableName);
        if (auditTable == null) {
            auditTable = toAuditTable(table);
            if (parameterService.is(ParameterConstants.AUTO_CONFIGURE_DATABASE)) {
                platform.alterTables(true, auditTable);
            }
            auditTable = platform.getTableFromCache(auditTable.getCatalog(), auditTable.getSchema(), auditTable.getName(), false);
            auditTables.put(tableName, auditTable);
        }
        DatabaseInfo dbInfo = platform.getDatabaseInfo();
        String auditTableName = auditTable.getQualifiedTableName(dbInfo.getDelimiterToken(), dbInfo.getCatalogSeparator(), dbInfo.getSchemaSeparator());
        ISqlTemplate template = platform.getSqlTemplate();
        Map<String, Object> values = null;
        if (eventType != DataEventType.DELETE) {
            values = new HashMap<String, Object>(getNewDataAsObject(null, dataMetaData, engine.getSymmetricDialect(), false));
        } else {
            values = new HashMap<String, Object>(getOldDataAsObject(null, dataMetaData, engine.getSymmetricDialect(), false));
        }
        Long sequence = (Long) context.get(auditTableName);
        if (sequence == null) {
            sequence = 1l + template.queryForLong(String.format("select max(%s) from %s", auditTable.getColumnWithName(COLUMN_AUDIT_ID).getName(), auditTableName));
        } else {
            sequence = 1l + sequence;
        }
        context.put(auditTable.getName(), sequence);
        values.put(auditTable.getColumnWithName(COLUMN_AUDIT_ID).getName(), sequence);
        values.put(auditTable.getColumnWithName(COLUMN_AUDIT_TIME).getName(), new Date());
        values.put(auditTable.getColumnWithName(COLUMN_AUDIT_EVENT).getName(), eventType.getCode());
        DmlStatement statement = platform.createDmlStatement(DmlType.INSERT, auditTable, null);
        int[] types = statement.getTypes();
        Object[] args = statement.getValueArray(values);
        String sql = statement.getSql();
        template.update(sql, args, types);
    }
    return null;
}
Also used : IDatabasePlatform(org.jumpmind.db.platform.IDatabasePlatform) Table(org.jumpmind.db.model.Table) DatabaseInfo(org.jumpmind.db.platform.DatabaseInfo) DataEventType(org.jumpmind.symmetric.io.data.DataEventType) IParameterService(org.jumpmind.symmetric.service.IParameterService) Date(java.util.Date) ISqlTemplate(org.jumpmind.db.sql.ISqlTemplate) TriggerHistory(org.jumpmind.symmetric.model.TriggerHistory) DmlStatement(org.jumpmind.db.sql.DmlStatement)

Example 20 with IDatabasePlatform

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

the class DataGapRouteReaderTest method buildReader.

protected DataGapRouteReader buildReader(int peekAheadMemoryThreshold, List<DataGap> dataGaps) throws Exception {
    when(parameterService.getEngineName()).thenReturn(ENGINE_NAME);
    when(parameterService.is(ParameterConstants.SYNCHRONIZE_ALL_JOBS)).thenReturn(true);
    when(parameterService.getInt(ParameterConstants.ROUTING_WAIT_FOR_DATA_TIMEOUT_SECONDS)).thenReturn(330);
    when(parameterService.getInt(ParameterConstants.ROUTING_PEEK_AHEAD_MEMORY_THRESHOLD)).thenReturn(peekAheadMemoryThreshold);
    when(parameterService.getInt(ParameterConstants.ROUTING_MAX_GAPS_TO_QUALIFY_IN_SQL)).thenReturn(100);
    when(parameterService.getInt(ParameterConstants.ROUTING_DATA_READER_THRESHOLD_GAPS_TO_USE_GREATER_QUERY)).thenReturn(100);
    when(parameterService.is(ParameterConstants.ROUTING_DATA_READER_ORDER_BY_DATA_ID_ENABLED)).thenReturn(true);
    IStatisticManager statisticManager = mock(StatisticManager.class);
    when(statisticManager.newProcessInfo((ProcessInfoKey) any())).thenReturn(new ProcessInfo());
    INodeService nodeService = mock(NodeService.class);
    when(nodeService.findIdentity()).thenReturn(new Node(NODE_ID, NODE_GROUP_ID));
    IDatabasePlatform platform = mock(IDatabasePlatform.class);
    when(platform.getSqlTemplate()).thenReturn(sqlTemplate);
    when(platform.getDatabaseInfo()).thenReturn(new DatabaseInfo());
    ISymmetricDialect symmetricDialect = mock(AbstractSymmetricDialect.class);
    when(symmetricDialect.supportsTransactionId()).thenReturn(true);
    when(symmetricDialect.getPlatform()).thenReturn(platform);
    IExtensionService extensionService = mock(ExtensionService.class);
    ISymmetricEngine engine = mock(AbstractSymmetricEngine.class);
    when(engine.getParameterService()).thenReturn(parameterService);
    when(engine.getStatisticManager()).thenReturn(statisticManager);
    when(engine.getNodeService()).thenReturn(nodeService);
    when(engine.getDataService()).thenReturn(dataService);
    when(engine.getSymmetricDialect()).thenReturn(symmetricDialect);
    when(engine.getExtensionService()).thenReturn(extensionService);
    IRouterService routerService = new RouterService(engine);
    when(engine.getRouterService()).thenReturn(routerService);
    ChannelRouterContext context = new ChannelRouterContext(NODE_ID, nodeChannel, mock(ISqlTransaction.class));
    context.setDataGaps(dataGaps);
    return new DataGapRouteReader(context, engine);
}
Also used : ISymmetricDialect(org.jumpmind.symmetric.db.ISymmetricDialect) RouterService(org.jumpmind.symmetric.service.impl.RouterService) IRouterService(org.jumpmind.symmetric.service.IRouterService) IDatabasePlatform(org.jumpmind.db.platform.IDatabasePlatform) DatabaseInfo(org.jumpmind.db.platform.DatabaseInfo) Node(org.jumpmind.symmetric.model.Node) ISymmetricEngine(org.jumpmind.symmetric.ISymmetricEngine) ProcessInfo(org.jumpmind.symmetric.model.ProcessInfo) IRouterService(org.jumpmind.symmetric.service.IRouterService) IStatisticManager(org.jumpmind.symmetric.statistic.IStatisticManager) ISqlTransaction(org.jumpmind.db.sql.ISqlTransaction) INodeService(org.jumpmind.symmetric.service.INodeService) IExtensionService(org.jumpmind.symmetric.service.IExtensionService)

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