public JPAEntityVariableType() { mappings = new JPAEntityMappings(); }
public Object getJPAEntity(String className, String idString) { Class<?> entityClass = null; entityClass = ReflectUtil.loadClass(className); EntityMetaData metaData = getEntityMetaData(entityClass); // Create primary key of right type Object primaryKey = createId(metaData, idString); return findEntity(entityClass, primaryKey); }
public String getJPAIdString(Object value) { EntityMetaData metaData = getEntityMetaData(value.getClass()); if (!metaData.isJPAEntity()) { throw new ActivitiIllegalArgumentException("Object is not a JPA Entity: class='" + value.getClass() + "', " + value); } Object idValue = getIdValue(value, metaData); return getIdString(idValue); }
@Override public boolean isAbleToStore(Object value) { boolean canStore = false; if (value instanceof List<?>) { List<?> list = (List<?>) value; if (list.size() > 0) { // We can only store the list if we are sure it's actually a // list of JPA entities. In case the // list is empty, we don't store it. canStore = true; Class<?> entityClass = mappings.getEntityMetaData(list.get(0).getClass()).getEntityClass(); for (Object entity : list) { canStore = entity != null && mappings.isJPAEntity(entity) && mappings.getEntityMetaData(entity.getClass()).getEntityClass().equals(entityClass); if (!canStore) { // In case the object is not a JPA entity or the class // doesn't match, we can't store the list break; } } } } return canStore; }
@Override public void setValue(Object value, ValueFields valueFields) { EntityManagerSession entityManagerSession = Context.getCommandContext().getSession(EntityManagerSession.class); if (entityManagerSession == null) { throw new ActivitiException("Cannot set JPA variable: " + EntityManagerSession.class + " not configured"); } else { // Before we set the value we must flush all pending changes from // the entitymanager // If we don't do this, in some cases the primary key will not yet // be set in the object // which will cause exceptions down the road. entityManagerSession.flush(); } if (value instanceof List<?> && ((List<?>) value).size() > 0) { List<?> list = (List<?>) value; List<String> ids = new ArrayList<String>(); String type = mappings.getJPAClassString(list.get(0)); for (Object entry : list) { ids.add(mappings.getJPAIdString(entry)); } // Store type in text field and the ID's as a serialized array valueFields.setBytes(serializeIds(ids)); valueFields.setTextValue(type); } else if (value == null) { valueFields.setBytes(null); valueFields.setTextValue(null); } else { throw new ActivitiIllegalArgumentException("Value is not a list of JPA entities: " + value); } }
public boolean isJPAEntity(Object value) { if (value != null) { // EntityMetaData will be added for all classes, even those who are // not // JPA-entities to prevent unneeded annotation scanning return getEntityMetaData(value.getClass()).isJPAEntity(); } return false; }
@Override public Object getValue(ValueFields valueFields) { byte[] bytes = valueFields.getBytes(); if (valueFields.getTextValue() != null && bytes != null) { String entityClass = valueFields.getTextValue(); List<Object> result = new ArrayList<Object>(); String[] ids = deserializeIds(bytes); for (String id : ids) { result.add(mappings.getJPAEntity(entityClass, id)); } return result; } return null; }
public boolean isAbleToStore(Object value) { if (value == null) { return true; } return mappings.isJPAEntity(value); }
public void setValue(Object value, ValueFields valueFields) { EntityManagerSession entityManagerSession = Context.getCommandContext().getSession(EntityManagerSession.class); if (entityManagerSession == null) { throw new ActivitiException("Cannot set JPA variable: " + EntityManagerSession.class + " not configured"); } else { // Before we set the value we must flush all pending changes from // the entitymanager // If we don't do this, in some cases the primary key will not yet // be set in the object // which will cause exceptions down the road. entityManagerSession.flush(); } if (value != null) { String className = mappings.getJPAClassString(value); String idString = mappings.getJPAIdString(value); valueFields.setTextValue(className); valueFields.setTextValue2(idString); } else { valueFields.setTextValue(null); valueFields.setTextValue2(null); } }
public String getJPAClassString(Object value) { if (value == null) { throw new ActivitiIllegalArgumentException("null value cannot be saved"); } EntityMetaData metaData = getEntityMetaData(value.getClass()); if (!metaData.isJPAEntity()) { throw new ActivitiIllegalArgumentException("Object is not a JPA Entity: class='" + value.getClass() + "', " + value); } // Extract the class from the Entity instance return metaData.getEntityClass().getName(); }
@Override public boolean isAbleToStore(Object value) { boolean canStore = false; if (value instanceof List<?>) { List<?> list = (List<?>) value; if (list.size() > 0) { // We can only store the list if we are sure it's actually a // list of JPA entities. In case the // list is empty, we don't store it. canStore = true; Class<?> entityClass = mappings.getEntityMetaData(list.get(0).getClass()).getEntityClass(); for (Object entity : list) { canStore = entity != null && mappings.isJPAEntity(entity) && mappings.getEntityMetaData(entity.getClass()).getEntityClass().equals(entityClass); if (!canStore) { // In case the object is not a JPA entity or the class // doesn't match, we can't store the list break; } } } } return canStore; }
public Object getValue(ValueFields valueFields) { if (valueFields.getTextValue() != null && valueFields.getTextValue2() != null) { return mappings.getJPAEntity(valueFields.getTextValue(), valueFields.getTextValue2()); } return null; }
public boolean isAbleToStore(Object value) { if (value == null) { return true; } return mappings.isJPAEntity(value); }
public String getJPAIdString(Object value) { EntityMetaData metaData = getEntityMetaData(value.getClass()); if (!metaData.isJPAEntity()) { throw new ActivitiIllegalArgumentException("Object is not a JPA Entity: class='" + value.getClass() + "', " + value); } Object idValue = getIdValue(value, metaData); return getIdString(idValue); }
public Object getJPAEntity(String className, String idString) { Class<?> entityClass = null; entityClass = ReflectUtil.loadClass(className); EntityMetaData metaData = getEntityMetaData(entityClass); // Create primary key of right type Object primaryKey = createId(metaData, idString); return findEntity(entityClass, primaryKey); }
@Override public void setValue(Object value, ValueFields valueFields) { EntityManagerSession entityManagerSession = Context.getCommandContext().getSession(EntityManagerSession.class); if (entityManagerSession == null) { throw new ActivitiException("Cannot set JPA variable: " + EntityManagerSession.class + " not configured"); } else { // Before we set the value we must flush all pending changes from // the entitymanager // If we don't do this, in some cases the primary key will not yet // be set in the object // which will cause exceptions down the road. entityManagerSession.flush(); } if (value instanceof List<?> && ((List<?>) value).size() > 0) { List<?> list = (List<?>) value; List<String> ids = new ArrayList<String>(); String type = mappings.getJPAClassString(list.get(0)); for (Object entry : list) { ids.add(mappings.getJPAIdString(entry)); } // Store type in text field and the ID's as a serialized array valueFields.setBytes(serializeIds(ids)); valueFields.setTextValue(type); } else if (value == null) { valueFields.setBytes(null); valueFields.setTextValue(null); } else { throw new ActivitiIllegalArgumentException("Value is not a list of JPA entities: " + value); } }
public boolean isJPAEntity(Object value) { if (value != null) { // EntityMetaData will be added for all classes, even those who are // not // JPA-entities to prevent unneeded annotation scanning return getEntityMetaData(value.getClass()).isJPAEntity(); } return false; }
@Override public Object getValue(ValueFields valueFields) { byte[] bytes = valueFields.getBytes(); if (valueFields.getTextValue() != null && bytes != null) { String entityClass = valueFields.getTextValue(); List<Object> result = new ArrayList<Object>(); String[] ids = deserializeIds(bytes); for (String id : ids) { result.add(mappings.getJPAEntity(entityClass, id)); } return result; } return null; }
public JPAEntityListVariableType() { mappings = new JPAEntityMappings(); }
public boolean isAbleToStore(Object value) { if(value == null) { return true; } return mappings.isJPAEntity(value); }