use of org.apache.cayenne.map.DetectedDbEntity in project cayenne by apache.
the class DbAttributeMerger method createTokensForMissingImported.
/**
* Add column to db
* @param original attribute found in model but missing in db
*/
@Override
Collection<MergerToken> createTokensForMissingImported(DbAttribute original) {
DbEntity originalDbEntity = original.getEntity();
List<MergerToken> tokens = new LinkedList<>();
tokens.add(getTokenFactory().createAddColumnToDb(originalDbEntity, original));
// Create not null check
if (original.isMandatory()) {
if (valueForNull.hasValueFor(originalDbEntity, original)) {
tokens.add(getTokenFactory().createSetValueForNullToDb(originalDbEntity, original, valueForNull));
}
tokens.add(getTokenFactory().createSetNotNullToDb(originalDbEntity, original));
}
if (original.isPrimaryKey() && originalDbEntity instanceof DetectedDbEntity && "VIEW".equals(((DetectedDbEntity) originalDbEntity).getType())) {
// Views doesn't has PKs in a database, but if the user selects some PKs in a model, we put these keys.
return null;
}
return tokens;
}
use of org.apache.cayenne.map.DetectedDbEntity 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.DetectedDbEntity 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);
}
use of org.apache.cayenne.map.DetectedDbEntity in project cayenne by apache.
the class EntityLoader method processResultSetRow.
@Override
protected void processResultSetRow(CatalogFilter catalog, SchemaFilter schema, DbLoadDataStore map, ResultSet rs) throws SQLException {
String name = rs.getString("TABLE_NAME");
String catalogName = rs.getString("TABLE_CAT");
String schemaName = rs.getString("TABLE_SCHEM");
String type = rs.getString("TABLE_TYPE");
// So skip them all together (it's about "name == null" check)
if (name == null || !schema.tables.isIncludeTable(name)) {
return;
}
if (!(catalog.name == null || catalog.name.equals(catalogName)) || !(schema.name == null || schema.name.equals(schemaName))) {
LOGGER.error(catalogName + "." + schema + "." + schemaName + " wrongly loaded for catalog/schema : " + catalog.name + "." + schema.name);
return;
}
DetectedDbEntity table = new DetectedDbEntity(name);
table.setCatalog(catalogName);
table.setSchema(schemaName);
table.setType(type);
addDbEntityToMap(table, map);
}
use of org.apache.cayenne.map.DetectedDbEntity in project cayenne by apache.
the class PrimaryKeyLoader method processResultSet.
@Override
void processResultSet(DbEntity dbEntity, DbLoadDataStore map, ResultSet rs) throws SQLException {
String columnName = rs.getString("COLUMN_NAME");
DbAttribute attribute = dbEntity.getAttribute(columnName);
if (attribute == null) {
// why an attribute might be null is not quiet clear
// but there is a bug report 731406 indicating that it is
// possible so just print the warning, and ignore
LOGGER.warn("Can't locate attribute for primary key: " + columnName);
return;
}
attribute.setPrimaryKey(true);
((DetectedDbEntity) dbEntity).setPrimaryKeyName(rs.getString("PK_NAME"));
}
Aggregations