List of usage examples for org.hibernate Session createFilter
@Deprecated org.hibernate.Query createFilter(Object collection, String queryString);
From source file:org.eclipse.emf.teneo.hibernate.mapping.elist.MapHibernatePersistableEMap.java
License:Open Source License
/** * Overridden because of access to size attribute. This version will try to read the collection * size without lading it if it is lazy loaded *///from www .j a va 2 s .co m @Override public int size() { if (size != 0) { return size; } // if we are not loaded yet, we return the size of the buffered lazy // load delegate if (!isMapValueIsEAttribute() && this.getORMMapDelegate() != null) { if (!this.isORMMapDelegateLoaded() && (this.getORMMapDelegate() instanceof AbstractPersistentCollection)) { if (cachedSize != null) { return cachedSize.intValue(); } try { // here is a neat trick. we use reflection to get the // session of the persistanMap. Field field = AbstractPersistentCollection.class.getDeclaredField("session"); field.setAccessible(true); Session s = (Session) field.get(this.getORMMapDelegate()); // now that we have the session, we can query the size of // the list without loading it cachedSize = ((Long) s.createFilter(this.getORMMapDelegate(), "select count(*)").list().get(0)); size = cachedSize.intValue(); return size; } catch (Throwable t) { // ignore on purpose, let the call to super handle it } } } // didnt work, so we simply call the parent version return super.size(); }
From source file:org.molasdin.wbase.hibernate.BasicHibernateRepository.java
License:Apache License
@Override @SuppressWarnings("unchecked") public <U> List<U> simpleFilteredCollection(final T owner, final Collection<U> collection, final String filter) { return support().run(new org.molasdin.wbase.transaction.Transactional<HibernateEngine, List<U>>() { @Override/*from w ww . j a v a2 s.c o m*/ public List<U> run(Transaction<HibernateEngine> tx) throws Exception { Session session = tx.engine().session(); attachRaw(owner, session); return (List<U>) session.createFilter(collection, filter).list(); } }); }
From source file:org.molasdin.wbase.hibernate.cursor.BasicFilteredHibernateCursor.java
License:Apache License
@SuppressWarnings("unchecked") @Override//from w w w .j a v a 2s .c o m public List<T> dataCallback(Session session) { StringBuilder builder = new StringBuilder(); session.buildLockRequest(LockOptions.NONE).lock(owner); builder.append(populateFilters()); builder.append(' '); List<Pair<String, Order>> orders = orders(); if (!orders.isEmpty()) { builder.append("order by "); boolean added = false; for (Pair<String, Order> order : orders) { if (added) { builder.append(","); } builder.append(String.format(FILTER_ORDER, order.getLeft(), Order.ASC.equals(order.getRight()) ? ORDER_ASC : ORDER_DESC)); added = true; } builder.append(' '); } return postProcessData((List<T>) session.createFilter(collectionProxy, builder.toString()) .setFirstResult(calculatedRowOffset()).setMaxResults(pageSize()).list()); }
From source file:org.molasdin.wbase.hibernate.cursor.BasicFilteredHibernateCursor.java
License:Apache License
@Override public Long totalCallback(Session session) { StringBuilder builder = new StringBuilder(); builder.append("select count(*) "); builder.append(populateFilters());//from w w w.j av a 2s . c o m session.buildLockRequest(LockOptions.NONE).lock(owner); return (Long) session.createFilter(collectionProxy, builder.toString()).uniqueResult(); }
From source file:us.mn.state.health.lims.organization.daoimpl.OrganizationTypeDAOImpl.java
License:Mozilla Public License
public List<Organization> getOrganizationsByTypeName(String orderByCol, String... names) throws LIMSRuntimeException { String sql = null;//ww w . j a v a 2s.c om try { sql = "from OrganizationType ot WHERE ot.name IN (:names) "; Session session = HibernateUtil.getSession(); org.hibernate.Query query = session.createQuery(sql).setParameterList("names", names); @SuppressWarnings("unchecked") OrganizationType ot = ((List<OrganizationType>) query.list()).get(0); sql = "where this.isActive = 'Y' "; if (null != orderByCol) { sql += " order by " + orderByCol; } @SuppressWarnings("unchecked") List<Organization> orgs2 = session.createFilter(ot.getOrganizations(), sql).list(); session.flush(); session.clear(); return orgs2; } catch (Exception e) { LogEvent.logError("OrganizationTypeDAOImpl", "getOrganizationsByTypeName()", e.toString()); throw new LIMSRuntimeException("Error in OrganizationType getOrganizationTypeByName()", e); } }