private List<ObjAttribute> getDuplicatedAttributes(ObjEntity superEntity) { List<ObjAttribute> result = new LinkedList<ObjAttribute>(); ObjEntity entity = mediator.getCurrentObjEntity(); for (ObjAttribute attribute : entity.getAttributes()) { if (superEntity.getAttribute(attribute.getName()) != null) { result.add(attribute); } } return result; }
private void appendSimpleProperties(Map<String, Object> dbDiff) { // populate changed columns if (currentPropertyDiff != null) { for (final Map.Entry<Object, Object> entry : currentPropertyDiff.entrySet()) { ObjAttribute attribute = objEntity.getAttribute(entry.getKey().toString()); // In case of a flattened attribute, ensure that it belongs to this bucket... DbAttribute dbAttribute = attribute.getDbAttribute(); if (dbAttribute.getEntity() == dbEntity) { dbDiff.put(dbAttribute.getName(), entry.getValue()); } } } }
ObjAttribute attribute = descriptor.getEntity().getAttribute(path); attributes.put(path, attribute);
private void appendSimpleProperties(Map dbDiff) { // populate changed columns if (currentPropertyDiff != null) { Iterator it = currentPropertyDiff.entrySet().iterator(); while (it.hasNext()) { Map.Entry entry = (Map.Entry) it.next(); ObjAttribute attribute = (ObjAttribute) objEntity.getAttribute(entry .getKey() .toString()); // this takes care of the flattened attributes, as 'getDbAttributeName' // returns the last path component... Attribute dbAttribute = dbEntity.getAttribute(attribute .getDbAttributeName()); dbDiff.put(dbAttribute.getName(), entry.getValue()); } } }
void addObjectField(String attributeName, String column) { ObjEntity entity = classDescriptor.getEntity(); ObjAttribute attribute = entity.getAttribute(attributeName); fields.put(attribute.getDbAttributePath(), column); reverseFields.put(column, attribute.getDbAttributePath()); }
AttributePropertyDecorator(ClassDescriptor owningClassDescriptor, AttributeProperty delegate) { this.delegate = delegate; this.attribute = owningClassDescriptor.getEntity().getAttribute(delegate.getName()); }
@Override public boolean isNameInUse(String name) { ObjEntity entity = (ObjEntity) parent; if (entity.getCallbackMethods().contains(name)) { return true; } if (name.startsWith("get")) { String conflictingProperty = NameUtil.uncapitalize(name.substring(3)); // check if either attribute or relationship name matches... if (entity.getAttribute(conflictingProperty) != null || entity.getRelationship(conflictingProperty) != null) { return true; } } return false; } });
@Override public boolean isNameInUse(String name) { ObjEntity entity = (ObjEntity) parent; // check if either attribute or relationship name matches... if (entity.getAttribute(name) != null || entity.getRelationship(name) != null) { return true; } // check if there's a callback method that shadows attribute getter (unlikely, but still) String conflictingCallback = "get" + NameUtil.capitalize(name); return entity.getCallbackMethods().contains(conflictingCallback); } });
/** * Returns a named attribute that either belongs to this ObjEntity or is inherited. * Returns null if no matching attribute is found. */ public Attribute getAttribute(String name) { Attribute attribute = super.getAttribute(name); if (attribute != null) { return attribute; } if (superEntityName == null) { return null; } ObjEntity superEntity = getSuperEntity(); return (superEntity != null) ? superEntity.getAttribute(name) : null; }
protected void processLastPathComponent() { ObjAttribute attribute = currentEntity.getAttribute(lastPathComponent); if (attribute != null) { processTerminatingAttribute(attribute); return; } ObjRelationship relationship = currentEntity.getRelationship(lastPathComponent); if (relationship != null) { processTerminatingRelationship(relationship); return; } throw new IllegalStateException("Invalid path component: " + lastPathComponent); }
public void setDuplicatedAttributes(List<ObjAttribute> attributes) { if (duplicatedAttributes == null) { duplicatedAttributes = new LinkedList<DuplicatedAttributeInfo>(); } duplicatedAttributes.clear(); for (ObjAttribute attribute : attributes) { DuplicatedAttributeInfo attributeInfo = new DuplicatedAttributeInfo(attribute.getName(), attribute.getType(), superEntity.getAttribute(attribute.getName()).getType(), DELETE_ACTION); duplicatedAttributes.add(attributeInfo); } attributesTable.setModel(new DuplicatedAttributeTableModel(getMediator(), this, duplicatedAttributes)); }
/** * Adds a result set column mapping for a single object property of a * specified entity that may differ from the root entity if inheritance is * involved. */ void addObjectField(String entityName, String attributeName, String column) { ObjEntity entity = classDescriptor.getEntity().getDataMap().getObjEntity(entityName); ObjAttribute attribute = entity.getAttribute(attributeName); fields.put(attribute.getDbAttributePath(), column); reverseFields.put(column, attribute.getDbAttributePath()); }
/** * Returns <code>true</code> if attribute inherited from a super entity. * * @since 3.0 */ public boolean isInherited() { ObjEntity owningEntity = getEntity(); if (owningEntity == null) { return false; } ObjEntity superEntity = owningEntity.getSuperEntity(); if (superEntity == null) { return false; } return superEntity.getAttribute(getName()) != null; }
ObjAttribute embedded = getAttribute(name.substring(0, dot)); if (embedded instanceof EmbeddedAttribute) { return ((EmbeddedAttribute) embedded).getAttribute(name.substring(dot + 1)); if (superEntity != null) { ObjAttribute superAttribute = superEntity.getAttribute(name); if (superAttribute == null) { return null;
private void applyChanges() { for (DuplicatedAttributeInfo attributeInfo : duplicatedAttributes) { if (attributeInfo.getAction().equals(DELETE_ACTION)) { entity.removeAttribute(attributeInfo.getName()); } if (attributeInfo.getAction().equals(RENAME_ACTION)) { ProjectUtil.setAttributeName(entity.getAttribute(attributeInfo.getName()), attributeInfo.getNewName()); } } }
/** * Returns a map of result column names to attribute db paths from the root * entity. */ public Map<String, String> getDbFields(EntityResolver resolver) { if (this.fields == null) { return Collections.emptyMap(); } Map<String, String> dbFields = new HashMap<>(); for (FieldResult field : fields) { if (field.isDbAttribute() || field.getAttributeName().startsWith("fetch.")) { dbFields.put(field.getAttributeName(), field.getColumn()); } else { ObjEntity entity = field.getEntityName() != null ? resolver.getObjEntity(field.getEntityName()) : getRootEntity(resolver); ObjAttribute attribute = entity.getAttribute(field.getAttributeName()); dbFields.put(attribute.getDbAttributePath(), field.getColumn()); } } return dbFields; }
ObjAttribute attribute = (ObjAttribute) targetEntity.getAttribute(relationship .getMapKey()); if (attribute == null) {
ObjAttribute attribute = targetEntity.getAttribute(relationship.getMapKey()); if (attribute == null) { throw new CayenneRuntimeException("Invalid map key '%s', no matching attribute found", relationship.getMapKey());
private void checkSuperEntityAttributes(ObjAttribute attribute, ValidationResult validationResult) { // Check there is an attribute in entity and super entity at the same time boolean selfAttribute = false; if (attribute.getEntity().getDeclaredAttribute(attribute.getName()) != null) { selfAttribute = true; } ObjEntity superEntity = attribute.getEntity().getSuperEntity(); if (selfAttribute && superEntity != null && superEntity.getAttribute(attribute.getName()) != null) { addFailure(validationResult, attribute, "'%s' and super '%s' can't have attribute '%s' together ", attribute.getEntity().getName(), superEntity.getName(), attribute.getName()); } }
@Test public void testGet_CompoundId_UnmappedPk() { // remove a part of PK from the ObjEntity DataMap dataMap = DB.getCayenneStack().getChannel().getEntityResolver().getDataMap("datamap"); ObjEntity E17 = dataMap.getObjEntity("E17"); ObjAttribute unmappedAttribute = E17.getAttribute("id2"); E17.removeAttribute("id2"); insert("e17", "id1, id2, name", "1, 1, 'aaa'"); insert("e17", "id1, id2, name", "2, 2, 'bbb'"); insert("e18", "id, e17_id1, e17_id2, name", "1, 1, 1, 'xxx'"); insert("e18", "id, e17_id1, e17_id2, name", "2, 1, 1, 'yyy'"); insert("e18", "id, e17_id1, e17_id2, name", "3, 2, 2, 'zzz'"); Response r1 = target("/e18/1").queryParam("include", E18.E17.getName()).request().get(); assertEquals(Status.OK.getStatusCode(), r1.getStatus()); assertEquals("{\"data\":[{\"id\":1,\"" + "e17\":{\"id\":{\"id1\":1,\"id2\":1},\"id1\":1,\"name\":\"aaa\"}," + "\"name\":\"xxx\"}],\"total\":1}", r1.readEntity(String.class)); // restore initial state E17.addAttribute(unmappedAttribute); }