Search in sources :

Example 16 with ISqlRowMapper

use of org.jumpmind.db.sql.ISqlRowMapper in project symmetric-ds by JumpMind.

the class DataGapDetectorTest method testGapInGapFull.

@Test
public void testGapInGapFull() throws Exception {
    detector.setFullGapAnalysis(true);
    when(contextService.is(ContextConstants.ROUTING_FULL_GAP_ANALYSIS)).thenReturn(true);
    @SuppressWarnings("unchecked") ISqlRowMapper<Long> mapper = (ISqlRowMapper<Long>) Matchers.anyObject();
    when(sqlTemplate.query(Matchers.anyString(), mapper, (Object[]) Matchers.anyVararg())).thenAnswer(new Answer<List<Long>>() {

        public List<Long> answer(InvocationOnMock invocation) {
            List<Long> dataIds = new ArrayList<Long>();
            long startId = (Long) invocation.getArguments()[2];
            long endId = (Long) invocation.getArguments()[3];
            if (startId == 5 && endId == 10) {
                dataIds.add(6L);
            } else if (startId == 15 && endId == 20) {
                dataIds.add(18L);
            } else if (startId == 21 && endId == 50000020) {
                dataIds.add(23L);
            }
            return dataIds;
        }
    });
    List<DataGap> dataGaps = new ArrayList<DataGap>();
    dataGaps.add(new DataGap(3, 3));
    dataGaps.add(new DataGap(5, 10));
    dataGaps.add(new DataGap(15, 20));
    dataGaps.add(new DataGap(21, 50000020));
    runGapDetector(dataGaps, new ArrayList<Long>(), true);
    verify(dataService).findDataGaps();
    verify(dataService).deleteDataGap(sqlTransaction, new DataGap(5, 10));
    verify(dataService).insertDataGap(sqlTransaction, new DataGap(5, 5));
    verify(dataService).insertDataGap(sqlTransaction, new DataGap(7, 10));
    verify(dataService).deleteDataGap(sqlTransaction, new DataGap(15, 20));
    verify(dataService).insertDataGap(sqlTransaction, new DataGap(15, 17));
    verify(dataService).insertDataGap(sqlTransaction, new DataGap(19, 20));
    verify(dataService).deleteDataGap(sqlTransaction, new DataGap(21, 50000020));
    verify(dataService).insertDataGap(sqlTransaction, new DataGap(21, 22));
    verify(dataService).insertDataGap(sqlTransaction, new DataGap(24, 50000023));
    verifyNoMoreInteractions(dataService);
}
Also used : DataGap(org.jumpmind.symmetric.model.DataGap) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) ISqlRowMapper(org.jumpmind.db.sql.ISqlRowMapper) Test(org.junit.Test)

Example 17 with ISqlRowMapper

use of org.jumpmind.db.sql.ISqlRowMapper in project symmetric-ds by JumpMind.

the class DataGapDetectorTest method testGapsOverlapThenDataFull.

@Test
public void testGapsOverlapThenDataFull() throws Exception {
    detector.setFullGapAnalysis(true);
    when(contextService.is(ContextConstants.ROUTING_FULL_GAP_ANALYSIS)).thenReturn(true);
    List<Long> dataIds = new ArrayList<Long>();
    dataIds.add(30953883L);
    @SuppressWarnings("unchecked") ISqlRowMapper<Long> mapper = (ISqlRowMapper<Long>) Matchers.anyObject();
    String sql = Matchers.anyString();
    when(sqlTemplate.query(sql, mapper, Matchers.eq(30953883L), Matchers.eq(80953883L))).thenReturn(dataIds);
    List<DataGap> dataGaps1 = new ArrayList<DataGap>();
    dataGaps1.add(new DataGap(30953883, 80953883));
    dataGaps1.add(new DataGap(30953884, 80953883));
    List<DataGap> dataGaps2 = new ArrayList<DataGap>();
    dataGaps2.add(new DataGap(30953884, 80953883));
    dataIds = new ArrayList<Long>();
    dataIds.add(30953883L);
    runGapDetector(dataGaps1, dataGaps2, dataIds, true);
    verify(dataService).findDataGaps();
    verify(dataService).deleteDataGap(sqlTransaction, new DataGap(30953884, 80953883));
    verify(dataService).deleteDataGap(sqlTransaction, new DataGap(30953883, 80953883));
    verify(dataService).insertDataGap(sqlTransaction, new DataGap(30953884, 80953883));
    verifyNoMoreInteractions(dataService);
}
Also used : DataGap(org.jumpmind.symmetric.model.DataGap) ArrayList(java.util.ArrayList) ISqlRowMapper(org.jumpmind.db.sql.ISqlRowMapper) Test(org.junit.Test)

