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);
}
}
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();
}
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;
}
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;
}
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];
}
}
Aggregations