@Test public void testFiltersAreApplied() { doInHibernate( this::sessionFactory, session -> { session.enableFilter( "ID" ).setParameter( "id", 3L ); List result = session.createQuery( "from Customer order by id" ).list(); assertFalse( result.isEmpty() ); Customer customer = (Customer) result.get( 0 ); assertSame( customer.getCustomerId(), 3L ); assertSame( customer.getOrders().size(), 2 ); SessionStatistics statistics = session.getStatistics(); assertSame( statistics.getEntityCount(), 9 ); Statistics sfStatistics = session.getSessionFactory().getStatistics(); assertSame( sfStatistics.getCollectionFetchCount(), 1L ); assertSame( sfStatistics.getQueries().length, 1 ); } ); }
public int getEntityCount() { return ss.getEntityCount(); }
public static String[] getSessionStatistics(final Session session) { if (isNull(session)) throw new NullPointerException("Parameter session is null"); final SessionStatistics stats = session.getStatistics(); return new String[] { "+ Session Statistics: " + session.toString(), "+", "+ Entity Count: " + stats.getEntityCount(), "+ Collection Count: " + stats.getCollectionCount(), "+", "+" }; }
@Override public long getCacheSize() throws SQLException { return getSession().getStatistics().getEntityCount(); }
@Override public int prepare(long id, Serializable context) { Context ctx = (Context) context; DB db = (DB) ctx.get(TxnConstants.DB); Session session = db.session(); SessionStatistics statistics = session.getStatistics(); Set<EntityKey> entityKeys = statistics.getEntityKeys(); ctx.log (String.format ("ENTITIES: (%d)", statistics.getEntityCount())); for (EntityKey ek : entityKeys) { Object obj = session.get(ek.getEntityName(), ek.getIdentifier()); LockMode lockMode = session.getCurrentLockMode(obj); ctx.log(String.format("[%s] %s %s", ek.getIdentifier(), ek.getEntityName(), lockMode)); } ctx.log ("==== COLLECTIONS ===="); Set<CollectionKey> collectionKeys = statistics.getCollectionKeys(); for (CollectionKey ck : collectionKeys) { ctx.log(String.format("[%s] %s", ck.getKey(), ck.getRole())); } ctx.log("====================="); return PREPARED | READONLY | NO_JOIN; }