use of org.apache.cayenne.map.DbEntity in project cayenne by apache.
the class OpenBaseMergerTokenFactory method createDropRelationshipToDb.
@Override
public MergerToken createDropRelationshipToDb(final DbEntity entity, final DbRelationship rel) {
return new DropRelationshipToDb(entity, rel) {
@Override
public List<String> createSql(DbAdapter adapter) {
// FK_NAME form jdbc metadata seem to be wrong. It contain a column name
// and not the 'relationshipName'
// TODO: tell openbase developer mail list
DbEntity source = getEntity();
DbEntity dest = rel.getTargetEntity();
// only use the first. See adapter
// TODO: can we be sure this is the first and same as used by the adapter?
DbJoin join = rel.getJoins().get(0);
return Collections.singletonList("delete from _SYS_RELATIONSHIP where " + " source_table = '" + dest.getFullyQualifiedName() + "'" + " and source_column = '" + join.getTargetName() + "'" + " and dest_table = '" + source.getFullyQualifiedName() + "'" + " and dest_column = '" + join.getSourceName() + "'");
}
};
}
use of org.apache.cayenne.map.DbEntity in project cayenne by apache.
the class SetPrimaryKeyToModel method execute.
@Override
public void execute(MergerContext mergerContext) {
DbEntity e = getEntity();
for (DbAttribute attr : e.getAttributes()) {
boolean wasPrimaryKey = attr.isPrimaryKey();
boolean willBePrimaryKey = primaryKeyNewAttributeNames.contains(attr.getName().toUpperCase());
if (wasPrimaryKey != willBePrimaryKey) {
attr.setPrimaryKey(willBePrimaryKey);
e.dbAttributeChanged(new AttributeEvent(this, attr, e));
mergerContext.getDelegate().dbAttributeModified(attr);
}
}
}
use of org.apache.cayenne.map.DbEntity in project cayenne by apache.
the class AttributeLoader method processResultSetRow.
@Override
protected void processResultSetRow(CatalogFilter catalog, SchemaFilter schema, DbLoadDataStore map, ResultSet rs) throws SQLException {
if (firstRow) {
supportAutoIncrement = checkForAutoIncrement(rs);
firstRow = false;
}
// for a reason not quiet apparent to me, Oracle sometimes
// returns duplicate record sets for the same table, messing up
// table names. E.g. for the system table "WK$_ATTR_MAPPING" columns
// are returned twice - as "WK$_ATTR_MAPPING" and "WK$$_ATTR_MAPPING"...
// Go figure
String tableName = rs.getString("TABLE_NAME");
DbEntity entity = map.getDbEntity(tableName);
if (entity == null) {
return;
}
// Filter out columns by name
String columnName = rs.getString("COLUMN_NAME");
PatternFilter columnFilter = schema.tables.getIncludeTableColumnFilter(tableName);
if (columnFilter == null || !columnFilter.isIncluded(columnName)) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Skip column '" + tableName + "." + columnName + "' (Path: " + catalog.name + "/" + schema.name + "; Filter: " + columnFilter + ")");
}
return;
}
DbAttribute attribute = createDbAttribute(rs);
addToDbEntity(entity, attribute);
}
use of org.apache.cayenne.map.DbEntity in project cayenne by apache.
the class DbLoadDataStore method addDbEntitySafe.
DbEntity addDbEntitySafe(DbEntity entity) {
if (!(entity instanceof DetectedDbEntity)) {
throw new IllegalArgumentException("Only DetectedDbEntity can be inserted in this map");
}
DbEntity old = getDbEntity(entity.getName());
if (old != null) {
removeDbEntity(old.getName());
}
addDbEntity(entity);
return old;
}
use of org.apache.cayenne.map.DbEntity in project cayenne by apache.
the class EntityLoader method addDbEntityToMap.
private void addDbEntityToMap(DetectedDbEntity table, DbLoadDataStore map) {
DbEntity oldEnt = map.addDbEntitySafe(table);
if (oldEnt != null) {
LOGGER.debug("Overwrite DbEntity: " + oldEnt.getName());
delegate.dbEntityRemoved(oldEnt);
}
delegate.dbEntityAdded(table);
}
Aggregations