/** * A part of the facade over the JPA API * Create an EntityManager from the EntityManagerFactory wrapped by this persistence context * @param tenantId * @return */ protected EntityManager createEntityManager(String tenantId) { return getEmf().createEntityManager(); }
/** * A part of the facade over the JPA API * Create an EntityManager from the EntityManagerFactory wrapped by this persistence context * @param tenantId * @return */ protected EntityManager createEntityManager(String tenantId) { return getEmf().createEntityManager(); }
/** * Query multiple results. * * @param tenantId the tenant id * @param name the name * @param parameters the parameters * @param hints the hints * @return the list */ @SuppressWarnings("rawtypes") public List queryMultipleResults(Map<String, String> tenantId, String name, Map<?, ?> parameters, Map<String, ?> hints) { EntityManager em = getEmf().createEntityManager(tenantId); try { Query query = constructQuery(em, name, parameters, hints); return query.getResultList(); } finally { em.close(); } }
/** * A part of the facade over the JPA API * Find an entity with the given name and id in JPA * @param tenantId * @param entityName * @param id * @param properties - query hints used on the find * @return */ public Object find(Map<String, String> tenantId, String entityName, Object id, Map<String, Object> properties) { EntityManager em = getEmf().createEntityManager(tenantId); try { return em.find(getClass(entityName), id, properties); } finally { em.close(); } }
/** * A part of the facade over the JPA API * Find an entity with the given name and id in JPA * @param tenantId * @param entityName * @param id * @param properties - query hints used on the find * @return */ public Object find(Map<String, String> tenantId, String entityName, Object id, Map<String, Object> properties) { EntityManager em = getEmf().createEntityManager(tenantId); try { return em.find(getClass(entityName), id, properties); } finally { em.close(); } }
/** * Query multiple results. * * @param tenantId the tenant id * @param name the name * @param parameters the parameters * @param hints the hints * @return the list */ @SuppressWarnings("rawtypes") public List queryMultipleResults(Map<String, String> tenantId, String name, Map<?, ?> parameters, Map<String, ?> hints) { EntityManager em = getEmf().createEntityManager(tenantId); try { Query query = constructQuery(em, name, parameters, hints); return query.getResultList(); } finally { em.close(); } }
/** * Does exist. * * @param tenantId the tenant id * @param entity the entity * @return true, if successful */ public boolean doesExist(Map<String, String> tenantId, Object entity) { DatabaseSession session = JpaHelper.getDatabaseSession(getEmf()); return session.doesObjectExist(entity); }
/** * Does exist. * * @param tenantId the tenant id * @param entity the entity * @return true, if successful */ public boolean doesExist(Map<String, String> tenantId, Object entity) { DatabaseSession session = JpaHelper.getDatabaseSession(getEmf()); return session.doesObjectExist(entity); }
/** * A part of the facade over the JPA API. * Persist an entity in JPA and commit. * @param tenantId * @param entity * @throws Exception */ public void create(Map<String, String> tenantId, Object entity) throws Exception { EntityManager em = getEmf().createEntityManager(tenantId); try { transaction.beginTransaction(em); em.persist(entity); transaction.commitTransaction(em); } catch (RollbackException ex) { throw ex; } catch (Exception ex) { transaction.rollbackTransaction(em); throw ex; } finally { em.close(); } }
/** * A part of the facade over the JPA API. * Persist an entity in JPA and commit. * @param tenantId * @param entity * @throws Exception */ public void create(Map<String, String> tenantId, Object entity) throws Exception { EntityManager em = getEmf().createEntityManager(tenantId); try { transaction.beginTransaction(em); em.persist(entity); transaction.commitTransaction(em); } catch (RollbackException ex) { throw ex; } catch (Exception ex) { transaction.rollbackTransaction(em); throw ex; } finally { em.close(); } }
EntityManager em = getEmf().createEntityManager(tenantId); Object mergedEntity; try {
EntityManager em = getEmf().createEntityManager(tenantId); Object mergedEntity; try {
/** * A part of the facade over the JPA API * Delete the given entity in JPA and commit the changes */ public void delete(Map<String, String> tenantId, String type, Object id) { EntityManager em = getEmf().createEntityManager(tenantId); try { transaction.beginTransaction(em); Object entity = em.find(getClass(type), id); if (entity != null) { em.remove(entity); } transaction.commitTransaction(em); } catch (RollbackException ex) { throw JPARSException.exceptionOccurred(ex); } catch (Exception ex) { transaction.rollbackTransaction(em); throw JPARSException.exceptionOccurred(ex); } finally { em.close(); } }
/** * A part of the facade over the JPA API * Delete the given entity in JPA and commit the changes */ public void delete(Map<String, String> tenantId, String type, Object id) { EntityManager em = getEmf().createEntityManager(tenantId); try { transaction.beginTransaction(em); Object entity = em.find(getClass(type), id); if (entity != null) { em.remove(entity); } transaction.commitTransaction(em); } catch (RollbackException ex) { throw JPARSException.exceptionOccurred(ex); } catch (Exception ex) { transaction.rollbackTransaction(em); throw JPARSException.exceptionOccurred(ex); } finally { em.close(); } }
/** * Query execute update. * * @param tenantId the tenant id * @param name the name * @param parameters the parameters * @param hints the hints * @return the int */ public int queryExecuteUpdate(Map<String, String> tenantId, String name, Map<?, ?> parameters, Map<String, ?> hints) { EntityManager em = getEmf().createEntityManager(tenantId); try { Query query = constructQuery(em, name, parameters, hints); transaction.beginTransaction(em); int result = query.executeUpdate(); transaction.commitTransaction(em); return result; } catch (RollbackException ex) { throw JPARSException.exceptionOccurred(ex); } catch (Exception ex) { transaction.rollbackTransaction(em); throw JPARSException.exceptionOccurred(ex); } finally { em.close(); } }
/** * Query execute update. * * @param tenantId the tenant id * @param name the name * @param parameters the parameters * @param hints the hints * @return the int */ public int queryExecuteUpdate(Map<String, String> tenantId, String name, Map<?, ?> parameters, Map<String, ?> hints) { EntityManager em = getEmf().createEntityManager(tenantId); try { Query query = constructQuery(em, name, parameters, hints); transaction.beginTransaction(em); int result = query.executeUpdate(); transaction.commitTransaction(em); return result; } catch (RollbackException ex) { throw JPARSException.exceptionOccurred(ex); } catch (Exception ex) { transaction.rollbackTransaction(em); throw JPARSException.exceptionOccurred(ex); } finally { em.close(); } }
/** * A convenience method to create a new dynamic entity of the given type * @param tenantId * @param type * @return */ public DynamicEntity newEntity(Map<String, String> tenantId, String type) { JPADynamicHelper helper = new JPADynamicHelper(getEmf()); DynamicEntity entity; try { entity = helper.newDynamicEntity(type); } catch (IllegalArgumentException e) { ClassDescriptor descriptor = getDescriptor(type); if (descriptor != null) { DynamicType jaxbType = (DynamicType) descriptor.getProperty(DynamicType.DESCRIPTOR_PROPERTY); if (jaxbType != null) { return jaxbType.newDynamicEntity(); } } JPARSLogger.exception("exception_thrown_while_creating_dynamic_entity", new Object[] { type }, e); throw e; } return entity; }
/** * A convenience method to create a new dynamic entity of the given type * @param tenantId * @param type * @return */ public DynamicEntity newEntity(Map<String, String> tenantId, String type) { JPADynamicHelper helper = new JPADynamicHelper(getEmf()); DynamicEntity entity; try { entity = helper.newDynamicEntity(type); } catch (IllegalArgumentException e) { ClassDescriptor descriptor = getDescriptor(type); if (descriptor != null) { DynamicType jaxbType = (DynamicType) descriptor.getProperty(DynamicType.DESCRIPTOR_PROPERTY); if (jaxbType != null) { return jaxbType.newDynamicEntity(); } } JPARSLogger.exception(getSessionLog(), "exception_thrown_while_creating_dynamic_entity", new Object[] { type }, e); throw e; } return entity; }
((FetchGroupTracker) entity)._persistence_setSession(JpaHelper.getDatabaseSession(getEmf())); } else if (descriptor.hasRelationships()) { for (DatabaseMapping mapping : descriptor.getMappings()) {
((FetchGroupTracker) entity)._persistence_setSession(JpaHelper.getDatabaseSession(getEmf())); } else if (descriptor.hasRelationships()) { for (DatabaseMapping mapping : descriptor.getMappings()) {