Search in sources :

Example 56 with DbAttribute

use of org.apache.cayenne.map.DbAttribute in project cayenne by apache.

the class PKDBGeneratorPanel method updateView.

void updateView(final DbEntity entity) {
    for (ItemListener listener : attributes.getItemListeners()) {
        attributes.removeItemListener(listener);
    }
    Collection<DbAttribute> pkAttributes = entity.getPrimaryKeys();
    if (pkAttributes.isEmpty()) {
        attributes.removeAllItems();
        attributes.addItem("<Entity has no PK columns>");
        attributes.setSelectedIndex(0);
        attributes.setEnabled(false);
    } else {
        attributes.setEnabled(true);
        MutableComboBoxModel model = new DefaultComboBoxModel(pkAttributes.toArray());
        String noSelection = "<Select Generated Column>";
        model.insertElementAt(noSelection, 0);
        model.setSelectedItem(noSelection);
        attributes.setModel(model);
        for (DbAttribute a : pkAttributes) {
            if (a.isGenerated()) {
                model.setSelectedItem(a);
                break;
            }
        }
        // listen for selection changes of the new entity
        attributes.addItemListener(new ItemListener() {

            public void itemStateChanged(ItemEvent e) {
                Object item = e.getItem();
                if (item instanceof DbAttribute) {
                    boolean generated = e.getStateChange() == ItemEvent.SELECTED;
                    DbAttribute a = (DbAttribute) item;
                    if (a.isGenerated() != generated) {
                        a.setGenerated(generated);
                        mediator.fireDbEntityEvent(new EntityEvent(this, entity));
                    }
                }
            }
        });
    }
    // revalidate as children layout has changed...
    revalidate();
}
Also used : ItemEvent(java.awt.event.ItemEvent) EntityEvent(org.apache.cayenne.map.event.EntityEvent) DbAttribute(org.apache.cayenne.map.DbAttribute) MutableComboBoxModel(javax.swing.MutableComboBoxModel) ItemListener(java.awt.event.ItemListener) DefaultComboBoxModel(javax.swing.DefaultComboBoxModel)

Example 57 with DbAttribute

use of org.apache.cayenne.map.DbAttribute in project cayenne by apache.

the class PKDBGeneratorPanel method onInitInternal.

protected void onInitInternal(DbEntity entity) {
    resetStrategy(entity, true, false);
    Collection pkAttributes = entity.getPrimaryKeys();
    // by default check the only numeric PK
    if (pkAttributes.size() == 1) {
        DbAttribute pk = (DbAttribute) pkAttributes.iterator().next();
        if (TypesMapping.isNumeric(pk.getType()) && !pk.isGenerated()) {
            pk.setGenerated(true);
            mediator.fireDbEntityEvent(new EntityEvent(this, entity));
        }
    }
    updateView(entity);
}
Also used : EntityEvent(org.apache.cayenne.map.event.EntityEvent) DbAttribute(org.apache.cayenne.map.DbAttribute) Collection(java.util.Collection)

Example 58 with DbAttribute

use of org.apache.cayenne.map.DbAttribute in project cayenne by apache.

the class PKGeneratorPanel method resetStrategy.

protected void resetStrategy(DbEntity entity, boolean resetCustomSequence, boolean resetDBGenerated) {
    boolean hasChanges = false;
    if (resetCustomSequence && entity.getPrimaryKeyGenerator() != null) {
        entity.setPrimaryKeyGenerator(null);
        hasChanges = true;
    }
    if (resetDBGenerated) {
        for (DbAttribute a : entity.getPrimaryKeys()) {
            if (a.isGenerated()) {
                a.setGenerated(false);
                hasChanges = true;
            }
        }
    }
    if (hasChanges) {
        mediator.fireDbEntityEvent(new EntityEvent(this, entity));
    }
}
Also used : EntityEvent(org.apache.cayenne.map.event.EntityEvent) DbAttribute(org.apache.cayenne.map.DbAttribute)

Example 59 with DbAttribute

use of org.apache.cayenne.map.DbAttribute in project cayenne by apache.

the class FindAction method searchInDbEntities.

private void searchInDbEntities(Pattern pattern, List<SearchResultEntry> result, DataMap dataMap) {
    for (DbEntity ent : dataMap.getDbEntities()) {
        if (match(ent.getName(), pattern)) {
            result.add(new SearchResultEntry(ent, ent.getName()));
        }
        for (DbAttribute attr : ent.getAttributes()) {
            if (match(attr.getName(), pattern)) {
                result.add(new SearchResultEntry(attr, ent.getName() + "." + attr.getName()));
            }
        }
        for (DbRelationship rel : ent.getRelationships()) {
            if (match(rel.getName(), pattern)) {
                result.add(new SearchResultEntry(rel, ent.getName() + "." + rel.getName()));
            }
        }
        checkCatalogOrSchema(pattern, result, ent, ent.getCatalog());
        checkCatalogOrSchema(pattern, result, ent, ent.getSchema());
    }
}
Also used : DetectedDbEntity(org.apache.cayenne.map.DetectedDbEntity) DbEntity(org.apache.cayenne.map.DbEntity) DbRelationship(org.apache.cayenne.map.DbRelationship) DbAttribute(org.apache.cayenne.map.DbAttribute)

