List of usage examples for javax.persistence EntityManager createQuery
public Query createQuery(CriteriaDelete deleteQuery);
Query
for executing a criteria delete query. From source file:com.medicaid.mmis.util.CodeMappingLoader.java
/** * Reads the code mapping xls and inserts any unmapped row to the legacy mapping table. * @throws InvalidFormatException if the input file is not recognized *///from ww w . j a v a2 s . c o m @SuppressWarnings("unchecked") public static void main(String[] args) throws IOException, PortalServiceException, InvalidFormatException { PropertyConfigurator.configure("log4j.properties"); logger = Logger.getLogger(CodeMappingLoader.class); EntityManagerFactory emf = Persistence.createEntityManagerFactory("cms-data-load"); EntityManager em = emf.createEntityManager(); Workbook workbook = WorkbookFactory.create(new File("mapping/CodeMapping.xlsx")); SequenceGeneratorBean sequence = new SequenceGeneratorBean(); sequence.setEm(em); try { em.getTransaction().begin(); List<LegacySystemMapping> rs = em.createQuery("Select l from LegacySystemMapping l").getResultList(); for (LegacySystemMapping mapping : rs) { em.remove(mapping); } importSheet(em, sequence, workbook, "ENROLLMENT_STATUS"); importSheet(em, sequence, workbook, "RISK_LEVEL"); importSheet(em, sequence, workbook, "SPECIALTY_CODE"); importSheet(em, sequence, workbook, "LICENSE_TYPE"); importSheet(em, sequence, workbook, "ISSUING_BOARD"); importSheet(em, sequence, workbook, "PROVIDER_TYPE"); importSheet(em, sequence, workbook, "COUNTY_CODE"); importSheet(em, sequence, workbook, "BEN_OWNER_TYPE"); importSheet(em, sequence, workbook, "LICENSE_STATUS"); importSheet(em, sequence, workbook, "COS"); em.getTransaction().commit(); } catch (Throwable t) { em.getTransaction().rollback(); logger.error("Could not complete import", t); throw new PortalServiceException("Error during import", t); } }
From source file:Professor.java
public static void main(String[] a) throws Exception { JPAUtil util = new JPAUtil(); EntityManagerFactory emf = Persistence.createEntityManagerFactory("ProfessorService"); EntityManager em = emf.createEntityManager(); ProfessorService service = new ProfessorService(em); em.getTransaction().begin();// w w w . j ava 2 s. co m Professor emp = service.createProfessor(1, "name", 100); emp = service.createProfessor(2, "name 2", 100); Collection emps = em.createQuery("SELECT e FROM Professor e").getResultList(); for (Iterator i = emps.iterator(); i.hasNext();) { Professor e = (Professor) i.next(); System.out.println("Professor " + e.getId() + ", " + e.getName()); } util.checkData("select * from Professor"); em.getTransaction().commit(); em.close(); emf.close(); }
From source file:Professor.java
public static void main(String[] a) throws Exception { JPAUtil util = new JPAUtil(); EntityManagerFactory emf = Persistence.createEntityManagerFactory("ProfessorService"); EntityManager em = emf.createEntityManager(); ProfessorService service = new ProfessorService(em); em.getTransaction().begin();/* w w w . j a v a 2s . co m*/ Professor emp = service.createProfessor(1, "name", 100); emp = service.createProfessor(2, "name 2", 100); Integer userId = 1; emp = em.find(Professor.class, userId); if (emp == null) { System.out.println(userId + " not found! "); } else { System.out.println("Found " + emp); } for (Object o : em.createQuery("SELECT u FROM Professor u").getResultList()) { System.out.println(o); } util.checkData("select * from Professor"); em.getTransaction().commit(); em.close(); emf.close(); }
From source file:com.callcenter.domain.Role.java
public static Role findRoleByNameIn(final java.util.Collection<String> names) { EntityManager em = Role.entityManager(); Query q = em.createQuery("SELECT Role FROM Role AS role WHERE role.name in (:names)"); q.setParameter("names", names); return (Role) q.getSingleResult(); }
From source file:org.apache.cxf.fediz.service.idp.service.jpa.EntitlementDAOJPAImpl.java
static EntitlementEntity getEntitlementEntity(String name, EntityManager em) { Query query = null;//w ww. j a v a2s .c o m query = em.createQuery("select e from Entitlement e where e.name=:name"); query.setParameter("name", name); //@SuppressWarnings("rawtypes") return (EntitlementEntity) query.getSingleResult(); }
From source file:org.apache.cxf.fediz.service.idp.service.jpa.ClaimDAOJPAImpl.java
static ClaimEntity getClaimEntity(String claimType, EntityManager em) { Query query = null;//from w w w . j a v a 2 s. com query = em.createQuery("select c from Claim c where c.claimType=:claimtype"); query.setParameter("claimtype", claimType); //@SuppressWarnings("rawtypes") return (ClaimEntity) query.getSingleResult(); }
From source file:ar.edu.unlp.sedici.sedici2003.model.Personas.java
public static int findPersonasesByApellidoYNombreCount(String apellido, String nombre) { if (apellido == null || apellido.length() == 0) apellido = ""; if (nombre == null) nombre = ""; apellido = Personas.convertirParaQuery(apellido); nombre = Personas.convertirParaQuery(nombre); String where = Personas.generateCondition(apellido, nombre); /*if (apellido == null || apellido.length() == 0) apellido=""; if (nombre == null) nombre = "";/*from w ww.j av a2 s .c o m*/ String where=Personas.generateCondition(apellido, nombre);*/ EntityManager em = Personas.entityManager(); Query q = em.createQuery("SELECT count(o) FROM Personas AS o " + where); if (apellido.length() != 0) q.setParameter("apellido", apellido); if (nombre.length() != 0) q.setParameter("nombre", nombre); return Integer.valueOf(q.getResultList().get(0).toString()); }
From source file:org.apache.cxf.fediz.service.idp.service.jpa.TrustedIdpDAOJPAImpl.java
static TrustedIdpEntity getTrustedIdpEntity(String realm, EntityManager em) { Query query = null;//from w ww . ja v a2 s. c o m query = em.createQuery("select t from TrustedIDP t where t.realm=:realm"); query.setParameter("realm", realm); //@SuppressWarnings("rawtypes") return (TrustedIdpEntity) query.getSingleResult(); }
From source file:org.apache.cxf.fediz.service.idp.service.jpa.RoleDAOJPAImpl.java
static RoleEntity getRoleEntity(String realm, EntityManager em) { Query query = null;// ww w . j a va 2 s .c o m query = em.createQuery("select i from IDP i where i.realm=:realm"); query.setParameter("realm", realm); //@SuppressWarnings("rawtypes") return (RoleEntity) query.getSingleResult(); }
From source file:com.vladmihalcea.CleanDbUtil.java
public static void cleanStore(final TransactionTemplate transactionTemplate, final EntityManager entityManager) { transactionTemplate.execute(new TransactionCallback<Void>() { @Override/* ww w. j a v a 2s . c om*/ public Void doInTransaction(TransactionStatus transactionStatus) { entityManager.createQuery("delete from SubVersion where id > 0").executeUpdate(); entityManager.createQuery("delete from Version where id > 0").executeUpdate(); entityManager.createQuery("delete from Image where id > 0").executeUpdate(); entityManager.createQuery("delete from WarehouseProductInfo where id > 0").executeUpdate(); entityManager.createQuery("delete from Product where id > 0").executeUpdate(); entityManager.createQuery("delete from Company where id > 0").executeUpdate(); entityManager.flush(); return null; } }); }