Search in sources :

Example 11 with Column

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

the class SqlPersistenceManager method refresh.

@Override
public void refresh(Object object, String catalogName, String schemaName, String tableName) {
    try {
        Table table = findTable(catalogName, schemaName, tableName);
        LinkedHashMap<String, Column> objectToTableMapping = mapObjectToTable(object, table);
        LinkedHashMap<String, Object> objectValuesByColumnName = getObjectValuesByColumnName(object, objectToTableMapping);
        Column[] columns = objectToTableMapping.values().toArray(new Column[objectToTableMapping.size()]);
        List<Column> keys = new ArrayList<Column>(1);
        for (Column column : columns) {
            if (column.isPrimaryKey()) {
                keys.add(column);
            }
        }
        DmlStatement statement = databasePlatform.createDmlStatement(DmlType.SELECT, table.getCatalog(), table.getSchema(), table.getName(), keys.toArray(new Column[keys.size()]), columns, null, null);
        String sql = statement.getSql();
        Object[] values = statement.getValueArray(objectValuesByColumnName);
        Row row = databasePlatform.getSqlTemplate().queryForRow(sql, values);
        if (row != null) {
            Set<String> propertyNames = objectToTableMapping.keySet();
            for (String propertyName : propertyNames) {
                Object value = row.get(objectToTableMapping.get(propertyName).getName());
                BeanUtils.copyProperty(object, propertyName, value);
            }
        }
    } catch (Exception e) {
        throw toRuntimeException(e);
    }
}
Also used : Table(org.jumpmind.db.model.Table) ArrayList(java.util.ArrayList) InvocationTargetException(java.lang.reflect.InvocationTargetException) Column(org.jumpmind.db.model.Column)

Example 12 with Column

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

the class Db2As400DdlReader method readIndices.

@Override
protected Collection<IIndex> readIndices(Connection connection, DatabaseMetaDataWrapper metaData, String tableName) throws SQLException {
    Map<String, IIndex> indices = new LinkedHashMap<String, IIndex>();
    if (getPlatformInfo().isIndicesSupported()) {
        ResultSet indexData = null;
        try {
            indexData = metaData.getIndices(getTableNamePatternForConstraints(tableName), false, false);
            Collection<Column> columns = readColumns(metaData, tableName);
            while (indexData.next()) {
                Map<String, Object> values = readMetaData(indexData, getColumnsForIndex());
                String columnName = (String) values.get("COLUMN_NAME");
                if (hasColumn(columns, columnName)) {
                    readIndex(metaData, values, indices);
                }
            }
        } finally {
            close(indexData);
        }
    }
    return indices.values();
}
Also used : IIndex(org.jumpmind.db.model.IIndex) Column(org.jumpmind.db.model.Column) ResultSet(java.sql.ResultSet) LinkedHashMap(java.util.LinkedHashMap)

Example 13 with Column

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

the class DbCompareRow method comparePks.

public int comparePks(DbCompareTables tables, DbCompareRow targetRow) {
    for (Column sourcePkColumn : table.getPrimaryKeyColumns()) {
        Column targetPkColumn = tables.getColumnMapping().get(sourcePkColumn);
        if (targetPkColumn == null) {
            return 0;
        }
        int result = dbValueComparator.compareValues(sourcePkColumn, targetPkColumn, rowValues.get(sourcePkColumn.getName()), targetRow.getRowValues().get(targetPkColumn.getName()));
        if (result != 0) {
            return result;
        }
    }
    return 0;
}
Also used : Column(org.jumpmind.db.model.Column)

Example 14 with Column

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

the class DbCompareRow method compareTo.

public Map<Column, String> compareTo(DbCompareTables tables, DbCompareRow targetRow) {
    Map<Column, String> deltas = new LinkedHashMap<Column, String>();
    for (Column sourceColumn : table.getColumns()) {
        Column targetColumn = tables.getColumnMapping().get(sourceColumn);
        if (targetColumn == null) {
            continue;
        }
        int result = dbValueComparator.compareValues(sourceColumn, targetColumn, rowValues.get(sourceColumn.getName()), targetRow.getRowValues().get(targetColumn.getName()));
        if (result != 0) {
            deltas.put(targetColumn, rowValues.get(sourceColumn.getName()));
        }
    }
    return deltas;
}
Also used : Column(org.jumpmind.db.model.Column) LinkedHashMap(java.util.LinkedHashMap)

Example 15 with Column

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

the class Trigger method filterIncludedColumns.

public Column[] filterIncludedColumns(Column[] src) {
    if (src != null) {
        List<String> includedColumnNames = getIncludedColumnNamesAsList();
        if (includedColumnNames.size() == 0) {
            return src;
        }
        List<Column> filtered = new ArrayList<Column>(src.length);
        for (int i = 0; i < src.length; i++) {
            Column col = src[i];
            if (includedColumnNames.contains(col.getName().toLowerCase())) {
                filtered.add(col);
            }
        }
        return filtered.toArray(new Column[filtered.size()]);
    } else {
        return new Column[0];
    }
}
Also used : Column(org.jumpmind.db.model.Column) ArrayList(java.util.ArrayList)

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