List of usage examples for javax.persistence EntityManager persist
public void persist(Object entity);
From source file:de.zib.gndms.infra.tests.FileTransferActionTest.java
@Test(groups = { "net", "db", "sys", "action", "task" }) public void testIt() throws ResourceException, ExecutionException, InterruptedException { EntityManager em = null; try {// ww w. j av a 2s .c om em = getSys().getEntityManagerFactory().createEntityManager(); em.getTransaction().begin(); em.persist(task); em.getTransaction().commit(); FileTransferTaskAction action = new FileTransferTaskAction(em, task); Future<AbstractTask> serializableFuture = getSys().submitAction(action, log); assert serializableFuture.get().getState().equals(TaskState.FINISHED); FileTransferResult ftr = (FileTransferResult) task.getData(); for (String s : Arrays.asList(ftr.getFiles())) System.out.println(s); } finally { if (em != null && em.isOpen()) em.close(); } }
From source file:net.anthonychaves.bookmarks.service.UserService.java
public User createUser(User user) { EntityManager em = emf.createEntityManager(); em.getTransaction().begin();/* ww w .j a v a 2s . c om*/ String apiKey = UUID.randomUUID().toString().replaceAll("-", "").substring(0, 16).toUpperCase(); user.setApiKey(apiKey); em.persist(user); em.getTransaction().commit(); return user; }
From source file:net.anthonychaves.bookmarks.service.UserService.java
public User addBookmarks(User user, List<Bookmark> bookmarks) { EntityManager em = emf.createEntityManager(); em.getTransaction().begin();/*from www . j av a2s .c o m*/ User u = findUser(user.getEmailAddress()); for (Bookmark bookmark : bookmarks) { bookmark.setUser(u); em.persist(bookmark); u.getBookmarks().add(bookmark); } em.getTransaction().commit(); return u; }
From source file:org.nuxeo.ecm.platform.ec.placeful.PlacefulServiceImpl.java
public void setAnnotation(EntityManager em, Annotation annotation) { em.persist(annotation); }
From source file:com.emc.plants.service.impl.LoginBean.java
/** * Create a new user.//from w ww . j a va 2 s . co m * * @param customerID The new customer ID. * @param password The password for the customer ID. * @param firstName First name. * @param lastName Last name. * @param addr1 Address line 1. * @param addr2 Address line 2. * @param addrCity City address information. * @param addrState State address information. * @param addrZip Zip code address information. * @param phone User's phone number. * @return CustomerInfo */ //@Transactional public CustomerInfo createNewUser(String customerID, String password, String firstName, String lastName, String addr1, String addr2, String addrCity, String addrState, String addrZip, String phone) { CustomerInfo customerInfo = null; /* customerHome = (CustomerHome) Util.getEJBLocalHome("java:comp/env/ejb/Customer", com.ibm.websphere.samples.pbwjpa.CustomerHome.class); try { // Only create new user if it doesn't already exist. customerHome.findByPrimaryKeyUpdate(customerID); } catch (ObjectNotFoundException onfe) { // Create customer and return true if all goes well. Customer customer = customerHome.create(new CustomerKey(customerID), password, firstName, lastName, addr1, addr2, addrCity, addrState, addrZip, phone); if (customer != null) customerInfo = new CustomerInfo(customer); } } catch (FinderException e) { e.printStackTrace(); } catch (CreateException e) { e.printStackTrace(); } */ Customer c = new Customer(customerID, password, firstName, lastName, addr1, addr2, addrCity, addrState, addrZip, phone); EntityManager em = entityManagerFactory.createEntityManager(); em.getTransaction().begin(); em.persist(c); em.flush(); em.getTransaction().commit(); customerInfo = new CustomerInfo(c); return customerInfo; }
From source file:com.headissue.pigeon.admin.AdminSurveyHandler.java
public int createSurvey(SurveyParameter p) { checkNotNull(p, "parameter is null"); checkNotNull(p.getSurvey(), "survey values are null"); Survey _survey = adminSurveyService.createSurvey(p.getSurvey(), new Date(p.getTimestamp())); EntityManager _manager = factory.createEntityManager(); try {//ww w. ja va 2s .c o m _manager.getTransaction().begin(); _manager.persist(_survey); _manager.getTransaction().commit(); return _survey.getId(); } catch (Exception e) { LogUtils.warn(log, e, "save the survey failed"); if (_manager.getTransaction().isActive()) { _manager.getTransaction().rollback(); } return 0; } finally { _manager.close(); } }
From source file:com.headissue.pigeon.service.AdminSurveyServiceTest.java
@Before public void setUp() throws Exception { injector.injectMembers(this); SurveyValue _value = getSurveyValue("testSurvey.json"); survey = adminSurveyService.createSurvey(_value, CREATE_DATE); EntityManager _manager = factory.createEntityManager(); _manager.getTransaction().begin();//from w ww .j a v a 2 s. c om _manager.persist(survey); _manager.getTransaction().commit(); _manager.close(); UserAnswerValues a = new UserAnswerValues(); a.setPageKey("testSurvey"); a.setUserData("gans"); a.setUserKey("gustav"); a.setAnswers(new ArrayList<UserAnswerValue>()); AnswerParameter p = new AnswerParameter(); p.setSurveyId(survey.getId()); p.setTimestamp(ANSWER_DATE.getTime()); p.setValues(a); LogUtils.debug(log, "survey id: %s", survey.getId()); for (Question q : survey.getQuestions()) { LogUtils.debug(log, "querstion id: %s", q.getId()); UserAnswerValue v = new UserAnswerValue(); v.setQuestionId(q.getId()); v.setValues(Arrays.asList(q.getAnswers().get(0).getText())); a.getAnswers().add(v); for (QuestionText qt : q.getAnswers()) { LogUtils.debug(log, "answert id: %s", qt.getId()); } } SessionManager _sessionManager = new SessionManager(); AnswerHandler _answerHandler = injector.getInstance(AnswerHandler.class); _answerHandler.receiveAnswer(_sessionManager.getCurrentSession(), p); }
From source file:facades.PersonFacadeDB.java
@Override public Person addPerson(String json) { //make person from Json Person p = gson.fromJson(json, Person.class); EntityManagerFactory emf = Persistence.createEntityManagerFactory(persistenceFileName); EntityManager em = emf.createEntityManager(); EntityTransaction transaction = em.getTransaction(); transaction.begin();/* w ww .j a v a2s . c o m*/ try { em.persist(p); transaction.commit(); } catch (Exception e) { transaction.rollback(); } finally { em.close(); } return p; }
From source file:org.apache.openjpa.jdbc.meta.strats.AbstractLobTest.java
public void insert(LobEntity le) { EntityManager em = emf.createEntityManager(); em.getTransaction().begin();/*w w w.j a v a 2 s . co m*/ em.persist(le); em.getTransaction().commit(); em.close(); }
From source file:fr.mby.opa.picsimpl.dao.DbPictureDao.java
@Override public Picture createPicture(final Picture picture, final Album album) throws PictureAlreadyExistsException { Assert.notNull(picture, "No Picture supplied !"); Assert.notNull(album, "No Album supplied !"); Assert.isNull(picture.getId(), "Id should not be set for creation !"); picture.setAlbum(album);//from w w w .java 2 s . c om new TxCallback(this.getEmf()) { @Override protected void executeInTransaction(final EntityManager em) { DbPictureDao.this.testHashUniqueness(picture, em); em.persist(picture); } }; return picture; }