Search in sources :

Example 61 with SessionFactoryImplementor

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");
    }
}
Also used : SpatialDialect(org.hibernate.spatial.SpatialDialect) SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) Dialect(org.hibernate.dialect.Dialect) SpatialDialect(org.hibernate.spatial.SpatialDialect)

Example 62 with SessionFactoryImplementor

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");
    }
}
Also used : SpatialDialect(org.hibernate.spatial.SpatialDialect) SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) Dialect(org.hibernate.dialect.Dialect) SpatialDialect(org.hibernate.spatial.SpatialDialect)

Example 63 with SessionFactoryImplementor

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);
    }
}
Also used : Type(org.hibernate.type.Type) SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor)

Example 64 with SessionFactoryImplementor

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());
}
Also used : EntityPersister(org.hibernate.persister.entity.EntityPersister) NaturalIdCacheKey(org.hibernate.cache.internal.NaturalIdCacheKey) SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ObjectOutputStream(java.io.ObjectOutputStream) Type(org.hibernate.type.Type) ByteArrayInputStream(java.io.ByteArrayInputStream) InvocationOnMock(org.mockito.invocation.InvocationOnMock) SessionImplementor(org.hibernate.engine.spi.SessionImplementor) Matchers.anyObject(org.mockito.Matchers.anyObject) ObjectInputStream(java.io.ObjectInputStream) Test(org.junit.Test)

Example 65 with SessionFactoryImplementor

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);
}
Also used : EntityUniqueKey(org.hibernate.engine.spi.EntityUniqueKey) SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) PersistenceContext(org.hibernate.engine.spi.PersistenceContext) UniqueKeyLoadable(org.hibernate.persister.entity.UniqueKeyLoadable)

Aggregations

SessionFactoryImplementor (org.hibernate.engine.spi.SessionFactoryImplementor)129 Test (org.junit.Test)46 Configuration (org.hibernate.cfg.Configuration)27 SQLException (java.sql.SQLException)18 Type (org.hibernate.type.Type)16 EntityPersister (org.hibernate.persister.entity.EntityPersister)13 Connection (java.sql.Connection)12 HibernateException (org.hibernate.HibernateException)12 PreparedStatement (java.sql.PreparedStatement)11 Metadata (org.hibernate.boot.Metadata)11 Statement (java.sql.Statement)10 ArrayList (java.util.ArrayList)10 JdbcConnectionAccess (org.hibernate.engine.jdbc.connections.spi.JdbcConnectionAccess)10 JdbcServices (org.hibernate.engine.jdbc.spi.JdbcServices)10 Serializable (java.io.Serializable)9 EncapsulatedCompositeIdResultSetProcessorTest (org.hibernate.test.loadplans.process.EncapsulatedCompositeIdResultSetProcessorTest)8 HashMap (java.util.HashMap)7 Integrator (org.hibernate.integrator.spi.Integrator)7 SessionFactoryServiceRegistry (org.hibernate.service.spi.SessionFactoryServiceRegistry)7 Map (java.util.Map)6