Example 18 with ISqlRowMapper

use of org.jumpmind.db.sql.ISqlRowMapper in project symmetric-ds by JumpMind.

the class DataGapDetectorTest method testGapsBeforeAndAfterFull.

@Test
public void testGapsBeforeAndAfterFull() throws Exception {
    detector.setFullGapAnalysis(true);
    when(contextService.is(ContextConstants.ROUTING_FULL_GAP_ANALYSIS)).thenReturn(true);
    List<Long> dataIds = new ArrayList<Long>();
    dataIds.add(843L);
    dataIds.add(844L);
    @SuppressWarnings("unchecked") ISqlRowMapper<Long> mapper = (ISqlRowMapper<Long>) Matchers.anyObject();
    String sql = Matchers.anyString();
    when(sqlTemplate.query(sql, mapper, Matchers.eq(841L), Matchers.eq(50000840L))).thenReturn(dataIds);
    List<DataGap> dataGaps1 = new ArrayList<DataGap>();
    dataGaps1.add(new DataGap(841, 50000840));
    List<DataGap> dataGaps2 = new ArrayList<DataGap>();
    dataGaps2.add(new DataGap(841, 842));
    dataGaps2.add(new DataGap(845, 50000844));
    dataIds = new ArrayList<Long>();
    dataIds.add(845L);
    runGapDetector(dataGaps1, dataGaps2, dataIds, true);
    verify(dataService).findDataGaps();
    verify(dataService).deleteDataGap(sqlTransaction, new DataGap(841, 50000840));
    verify(dataService).insertDataGap(sqlTransaction, new DataGap(841, 842));
    verify(dataService).insertDataGap(sqlTransaction, new DataGap(845, 50000844));
    verify(dataService).deleteDataGap(sqlTransaction, new DataGap(845, 50000844));
    verify(dataService).insertDataGap(sqlTransaction, new DataGap(846, 50000845));
    verifyNoMoreInteractions(dataService);
}
Also used : DataGap(org.jumpmind.symmetric.model.DataGap) ArrayList(java.util.ArrayList) ISqlRowMapper(org.jumpmind.db.sql.ISqlRowMapper) Test(org.junit.Test)

Example 19 with ISqlRowMapper

use of org.jumpmind.db.sql.ISqlRowMapper in project symmetric-ds by JumpMind.

the class SqliteDdlReader method getTriggers.

public List<Trigger> getTriggers(final String catalog, final String schema, final String tableName) throws SqlException {
    List<Trigger> triggers = new ArrayList<Trigger>();
    String sql = "SELECT " + "name AS trigger_name, " + "tbl_name AS table_name, " + "rootpage, " + "sql, " + "type AS object_type " + "FROM sqlite_master " + "WHERE table_name=? AND object_type='trigger';";
    triggers = platform.getSqlTemplate().query(sql, new ISqlRowMapper<Trigger>() {

        public Trigger mapRow(Row row) {
            Trigger trigger = new Trigger();
            trigger.setName(row.getString("trigger_name"));
            trigger.setTableName(row.getString("table_name"));
            trigger.setEnabled(true);
            trigger.setSource(row.getString("sql"));
            row.remove("sql");
            trigger.setMetaData(row);
            return trigger;
        }
    }, tableName.toLowerCase());
    return triggers;
}
Also used : Trigger(org.jumpmind.db.model.Trigger) ArrayList(java.util.ArrayList) Row(org.jumpmind.db.sql.Row) ISqlRowMapper(org.jumpmind.db.sql.ISqlRowMapper)

Example 20 with ISqlRowMapper

use of org.jumpmind.db.sql.ISqlRowMapper in project symmetric-ds by JumpMind.

the class Db2DdlReader method getTriggers.

