public CayenneFieldType(ObjEntity objEntity, ObjAttribute objAttribute, SecureEntity secureEntity) { super(objAttribute.getName(), objAttribute.getJavaClass(), secureEntity); String capName = StringUtilities.capitalize(getName()); Class<?> declaringClass = objEntity.getJavaClass(); try { getter = declaringClass.getMethod("get" + capName); } catch (Exception e) {} if (getter == null) { try { getter = declaringClass.getMethod("is" + capName); } catch (Exception e) {} } if (getter != null) { try { setter = declaringClass.getMethod("set" + capName, getter.getReturnType()); } catch (Exception e) {} } } }
/** * Implements an attributes compilation step. Called internally from "compile". */ protected void compileAttributes(Map allDescriptors) { // only include this entity attributes and skip superclasses... Iterator it = entity.getDeclaredAttributes().iterator(); while (it.hasNext()) { ObjAttribute attribute = (ObjAttribute) it.next(); Class propertyType = attribute.getJavaClass(); PropertyAccessor accessor = makeAccessor(attribute.getName(), propertyType); allDescriptors.put(attribute.getName(), persistent ? new SimplePersistentProperty(this, accessor) : new SimpleProperty(this, accessor)); } }
protected void createAttributeProperty(PersistentDescriptor descriptor, ObjAttribute attribute) { Class<?> propertyType = attribute.getJavaClass(); Accessor accessor = createAccessor(descriptor, attribute.getName(), propertyType); descriptor.addDeclaredProperty(new SimpleAttributeProperty(descriptor, accessor, attribute)); }
protected void createEmbeddedAttributeProperty(PersistentDescriptor descriptor, EmbeddedAttribute embeddedAttribute, ObjAttribute attribute) { Class<?> embeddableClass = embeddedAttribute.getJavaClass(); String propertyPath = attribute.getName(); int lastDot = propertyPath.lastIndexOf('.'); if (lastDot <= 0 || lastDot == propertyPath.length() - 1) { throw new IllegalArgumentException("Invalid embeddable path: " + propertyPath); } String embeddableName = propertyPath.substring(lastDot + 1); EmbeddableDescriptor embeddableDescriptor = createEmbeddableDescriptor(embeddedAttribute); Accessor embeddedAccessor = createAccessor(descriptor, embeddedAttribute.getName(), embeddableClass); Accessor embeddedableAccessor = createEmbeddableAccessor(embeddableDescriptor, embeddableName, attribute.getJavaClass()); Accessor accessor = new EmbeddedFieldAccessor(embeddableDescriptor, embeddedAccessor, embeddedableAccessor); descriptor.addDeclaredProperty(new SimpleAttributeProperty(descriptor, accessor, attribute)); }
Mapper createSafeKeyMapper(Mapper unsafe) { KeyAdapter keyAdapter; if (paths.size() > 1) { // TODO: mapping keyMapAdapters by type doesn't take into account // composition and hierarchy of the keys ... need a different // approach. for now resorting to the hacks below keyAdapter = keyAdapterFactory.adapter(List.class); } else { Object attributeOrRelationship = ExpressionFactory.exp(paths.iterator().next()).evaluate(entity); Class<?> type; if (attributeOrRelationship instanceof ObjAttribute) { type = ((ObjAttribute) attributeOrRelationship).getJavaClass(); } else if (attributeOrRelationship instanceof ObjRelationship) { type = ((ObjRelationship) attributeOrRelationship).getTargetEntity().getJavaClass(); } else { type = null; } keyAdapter = keyAdapterFactory.adapter(type); } return new SafeMapKeyMapper(unsafe, keyAdapter); }
public EntityIdCoder(ObjEntity entity) { this.entityName = entity.getName(); this.converters = new TreeMap<String, Converter>(); for (ObjAttribute attribute : entity.getAttributes()) { if (attribute.isPrimaryKey()) { converters.put(attribute.getDbAttributeName(), create(attribute.getJavaClass())); } } for (DbAttribute attribute : entity.getDbEntity().getPrimaryKeys()) { if (!converters.containsKey(attribute.getName())) { String type = TypesMapping .getJavaBySqlType(attribute.getType()); try { converters.put(attribute.getName(), create(Util.getJavaClass(type))); } catch (ClassNotFoundException e) { throw new CayenneRuntimeException( "Can't instantiate class " + type, e); } } } if (converters.isEmpty()) { throw new IllegalArgumentException("Entity has no PK definied: " + entity.getName()); } this.idSize = (int) Math.ceil(converters.size() / 0.75d); }
Class<?> javaClass = objAttr.getJavaClass(); if (javaClass.isPrimitive() && value instanceof Number && ((Number) value).intValue() == 0) {