Search in sources :

Example 61 with DbEntity

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

the class DbEntityTab method setQualifier.

void setQualifier(String qualifier) {
    if (qualifier != null && qualifier.trim().length() == 0) {
        qualifier = null;
    }
    DbEntity ent = mediator.getCurrentDbEntity();
    if (ent != null && !Util.nullSafeEquals(ent.getQualifier(), qualifier)) {
        ExpressionConvertor convertor = new ExpressionConvertor();
        try {
            String oldQualifier = convertor.valueAsString(ent.getQualifier());
            if (!Util.nullSafeEquals(oldQualifier, qualifier)) {
                Expression exp = (Expression) convertor.stringAsValue(qualifier);
                ent.setQualifier(exp);
                mediator.fireDbEntityEvent(new EntityEvent(this, ent));
            }
        } catch (IllegalArgumentException ex) {
            // unparsable qualifier
            throw new ValidationException(ex.getMessage());
        }
    }
}
Also used : ValidationException(org.apache.cayenne.validation.ValidationException) DbEntity(org.apache.cayenne.map.DbEntity) Expression(org.apache.cayenne.exp.Expression) EntityEvent(org.apache.cayenne.map.event.EntityEvent) ExpressionConvertor(org.apache.cayenne.modeler.util.ExpressionConvertor)

Example 62 with DbEntity

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

the class DbEntityTab method setCatalog.

void setCatalog(String text) {
    if (text != null && text.trim().length() == 0) {
        text = null;
    }
    DbEntity ent = mediator.getCurrentDbEntity();
    if (ent != null && !Util.nullSafeEquals(ent.getCatalog(), text)) {
        ent.setCatalog(text);
        mediator.fireDbEntityEvent(new EntityEvent(this, ent));
    }
}
Also used : DbEntity(org.apache.cayenne.map.DbEntity) EntityEvent(org.apache.cayenne.map.event.EntityEvent)

Example 63 with DbEntity

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

the class DbEntityTabbedView method currentDbEntityChanged.

/**
 * If entity is null hides it's contents, otherwise makes it visible.
 */
public void currentDbEntityChanged(EntityDisplayEvent e) {
    Entity entity = e.getEntity();
    if (e.isMainTabFocus() && entity instanceof DbEntity) {
        if (getSelectedComponent() != entityPanel) {
            setSelectedComponent(entityPanel);
            entityPanel.setVisible(true);
        }
    }
    resetRemoveButtons();
    setVisible(e.getEntity() != null);
    if (projectController.getEntityTabSelection() < getTabCount()) {
        setSelectedIndex(projectController.getEntityTabSelection());
    }
}
Also used : DbEntity(org.apache.cayenne.map.DbEntity) Entity(org.apache.cayenne.map.Entity) DbEntity(org.apache.cayenne.map.DbEntity)

Example 64 with DbEntity

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

the class RemoveEntityAction method performAction.

@Override
public void performAction(ActionEvent e, boolean allowAsking) {
    ConfirmRemoveDialog dialog = getConfirmDeleteDialog(allowAsking);
    Entity entity = builder.getSelectedEntity();
    if (entity == null) {
        return;
    }
    if (entity instanceof ObjEntity) {
        if (dialog.shouldDelete("ObjEntity", entity.getName())) {
            application.getUndoManager().addEdit(new RemoveUndoableEdit(entity.getDataMap(), (ObjEntity) entity));
            removeObjEntity(entity.getDataMap(), (ObjEntity) entity);
        }
    } else {
        if (dialog.shouldDelete("DbEntity", entity.getName())) {
            application.getUndoManager().addEdit(new RemoveUndoableEdit(entity.getDataMap(), (DbEntity) entity));
            removeDbEntity(entity.getDataMap(), (DbEntity) entity);
        }
    }
}
Also used : ObjEntity(org.apache.cayenne.map.ObjEntity) DbEntity(org.apache.cayenne.map.DbEntity) Entity(org.apache.cayenne.map.Entity) ObjEntity(org.apache.cayenne.map.ObjEntity) DbEntity(org.apache.cayenne.map.DbEntity) RemoveUndoableEdit(org.apache.cayenne.modeler.undo.RemoveUndoableEdit) ConfirmRemoveDialog(org.apache.cayenne.modeler.dialog.ConfirmRemoveDialog)

Example 65 with DbEntity

use of org.apache.cayenne.map.DbEntity 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)

Aggregations

DbEntity (org.apache.cayenne.map.DbEntity)273 DbAttribute (org.apache.cayenne.map.DbAttribute)106 Test (org.junit.Test)106 ObjEntity (org.apache.cayenne.map.ObjEntity)64 DbRelationship (org.apache.cayenne.map.DbRelationship)55 DataMap (org.apache.cayenne.map.DataMap)47 ObjAttribute (org.apache.cayenne.map.ObjAttribute)26 ArrayList (java.util.ArrayList)25 DbJoin (org.apache.cayenne.map.DbJoin)24 MergerToken (org.apache.cayenne.dbsync.merge.token.MergerToken)20 ObjRelationship (org.apache.cayenne.map.ObjRelationship)19 CayenneRuntimeException (org.apache.cayenne.CayenneRuntimeException)16 JdbcAdapter (org.apache.cayenne.dba.JdbcAdapter)16 Entity (org.apache.cayenne.map.Entity)16 List (java.util.List)15 DbAdapter (org.apache.cayenne.dba.DbAdapter)15 EntityEvent (org.apache.cayenne.map.event.EntityEvent)14 HashMap (java.util.HashMap)12 SelectQuery (org.apache.cayenne.query.SelectQuery)12 DataChannelDescriptor (org.apache.cayenne.configuration.DataChannelDescriptor)11