Search in sources :

Example 46 with Column

use of org.jumpmind.db.model.Column in project symmetric-ds by JumpMind.

the class DbExportImportTest method compareRows.

protected void compareRows(Table table, List<Row> one, List<Row> two) {
    if (one.size() != two.size()) {
        Assert.fail("First list had " + one.size() + " and second list had " + two.size());
    }
    for (int i = 0; i < one.size(); i++) {
        Row rOne = one.get(i);
        Row rTwo = two.get(i);
        Set<String> keys = rOne.keySet();
        for (String key : keys) {
            Object oOne = rOne.get(key);
            Object oTwo = rTwo.get(key);
            Column column = table.getColumnWithName(key);
            /*
                 * special comparison for sqlite. the result reports all types
                 * as text even though the jdbc table metadata reports the types
                 * as dates
                 */
            if (column != null && (column.getMappedType().equals("DATE") || column.getMappedType().equals("TIME") || column.getMappedType().equals("TIMESTAMP")) && oOne instanceof String && oTwo instanceof String) {
                oOne = FormatUtils.parseDate(oOne.toString(), FormatUtils.TIMESTAMP_PATTERNS);
                oTwo = FormatUtils.parseDate(oTwo.toString(), FormatUtils.TIMESTAMP_PATTERNS);
            }
            if (!ObjectUtils.equals(oOne, oTwo)) {
                Assert.fail("The " + i + " element was not the same.  The column " + key + " had a value of " + rOne.get(key) + " for one row and " + rTwo.get(key) + " for the other");
            }
        }
    }
}
Also used : Column(org.jumpmind.db.model.Column) Row(org.jumpmind.db.sql.Row)

Example 47 with Column

use of org.jumpmind.db.model.Column in project symmetric-ds by JumpMind.

the class MsSqlBulkDatabaseWriterTest method testInsertReorderColumns.

@Test
public void testInsertReorderColumns() throws Exception {
    if (shouldTestRun(platform)) {
        String id = getNextId();
        String[] values = { "string with space in it", "string-with-no-space", "string with space in it", "string-with-no-space", "2007-01-02 00:00:00.000", "2007-02-03 04:05:06.000", "0", "47", "67.89", "-0.0747663", encode("string with space in it"), id };
        List<CsvData> data = new ArrayList<CsvData>();
        data.add(new CsvData(DataEventType.INSERT, (String[]) ArrayUtils.clone(values)));
        Table table = (Table) platform.getTableFromCache(getTestTable(), false).clone();
        Column firstColumn = table.getColumn(0);
        table.removeColumn(firstColumn);
        table.addColumn(firstColumn);
        writeData(new MsSqlBulkDatabaseWriter(platform, stagingManager, new CommonsDbcpNativeJdbcExtractor(), 1000, false, uncPath, null, null), new TableCsvData(table, data));
        values = (String[]) ArrayUtils.remove(values, values.length - 1);
        values = (String[]) ArrayUtils.add(values, 0, id);
        assertTestTableEquals(id, values);
    }
}
Also used : Table(org.jumpmind.db.model.Table) Column(org.jumpmind.db.model.Column) MsSqlBulkDatabaseWriter(org.jumpmind.symmetric.io.MsSqlBulkDatabaseWriter) ArrayList(java.util.ArrayList) CommonsDbcpNativeJdbcExtractor(org.springframework.jdbc.support.nativejdbc.CommonsDbcpNativeJdbcExtractor) CsvData(org.jumpmind.symmetric.io.data.CsvData) Test(org.junit.Test)

Example 48 with Column

use of org.jumpmind.db.model.Column in project symmetric-ds by JumpMind.

the class AbstractSymmetricDialect method orderColumns.

@Deprecated
public Column[] orderColumns(String[] columnNames, Table table) {
    Column[] unorderedColumns = table.getColumns();
    Column[] orderedColumns = new Column[columnNames.length];
    for (int i = 0; i < columnNames.length; i++) {
        String name = columnNames[i];
        for (Column column : unorderedColumns) {
            if (column.getName().equalsIgnoreCase(name)) {
                orderedColumns[i] = column;
                break;
            }
        }
    }
    return orderedColumns;
}
Also used : Column(org.jumpmind.db.model.Column)

Example 49 with Column

use of org.jumpmind.db.model.Column in project symmetric-ds by JumpMind.

the class AbstractTriggerTemplate method aliasedPrimaryKeyJoin.

protected String aliasedPrimaryKeyJoin(String aliasOne, String aliasTwo, Column[] columns) {
    StringBuilder b = new StringBuilder();
    for (Column column : columns) {
        b.append(aliasOne).append(".\"").append(column.getName()).append("\"");
        b.append("=").append(aliasTwo).append(".\"").append(column.getName()).append("\"");
        if (!column.equals(columns[columns.length - 1])) {
            b.append(" and ");
        }
    }
    return b.toString();
}
Also used : Column(org.jumpmind.db.model.Column)

Example 50 with Column

use of org.jumpmind.db.model.Column in project symmetric-ds by JumpMind.

the class AbstractTriggerTemplate method buildColumnsString.

protected ColumnString buildColumnsString(String origTableAlias, String tableAlias, String columnPrefix, Column[] columns, DataEventType dml, boolean isOld, Channel channel, Trigger trigger) {
    String columnsText = "";
    boolean containsLob = false;
    String lastCommandToken = symmetricDialect.escapesTemplatesForDatabaseInserts() ? (triggerConcatCharacter + "'',''" + triggerConcatCharacter) : (triggerConcatCharacter + "','" + triggerConcatCharacter);
    for (int i = 0; i < columns.length; i++) {
        Column column = columns[i];
        if (column != null) {
            ColumnString columnString = fillOutColumnTemplate(origTableAlias, tableAlias, columnPrefix, column, dml, isOld, channel, trigger);
            columnsText = columnsText + "\n          " + columnString.columnString + lastCommandToken;
            containsLob |= columnString.isBlobClob;
        }
    }
    if (columnsText.endsWith(lastCommandToken)) {
        columnsText = columnsText.substring(0, columnsText.length() - lastCommandToken.length());
    }
    return new ColumnString(columnsText, containsLob);
}
Also used : Column(org.jumpmind.db.model.Column)

Aggregations

Column (org.jumpmind.db.model.Column)179 Table (org.jumpmind.db.model.Table)78 ArrayList (java.util.ArrayList)34 IndexColumn (org.jumpmind.db.model.IndexColumn)23 PlatformColumn (org.jumpmind.db.model.PlatformColumn)21 Test (org.junit.Test)16 Row (org.jumpmind.db.sql.Row)15 LinkedHashMap (java.util.LinkedHashMap)12 ResultSet (java.sql.ResultSet)11 DmlStatement (org.jumpmind.db.sql.DmlStatement)10 SqlException (org.jumpmind.db.sql.SqlException)10 InvocationTargetException (java.lang.reflect.InvocationTargetException)9 IIndex (org.jumpmind.db.model.IIndex)9 HashMap (java.util.HashMap)8 ForeignKey (org.jumpmind.db.model.ForeignKey)8 CsvData (org.jumpmind.symmetric.io.data.CsvData)8 PreparedStatement (java.sql.PreparedStatement)7 IOException (java.io.IOException)6 SQLException (java.sql.SQLException)6 Reference (org.jumpmind.db.model.Reference)6