@Override public List<VoteEntity> getVotes(Filter queryVote) { Session currentSession = sessionFactory.getCurrentSession(); Criteria criteria = currentSession.createCriteria(VoteEntity.class); if(!isEmpty(queryVote)){ if (queryVote.getTag() != null) { criteria.add(Expression.eq("tag", queryVote.getTag())); } if (queryVote.getMood() != null) { criteria.add(Expression.eq("mood", queryVote.getMood())); } if (queryVote.getTime() != null) { Interval interval = Utils.getIntervalFormTimeEnum(queryVote.getTime()); criteria.add(Restrictions.between("time", interval.getStartMillis(), interval.getEndMillis())); } return criteria.list(); }else{ return ((SessionImpl)currentSession).find("from VoteEntity"); } }
/** * Initialize Collection (detached or not) * @param collection collection to initialize * @param session Session to use for initialization */ public static void initializeCollection(Collection collection, Session session) { if (collection instanceof AbstractPersistentCollection) { AbstractPersistentCollection ps = (AbstractPersistentCollection) collection; log.debug("Initalizing PersistentCollection of role: " + ps.getRole()); if (!ps.wasInitialized()) { SessionImpl source = (SessionImpl) session; PersistenceContext context = source.getPersistenceContext(); CollectionPersister cp = source.getFactory().getCollectionPersister(ps.getRole()); if (context.getCollectionEntry(ps) == null) { // detached context.addUninitializedDetachedCollection(cp, ps); } ps.setCurrentSession(context.getSession()); Hibernate.initialize(collection); } } }
public void testReplicate() throws Exception { Session s = openSession(); Container baz = new Container(); Contained f = new Contained(); List list = new ArrayList(); list.add(baz); f.setBag(list); List list2 = new ArrayList(); list2.add(f); baz.setBag(list2); s.save(f); s.save(baz); s.flush(); s.connection().commit(); s.close(); s = openSession(); s.replicate(baz, ReplicationMode.OVERWRITE); // HHH-2378 SessionImpl x = (SessionImpl)s; EntityEntry entry = x.getPersistenceContext().getEntry( baz ); assertNull(entry.getVersion()); s.flush(); s.connection().commit(); s.close(); s = openSession(); s.replicate(baz, ReplicationMode.IGNORE); s.flush(); s.connection().commit(); s.close(); s = openSession(); s.delete(baz); s.delete(f); s.flush(); s.connection().commit(); s.close(); }
public void testBorrowedConnections() throws Throwable { prepare(); Session s = getSessionUnderTest(); Connection conn = s.connection(); assertTrue( ( ( SessionImpl ) s ).getJDBCContext().getConnectionManager().hasBorrowedConnection() ); conn.close(); assertFalse( ( ( SessionImpl ) s ).getJDBCContext().getConnectionManager().hasBorrowedConnection() ); release( s ); done(); }
/** * Return whether the given Hibernate Session will always hold the same * JDBC Connection. This is used to check whether the transaction manager * can safely prepare and clean up the JDBC Connection used for a transaction. * <p>Default implementation checks the Session's connection release mode * to be "on_close". Unfortunately, this requires casting to SessionImpl, * as of Hibernate 3.1. If that cast doesn't work, we'll simply assume * we're safe and return {@code true}. * @param session the Hibernate Session to check * @see org.hibernate.impl.SessionImpl#getConnectionReleaseMode() * @see org.hibernate.ConnectionReleaseMode#ON_CLOSE */ protected boolean isSameConnectionForEntireSession(Session session) { if (!(session instanceof SessionImpl)) { // The best we can do is to assume we're safe. return true; } ConnectionReleaseMode releaseMode = ((SessionImpl) session).getConnectionReleaseMode(); return ConnectionReleaseMode.ON_CLOSE.equals(releaseMode); }
/** * Get the underlying database connection from the JPA Entity Manager (DBUnit needs this connection). * @return Database Connection * @throws Exception */ private IDatabaseConnection getDatabaseConnection() throws Exception { return new DatabaseConnection(((SessionImpl) (bookManager.getEntityManager().getDelegate())).connection()); }