use of org.apache.cayenne.map.Entity in project cayenne by apache.
the class DataMapUtils method getParameterNames.
private Map<String, String> getParameterNames(Expression expression, Object root) {
if (expression != null) {
Map<String, String> types = new HashMap<>();
String typeName = "";
List<String> names = new LinkedList<>();
for (int i = 0; i < expression.getOperandCount(); i++) {
Object operand = expression.getOperand(i);
if (operand instanceof Expression) {
types.putAll(getParameterNames((Expression) operand, root));
}
if (operand instanceof ASTObjPath) {
PathComponent<ObjAttribute, ObjRelationship> component = ((Entity) root).lastPathComponent((ASTObjPath) operand, null);
ObjAttribute attribute = component.getAttribute();
if (attribute != null) {
typeName = attribute.getType();
} else {
ObjRelationship relationship = component.getRelationship();
if (relationship != null) {
typeName = relationship.getTargetEntity().getClassName();
} else {
typeName = "Object";
}
}
}
if (operand instanceof ASTList) {
Object[] values = (Object[]) ((ASTList) operand).getOperand(0);
for (Object value : values) {
if (value instanceof ExpressionParameter) {
names.add(((ExpressionParameter) value).getName());
}
}
}
if (operand instanceof ExpressionParameter) {
names.add(((ExpressionParameter) operand).getName());
}
}
for (String name : names) {
types.put(Util.underscoredToJava(name, false), typeName);
}
return types;
}
return Collections.emptyMap();
}
use of org.apache.cayenne.map.Entity in project cayenne by apache.
the class SelectQueryValidator method validate.
void validate(SelectQueryDescriptor query, ValidationResult validationResult) {
validateName(query, validationResult);
validateCacheGroup(query, validationResult);
// Resolve root to Entity for further validation
Entity root = validateRoot(query, validationResult);
// validate path-based parts
if (root != null) {
validateQualifier(root, query.getQualifier(), validationResult);
for (final Ordering ordering : query.getOrderings()) {
validateOrdering(query, root, ordering, validationResult);
}
if (query.getPrefetchesMap() != null) {
for (String prefetchPath : query.getPrefetchesMap().keySet()) {
validatePrefetch(root, prefetchPath, validationResult);
}
}
}
}
use of org.apache.cayenne.map.Entity in project cayenne by apache.
the class EntityMergeSupport method addMissingRelationship.
private void addMissingRelationship(ObjEntity entity, DbRelationship dbRelationship) {
// getting DataMap from DbRelationship's source entity. This is the only object in our arguments that
// is guaranteed to be a part of the map....
DataMap dataMap = dbRelationship.getSourceEntity().getDataMap();
DbEntity targetEntity = dbRelationship.getTargetEntity();
Collection<ObjEntity> mappedObjEntities = dataMap.getMappedEntities(targetEntity);
if (mappedObjEntities.isEmpty()) {
if (targetEntity == null) {
targetEntity = new DbEntity(dbRelationship.getTargetEntityName());
}
if (dbRelationship.getTargetEntityName() != null) {
boolean needGeneratedEntity = createObjRelationship(entity, dbRelationship, nameGenerator.objEntityName(targetEntity));
if (needGeneratedEntity) {
LOGGER.warn("Can't find ObjEntity for " + dbRelationship.getTargetEntityName());
LOGGER.warn("Db Relationship (" + dbRelationship + ") will have GUESSED Obj Relationship reflection. ");
}
}
} else {
for (Entity mappedTarget : mappedObjEntities) {
createObjRelationship(entity, dbRelationship, mappedTarget.getName());
}
}
}
use of org.apache.cayenne.map.Entity in project cayenne by apache.
the class ObjEntityTabbedView method currentObjEntityChanged.
public void currentObjEntityChanged(EntityDisplayEvent e) {
Entity entity = e.getEntity();
if (e.isMainTabFocus() && entity instanceof ObjEntity) {
if (getSelectedComponent() != entityPanel) {
setSelectedComponent(entityPanel);
entityPanel.setVisible(true);
}
}
resetRemoveButtons();
setVisible(e.getEntity() != null);
if (getRootPane() != null) {
if (projectController.getEntityTabSelection() < getTabCount()) {
setSelectedIndex(projectController.getEntityTabSelection());
}
}
}
use of org.apache.cayenne.map.Entity in project cayenne by apache.
the class SelectQueryOrderingTab method initFromModel.
protected void initFromModel() {
QueryDescriptor query = mediator.getCurrentQuery();
if (query == null || !QueryDescriptor.SELECT_QUERY.equals(query.getType())) {
processInvalidModel("Unknown query.");
return;
}
if (!(query.getRoot() instanceof Entity)) {
processInvalidModel("SelectQuery has no root set.");
return;
}
this.selectQuery = (SelectQueryDescriptor) query;
browser.setModel(createBrowserModel((Entity) selectQuery.getRoot()));
table.setModel(createTableModel());
// init column sizes
table.getColumnModel().getColumn(0).setPreferredWidth(250);
cardLayout.show(this, REAL_PANEL);
}
Aggregations