public Response processInsert(ObjectList insert) { // EntityTransaction tx = null; // EntityManager em = null; Response response = null; mapper = new CreateObjectsFromXml(requestCredentials, insert, null); try { // add objects to database // em = MorphbankConfig.getEntityManager(); // tx = em.getTransaction(); // tx.begin(); response = mapper.processObjects(); // tx.commit(); } catch (Exception e) { e.printStackTrace(); mapper.reportSuccess(null, null); // if (tx.isActive()) { // tx.rollback(); // } } return finalizeResponse(mapper.getResponse()); }
public Response processUpdate(Credentials requestCredentials, ObjectList update) { EntityTransaction tx = null; EntityManager em = null; boolean localTransaction = false; mapper = new UpdateObjectsFromXml(requestCredentials, update, MorphbankConfig.getRemoteServer()); try { // add objects to database // TODO process updates one object per transaction! // em = MorphbankConfig.getEntityManager(); // tx = em.getTransaction(); // if (!tx.isActive()) { // localTransaction = true; // tx.begin(); // } mapper.processObjects(); // if (localTransaction) tx.commit(); } catch (Exception e) { e.printStackTrace(); mapper.reportSuccess(null, null); if (localTransaction) tx.rollback(); } return finalizeResponse(mapper.getResponse()); }
public Response finalizeResponse(Response response) { // prepare status if (mapper != null) { StringBuffer status = new StringBuffer("All objects were "); if (mapper.failure) { status.append("not saved because of failure. Please see individual objects for details"); } else { status.append("saved"); } status.append("\nNumber of objects: ").append(mapper.numObjects); status.append("\nNumber of objects with insert problems: ").append(mapper.failedObjects); response.setStatus(status.toString()); response.setNumberAffected(mapper.failure ? 0 : mapper.successObjects); return mapper.getResponse(); } // must have been a query: no mapper if (response != null) response.setStatus("query ok"); return response; }