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();
}
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();
}
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();
}
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();
}
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);
}
}
Aggregations