public void initJpa() { if (jpaPersistenceUnitName != null) { jpaEntityManagerFactory = JpaHelper.createEntityManagerFactory(jpaPersistenceUnitName); } if (jpaEntityManagerFactory != null) { sessionFactories.put(EntityManagerSession.class, new EntityManagerSessionFactory(jpaEntityManagerFactory, jpaHandleTransaction, jpaCloseEntityManager)); VariableType jpaType = variableTypes.getVariableType(JPAEntityVariableType.TYPE_NAME); // Add JPA-type if (jpaType == null) { // We try adding the variable right before SerializableType, if // available int serializableIndex = variableTypes.getTypeIndex(SerializableType.TYPE_NAME); if (serializableIndex > -1) { variableTypes.addType(new JPAEntityVariableType(), serializableIndex); } else { variableTypes.addType(new JPAEntityVariableType()); } } jpaType = variableTypes.getVariableType(JPAEntityListVariableType.TYPE_NAME); // Add JPA-list type after regular JPA type if not already present if (jpaType == null) { variableTypes.addType(new JPAEntityListVariableType(), variableTypes.getTypeIndex(JPAEntityVariableType.TYPE_NAME)); } } }
@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; }
@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); } }
@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 void initJpa() { if (jpaPersistenceUnitName != null) { jpaEntityManagerFactory = JpaHelper.createEntityManagerFactory(jpaPersistenceUnitName); } if (jpaEntityManagerFactory != null) { sessionFactories.put(EntityManagerSession.class, new EntityManagerSessionFactory(jpaEntityManagerFactory, jpaHandleTransaction, jpaCloseEntityManager)); VariableType jpaType = variableTypes.getVariableType(JPAEntityVariableType.TYPE_NAME); // Add JPA-type if (jpaType == null) { // We try adding the variable right before SerializableType, if // available int serializableIndex = variableTypes.getTypeIndex(SerializableType.TYPE_NAME); if (serializableIndex > -1) { variableTypes.addType(new JPAEntityVariableType(), serializableIndex); } else { variableTypes.addType(new JPAEntityVariableType()); } } jpaType = variableTypes.getVariableType(JPAEntityListVariableType.TYPE_NAME); // Add JPA-list type after regular JPA type if not already present if (jpaType == null) { variableTypes.addType(new JPAEntityListVariableType(), variableTypes.getTypeIndex(JPAEntityVariableType.TYPE_NAME)); } } }
@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); } }
@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<>(); String[] ids = deserializeIds(bytes); for (String id : ids) { result.add(mappings.getJPAEntity(entityClass, id)); } return result; } return null; }
protected void initJpa() { if (jpaPersistenceUnitName != null) { jpaEntityManagerFactory = JpaHelper.createEntityManagerFactory(jpaPersistenceUnitName); } if (jpaEntityManagerFactory != null) { sessionFactories.put(EntityManagerSession.class, new EntityManagerSessionFactory(jpaEntityManagerFactory, jpaHandleTransaction, jpaCloseEntityManager)); VariableType jpaType = variableTypes.getVariableType(JPAEntityVariableType.TYPE_NAME); // Add JPA-type if (jpaType == null) { // We try adding the variable right before SerializableType, if available int serializableIndex = variableTypes.getTypeIndex(SerializableType.TYPE_NAME); if (serializableIndex > -1) { variableTypes.addType(new JPAEntityVariableType(), serializableIndex); } else { variableTypes.addType(new JPAEntityVariableType()); } } jpaType = variableTypes.getVariableType(JPAEntityListVariableType.TYPE_NAME); // Add JPA-list type after regular JPA type if not already present if (jpaType == null) { variableTypes.addType(new JPAEntityListVariableType(), variableTypes.getTypeIndex(JPAEntityVariableType.TYPE_NAME)); } } }
@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 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); } }