/** * Get the value of the entity identifier attribute. * * @param bean * a managed entity instance */ public Object getId(Object bean, EntityManager entityManager) { return Entity.forBean(bean).getIdentifier(bean); }
/** * Get the value of the entity identifier attribute. * * @param bean a managed entity instance */ public Object getId(Object bean, EntityManager entityManager) { return Entity.forClass( bean.getClass() ).getIdentifier(bean); }
/** * Returns the class of an entity bean instance * * @param bean * The entity bean instance * @return The class of the entity bean */ public Class getBeanClass(Object bean) { return Entity.forBean(bean).getBeanClass(); }
public Method getPrePersistMethod(Object bean, EntityManager entityManager) { return Entity.forBean(bean).getPrePersistMethod(); }
public Method getPreRemoveMethod(Object bean, EntityManager entityManager) { return Entity.forBean(bean).getPreRemoveMethod(); }
private void mergeAnnotationAndOrmXml(EjbEntityDescriptor descriptor) this.name = lookupName(getBeanClass(), descriptor); if (this.name == null) throw new NotEntityException("Unable to establish name of entity " + getBeanClass()); this.preRemoveMethod = getEntityCallbackMethod(getBeanClass(), descriptor.getPreRemoveMethodName()); this.prePersistMethod = getEntityCallbackMethod(getBeanClass(), descriptor.getPrePersistMethodName()); this.preUpdateMethod = getEntityCallbackMethod(getBeanClass(), descriptor.getPreUpdateMethodName()); this.postLoadMethod = getEntityCallbackMethod(getBeanClass(), descriptor.getPostLoadMethodName()); this.identifierField = descriptor.getIdentifierFieldName() != null ? Reflections.getField(getBeanClass(), descriptor.getIdentifierFieldName()) : null; this.identifierGetter = descriptor.getIdentifierPropertyName() != null ? Reflections.getGetterMethod(getBeanClass(), descriptor.getIdentifierPropertyName()) : null; this.versionField = descriptor.getVersionFieldName() != null ? Reflections.getField(getBeanClass(), descriptor.getVersionFieldName()) : null; this.versionGetter = descriptor.getVersionPropertyName() != null ? Reflections.getGetterMethod(getBeanClass(), descriptor.getVersionPropertyName()) : null; for ( Class<?> clazz=getBeanClass(); clazz!=Object.class; clazz = clazz.getSuperclass() ) setAccessible(this.preRemoveMethod); setAccessible(this.prePersistMethod); setAccessible(this.preUpdateMethod); setAccessible(this.postLoadMethod); setAccessible(this.identifierField); setAccessible(this.identifierGetter); setAccessible(this.versionField); setAccessible(this.versionGetter);
/** * Get the value of the entity version attribute. * * @param bean * a managed entity instance */ public Object getVersion(Object bean, EntityManager entityManager) { return Entity.forBean(bean).getVersion(bean); }
public Method getPostLoadMethod(Object bean, EntityManager entityManager) { return Entity.forBean(bean).getPostLoadMethod(); }
public Method getPreUpdateMethod(Object bean, EntityManager entityManager) { return Entity.forBean(bean).getPreUpdateMethod(); }
public Method getPrePersistMethod(Class beanClass, EntityManager entityManager) { return Entity.forClass(beanClass).getPrePersistMethod(); }
public Method getPostLoadMethod(Class beanClass, EntityManager entityManager) { return Entity.forClass(beanClass).getPostLoadMethod(); }
public Method getPreRemoveMethod(Class beanClass, EntityManager entityManager) { return Entity.forClass(beanClass).getPreRemoveMethod(); }
public Method getPreUpdateMethod(Class beanClass, EntityManager entityManager) { return Entity.forClass(beanClass).getPreUpdateMethod(); }
/** * Get the value of the entity version attribute. * * @param bean a managed entity instance */ public Object getVersion(Object bean, EntityManager entityManager) { return Entity.forClass( bean.getClass() ).getVersion(bean); }
/** * Get the name of the entity * * @param bean * @param entityManager * * @throws IllegalArgumentException if the passed object is not an entity */ public String getName(Object bean, EntityManager entityManager) throws IllegalArgumentException { return Entity.forClass(bean.getClass()).getName(); }
/** * Returns the class of an entity bean instance * * @param bean The entity bean instance * @return The class of the entity bean */ public Class getBeanClass(Object bean) { return Entity.forClass(bean.getClass()).getBeanClass(); }
public static Entity forClass(Class clazz) { if (!Contexts.isApplicationContextActive()) { throw new IllegalStateException("No application context active"); } Class entityClass = Seam.getEntityClass(clazz); if (entityClass == null) { throw new NotEntityException("Not an entity class: " + clazz.getName()); } String name = getModelName(entityClass); Model model = (Model) Contexts.getApplicationContext().get(name); if (model == null || !(model instanceof Entity)) { Entity entity = new Entity(entityClass); Contexts.getApplicationContext().set(name, entity); return entity; } else { return (Entity) model; } }
public static Entity forBean(Object bean) { return forClass(bean.getClass()); }
public Object getIdentifier(Object entity) { if (identifierGetter != null) { return Reflections.invokeAndWrap(identifierGetter, entity); } else if (identifierField != null) { return Reflections.getAndWrap(identifierField, entity); } else { throw new IllegalStateException("@Id attribute not found for entity class: " + getBeanClass().getName()); } }