List of usage examples for javax.persistence EntityManager find
public <T> T find(Class<T> entityClass, Object primaryKey);
From source file:com.sun.socialsite.business.impl.JPAPersistenceStrategy.java
/** * Remove object from persistence storage. * @param clazz the class of object to remove * @param id the id of the object to remove * @throws SocialSiteException on any error deleting object *///from w ww .j a va 2 s . c om public void remove(Class<?> clazz, String id) throws SocialSiteException { EntityManager em = getEntityManager(true); Object po = em.find(clazz, id); em.remove(po); }
From source file:com.sun.socialsite.business.impl.JPAPersistenceStrategy.java
/** * Remove object from persistence storage. * @param clazz the class of object to remove * @param id the id of the object to remove * @throws SocialSiteException on any error deleting object *//*from ww w . ja v a2s . c o m*/ public void remove(Class<?> clazz, int id) throws SocialSiteException { EntityManager em = getEntityManager(true); Object po = em.find(clazz, id); em.remove(po); }
From source file:de.iai.ilcd.model.dao.CommonDataStockDao.java
/** * Get a root data stock by it's database ID * //w ww . j a v a 2 s .co m * @param id * id of data stock to find * @return loaded data stock */ public RootDataStock getRootDataStockById(long id) { EntityManager em = PersistenceUtil.getEntityManager(); return em.find(RootDataStock.class, new Long(id)); }
From source file:de.iai.ilcd.model.dao.CommonDataStockDao.java
/** * Get a root data stock by it's database ID * /*from w ww . j a va 2 s . c o m*/ * @param id * id of data stock to find * @return loaded data stock */ public DataStock getNonRootDataStockById(long id) { EntityManager em = PersistenceUtil.getEntityManager(); return em.find(DataStock.class, new Long(id)); }
From source file:eu.optimis.trustedinstance.DBStorage.java
@SuppressWarnings("finally") public boolean update(DBStorageEntry entry) { boolean result = true; EntityManager em = emf.createEntityManager(); try {//w w w .j a v a 2s . co m em.getTransaction().begin(); DBStorageEntry update = em.find(DBStorageEntry.class, entry.getKey()); update.setLicenseToken(entry.getLicenseToken()); em.getTransaction().commit(); } catch (Exception e) { result = false; } finally { em.close(); return result; } }
From source file:com.headissue.pigeon.admin.AdminSurveyHandler.java
public boolean disableSurvey(int _surveyId) { if (_surveyId <= 0) { return false; }//from w w w . ja v a 2 s . co m EntityManager _manager = factory.createEntityManager(); try { Survey s = _manager.find(Survey.class, _surveyId); if (s == null) { return false; } _manager.getTransaction().begin(); s.setStatus(SurveyStatus.DISABLED); _manager.getTransaction().commit(); return true; } catch (Exception e) { LogUtils.warn(log, "set survey '%s' to disabled failed", _surveyId); _manager.getTransaction().rollback(); return false; } finally { _manager.close(); } }
From source file:eu.optimis.trustedinstance.DBStorage.java
@SuppressWarnings("finally") public DBStorageEntry get(String resourceKey) throws Exception { DBStorageEntry result = null;// w ww .ja v a2s.co m EntityManager em = emf.createEntityManager(); try { em.getTransaction().begin(); result = (DBStorageEntry) em.find(DBStorageEntry.class, resourceKey); em.getTransaction().commit(); } catch (Exception e) { result = null; throw e; } finally { em.close(); return result; } }
From source file:nl.b3p.viewer.admin.stripes.ComponentConfigLayerListActionBean.java
public Resolution source() { EntityManager em = Stripersist.getEntityManager(); JSONArray jsonArray = new JSONArray(); if (appId != null) { Application app = em.find(Application.class, appId); List<ApplicationLayer> layers = LayerListHelper.getLayers(app.getRoot(), filterable, bufferable, editable, influence, arc, wfs, attribute, false, null); for (ApplicationLayer layer : layers) { try { jsonArray.put(layer.toJSONObject()); } catch (JSONException je) { log.error("Error while getting JSONObject of Layer with id: " + layer.getId(), je); }//w w w . jav a 2 s.c o m } } return new StreamingResolution("application/json", new StringReader(jsonArray.toString())); }
From source file:com.headissue.pigeon.admin.AdminSurveyHandler.java
public SurveyValue getSurvey(int _surveyId) { if (_surveyId <= 0) { return defaultSurvey; }//from w ww .j a v a 2 s . c o m EntityManager _manager = factory.createEntityManager(); try { Survey _survey = _manager.find(Survey.class, _surveyId); if (_survey == null || _survey.getStatus() == SurveyStatus.DISABLED) { return defaultSurvey; } return adminSurveyService.fromSurvey(_survey); } catch (Exception e) { LogUtils.warn(log, e, "get the survey '%s' failed", _surveyId); return defaultSurvey; } finally { _manager.close(); } }
From source file:com.emc.plants.service.impl.LoginBean.java
/** * Verify that the user exists and the password is value. * /*ww w .jav a2s. c o m*/ * @param customerID The customer ID * @param password The password for the customer ID * @return String with a results message. */ public String verifyUserAndPassword(String customerID, String password) { // Try to get customer. String results = null; Customer customer = null; /* CustomerHome customerHome = (CustomerHome) Util.getEJBLocalHome("java:comp/env/ejb/Customer", com.ibm.websphere.samples.pbwjpa.CustomerHome.class); try { customer = customerHome.findByPrimaryKey(new CustomerKey(customerID)); } catch (ObjectNotFoundException e) { } } catch (FinderException e) { e.printStackTrace(); } */ EntityManager em = entityManagerFactory.createEntityManager(); customer = em.find(Customer.class, customerID); // Does customer exists? if (customer != null) { if (!customer.verifyPassword(password)) // Is password correct? { results = "\nPassword does not match for : " + customerID; Util.debug("Password given does not match for userid=" + customerID); } } else // Customer was not found. { results = "\nCould not find account for : " + customerID; Util.debug("customer " + customerID + " NOT found"); } return results; }