use of org.hibernate.engine.spi.SessionFactoryImplementor in project hibernate-orm by hibernate.
the class CorrectnessTestCase method checkForEmptyPendingPuts.
protected void checkForEmptyPendingPuts() throws Exception {
Field pp = PutFromLoadValidator.class.getDeclaredField("pendingPuts");
pp.setAccessible(true);
Method getInvalidators = null;
List<DelayedInvalidators> delayed = new LinkedList<>();
for (int i = 0; i < sessionFactories.length; i++) {
SessionFactoryImplementor sfi = (SessionFactoryImplementor) sessionFactories[i];
for (Object regionName : sfi.getCache().getSecondLevelCacheRegionNames()) {
PutFromLoadValidator validator = getPutFromLoadValidator(sfi, (String) regionName);
if (validator == null) {
log.warn("No validator for " + regionName);
continue;
}
ConcurrentMap<Object, Object> map = (ConcurrentMap) pp.get(validator);
for (Iterator<Map.Entry<Object, Object>> iterator = map.entrySet().iterator(); iterator.hasNext(); ) {
Map.Entry entry = iterator.next();
if (getInvalidators == null) {
getInvalidators = entry.getValue().getClass().getMethod("getInvalidators");
getInvalidators.setAccessible(true);
}
java.util.Collection invalidators = (java.util.Collection) getInvalidators.invoke(entry.getValue());
if (invalidators != null && !invalidators.isEmpty()) {
delayed.add(new DelayedInvalidators(map, entry.getKey()));
}
}
}
}
// poll until all invalidations come
long deadline = System.currentTimeMillis() + 30000;
while (System.currentTimeMillis() < deadline) {
iterateInvalidators(delayed, getInvalidators, (k, i) -> {
});
if (delayed.isEmpty()) {
break;
}
Thread.sleep(1000);
}
if (!delayed.isEmpty()) {
iterateInvalidators(delayed, getInvalidators, (k, i) -> log.warnf("Left invalidators on key %s: %s", k, i));
throw new IllegalStateException("Invalidators were not cleared: " + delayed.size());
}
}
use of org.hibernate.engine.spi.SessionFactoryImplementor in project hibernate-orm by hibernate.
the class CacheKeySerializationTest method getSessionFactory.
private SessionFactoryImplementor getSessionFactory(String cacheKeysFactory) {
Configuration configuration = new Configuration().setProperty(Environment.USE_SECOND_LEVEL_CACHE, "true").setProperty(Environment.CACHE_REGION_FACTORY, TestInfinispanRegionFactory.class.getName()).setProperty(Environment.DEFAULT_CACHE_CONCURRENCY_STRATEGY, "transactional").setProperty(AvailableSettings.SHARED_CACHE_MODE, "ALL").setProperty(Environment.HBM2DDL_AUTO, "create-drop");
if (cacheKeysFactory != null) {
configuration.setProperty(Environment.CACHE_KEYS_FACTORY, cacheKeysFactory);
}
configuration.addAnnotatedClass(WithSimpleId.class);
configuration.addAnnotatedClass(WithEmbeddedId.class);
return (SessionFactoryImplementor) configuration.buildSessionFactory();
}
use of org.hibernate.engine.spi.SessionFactoryImplementor in project hibernate-orm by hibernate.
the class CacheKeySerializationTest method testId.
private void testId(CacheKeysFactory cacheKeysFactory, String entityName, Object id) throws Exception {
final SessionFactoryImplementor sessionFactory = getSessionFactory(cacheKeysFactory.getClass().getName());
final EntityPersister persister = sessionFactory.getEntityPersister(entityName);
final Object key = cacheKeysFactory.createEntityKey(id, persister, sessionFactory, null);
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
final ObjectOutputStream oos = new ObjectOutputStream(baos);
oos.writeObject(key);
final ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray()));
final Object keyClone = ois.readObject();
try {
assertEquals(key, keyClone);
assertEquals(keyClone, key);
assertEquals(key.hashCode(), keyClone.hashCode());
final Object idClone = cacheKeysFactory.getEntityId(keyClone);
assertEquals(id.hashCode(), idClone.hashCode());
assertEquals(id, idClone);
assertEquals(idClone, id);
assertTrue(persister.getIdentifierType().isEqual(id, idClone, sessionFactory));
assertTrue(persister.getIdentifierType().isEqual(idClone, id, sessionFactory));
sessionFactory.close();
} finally {
sessionFactory.close();
}
}
use of org.hibernate.engine.spi.SessionFactoryImplementor in project hibernate-orm by hibernate.
the class SpatialProjections method extent.
/**
* Applies an extent projection to the specified geometry function
*
* <p>The extent of a set of {@code Geometry}s is the union of their bounding boxes.</p>
*
* @param propertyName The property to use for calculating the extent
*
* @return an extent-projection for the specified property.
*/
public static Projection extent(final String propertyName) {
return new SimpleProjection() {
public Type[] getTypes(Criteria criteria, CriteriaQuery criteriaQuery) throws HibernateException {
return new Type[] { criteriaQuery.getType(criteria, propertyName) };
}
public String toSqlString(Criteria criteria, int position, CriteriaQuery criteriaQuery) throws HibernateException {
final StringBuilder stbuf = new StringBuilder();
final SessionFactoryImplementor factory = criteriaQuery.getFactory();
final String[] columns = criteriaQuery.getColumnsUsingProjection(criteria, propertyName);
final Dialect dialect = factory.getDialect();
if (dialect instanceof SpatialDialect) {
final SpatialDialect seDialect = (SpatialDialect) dialect;
stbuf.append(seDialect.getSpatialAggregateSQL(columns[0], SpatialAggregate.EXTENT));
stbuf.append(" as y").append(position).append('_');
return stbuf.toString();
}
return null;
}
};
}
use of org.hibernate.engine.spi.SessionFactoryImplementor in project uPortal by Jasig.
the class HibernateDbLoader method setConfiguration.
@Override
public void setConfiguration(String persistenceUnit, HibernateConfiguration hibernateConfiguration) {
final SessionFactoryImplementor sessionFactory = hibernateConfiguration.getSessionFactory();
this.dialect = sessionFactory.getDialect();
this.configuration = hibernateConfiguration.getConfiguration();
}
Aggregations