List of usage examples for org.hibernate.engine.spi SharedSessionContractImplementor getFactory
SessionFactoryImplementor getFactory();
From source file:com.blazebit.persistence.integration.hibernate.CustomBasicCollectionPersister.java
License:Apache License
@Override protected CollectionInitializer createSubselectInitializer(SubselectFetch subselect, SharedSessionContractImplementor session) { return new CustomSubselectCollectionLoader(this, subselect.toSubselectString(getCollectionType().getLHSPropertyName()), subselect.getResult(), subselect.getQueryParameters(), subselect.getNamedParameterLocMap(), session.getFactory(), session.getLoadQueryInfluencers()); }
From source file:com.blazebit.persistence.integration.hibernate.CustomOneToManyPersister.java
License:Apache License
@Override protected CollectionInitializer createSubselectInitializer(SubselectFetch subselect, SharedSessionContractImplementor session) { return new CustomSubselectOneToManyLoader(this, subselect.toSubselectString(getCollectionType().getLHSPropertyName()), subselect.getResult(), subselect.getQueryParameters(), subselect.getNamedParameterLocMap(), session.getFactory(), session.getLoadQueryInfluencers()); }
From source file:com.hazelcast.hibernate.region.NaturalIdCacheKey.java
License:Open Source License
@SuppressWarnings("checkstyle:magicnumber") public NaturalIdCacheKey(final Object[] naturalIdValues, Type[] propertyTypes, int[] naturalIdPropertyIndexes, final String entityName, final SharedSessionContractImplementor session) { this.naturalIdValues = new Serializable[naturalIdValues.length]; this.entityName = entityName; this.tenantId = session.getTenantIdentifier(); SessionFactoryImplementor factory = session.getFactory(); int result = 1; result = 31 * result + (entityName != null ? entityName.hashCode() : 0); result = 31 * result + (tenantId != null ? tenantId.hashCode() : 0); for (int i = 0; i < naturalIdValues.length; i++) { final int naturalIdPropertyIndex = naturalIdPropertyIndexes[i]; final Type type = propertyTypes[naturalIdPropertyIndex]; final Object value = naturalIdValues[i]; result = 31 * result + (value != null ? type.getHashCode(value, factory) : 0); if (type instanceof EntityType && type.getSemiResolvedType(factory).getReturnedClass().isInstance(value)) { this.naturalIdValues[i] = (Serializable) value; } else {//from w ww. j a v a 2 s.com this.naturalIdValues[i] = type.disassemble(value, session, null); } } this.hashCode = result; }
From source file:net.e6tech.elements.persist.hibernate.ModifiedTableGenerator.java
License:Apache License
@Override public Serializable generate(final SharedSessionContractImplementor session, final Object obj) { final SqlStatementLogger statementLogger = session.getFactory().getServiceRegistry() .getService(JdbcServices.class).getSqlStatementLogger(); final SessionEventListenerManager statsCollector = session.getEventListenerManager(); return optimizer.generate(new AccessCallback() { @Override/*ww w . j a v a 2 s . co m*/ public IntegralDataTypeHolder getNextValue() { return session.getTransactionCoordinator().createIsolationDelegate() .delegateWork(new AbstractReturningWork<IntegralDataTypeHolder>() { @Override public IntegralDataTypeHolder execute(Connection connection) throws SQLException { final IntegralDataTypeHolder value = makeValue(); int rows; do { final PreparedStatement selectPS = prepareStatement(connection, selectQuery, statementLogger, statsCollector); try { selectPS.setString(1, segmentValue); final ResultSet selectRS = executeQuery(selectPS, statsCollector); if (!selectRS.next()) { value.initialize(initialValue); final PreparedStatement insertPS = prepareStatement(connection, insertQuery, statementLogger, statsCollector); try { LOG.tracef("binding parameter [%s] - [%s]", 1, segmentValue); insertPS.setString(1, segmentValue); value.bind(insertPS, 2); executeUpdate(insertPS, statsCollector); } finally { insertPS.close(); } } else { value.initialize(selectRS, 1); } selectRS.close(); } catch (SQLException e) { LOG.unableToReadOrInitHiValue(e); throw e; } finally { selectPS.close(); } final PreparedStatement updatePS = prepareStatement(connection, updateQuery, statementLogger, statsCollector); try { final IntegralDataTypeHolder updateValue = value.copy(); if (optimizer.applyIncrementSizeToSourceValues()) { updateValue.add(incrementSize); } else { updateValue.increment(); } updateValue.bind(updatePS, 1); value.bind(updatePS, 2); updatePS.setString(3, segmentValue); rows = executeUpdate(updatePS, statsCollector); } catch (SQLException e) { LOG.unableToUpdateQueryHiValue(renderedTableName, e); throw e; } finally { updatePS.close(); } } while (rows == 0); accessCount++; return value; } }, true); } @Override public String getTenantIdentifier() { return session.getTenantIdentifier(); } }); }