public String getQualifiedClassName() { return entity.getClassName(); }
public String getQualifiedClassName() { return entity.getClassName(); }
/** * @since 4.0 */ public ObjEntity getObjEntity(Class<?> entityClass) { if (entityClass == null) { return null; } String className = entityClass.getName(); for (ObjEntity e : objEntityMap.values()) { if (className.equals(e.getClassName())) { return e; } } return null; }
/** * 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; }
/** * 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; }
/** * Returns an ObjEntity for a DataObject class name. * * @since 1.1 */ public ObjEntity getObjEntityForJavaClass(String javaClassName) { if (javaClassName == null) { return null; } for (ObjEntity entity : getObjEntities()) { if (javaClassName.equals(entity.getClassName())) { return entity; } } return null; }
protected String getClassName(ObjEntity entity) { return clientUpdate ? entity.getClientClassName() : entity.getClassName(); }
/** * Returns an ObjEntity for a DataObject class name. * * @since 1.1 */ public ObjEntity getObjEntityForJavaClass(String javaClassName) { if (javaClassName == null) { return null; } Iterator it = getObjEntityMap().entrySet().iterator(); while (it.hasNext()) { Map.Entry entry = (Map.Entry) it.next(); ObjEntity entity = (ObjEntity) entry.getValue(); if (javaClassName.equals(entity.getClassName())) { return entity; } } return null; }
/** * @deprecated since 1.2 */ public void setResultType(String resultType) { this.resultEntity = null; if (resultType != null) { // find entity with matching class name Iterator it = dataMap.getObjEntities().iterator(); while (it.hasNext()) { ObjEntity next = (ObjEntity) it.next(); if (resultType.equals(next.getClassName())) { this.resultEntity = next.getName(); break; } } } }
private Collection<Class<?>> getAnnotatedEntities(Class<? extends Annotation> annotationType) { Collection<Class<?>> entities = entitiesByAnnotation.get(annotationType.getName()); if (entities == null) { // ensure no dupes entities = new HashSet<>(); for (ObjEntity entity : entityResolver.getObjEntities()) { Class<?> entityType; try { entityType = Util.getJavaClass(entity.getClassName()); } catch (ClassNotFoundException e) { throw new CayenneRuntimeException("Class not found: " + entity.getClassName(), e); } // ensure that we don't register the same callback for multiple // classes in the same hierarchy, so find the topmost type using // a given annotation and register it once // TODO: This ignores "excludeSuperclassListeners" setting, // which is not possible with annotations anyways while (entityType != null && entityType.isAnnotationPresent(annotationType)) { Class<?> superType = entityType.getSuperclass(); if (superType == null || !superType.isAnnotationPresent(annotationType)) { entities.add(entityType); break; } entityType = superType; } } entitiesByAnnotation.put(annotationType.getName(), entities); } return entities; }
/** * Returns whether this entity is "generic", meaning it is not mapped to a * unique Java class. Criterion for generic entities is that it either has * no Java class mapped or its class is the same as DataMap's default * superclass, or it is CayenneDataObject. * * @since 1.2 */ public boolean isGeneric() { String className = getClassName(); return className == null || DEFAULT_GENERIC_CLASSES.contains(className) || (getDataMap() != null && className.equals(getDataMap().getDefaultSuperclass())); }
/** * Returns whether this entity is "generic", meaning it is not mapped to a unique Java * class. Criterion for generic entities is that it either has no Java class mapped or * its class is the same as DataMap's default superclass, or it is CayenneDataObject. * * @since 1.2 */ public boolean isGeneric() { String className = getClassName(); return className == null || DEFAULT_GENERIC_CLASSES.contains(className) || (getDataMap() != null && className.equals(getDataMap() .getDefaultSuperclass())); }
protected void compileSubclassMapping( EntityResolver resolver, Map subclassDescriptors, EntityInheritanceTree treeNode) { ObjEntity entity = treeNode.getEntity(); ClassDescriptor descriptor = resolver.getClassDescriptor(entity.getName()); subclassDescriptors.put(entity.getClassName(), descriptor); Iterator it = treeNode.getChildren().iterator(); while (it.hasNext()) { EntityInheritanceTree child = (EntityInheritanceTree) it.next(); compileSubclassMapping(resolver, subclassDescriptors, child); } }
void setClassName(String className) { if (className != null && className.trim().length() == 0) { className = null; } ObjEntity entity = mediator.getCurrentObjEntity(); // "ent" may be null if we quit editing by changing tree selection if (entity != null && !Util.nullSafeEquals(entity.getClassName(), className)) { entity.setClassName(className); mediator.fireObjEntityEvent(new EntityEvent(this, entity)); } }
/** * Returns a non-null class name. For generic entities with no class * specified explicitly, default DataMap superclass is used, and if it is * not set - CayenneDataObject is used. * * @since 4.0 */ public String getJavaClassName() { String name = getClassName(); if (name == null && getDataMap() != null) { name = getDataMap().getDefaultSuperclass(); } if (name == null) { name = CAYENNE_DATA_OBJECT_CLASS; } return name; }
private String suggestedServerClassName() { String pkg = entity.getDataMap() == null ? null : entity.getDataMap().getDefaultPackage(); return suggestedClassName(entity.getName(), pkg, entity.getClassName()); }
private ValidationFailure validateEntity(ObjEntity entity) { String name = entity.getName(); if (entity.isGeneric()) { return new SimpleValidationFailure(name, "Generic class"); } ValidationFailure emptyClass = BeanValidationFailure.validateNotEmpty(name, "className", entity.getClassName()); if (emptyClass != null) { return emptyClass; } ValidationFailure badClass = BeanValidationFailure.validateJavaClassName(name, "className", entity.getClassName()); if (badClass != null) { return badClass; } if (entity.getSuperClassName() != null) { ValidationFailure badSuperClass = BeanValidationFailure.validateJavaClassName(name, "superClassName", entity.getSuperClassName()); if (badSuperClass != null) { return badSuperClass; } } return null; }
/** * Returns Java class of persistent objects described by this entity. For generic * entities with no class specified explicitly, default DataMap superclass is used, * and if it is not set - CayenneDataObject is used. Casts any thrown exceptions into * CayenneRuntimeException. * * @since 1.2 */ public Class getJavaClass() { String name = getClassName(); if (name == null && getDataMap() != null) { name = getDataMap().getDefaultSuperclass(); } if (name == null) { name = CAYENNE_DATA_OBJECT_CLASS; } try { return Util.getJavaClass(name); } catch (ClassNotFoundException e) { throw new CayenneRuntimeException("Failed to load class " + name + ": " + e.getMessage(), e); } }
protected void indexSubclassDescriptors(PersistentDescriptor descriptor, EntityInheritanceTree inheritanceTree) { if (inheritanceTree != null) { for (EntityInheritanceTree child : inheritanceTree.getChildren()) { ObjEntity childEntity = child.getEntity(); descriptor.addSubclassDescriptor(childEntity.getClassName(), descriptorMap.getDescriptor(childEntity.getName())); indexSubclassDescriptors(descriptor, child); } } }
private void validateClassName(ObjEntity ent, ProjectPath path, Validator validator) { String className = ent.getClassName(); // if mapped to default class, ignore... if (Util.isEmptyString(className)) { return; } MappingNamesHelper helper = MappingNamesHelper.getInstance(); String invalidChars = helper.invalidCharsInJavaClassName(className); if (invalidChars != null) { validator.registerWarning( "ObjEntity Java class contains invalid characters: " + invalidChars, path); } else if (helper.invalidDataObjectClass(className)) { validator.registerWarning( "ObjEntity Java class is invalid: " + className, path); } else if (className.indexOf('.') < 0) { validator.registerWarning( "Placing Java class in default package is discouraged: " + className, path); } }