@Override public String toString() { return "DynamicEntityType(" + getName() + ") - " + getDescriptor(); } }
@Override public Class<?> getPropertyType(String propertyName) { return getMapping(propertyName).getAttributeClassification(); }
/** * After entity is created, initialize all required attributes. * @param type * @param entity */ public void initializeProperties(DynamicTypeImpl type, DynamicEntityImpl entity) { if (type != null) { for (DatabaseMapping mapping : type.getMappingsRequiringInitialization()) { initializeDefaultValue(mapping, entity); } } }
public int getPropertyIndex(String propertyName) { return getMappings().indexOf(getMapping(propertyName)); }
public DynamicTypeInstantiationPolicy(DynamicTypeImpl type) { this.type = type; this.descriptor = type.getDescriptor(); }
RelationalDescriptor descriptor = new RelationalDescriptor(); descriptor.setJavaClass(dynamicClass); this.entityType = new DynamicTypeImpl(descriptor, parentType); DynamicPropertiesManager dpm = (DynamicPropertiesManager)dpmField.get(null); dpm.setType(entityType); entityType.setDynamicPropertiesManager(dpm);
/** * Lookup the constructor. */ @Override public void initialize(AbstractSession session) throws DescriptorException { try { this.constructor = PrivilegedAccessHelper.getDeclaredConstructorFor(getType().getJavaClass(), new Class[] { DynamicTypeImpl.class }, true); this.constructor.setAccessible(true); } catch (NoSuchMethodException exception) { throw DescriptorException.noSuchMethodWhileInitializingInstantiationPolicy(getType().getName() + ".<Default Constructor>", getDescriptor(), exception); } }
@Override public String marshal(Object v) throws Exception { if (null == v) { return null; } String href = null; String version = context.getVersion(); if (version != null) { href = baseURI + version + "/" + context.getName() + "/entity/" + v.getClass().getSimpleName() + "/" + IdHelper.stringifyId((DynamicEntityImpl) v, ((DynamicEntityImpl) v).getType().getName(), context); } else { href = baseURI + context.getName() + "/entity/" + v.getClass().getSimpleName() + "/" + IdHelper.stringifyId((DynamicEntityImpl) v, ((DynamicEntityImpl) v).getType().getName(), context); } return href; } }
ClassDescriptor desc = typ.getDescriptor(); DynamicTypeImpl typImpl = ((DynamicTypeImpl)typ); typImpl.setDescriptor(desc); try { Field dpmField = desc.getJavaClass().getField(DynamicPropertiesManager.PROPERTIES_MANAGER_FIELD); DynamicPropertiesManager dpm = (DynamicPropertiesManager)dpmField.get(null); dpm.setType(typImpl); typImpl.setDynamicPropertiesManager(dpm);
/** * Create an EntityTypeBuilder for an existing descriptor. This is used * * @param dcl * @param descriptor * @param parentType * provided since the InheritancePolicy on the descriptor may not * have its parent descriptor initialized. */ public DynamicTypeBuilder(DynamicClassLoader dcl, ClassDescriptor descriptor, DynamicType parentType) { this.entityType = new DynamicTypeImpl(descriptor, parentType); if (descriptor.getJavaClass() == null) { addDynamicClasses(dcl, descriptor.getJavaClassName(), parentType); } configure(descriptor); }
DynamicPropertiesManager dpm = (DynamicPropertiesManager)dpmField.get(null); dpm.setType(type); ((DynamicTypeImpl)type).setDynamicPropertiesManager(dpm);
public void checkSet(String propertyName, Object value) { if (contains(propertyName)) { type.checkSet(propertyName, value); } else { throw DynamicException.invalidPropertyName(type, propertyName); } }
public boolean contains(String propertyName) { boolean contains = false; if (type != null && type.getDescriptor() != null) { for (DatabaseMapping dm : type.getDescriptor().getMappings()) { if (dm.getAttributeName().equals(propertyName)) { contains = true; break; } } } return contains; }
RelationalDescriptor descriptor = new RelationalDescriptor(); descriptor.setJavaClass(dynamicClass); this.entityType = new DynamicTypeImpl(descriptor, parentType); DynamicPropertiesManager dpm = (DynamicPropertiesManager)dpmField.get(null); dpm.setType(entityType); entityType.setDynamicPropertiesManager(dpm);
@Override public String marshal(Object v) throws Exception { if (null == v) { return null; } String href = null; String version = context.getVersion(); if (version != null) { href = baseURI + version + "/" + context.getName() + "/entity/" + v.getClass().getSimpleName() + "/" + IdHelper.stringifyId((DynamicEntityImpl) v, ((DynamicEntityImpl) v).getType().getName(), context); } else { href = baseURI + context.getName() + "/entity/" + v.getClass().getSimpleName() + "/" + IdHelper.stringifyId((DynamicEntityImpl) v, ((DynamicEntityImpl) v).getType().getName(), context); } return href; } }
ClassDescriptor desc = typ.getDescriptor(); DynamicTypeImpl typImpl = ((DynamicTypeImpl)typ); typImpl.setDescriptor(desc); try { Field dpmField = desc.getJavaClass().getField(DynamicPropertiesManager.PROPERTIES_MANAGER_FIELD); DynamicPropertiesManager dpm = (DynamicPropertiesManager)dpmField.get(null); dpm.setType(typImpl); typImpl.setDynamicPropertiesManager(dpm);
RelationalDescriptor descriptor = new RelationalDescriptor(); descriptor.setJavaClass(dynamicClass); this.entityType = new DynamicTypeImpl(descriptor, parentType);
DynamicPropertiesManager dpm = (DynamicPropertiesManager)dpmField.get(null); dpm.setType(type); ((DynamicTypeImpl)type).setDynamicPropertiesManager(dpm);
public void checkSet(String propertyName, Object value) { if (contains(propertyName)) { type.checkSet(propertyName, value); } else { throw DynamicException.invalidPropertyName(type, propertyName); } }
public List<String> getPropertyNames() { List<String> propertyNames = new ArrayList<String>(); if (type != null && type.getDescriptor() != null) { for (DatabaseMapping dm : type.getDescriptor().getMappings()) { propertyNames.add(dm.getAttributeName()); } } return propertyNames; }