@Test public void checkCreateEntity() throws ODataJPAProcessException, ODataJPAModelException { doReturn(helper.getJPAEntityType("AdministrativeDivisions")).when(requestEntity).getEntityType(); data.put("divisionCode", "DE51"); data.put("codeID", "NUTS2"); data.put("countryCode", "DEU"); data.put("codePublisher", "Eurostat"); final Object act = cut.createEntity(requestEntity, em); assertNotNull(act); assertEquals("NUTS2", ((AdministrativeDivision) act).getCodeID()); verify(em).persist(act); }
@Override public Object createEntity(final JPARequestEntity requestEntity, final EntityManager em) throws ODataJPAProcessException { Object instance = null; if (requestEntity.getKeys().isEmpty()) { instance = createOneEntity(requestEntity, em, null); final Object old = em.find(requestEntity.getEntityType().getTypeClass(), requestEntity.getModifyUtil().createPrimaryKey(requestEntity.getEntityType(), instance)); if (old != null) throw new JPAExampleModifyException(ENTITY_ALREADY_EXISTS, HttpStatusCode.BAD_REQUEST); } else { instance = findEntity(requestEntity, em); } processRelatedEntities(requestEntity.getRelatedEntities(), instance, requestEntity.getModifyUtil(), em); em.persist(instance); return instance; }
JPAExampleCUDRequestHandler extends JPAAbstractCUDRequestHandler { @Override public Object createEntity(final JPARequestEntity requestEntity, final EntityManager em) throws ODataJPAProcessException { Object instance = null; if (requestEntity.getKeys().isEmpty()) { instance = createOneEntity(requestEntity, em, null); final Object old = em.find(requestEntity.getEntityType().getTypeClass(), requestEntity.getModifyUtil().createPrimaryKey(requestEntity.getEntityType(), instance)); if (old != null) throw new JPAExampleModifyException(ENTITY_ALREADY_EXISTS, HttpStatusCode.BAD_REQUEST); } else { instance = findEntity(requestEntity, em); } processRelatedEntities(requestEntity.getRelatedEntities(), instance, requestEntity.getModifyUtil(), em); em.persist(instance); return instance; } }
JPAExampleCUDRequestHandler extends JPAAbstractCUDRequestHandler { @Override public Object createEntity(final JPARequestEntity requestEntity, final EntityManager em) throws ODataJPAProcessException { Object instance = null; if (requestEntity.getKeys().isEmpty()) { instance = createOneEntity(requestEntity, em, null); final Object old = em.find(requestEntity.getEntityType().getTypeClass(), requestEntity.getModifyUtil().createPrimaryKey(requestEntity.getEntityType(), instance)); if (old != null) throw new JPAExampleModifyException(ENTITY_ALREADY_EXISTS, HttpStatusCode.BAD_REQUEST); } else { instance = findEntity(requestEntity, em); } processRelatedEntities(requestEntity.getRelatedEntities(), instance, requestEntity.getModifyUtil(), em); em.persist(instance); return instance; } JPAExampleCUDRequestHandler(); }
JPAExampleCUDRequestHandler extends JPAAbstractCUDRequestHandler { @Override public Object createEntity(final JPARequestEntity requestEntity, final EntityManager em) throws ODataJPAProcessException { Object instance = null; if (requestEntity.getKeys().isEmpty()) { instance = createOneEntity(requestEntity, em, null); final Object old = em.find(requestEntity.getEntityType().getTypeClass(), requestEntity.getModifyUtil().createPrimaryKey(requestEntity.getEntityType(), instance)); if (old != null) throw new JPAExampleModifyException(ENTITY_ALREADY_EXISTS, HttpStatusCode.BAD_REQUEST); } else { instance = findEntity(requestEntity, em); } processRelatedEntities(requestEntity.getRelatedEntities(), instance, requestEntity.getModifyUtil(), em); em.persist(instance); return instance; } JPAExampleCUDRequestHandler(); @Override Object createEntity(final JPARequestEntity requestEntity, final EntityManager em); @Override void deleteEntity(JPARequestEntity requestEntity, EntityManager em); @Override JPAUpdateResult updateEntity(final JPARequestEntity requestEntity, final EntityManager em,
      final HttpMethod method); @Override void validateChanges(EntityManager em); }
JPAExampleCUDRequestHandler extends JPAAbstractCUDRequestHandler { @Override public Object createEntity(final JPARequestEntity requestEntity, final EntityManager em) throws ODataJPAProcessException { Object instance = null; if (requestEntity.getKeys().isEmpty()) { instance = createOneEntity(requestEntity, em, null); final Object old = em.find(requestEntity.getEntityType().getTypeClass(), requestEntity.getModifyUtil().createPrimaryKey(requestEntity.getEntityType(), instance)); if (old != null) throw new JPAExampleModifyException(ENTITY_ALREADY_EXISTS, HttpStatusCode.BAD_REQUEST); } else { instance = findEntity(requestEntity, em); } processRelatedEntities(requestEntity.getRelatedEntities(), instance, requestEntity.getModifyUtil(), em); em.persist(instance); return instance; } JPAExampleCUDRequestHandler(); @Override Object createEntity(final JPARequestEntity requestEntity, final EntityManager em); @Override void deleteEntity(JPARequestEntity requestEntity, EntityManager em); @Override JPAUpdateResult updateEntity(final JPARequestEntity requestEntity, final EntityManager em,
      final HttpMethod method); @Override void validateChanges(EntityManager em);  }