/** * Returns an ObjEntity stripped of any server-side information, such as DbEntity * mapping. "clientClassName" property of this entity is used to intialize "className" * property of returned entity. * * @since 1.2 */ public ObjEntity getClientEntity() { ObjEntity entity = new ObjEntity(getName()); entity.setClassName(getClientClassName()); entity.setSuperClassName(getClientSuperClassName()); entity.setSuperEntityName(getSuperEntityName()); // TODO: should we also copy lock type? // copy attributes Iterator attributes = getDeclaredAttributes().iterator(); while (attributes.hasNext()) { ObjAttribute attribute = (ObjAttribute) attributes.next(); entity.addAttribute(attribute.getClientAttribute()); } // copy relationships Iterator relationships = getDeclaredRelationships().iterator(); while (relationships.hasNext()) { ObjRelationship relationship = (ObjRelationship) relationships.next(); entity.addRelationship(relationship.getClientRelationship()); } return entity; }
/** * Creates an ObjectId from the values in the snapshot. If needed attributes are * missing in a snapshot, CayenneRuntimeException is thrown. */ // TODO: andrus, 5/25/2006 - deprecate this method - it is unused public ObjectId createObjectId(ObjEntity entity) { return createObjectId(entity.getName(), entity.getDbEntity()); }
public ObjRelationshipTableModel(ObjEntity entity, ProjectController mediator, Object eventSource) { super(mediator, eventSource, new ArrayList<>(entity.getRelationships())); this.entity = entity; // order using local comparator Collections.sort(objectList, new RelationshipComparator()); }
/** * Returns a fully-qualified name of the super class of the DataObject * class. This value is used as a hint for class generation. If the entity * inherits from another entity, a superclass is the class of that entity. */ public String getSuperClassName() { ObjEntity superEntity = getSuperEntity(); return (superEntity != null) ? superEntity.getClassName() : superClassName; }
protected String getClassName(ObjEntity entity) { return clientUpdate ? entity.getClientClassName() : entity.getClassName(); }
/** * Returns true if this entity is allowed to be used on the client. Checks * that parent DataMap allows client entities and also that this entity is * not explicitly disabled for the client use. * * @since 1.2 */ public boolean isClientAllowed() { return getDataMap() != null && !isServerOnly() && getDataMap().isClientSupported(); }
public void encodeAsXML(XMLEncoder encoder) { encoder.print("<obj-entity name=\""); encoder.print(getName()); if (getSuperEntityName() != null && getSuperEntity() != null) { encoder.print("\" superEntityName=\""); encoder.print(getSuperEntityName()); if (isAbstract()) { encoder.print("\" abstract=\"true"); if (isServerOnly()) { encoder.print("\" serverOnly=\"true"); if (getClassName() != null) { encoder.print("\" className=\""); encoder.print(getClassName()); if (getClientClassName() != null) { encoder.print("\" clientClassName=\""); encoder.print(getClientClassName()); if (isReadOnly()) { encoder.print("\" readOnly=\"true"); if (getDeclaredLockType() == LOCK_TYPE_OPTIMISTIC) { encoder.print("\" lock-type=\"optimistic"); if (getDbEntityName() != null && getDbEntity() != null) {
encoder.print(getName()); if (getSuperEntityName() != null && getSuperEntity() != null) { encoder.print("\" superEntityName=\""); encoder.print(getSuperEntityName()); if (isServerOnly()) { encoder.print("\" serverOnly=\"true"); if (getClassName() != null) { encoder.print("\" className=\""); encoder.print(getClassName()); if (getClientClassName() != null) { encoder.print("\" clientClassName=\""); encoder.print(getClientClassName()); if (isReadOnly()) { encoder.print("\" readOnly=\"true"); if (getDeclaredLockType() == LOCK_TYPE_OPTIMISTIC) { encoder.print("\" lock-type=\"optimistic"); if (getSuperEntityName() == null && getDbEntity() != null) { encoder.print("\" dbEntityName=\""); encoder.print(Util.encodeXmlAttribute(getDbEntityName())); if (getSuperEntityName() == null && getSuperClassName() != null) { encoder.print("\" superClassName=\"");
void validateSuperClassName(ObjEntity entity, ValidationResult validationResult) { String superClassName = entity.getSuperClassName(); entity, "ObjEntity '%s' Java superclass '%s' contains invalid characters: %s", entity.getName(), superClassName, invalidChars); entity, "ObjEntity '%s' Java superclass '%s' is a reserved word", entity.getName(), superClassName); if (entity.getDbEntityName() != null && entity.getSuperEntityName() != null) { addFailure( validationResult, entity, "Sub ObjEntity '%s' has database table declaration different from super ObjEntity '%s'", entity.getName(), entity.getSuperEntityName()); DataMap map = entity.getDataMap(); if (map == null) { return;
private String suggestedClientClassName() { // do not updated client class name if it is not allowed if (!entity.isClientAllowed()) { return null; } String pkg = entity.getDataMap() == null ? null : entity.getDataMap().getDefaultClientPackage(); return suggestedClassName(entity.getName(), pkg, entity.getClientClassName()); }
protected <T> void loadCayenneEntity(CayenneAgEntity<T> agEntity, AgDataMap dataMap) { for (ObjAttribute a : objEntity.getAttributes()) { Class<?> type = typeForName(a.getType()); CayenneAgAttribute agAttribute = new CayenneAgAttribute(a, type); for (ObjRelationship r : objEntity.getRelationships()) { List<DbRelationship> dbRelationshipsList = r.getDbRelationships(); for (DbAttribute pk : objEntity.getDbEntity().getPrimaryKeys()) { ObjAttribute attribute = objEntity.getAttributeForDbAttribute(pk); Class<?> type; AgAttribute id;
private void searchInObjEntities(Pattern pattern, List<SearchResultEntry> result, DataMap dataMap) { for (ObjEntity ent : dataMap.getObjEntities()) { if (match(ent.getName(), pattern)) { result.add(new SearchResultEntry(ent, ent.getName())); } for (ObjAttribute attr : ent.getAttributes()) { if (match(attr.getName(), pattern)) { result.add(new SearchResultEntry(attr, ent.getName() + "." + attr.getName())); } } for (ObjRelationship rel : ent.getRelationships()) { if (match(rel.getName(), pattern)) { result.add(new SearchResultEntry(rel, ent.getName() + "." + rel.getName())); } } } }
private String suggestedServerClassName() { String pkg = entity.getDataMap() == null ? null : entity.getDataMap().getDefaultPackage(); return suggestedClassName(entity.getName(), pkg, entity.getClassName()); }
public List<ObjEntity> getSelectedEntities() { List<ObjEntity> selected = new ArrayList<>(selectedEntities.size()); for (Object classObj : classes) { if (classObj instanceof ObjEntity && selectedEntities.contains(((ObjEntity) classObj).getName())) { selected.add(((ObjEntity) classObj)); } } return selected; }
if (entity == null || entity.getDbEntity() == null) { return false; while (rait.hasNext()) { DbAttribute da = (DbAttribute) rait.next(); ObjAttribute oa = entity.getAttributeForDbAttribute(da); while (oa != null) { String attrName = oa.getName(); entity.removeAttribute(attrName); changed = true; oa = entity.getAttributeForDbAttribute(da); entity.addAttribute(oa); changed = true; or.setSourceEntity(entity); or.setTargetEntity(mappedTarget); entity.addRelationship(or); changed = true;
private Collection<ObjAttribute> getMutablePrimaryKeys() { if (getDbEntity() == null) { throw new CayenneRuntimeException("No DbEntity for ObjEntity: %s", getName()); } Collection<DbAttribute> pkAttributes = getDbEntity().getPrimaryKeys(); Collection<ObjAttribute> attributes = new ArrayList<>(pkAttributes.size()); for (DbAttribute pk : pkAttributes) { ObjAttribute attribute = getAttributeForDbAttribute(pk); // create synthetic attribute if (attribute == null) { attribute = new SyntheticPKObjAttribute(Util.underscoredToJava(pk.getName(), false)); attribute.setDbAttributePath(pk.getName()); attribute.setType(TypesMapping.getJavaBySqlType(pk.getType())); } attributes.add(attribute); } return attributes; }
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()); } }
Map info = helper.entityPListMap(e.getName()); List rinfo = (List) info.get("relationships"); if (rinfo == null) { e.addRelationship(flatRel);
Map entityPlistMap = helper.entityPListMap(objEntity.getName()); List classProps = (List) entityPlistMap.get("classProperties"); List rinfo = (List) entityPlistMap.get("relationships"); DbEntity dbSrc = objEntity.getDbEntity(); Iterator it = rinfo.iterator(); while (it.hasNext()) { DbEntity dbTarget = target.getDbEntity(); Map targetPlistMap = helper.entityPListMap(targetName); Collection targetAttributes = (Collection) targetPlistMap.get("attributes"); rel.setSourceEntity(objEntity); rel.setTargetEntityName(target); objEntity.addRelationship(rel);
public int compare(ObjEntity o1, ObjEntity o2) { if (o1 == o2) { return 0; } DbEntity t1 = o1.getDbEntity(); DbEntity t2 = o2.getDbEntity(); return weightedDbEntityComparator.compare(t1, t2); } }