List of usage examples for org.hibernate FetchMode SELECT
FetchMode SELECT
To view the source code for org.hibernate FetchMode SELECT.
Click Source Link
From source file:com.scopix.periscope.operatorqueuepriority.dao.OperatorQueuePriorityDAOImpl.java
License:Open Source License
/** * List objects of type OperatorQueuePriority sorted by Corporate Name * @return List<OperatorQueuePriority> *//*from w ww.j a v a2 s. c o m*/ @Override public List<OperatorQueuePriority> listByCorporateName() { log.info("executing listByCorporateName()"); List<OperatorQueuePriority> list; Criteria criteria = this.getSession().createCriteria(OperatorQueuePriority.class); criteria.addOrder(Order.asc("corporateName")); criteria.addOrder(Order.asc("priority")); criteria.setFetchMode("userSubscriptions", FetchMode.SELECT); list = criteria.list(); log.info("end)"); return list; }
From source file:com.scopix.periscope.operatorqueuepriority.dao.OperatorQueuePriorityDAOImpl.java
License:Open Source License
/** * finds a OperatorQueuePriority by corporate Id and Operator Queue Name * @param corporateId//from www. j a v a 2 s. co m * @param operatorQueueName * @return OperatorQueuePriority */ @Override public OperatorQueuePriority getByCorporateIdAndOperatorQueueName(Integer corporateId, String operatorQueueName) { Criteria criteria = this.getSession().createCriteria(OperatorQueuePriority.class); criteria.setMaxResults(1); criteria.add(Restrictions.eq("corporateId", corporateId)); criteria.add(Restrictions.eq("operatorQueueName", operatorQueueName)); criteria.setFetchMode("userSubscriptions", FetchMode.SELECT); OperatorQueuePriority operatorQueuePriority = (OperatorQueuePriority) criteria.uniqueResult(); return operatorQueuePriority; }
From source file:com.smartitengineering.dao.impl.hibernate.AbstractDAO.java
License:Open Source License
@SuppressWarnings("unchecked") private void processNestedParameter(Criteria criteria, String element, QueryParameter parameter) { FetchMode mode;/*from ww w. j ava2s. c o m*/ CompositionQueryParameter queryParameter = QueryParameterCastHelper.COMPOSITION_PARAM_FOR_NESTED_TYPE .cast(parameter); switch (queryParameter.getFetchMode()) { case EAGER: mode = FetchMode.EAGER; break; case SELECT: mode = FetchMode.SELECT; break; case JOIN: mode = FetchMode.JOIN; break; case LAZY: mode = FetchMode.LAZY; break; default: case DEFAULT: mode = FetchMode.DEFAULT; break; } criteria.setFetchMode(element, ((mode == null) ? FetchMode.JOIN : mode)); Collection<QueryParameter> nestedParameters = queryParameter.getNestedParameters(); if (nestedParameters == null || nestedParameters.size() <= 0) { return; } Criteria nestedCriteria = criteria.createCriteria(element); for (QueryParameter nestedQueryParameter : nestedParameters) { if (!nestedQueryParameter.isInitialized()) { continue; } processCriteria(nestedCriteria, getPropertyName(nestedQueryParameter), nestedQueryParameter); } }
From source file:com.valco.dao.NotasVentaDAO.java
public List<NotasDeVenta> getNotasDeVenta() throws Exception { Session session = HibernateUtil.getSessionFactory().openSession(); Transaction tx = null;/*from www. jav a 2 s . c o m*/ List<NotasDeVenta> notas = new ArrayList<NotasDeVenta>(); try { tx = session.beginTransaction(); Criteria q = session.createCriteria(NotasDeVenta.class).setFetchMode("repartidores", FetchMode.JOIN); q.setFetchMode("productosInventarios", FetchMode.SELECT).setFetchMode("clientes", FetchMode.JOIN) .add(Restrictions.eq("estatus", "ASIGNADA")); notas = (List<NotasDeVenta>) q.list(); return notas; } catch (HibernateException he) { throw new Exception("Ocurri un error al consultar los clientes."); } finally { try { if (session.isOpen()) { session.close(); } } catch (HibernateException he) { throw new Exception("Ocurri un error al consultar los clientes."); } } }
From source file:com.valco.dao.NotasVentaDAO.java
public List<NotasDeVenta> getAsignacionNotasDeVenta() throws Exception { Session session = HibernateUtil.getSessionFactory().openSession(); Transaction tx = null;/*from ww w.j a va 2s. com*/ List<NotasDeVenta> notas = new ArrayList<NotasDeVenta>(); try { tx = session.beginTransaction(); Criteria q = session.createCriteria(NotasDeVenta.class).setFetchMode("repartidores", FetchMode.JOIN); q.setFetchMode("productosInventarios", FetchMode.SELECT); notas = (List<NotasDeVenta>) q.list(); return notas; } catch (HibernateException he) { throw new Exception("Ocurri un error al consultar los clientes."); } finally { try { if (session.isOpen()) { session.close(); } } catch (HibernateException he) { throw new Exception("Ocurri un error al consultar los clientes."); } } }
From source file:control.dao.StaffDAO.java
public List<Object> getStaffList(String key, int type, int page) { int firstResult = (page - 1) * 20; int totalSize; Session session = utils.HibernateUtils.getSessionFactory().getCurrentSession(); List<Object> resultSet = new ArrayList<>(); boolean searchByFirstName = true; try {//from w w w . jav a 2 s . c o m session.beginTransaction(); // Query qr =session.createQuery("from " // +Staff.class.getName() // + " s left join fetch s.roleCollection"); // session.createQuery(") Criteria crit = session.createCriteria(Staff.class); crit.setFetchMode("roleCollection", FetchMode.SELECT); crit.addOrder(Order.asc("id")); crit.setProjection(Projections.projectionList().add(Projections.property("id")) .add(Projections.property("userName")).add(Projections.property("firstName")) .add(Projections.property("lastName")).add(Projections.property("phone")) .add(Projections.property("email")).add(Projections.property("status"))); switch (type) { case 0: break; case 1: crit.add(Restrictions.ilike("userName", "%" + key + "%")); break; case 2: while (true) { if (searchByFirstName) { crit.add(Restrictions.ilike("firstName", "%" + key + "%")); searchByFirstName = crit.list().isEmpty(); if (searchByFirstName) { break; } } else { crit.add(Restrictions.ilike("lastName", "%" + key + "%")); break; } } break; case 3: crit.add(Restrictions.ilike("phone", "%" + key + "%")); break; case 4: crit.add(Restrictions.ilike("email", "%" + key + "%")); break; case 5: crit.add(Restrictions.ilike("adress", "%" + key + "%")); break; } totalSize = crit.list().size(); crit.setFirstResult(firstResult); crit.setMaxResults(20); resultSet = crit.list(); resultSet.add(totalSize); return resultSet == null ? new ArrayList<>() : resultSet; } catch (Exception e) { e.printStackTrace(); return new ArrayList<>(); } finally { if (session.getTransaction().isActive()) { session.getTransaction().commit(); } } }
From source file:eu.ist_phosphorus.harmony.idb.database.hibernate.Connections.java
License:Open Source License
/** * load Endpoints from DB. This will override all stored endpoints!! *///from w w w . j av a 2 s .co m @SuppressWarnings("unchecked") public final void loadNrpsConnections() throws DatabaseException { // get nrpsConnections from DB List<NrpsConnections> ncList = (List<NrpsConnections>) (new TransactionManager( new Long(this.PK_Connections)) { @Override protected void dbOperation() { this.result = this.session.createCriteria(NrpsConnections.class).setFetchMode("", FetchMode.SELECT) .add(Restrictions.like("fkConnection", this.arg)).list(); } }).getResult(); // clear old nrpsConnections this.nrpsConnections.clear(); // put new nrpsConnections from DB into the set for (NrpsConnections nc : ncList) { this.nrpsConnections.put(nc.getDomain(), nc); } }
From source file:eu.ist_phosphorus.harmony.idb.database.hibernate.Domain.java
License:Open Source License
/** * Locate a TNA address, i.e. match the given address against prefixes of * domains in the database.//ww w . j a v a2 s.c o m * * @param tna * TNA of endpoint to locate. * @return Domain where the endpoint is located. * @throws DatabaseException * @throws HibernateException */ @Transient @SuppressWarnings("unchecked") public static final Domain getDomainMatchingTNA(final String tna) throws HibernateException, DatabaseException { return (Domain) (new TransactionManager(tna) { @Override protected void dbOperation() { final List<TNAPrefix> tmpPrefix = this.session.createCriteria(TNAPrefix.class) .setFetchMode("TNAPrefix", FetchMode.SELECT).list(); TNAPrefix match = null; for (final TNAPrefix prefix : tmpPrefix) { if (prefix.matchesPrefix((String) this.arg)) { match = prefix; // TODO longest prefix match } } if (match != null) { this.result = this.session.get(Domain.class, match.getDomain().getName()); } } }).getResult(); }
From source file:eu.ist_phosphorus.harmony.idb.database.hibernate.Domain.java
License:Open Source License
@SuppressWarnings("unchecked") public static final Set<Domain> loadAll() throws DatabaseException { return (Set<Domain>) (new TransactionManager() { @Override/*ww w .j a v a2s. co m*/ protected void dbOperation() { final Set<Domain> result = new HashSet<Domain>(); final List<Domain> tmpDomain = this.session.createCriteria(Domain.class) .setFetchMode("Domain", FetchMode.SELECT).list(); for (final Domain d : tmpDomain) { result.add(d); } this.result = result; } }).getResult(); }
From source file:eu.ist_phosphorus.harmony.idb.database.hibernate.Domain.java
License:Open Source License
@SuppressWarnings("unchecked") public final Set<VIEW_InterDomainLink> loadAllLinks() throws DatabaseException { return (Set<VIEW_InterDomainLink>) (new TransactionManager() { @Override//from w w w . j av a2s .c om protected void dbOperation() { final Set<VIEW_InterDomainLink> result = new HashSet<VIEW_InterDomainLink>(); for (final Endpoint e : Domain.this.getEndpoints()) { final List<VIEW_InterDomainLink> tmpSrc = this.session .createCriteria(VIEW_InterDomainLink.class).setFetchMode("", FetchMode.SELECT) .add(Restrictions.like("sourceEndpoint", e)).list(); final List<VIEW_InterDomainLink> tmpDst = this.session .createCriteria(VIEW_InterDomainLink.class).setFetchMode("", FetchMode.SELECT) .add(Restrictions.like("destEndpoint", e)).list(); for (final VIEW_InterDomainLink l : tmpSrc) { result.add(l); } for (final VIEW_InterDomainLink l : tmpDst) { result.add(l); } } this.result = result; } }).getResult(); }