use of org.apache.cayenne.dbsync.naming.ObjectNameGenerator in project cayenne by apache.
the class EntitySyncController method createMerger.
public EntityMergeSupport createMerger() {
Collection<ObjEntity> entities = getObjEntities();
if (entities.isEmpty()) {
return null;
}
ObjectNameGenerator namingStrategy;
try {
namingStrategy = NameGeneratorPreferences.getInstance().createNamingStrategy(application);
} catch (Throwable e) {
namingStrategy = NameGeneratorPreferences.defaultNameGenerator();
}
// TODO: Modeler-controlled defaults for all the hardcoded boolean flags here.
EntityMergeSupport merger = new EntityMergeSupport(namingStrategy, NamePatternMatcher.EXCLUDE_ALL, true, true, false);
// see if we need to remove meaningful attributes...
for (ObjEntity entity : entities) {
if (!merger.getMeaningfulFKs(entity).isEmpty()) {
return confirmMeaningfulFKs(namingStrategy);
}
}
return merger;
}
use of org.apache.cayenne.dbsync.naming.ObjectNameGenerator in project cayenne by apache.
the class DefaultDbImportAction method applyTokens.
private boolean applyTokens(DataMap targetDataMap, Collection<MergerToken> tokens, DbImportConfiguration config) {
if (tokens.isEmpty()) {
logger.info("");
logger.info("Detected changes: No changes to import.");
return false;
}
final Collection<ObjEntity> loadedObjEntities = new LinkedList<>();
ModelMergeDelegate mergeDelegate = new ProxyModelMergeDelegate(config.createMergeDelegate()) {
@Override
public void objEntityAdded(ObjEntity ent) {
loadedObjEntities.add(ent);
super.objEntityAdded(ent);
}
};
ObjectNameGenerator nameGenerator = config.createNameGenerator();
MergerContext mergerContext = MergerContext.builder(targetDataMap).delegate(mergeDelegate).nameGenerator(nameGenerator).usingPrimitives(config.isUsePrimitives()).usingJava7Types(config.isUseJava7Types()).meaningfulPKFilter(config.createMeaningfulPKFilter()).build();
for (MergerToken token : tokens) {
try {
token.execute(mergerContext);
} catch (Throwable th) {
String message = "Migration Error. Can't apply changes from token: " + token.getTokenName() + " (" + token.getTokenValue() + ")";
logger.error(message, th);
mergerContext.getValidationResult().addFailure(new SimpleValidationFailure(th, message));
}
}
ValidationResult failures = mergerContext.getValidationResult();
if (failures.hasFailures()) {
logger.info("Migration Complete.");
logger.warn("Migration finished. The following problem(s) were encountered and ignored.");
for (ValidationFailure failure : failures.getFailures()) {
logger.warn(failure.toString());
}
} else {
logger.info("Migration Complete Successfully.");
}
flattenManyToManyRelationships(targetDataMap, loadedObjEntities, nameGenerator);
relationshipsSanity(targetDataMap);
return true;
}
Aggregations