public List<Trigger> getTriggers(final String catalog, final String schema, final String tableName) throws SqlException {
    List<Trigger> triggers = new ArrayList<Trigger>();
    log.debug("Reading triggers for: " + tableName);
    JdbcSqlTemplate sqlTemplate = (JdbcSqlTemplate) platform.getSqlTemplate();
    String sql = "SELECT " + "NAME as TRIGGER_NAME, " + "SCHEMA, " + "DEFINER, " + "TBNAME as TABLE_NAME, " + "TBCREATOR as TABLE_CREATOR, " + "TRIGEVENT as TRIGGER_TYPE, " + "TRIGTIME as TRIGGER_TIME, " + "GRANULARITY, " + "VALID, " + "TEXT, " + "ENABLED, " + "CREATE_TIME, " + "FUNC_PATH as FUNCTION_PATH, " + "ALTER_TIME as LAST_ALTERED " + "FROM SYSIBM.SYSTRIGGERS " + "WHERE TBNAME=? and SCHEMA=?";
    triggers = sqlTemplate.query(sql, new ISqlRowMapper<Trigger>() {

        public Trigger mapRow(Row row) {
            Trigger trigger = new Trigger();
            trigger.setName(row.getString("TRIGGER_NAME"));
            trigger.setSchemaName(row.getString("SCHEMA"));
            trigger.setTableName(row.getString("TABLE_NAME"));
            trigger.setEnabled(row.getString("ENABLED").equals("Y"));
            trigger.setSource(row.getString("TEXT"));
            row.remove("TEXT");
            String trigEvent = row.getString("TRIGGER_TYPE");
            switch(trigEvent.charAt(0)) {
                case ('I'):
                    trigEvent = "INSERT";
                    break;
                case ('U'):
                    trigEvent = "UPDATE";
                    break;
                case ('D'):
                    trigEvent = "DELETE";
            }
            trigger.setTriggerType(TriggerType.valueOf(trigEvent));
            row.put("TRIGGER_TYPE", trigEvent);
            switch(row.getString("TRIGGER_TIME").charAt(0)) {
                case ('A'):
                    row.put("TRIGGER_TIME", "AFTER");
                    break;
                case ('B'):
                    row.put("TRIGGER_TIME", "BEFORE");
                    break;
                case ('I'):
                    row.put("TRIGGER_TIME", "INSTEAD OF");
            }
            if (row.getString("GRANULARITY").equals("S"))
                row.put("GRANULARITY", "ONCE PER STATEMENT");
            else if (row.getString("GRANULARITY").equals("R"))
                row.put("GRANULARITY", "ONCE PER ROW");
            trigger.setMetaData(row);
            return trigger;
        }
    }, tableName, schema);
    return triggers;
}
Also used : JdbcSqlTemplate(org.jumpmind.db.sql.JdbcSqlTemplate) Trigger(org.jumpmind.db.model.Trigger) ArrayList(java.util.ArrayList) Row(org.jumpmind.db.sql.Row) ISqlRowMapper(org.jumpmind.db.sql.ISqlRowMapper)

Aggregations

ISqlRowMapper (org.jumpmind.db.sql.ISqlRowMapper)29 ArrayList (java.util.ArrayList)27 Row (org.jumpmind.db.sql.Row)23 Trigger (org.jumpmind.db.model.Trigger)18 JdbcSqlTemplate (org.jumpmind.db.sql.JdbcSqlTemplate)18 DataGap (org.jumpmind.symmetric.model.DataGap)6 Test (org.junit.Test)6 HashMap (java.util.HashMap)2 List (java.util.List)2 ISqlTemplate (org.jumpmind.db.sql.ISqlTemplate)2 Date (java.util.Date)1 DatabaseInfo (org.jumpmind.db.platform.DatabaseInfo)1 IDatabasePlatform (org.jumpmind.db.platform.IDatabasePlatform)1 IExtensionPoint (org.jumpmind.extension.IExtensionPoint)1 INodeGroupExtensionPoint (org.jumpmind.symmetric.ext.INodeGroupExtensionPoint)1 CsvData (org.jumpmind.symmetric.io.data.CsvData)1 Grouplet (org.jumpmind.symmetric.model.Grouplet)1 GroupletLink (org.jumpmind.symmetric.model.GroupletLink)1 NodeChannel (org.jumpmind.symmetric.model.NodeChannel)1 TriggerRouterGrouplet (org.jumpmind.symmetric.model.TriggerRouterGrouplet)1