Search in sources :

Example 46 with ObjEntity

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());
}
Also used : ObjEntity(org.apache.cayenne.map.ObjEntity) Expression(org.apache.cayenne.exp.Expression) DbAttribute(org.apache.cayenne.map.DbAttribute) Test(org.junit.Test)

Example 47 with ObjEntity

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);
}
Also used : ObjEntity(org.apache.cayenne.map.ObjEntity) ObjAttribute(org.apache.cayenne.map.ObjAttribute) Test(org.junit.Test)

Example 48 with ObjEntity

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();
    }
}
Also used : ObjEntity(org.apache.cayenne.map.ObjEntity) SQLException(java.sql.SQLException) MergerToken(org.apache.cayenne.dbsync.merge.token.MergerToken) MergerContext(org.apache.cayenne.dbsync.merge.context.MergerContext) LinkedList(java.util.LinkedList) DataSource(javax.sql.DataSource)

Example 49 with ObjEntity

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;
}
Also used : EntityMergeSupport(org.apache.cayenne.dbsync.merge.context.EntityMergeSupport) ObjEntity(org.apache.cayenne.map.ObjEntity) ObjectNameGenerator(org.apache.cayenne.dbsync.naming.ObjectNameGenerator)

Example 50 with ObjEntity

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);
    }
}
Also used : ObjEntity(org.apache.cayenne.map.ObjEntity) DbEntity(org.apache.cayenne.map.DbEntity) DbAttribute(org.apache.cayenne.map.DbAttribute) EmbeddableAttribute(org.apache.cayenne.map.EmbeddableAttribute)

Aggregations

ObjEntity (org.apache.cayenne.map.ObjEntity)294 Test (org.junit.Test)110 DbEntity (org.apache.cayenne.map.DbEntity)72 ObjAttribute (org.apache.cayenne.map.ObjAttribute)68 ObjRelationship (org.apache.cayenne.map.ObjRelationship)62 DataMap (org.apache.cayenne.map.DataMap)57 DbAttribute (org.apache.cayenne.map.DbAttribute)37 DbRelationship (org.apache.cayenne.map.DbRelationship)29 CayenneRuntimeException (org.apache.cayenne.CayenneRuntimeException)27 ObjectId (org.apache.cayenne.ObjectId)26 ClassDescriptor (org.apache.cayenne.reflect.ClassDescriptor)22 ArrayList (java.util.ArrayList)19 Embeddable (org.apache.cayenne.map.Embeddable)18 EntityResolver (org.apache.cayenne.map.EntityResolver)17 DataChannelDescriptor (org.apache.cayenne.configuration.DataChannelDescriptor)16 Expression (org.apache.cayenne.exp.Expression)15 Persistent (org.apache.cayenne.Persistent)12 EntityEvent (org.apache.cayenne.map.event.EntityEvent)12 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)12 Entity (org.apache.cayenne.map.Entity)11