Search in sources :

Example 71 with DbEntity

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

the class CatalogUpdateController method updateCatalog.

protected void updateCatalog() {
    boolean doAll = isAllEntities();
    String defaultCatalog = dataMap.getDefaultCatalog();
    // set catalog for DbEntities
    for (DbEntity entity : dataMap.getDbEntities()) {
        if (doAll || Util.isEmptyString(entity.getCatalog())) {
            if (!Util.nullSafeEquals(defaultCatalog, entity.getCatalog())) {
                entity.setCatalog(defaultCatalog);
                // any way to batch events, a big change will flood the app
                // with entity events..?
                mediator.fireDbEntityEvent(new EntityEvent(this, entity));
            }
        }
    }
    // set catalog for procedures...
    for (Procedure procedure : dataMap.getProcedures()) {
        if (doAll || Util.isEmptyString(procedure.getCatalog())) {
            if (!Util.nullSafeEquals(defaultCatalog, procedure.getCatalog())) {
                procedure.setCatalog(defaultCatalog);
                // any way to batch events, a big change will flood the app
                // with procedure events..?
                mediator.fireProcedureEvent(new ProcedureEvent(this, procedure));
            }
        }
    }
    view.dispose();
}
Also used : DbEntity(org.apache.cayenne.map.DbEntity) EntityEvent(org.apache.cayenne.map.event.EntityEvent) ProcedureEvent(org.apache.cayenne.configuration.event.ProcedureEvent) Procedure(org.apache.cayenne.map.Procedure)

Example 72 with DbEntity

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

the class TableSelectorController method checkAllAction.

public void checkAllAction() {
    boolean isCheckAllSelected = view.getCheckAll().isSelected();
    if (isCheckAllSelected) {
        selectableTablesList.clear();
        selectableTablesList.addAll(tables);
        excludedTables.clear();
    } else {
        excludedTables.clear();
        for (DbEntity table : tables) {
            excludedTables.put(table.getName(), table);
        }
        selectableTablesList.clear();
    }
    tableBinding.updateView();
}
Also used : DbEntity(org.apache.cayenne.map.DbEntity)

Example 73 with DbEntity

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

the class ObjRelationshipInfo method createRelationship.

/**
 * Creates a new relationship connecting currently selected source entity
 * with ObjRelationship target entity. User is allowed to edit the
 * relationship, change its name, and create joins.
 */
protected void createRelationship() {
    DbRelationship dbRel = getLastRelationship();
    DbEntity source = dbRel != null ? dbRel.getTargetEntity() : null;
    DbRelationshipTarget targetModel = new DbRelationshipTarget(mediator, getStartEntity(), source);
    targetModel.startupAction();
    if (!targetModel.isSavePressed()) {
        return;
    }
    DbRelationship dbRelationship = new DbRelationship();
    dbRelationship.setSourceEntity(targetModel.getSource());
    dbRelationship.setTargetEntityName(targetModel.getTarget());
    dbRelationship.setToMany(targetModel.isToMany());
    dbRelationship.setName(createNamingStrategy(NameGeneratorPreferences.getInstance().getLastUsedStrategies().get(0)).relationshipName(dbRelationship));
    targetModel.getSource().addRelationship(dbRelationship);
    // TODO: creating relationship outside of ResolveDbRelationshipDialog
    // confuses it to send incorrect event - CHANGE instead of ADD
    ResolveDbRelationshipDialog dialog = new ResolveDbRelationshipDialog(dbRelationship);
    dialog.setVisible(true);
    if (dialog.isCancelPressed()) {
        targetModel.getSource().removeRelationship(dbRelationship.getName());
    } else {
        MultiColumnBrowser pathBrowser = getPathBrowser();
        Object[] oldPath = targetModel.isSource1Selected() ? new Object[] { getStartEntity() } : pathBrowser.getSelectionPath().getPath();
        /**
         * Update the view
         */
        EntityTreeModel treeModel = (EntityTreeModel) pathBrowser.getModel();
        treeModel.invalidate();
        pathBrowser.setSelectionPath(new TreePath(new Object[] { getStartEntity() }));
        pathBrowser.repaint();
        Object[] path = new Object[oldPath.length + 1];
        System.arraycopy(oldPath, 0, path, 0, path.length - 1);
        path[path.length - 1] = dbRelationship;
        pathBrowser.setSelectionPath(new TreePath(path));
    }
    dialog.dispose();
}
Also used : ResolveDbRelationshipDialog(org.apache.cayenne.modeler.dialog.ResolveDbRelationshipDialog) MultiColumnBrowser(org.apache.cayenne.modeler.util.MultiColumnBrowser) DbEntity(org.apache.cayenne.map.DbEntity) TreePath(javax.swing.tree.TreePath) EntityTreeModel(org.apache.cayenne.modeler.util.EntityTreeModel) DbRelationship(org.apache.cayenne.map.DbRelationship)

