use of org.hibernate.engine.spi.SessionFactoryImplementor in project hibernate-orm by hibernate.
the class SpatialFilter method toSqlString.
@Override
public String toSqlString(Criteria criteria, CriteriaQuery criteriaQuery) throws HibernateException {
final SessionFactoryImplementor factory = criteriaQuery.getFactory();
final String[] columns = criteriaQuery.getColumnsUsingProjection(criteria, this.propertyName);
final Dialect dialect = factory.getDialect();
if (dialect instanceof SpatialDialect) {
final SpatialDialect seDialect = (SpatialDialect) dialect;
return seDialect.getSpatialFilterExpression(columns[0]);
} else {
throw new IllegalStateException("Dialect must be spatially enabled dialect");
}
}
use of org.hibernate.engine.spi.SessionFactoryImplementor in project hibernate-orm by hibernate.
the class OracleSpatialProjection method toSqlString.
@Override
public String toSqlString(Criteria criteria, int position, CriteriaQuery criteriaQuery) throws HibernateException {
final SessionFactoryImplementor factory = criteriaQuery.getFactory();
final String[] columns = criteriaQuery.getColumnsUsingProjection(criteria, this.propertyName);
final Dialect dialect = factory.getDialect();
if (dialect instanceof SpatialDialect) {
final SpatialDialect seDialect = (SpatialDialect) dialect;
return new StringBuffer(seDialect.getSpatialAggregateSQL(columns[0], this.aggregate)).append(" y").append(position).append("_").toString();
} else {
throw new IllegalStateException("Dialect must be spatially enabled dialect");
}
}
use of org.hibernate.engine.spi.SessionFactoryImplementor in project hibernate-orm by hibernate.
the class AbstractNullnessCheckNode method initialize.
@Override
public void initialize() {
// TODO : this really needs to be delayed unitl afterQuery we definitively know the operand node type;
// where this is currently a problem is parameters for which where we cannot unequivocally
// resolve an expected type
Type operandType = extractDataType(getOperand());
if (operandType == null) {
return;
}
SessionFactoryImplementor sessionFactory = getSessionFactoryHelper().getFactory();
int operandColumnSpan = operandType.getColumnSpan(sessionFactory);
if (operandColumnSpan > 1) {
mutateRowValueConstructorSyntax(operandColumnSpan);
}
}
use of org.hibernate.engine.spi.SessionFactoryImplementor in project hibernate-orm by hibernate.
the class NaturalIdCacheKeyTest method testSerializationRoundTrip.
@Test
public void testSerializationRoundTrip() throws Exception {
final EntityPersister entityPersister = mock(EntityPersister.class);
final SessionImplementor sessionImplementor = mock(SessionImplementor.class);
final SessionFactoryImplementor sessionFactoryImplementor = mock(SessionFactoryImplementor.class);
final Type mockType = mock(Type.class);
when(entityPersister.getRootEntityName()).thenReturn("EntityName");
when(sessionImplementor.getFactory()).thenReturn(sessionFactoryImplementor);
when(entityPersister.getNaturalIdentifierProperties()).thenReturn(new int[] { 0, 1, 2 });
when(entityPersister.getPropertyTypes()).thenReturn(new Type[] { mockType, mockType, mockType });
when(mockType.getHashCode(anyObject(), eq(sessionFactoryImplementor))).thenAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
return invocation.getArguments()[0].hashCode();
}
});
when(mockType.disassemble(anyObject(), eq(sessionImplementor), eq(null))).thenAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
return invocation.getArguments()[0];
}
});
final NaturalIdCacheKey key = (NaturalIdCacheKey) DefaultCacheKeysFactory.staticCreateNaturalIdKey(new Object[] { "a", "b", "c" }, entityPersister, sessionImplementor);
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
final ObjectOutputStream oos = new ObjectOutputStream(baos);
oos.writeObject(key);
final ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(baos.toByteArray()));
final NaturalIdCacheKey keyClone = (NaturalIdCacheKey) ois.readObject();
assertEquals(key, keyClone);
assertEquals(key.hashCode(), keyClone.hashCode());
assertEquals(key.toString(), keyClone.toString());
assertEquals(key.getEntityName(), keyClone.getEntityName());
assertArrayEquals(key.getNaturalIdValues(), keyClone.getNaturalIdValues());
assertEquals(key.getTenantId(), keyClone.getTenantId());
}
use of org.hibernate.engine.spi.SessionFactoryImplementor in project hibernate-orm by hibernate.
the class EntityType method loadByUniqueKey.
/**
* Load an instance by a unique key that is not the primary key.
*
* @param entityName The name of the entity to load
* @param uniqueKeyPropertyName The name of the property defining the uniqie key.
* @param key The unique key property value.
* @param session The originating session.
*
* @return The loaded entity
*
* @throws HibernateException generally indicates problems performing the load.
*/
public Object loadByUniqueKey(String entityName, String uniqueKeyPropertyName, Object key, SharedSessionContractImplementor session) throws HibernateException {
final SessionFactoryImplementor factory = session.getFactory();
UniqueKeyLoadable persister = (UniqueKeyLoadable) factory.getMetamodel().entityPersister(entityName);
//TODO: implement caching?! proxies?!
EntityUniqueKey euk = new EntityUniqueKey(entityName, uniqueKeyPropertyName, key, getIdentifierOrUniqueKeyType(factory), persister.getEntityMode(), session.getFactory());
final PersistenceContext persistenceContext = session.getPersistenceContext();
Object result = persistenceContext.getEntity(euk);
if (result == null) {
result = persister.loadByUniqueKey(uniqueKeyPropertyName, key, session);
}
return result == null ? null : persistenceContext.proxyFor(result);
}
Aggregations