use of org.apache.cayenne.map.DbEntity in project cayenne by apache.
the class DbAttributeMerger method checkType.
private void checkType(DbAttribute original, DbAttribute imported, List<MergerToken> tokens) {
if (!needUpdateType(original, imported)) {
return;
}
DbEntity originalDbEntity = original.getEntity();
tokens.add(getTokenFactory().createSetColumnTypeToDb(originalDbEntity, imported, original));
}
use of org.apache.cayenne.map.DbEntity 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.DbEntity in project cayenne by apache.
the class DbRelationshipMerger method createTokensForMissingImported.
/**
* @param original DbRelationship that is in model but not in db
* @return generated tokens
*/
@Override
Collection<MergerToken> createTokensForMissingImported(DbRelationship original) {
if (skipRelationshipsTokens) {
return null;
}
DbEntity originalDbEntity = getOriginalSourceDbEntity(original);
MergerToken token = getTokenFactory().createAddRelationshipToDb(originalDbEntity, original);
return Collections.singleton(token);
}
use of org.apache.cayenne.map.DbEntity in project cayenne by apache.
the class DbRelationshipMerger method createTokensForMissingOriginal.
/**
* @param imported DbRelationship that is in db but not in model
* @return generated tokens
*/
@Override
Collection<MergerToken> createTokensForMissingOriginal(DbRelationship imported) {
DbEntity originalDbEntity = getOriginalSourceDbEntity(imported);
DbEntity targetEntity = getOriginalTargetDbEntity(imported);
if (targetEntity != null) {
imported.setTargetEntityName(targetEntity);
}
imported.setSourceEntity(originalDbEntity);
// manipulate the joins to match the DbAttributes in the model
for (DbJoin join : imported.getJoins()) {
DbAttribute sourceAttr = findDbAttribute(originalDbEntity, join.getSourceName());
if (sourceAttr != null) {
join.setSourceName(sourceAttr.getName());
}
DbAttribute targetAttr = findDbAttribute(targetEntity, join.getTargetName());
if (targetAttr != null) {
join.setTargetName(targetAttr.getName());
}
}
// Add all relationships. Tokens will decide whether or not to execute
MergerToken token = getTokenFactory().createDropRelationshipToDb(originalDbEntity, imported);
return Collections.singleton(token);
}
use of org.apache.cayenne.map.DbEntity in project cayenne by apache.
the class EntityMergeSupport method addMissingRelationship.
private void addMissingRelationship(ObjEntity entity, DbRelationship dbRelationship) {
// getting DataMap from DbRelationship's source entity. This is the only object in our arguments that
// is guaranteed to be a part of the map....
DataMap dataMap = dbRelationship.getSourceEntity().getDataMap();
DbEntity targetEntity = dbRelationship.getTargetEntity();
Collection<ObjEntity> mappedObjEntities = dataMap.getMappedEntities(targetEntity);
if (mappedObjEntities.isEmpty()) {
if (targetEntity == null) {
targetEntity = new DbEntity(dbRelationship.getTargetEntityName());
}
if (dbRelationship.getTargetEntityName() != null) {
boolean needGeneratedEntity = createObjRelationship(entity, dbRelationship, nameGenerator.objEntityName(targetEntity));
if (needGeneratedEntity) {
LOGGER.warn("Can't find ObjEntity for " + dbRelationship.getTargetEntityName());
LOGGER.warn("Db Relationship (" + dbRelationship + ") will have GUESSED Obj Relationship reflection. ");
}
}
} else {
for (Entity mappedTarget : mappedObjEntities) {
createObjRelationship(entity, dbRelationship, mappedTarget.getName());
}
}
}
Aggregations