use of org.apache.cayenne.map.ObjEntity in project cayenne by apache.
the class IdPropertyIT method testEvaluateEntity.
@Test
public void testEvaluateEntity() {
Expression exp = Painting.TO_ARTIST.dot(Artist.ARTIST_ID_PK_PROPERTY).getExpression();
ObjEntity painting = context.getEntityResolver().getObjEntity(Painting.class);
Object result = exp.evaluate(painting);
assertNotNull(result);
assertThat(result, instanceOf(DbAttribute.class));
DbAttribute pk = (DbAttribute) result;
assertEquals("ARTIST_ID", pk.getName());
assertTrue(pk.isPrimaryKey());
}
use of org.apache.cayenne.map.ObjEntity in project cayenne by apache.
the class ASTObjPathIT method testEvaluate_ObjEntity.
@Test
public void testEvaluate_ObjEntity() {
ASTObjPath node = new ASTObjPath("paintingArray.paintingTitle");
ObjEntity ae = context.getEntityResolver().getObjEntity(Artist.class);
Object target = node.evaluate(ae);
assertTrue(target instanceof ObjAttribute);
}
use of org.apache.cayenne.map.ObjEntity in project cayenne by apache.
the class MergerOptions method generateSchemaAction.
/**
* Performs configured schema operations via DbGenerator.
*/
public void generateSchemaAction() {
refreshGeneratorAction();
// sanity check...
List<MergerToken> tokensToMigrate = tokens.getSelectedTokens();
if (tokensToMigrate.isEmpty()) {
JOptionPane.showMessageDialog(getView(), "Nothing to migrate.");
return;
}
DataSource dataSource;
try {
dataSource = connectionInfo.makeDataSource(getApplication().getClassLoadingService());
} catch (SQLException ex) {
reportError("Migration Error", ex);
return;
}
final Collection<ObjEntity> loadedObjEntities = new LinkedList<>();
MergerContext mergerContext = MergerContext.builder(dataMap).syntheticDataNode(dataSource, adapter).delegate(createDelegate(loadedObjEntities)).build();
boolean modelChanged = applyTokens(tokensToMigrate, mergerContext);
DefaultDbImportAction.flattenManyToManyRelationships(dataMap, loadedObjEntities, mergerContext.getNameGenerator());
notifyProjectModified(modelChanged);
reportFailures(mergerContext);
if (tokens.isReverse()) {
getApplication().getUndoManager().discardAllEdits();
}
}
use of org.apache.cayenne.map.ObjEntity 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.map.ObjEntity in project cayenne by apache.
the class BoxCellRenderer method setUpdatedValueAt.
@Override
public void setUpdatedValueAt(Object value, int row, int col) {
EmbeddableAttribute attribute = getEmbeddableAttribute(row);
if (col == DB_ATTRIBUTE) {
attribute.setDbAttributeName(value != null ? value.toString() : null);
fireTableCellUpdated(row, col);
this.isAttributeOverrideChange = true;
((ObjAttributeInfoDialogView) ((ObjAttributeInfoDialog) eventSource).getView()).getSaveButton().setEnabled(true);
if (value != null) {
DbEntity currentEnt = ((ObjEntity) attr.getEntity()).getDbEntity();
if (currentEnt != null) {
DbAttribute dbAttr = (DbAttribute) currentEnt.getAttribute(value.toString());
if (dbAttr != null) {
fireTableCellUpdated(DB_ATTRIBUTE_TYPE, col);
}
}
}
fireTableRowsUpdated(row, row);
}
}
Aggregations