Example 74 with DbEntity

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

the class ObjRelationshipInfo method valueChanged.

/**
 * Sets list of DB Relationships current ObjRelationship is mapped to
 */
public void valueChanged(TreeSelectionEvent e) {
    TreePath selectedPath = e.getPath();
    // at least two elements to constitute a valid ordering path
    if (selectedPath == null || selectedPath.getPathCount() < 2) {
        return;
    }
    Relationship rel = (Relationship) selectedPath.getLastPathComponent();
    DbEntity target = (DbEntity) rel.getTargetEntity();
    /**
     * Initialize root with one of mapped ObjEntities.
     */
    Collection<ObjEntity> objEntities = target.getDataMap().getMappedEntities(target);
    List<DbRelationship> relPath = new Vector<DbRelationship>(selectedPath.getPathCount() - 1);
    for (int i = 1; i < selectedPath.getPathCount(); i++) {
        relPath.add((DbRelationship) selectedPath.getPathComponent(i));
    }
    setDbRelationships(relPath);
    updateCollectionChoosers();
}
Also used : ObjEntity(org.apache.cayenne.map.ObjEntity) TreePath(javax.swing.tree.TreePath) DbEntity(org.apache.cayenne.map.DbEntity) Relationship(org.apache.cayenne.map.Relationship) DbRelationship(org.apache.cayenne.map.DbRelationship) ObjRelationship(org.apache.cayenne.map.ObjRelationship) DbRelationship(org.apache.cayenne.map.DbRelationship) Vector(java.util.Vector)

Example 75 with DbEntity

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

the class SybaseUnitDbAdapter method willCreateTables.

@Override
public void willCreateTables(Connection con, DataMap map) throws Exception {
    // Sybase does not support NULLable BIT columns...
    DbEntity e = map.getDbEntity("PRIMITIVES_TEST");
    if (e != null) {
        e.getAttribute("BOOLEAN_COLUMN").setMandatory(true);
    }
    DbEntity e1 = map.getDbEntity("INHERITANCE_SUB_ENTITY3");
    if (e1 != null) {
        e1.getAttribute("SUBENTITY_BOOL_ATTR").setMandatory(true);
    }
    DbEntity e2 = map.getDbEntity("MT_TABLE_BOOL");
    if (e2 != null) {
        e2.getAttribute("BOOLEAN_COLUMN").setMandatory(true);
    }
    DbEntity e3 = map.getDbEntity("QUALIFIED1");
    if (e3 != null) {
        e3.getAttribute("DELETED").setMandatory(true);
    }
    DbEntity e4 = map.getDbEntity("QUALIFIED2");
    if (e4 != null) {
        e4.getAttribute("DELETED").setMandatory(true);
    }
    DbEntity e5 = map.getDbEntity("Painting");
    if (e5 != null) {
        if (e5.getAttribute("NEWCOL2") != null) {
            e5.getAttribute("DELETED").setMandatory(true);
        }
    }
    DbEntity e6 = map.getDbEntity("SOFT_TEST");
    if (e6 != null) {
        e6.getAttribute("DELETED").setMandatory(true);
    }
}
Also used : DbEntity(org.apache.cayenne.map.DbEntity)

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