Example 60 with DbAttribute

use of org.apache.cayenne.map.DbAttribute in project cayenne by apache.

the class FindAction method jumpToAttributeResult.

private static void jumpToAttributeResult(SearchResultEntry searchResultEntry, EditorView editor, DataChannelDescriptor domain) {
    DataMap map;
    Entity entity;
    if (searchResultEntry.getObject() instanceof Attribute) {
        map = ((Attribute) searchResultEntry.getObject()).getEntity().getDataMap();
        entity = ((Attribute) searchResultEntry.getObject()).getEntity();
    } else {
        map = ((Relationship) searchResultEntry.getObject()).getSourceEntity().getDataMap();
        entity = ((Relationship) searchResultEntry.getObject()).getSourceEntity();
    }
    buildAndSelectTreePath(map, entity, editor);
    if (searchResultEntry.getObject() instanceof Attribute) {
        AttributeDisplayEvent event = new AttributeDisplayEvent(editor.getProjectTreeView(), (Attribute) searchResultEntry.getObject(), entity, map, domain);
        event.setMainTabFocus(true);
        if (searchResultEntry.getObject() instanceof DbAttribute) {
            editor.getDbDetailView().currentDbAttributeChanged(event);
        } else {
            editor.getObjDetailView().currentObjAttributeChanged(event);
        }
    } else if (searchResultEntry.getObject() instanceof Relationship) {
        RelationshipDisplayEvent event = new RelationshipDisplayEvent(editor.getProjectTreeView(), (Relationship) searchResultEntry.getObject(), entity, map, domain);
        event.setMainTabFocus(true);
        if (searchResultEntry.getObject() instanceof DbRelationship) {
            editor.getDbDetailView().currentDbRelationshipChanged(event);
        } else {
            editor.getObjDetailView().currentObjRelationshipChanged(event);
        }
    }
}
Also used : ObjEntity(org.apache.cayenne.map.ObjEntity) DetectedDbEntity(org.apache.cayenne.map.DetectedDbEntity) Entity(org.apache.cayenne.map.Entity) DbEntity(org.apache.cayenne.map.DbEntity) EmbeddableAttributeDisplayEvent(org.apache.cayenne.modeler.event.EmbeddableAttributeDisplayEvent) AttributeDisplayEvent(org.apache.cayenne.modeler.event.AttributeDisplayEvent) DbAttribute(org.apache.cayenne.map.DbAttribute) ObjAttribute(org.apache.cayenne.map.ObjAttribute) Attribute(org.apache.cayenne.map.Attribute) EmbeddableAttribute(org.apache.cayenne.map.EmbeddableAttribute) Relationship(org.apache.cayenne.map.Relationship) DbRelationship(org.apache.cayenne.map.DbRelationship) ObjRelationship(org.apache.cayenne.map.ObjRelationship) DbRelationship(org.apache.cayenne.map.DbRelationship) DbAttribute(org.apache.cayenne.map.DbAttribute) DataMap(org.apache.cayenne.map.DataMap) RelationshipDisplayEvent(org.apache.cayenne.modeler.event.RelationshipDisplayEvent)

Aggregations

DbAttribute (org.apache.cayenne.map.DbAttribute)194 DbEntity (org.apache.cayenne.map.DbEntity)109 Test (org.junit.Test)67 ObjEntity (org.apache.cayenne.map.ObjEntity)36 DbRelationship (org.apache.cayenne.map.DbRelationship)35 ObjAttribute (org.apache.cayenne.map.ObjAttribute)32 CayenneRuntimeException (org.apache.cayenne.CayenneRuntimeException)21 DbJoin (org.apache.cayenne.map.DbJoin)18 HashMap (java.util.HashMap)16 ObjRelationship (org.apache.cayenne.map.ObjRelationship)16 ArrayList (java.util.ArrayList)14 DbAttributeBinding (org.apache.cayenne.access.translator.DbAttributeBinding)12 DataMap (org.apache.cayenne.map.DataMap)11 JdbcAdapter (org.apache.cayenne.dba.JdbcAdapter)10 QuotingStrategy (org.apache.cayenne.dba.QuotingStrategy)10 MergerToken (org.apache.cayenne.dbsync.merge.token.MergerToken)10 DeleteBatchQuery (org.apache.cayenne.query.DeleteBatchQuery)10 ClassDescriptor (org.apache.cayenne.reflect.ClassDescriptor)10 ObjectId (org.apache.cayenne.ObjectId)9 Expression (org.apache.cayenne.exp.Expression)8