use of org.apache.cayenne.map.Entity in project cayenne by apache.
the class EntityEventTest method testNameChange1.
@Test
public void testNameChange1() throws Exception {
Entity d = new DbEntity("abc");
EntityEvent e = new EntityEvent(new Object(), d, "xyz");
assertEquals(d.getName(), e.getNewName());
assertTrue(e.isNameChange());
}
use of org.apache.cayenne.map.Entity in project cayenne by apache.
the class RootSelectionHandler method actionPerformed.
public void actionPerformed(ActionEvent ae) {
QueryDescriptor query = queryTab.getQuery();
if (query != null) {
Entity root = (Entity) queryTab.getQueryRoot().getModel().getSelectedItem();
if (root != null) {
query.setRoot(root);
if (needChangeName) {
// not changed by user
/*
* Doing auto name change, following CAY-888 #2
*/
String newPrefix = root.getName() + "Query";
newName = newPrefix;
DataMap map = queryTab.getMediator().getCurrentDataMap();
long postfix = 1;
while (map.getQueryDescriptor(newName) != null) {
newName = newPrefix + (postfix++);
}
queryTab.getNameField().setText(newName);
}
}
}
}
use of org.apache.cayenne.map.Entity in project cayenne by apache.
the class SQLTemplatePrefetchTab method initFromModel.
protected void initFromModel() {
QueryDescriptor query = mediator.getCurrentQuery();
if (query == null || !QueryDescriptor.SQL_TEMPLATE.equals(query.getType())) {
processInvalidModel("Unknown query.");
return;
}
if (!(query.getRoot() instanceof Entity)) {
processInvalidModel("SQLTemplate has no root set.");
return;
}
this.sqlTemplate = (SQLTemplateDescriptor) query;
browser.setModel(createBrowserModel((Entity) sqlTemplate.getRoot()));
table.setModel(createTableModel());
setUpPrefetchBox(table.getColumnModel().getColumn(2));
// init column sizes
table.getColumnModel().getColumn(0).setPreferredWidth(250);
cardLayout.show(this, REAL_PANEL);
}
use of org.apache.cayenne.map.Entity in project cayenne by apache.
the class SelectQueryMainTab method createQualifier.
/**
* Method to create and check an expression
* @param text String to be converted as Expression
* @return Expression if a new expression was created, null otherwise.
* @throws ValidationException if <code>text</code> can't be converted
*/
Expression createQualifier(String text) throws ValidationException {
SelectQueryDescriptor query = getQuery();
if (query == null) {
return null;
}
ExpressionConvertor convertor = new ExpressionConvertor();
try {
String oldQualifier = convertor.valueAsString(query.getQualifier());
if (!Util.nullSafeEquals(oldQualifier, text)) {
Expression exp = (Expression) convertor.stringAsValue(text);
/*
* Advanced checking. See CAY-888 #1
*/
if (query.getRoot() instanceof Entity) {
checkExpression((Entity) query.getRoot(), exp);
}
return exp;
}
return null;
} catch (IllegalArgumentException ex) {
// unparsable qualifier
throw new ValidationException(ex.getMessage());
}
}
use of org.apache.cayenne.map.Entity in project cayenne by apache.
the class ObjAttributeInfoDialog method getFirstEntity.
private Entity getFirstEntity() {
Iterator<CayenneMapEntry> it = attribute.getDbPathIterator();
Entity firstEnt = attribute.getDbAttribute().getEntity();
boolean setEnt = false;
while (it.hasNext()) {
Object ob = it.next();
if (ob instanceof DbRelationship) {
if (!setEnt) {
firstEnt = ((DbRelationship) ob).getSourceEntity();
setEnt = true;
}
} else if (ob instanceof DbAttribute) {
if (!setEnt) {
firstEnt = ((DbAttribute) ob).getEntity();
}
}
}
return firstEnt;
}
Aggregations