Search in sources :

Example 96 with SessionFactoryImplementor

use of org.hibernate.engine.spi.SessionFactoryImplementor in project hibernate-orm by hibernate.

the class PessimisticWriteUpdateLockingStrategy method generateLockString.

protected String generateLockString() {
    final SessionFactoryImplementor factory = lockable.getFactory();
    final Update update = new Update(factory.getDialect());
    update.setTableName(lockable.getRootTableName());
    update.addPrimaryKeyColumns(lockable.getRootTableIdentifierColumnNames());
    update.setVersionColumnName(lockable.getVersionColumnName());
    update.addColumn(lockable.getVersionColumnName());
    if (factory.getSessionFactoryOptions().isCommentsEnabled()) {
        update.setComment(lockMode + " lock " + lockable.getEntityName());
    }
    return update.toStatementString();
}
Also used : SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) Update(org.hibernate.sql.Update)

Example 97 with SessionFactoryImplementor

use of org.hibernate.engine.spi.SessionFactoryImplementor in project hibernate-orm by hibernate.

the class SelectLockingStrategy method generateLockString.

protected String generateLockString(int timeout) {
    final SessionFactoryImplementor factory = getLockable().getFactory();
    final LockOptions lockOptions = new LockOptions(getLockMode());
    lockOptions.setTimeOut(timeout);
    final SimpleSelect select = new SimpleSelect(factory.getDialect()).setLockOptions(lockOptions).setTableName(getLockable().getRootTableName()).addColumn(getLockable().getRootTableIdentifierColumnNames()[0]).addCondition(getLockable().getRootTableIdentifierColumnNames(), "=?");
    if (getLockable().isVersioned()) {
        select.addCondition(getLockable().getVersionColumnName(), "=?");
    }
    if (factory.getSessionFactoryOptions().isCommentsEnabled()) {
        select.setComment(getLockMode() + " lock " + getLockable().getEntityName());
    }
    return select.toStatementString();
}
Also used : LockOptions(org.hibernate.LockOptions) SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) SimpleSelect(org.hibernate.sql.SimpleSelect)

Example 98 with SessionFactoryImplementor

use of org.hibernate.engine.spi.SessionFactoryImplementor in project hibernate-orm by hibernate.

the class InPredicate method render.

@Override
public String render(boolean isNegated, RenderingContext renderingContext) {
    final StringBuilder buffer = new StringBuilder();
    final Expression exp = getExpression();
    if (ParameterExpressionImpl.class.isInstance(exp)) {
        // technically we only need to CAST (afaik) if expression and all values are parameters.
        // but checking for that condition could take long time on a lon value list
        final ParameterExpressionImpl parameterExpression = (ParameterExpressionImpl) exp;
        final SessionFactoryImplementor sfi = criteriaBuilder().getEntityManagerFactory().unwrap(SessionFactoryImplementor.class);
        final Type mappingType = sfi.getTypeResolver().heuristicType(parameterExpression.getParameterType().getName());
        buffer.append("cast(").append(parameterExpression.render(renderingContext)).append(" as ").append(mappingType.getName()).append(")");
    } else {
        buffer.append(((Renderable) getExpression()).render(renderingContext));
    }
    if (isNegated) {
        buffer.append(" not");
    }
    buffer.append(" in ");
    // subquery expressions are already wrapped in parenthesis, so we only need to
    // render the parenthesis here if the values represent an explicit value list
    boolean isInSubqueryPredicate = getValues().size() == 1 && Subquery.class.isInstance(getValues().get(0));
    if (isInSubqueryPredicate) {
        buffer.append(((Renderable) getValues().get(0)).render(renderingContext));
    } else {
        buffer.append('(');
        String sep = "";
        for (Expression value : getValues()) {
            buffer.append(sep).append(((Renderable) value).render(renderingContext));
            sep = ", ";
        }
        buffer.append(')');
    }
    return buffer.toString();
}
Also used : Type(org.hibernate.type.Type) LiteralExpression(org.hibernate.query.criteria.internal.expression.LiteralExpression) Expression(javax.persistence.criteria.Expression) SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) ParameterExpressionImpl(org.hibernate.query.criteria.internal.expression.ParameterExpressionImpl) Subquery(javax.persistence.criteria.Subquery)

Example 99 with SessionFactoryImplementor

use of org.hibernate.engine.spi.SessionFactoryImplementor in project hibernate-orm by hibernate.

the class AccessMappingTest method testFieldAnnotationPlacement.

@Test
public void testFieldAnnotationPlacement() throws Exception {
    Configuration cfg = new Configuration();
    Class<?> classUnderTest = Course6.class;
    cfg.addAnnotatedClass(classUnderTest);
    cfg.addAnnotatedClass(Student.class);
    SessionFactoryImplementor factory = (SessionFactoryImplementor) cfg.buildSessionFactory(serviceRegistry);
    try {
        EntityTuplizer tuplizer = factory.getEntityPersister(classUnderTest.getName()).getEntityMetamodel().getTuplizer();
        assertTrue("Field access should be used.", tuplizer.getIdentifierGetter() instanceof GetterFieldImpl);
    } finally {
        factory.close();
    }
}
Also used : EntityTuplizer(org.hibernate.tuple.entity.EntityTuplizer) GetterFieldImpl(org.hibernate.property.access.spi.GetterFieldImpl) Configuration(org.hibernate.cfg.Configuration) SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) Test(org.junit.Test)

Example 100 with SessionFactoryImplementor

use of org.hibernate.engine.spi.SessionFactoryImplementor in project hibernate-orm by hibernate.

the class AccessMappingTest method testExplicitPropertyAccessAnnotationsWithHibernateStyleOverride.

@Test
public void testExplicitPropertyAccessAnnotationsWithHibernateStyleOverride() throws Exception {
    Configuration cfg = new Configuration();
    Class<?> classUnderTest = Course3.class;
    cfg.addAnnotatedClass(classUnderTest);
    cfg.addAnnotatedClass(Student.class);
    SessionFactoryImplementor factory = (SessionFactoryImplementor) cfg.buildSessionFactory(serviceRegistry);
    try {
        EntityTuplizer tuplizer = factory.getEntityPersister(classUnderTest.getName()).getEntityMetamodel().getTuplizer();
        assertTrue("Field access should be used.", tuplizer.getIdentifierGetter() instanceof GetterFieldImpl);
        assertTrue("Property access should be used.", tuplizer.getGetter(0) instanceof GetterMethodImpl);
    } finally {
        factory.close();
    }
}
Also used : EntityTuplizer(org.hibernate.tuple.entity.EntityTuplizer) GetterFieldImpl(org.hibernate.property.access.spi.GetterFieldImpl) Configuration(org.hibernate.cfg.Configuration) SessionFactoryImplementor(org.hibernate.engine.spi.SessionFactoryImplementor) GetterMethodImpl(org.hibernate.property.access.spi.GetterMethodImpl) Test(org.junit.Test)

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