Java Code Examples for org.hibernate.engine.spi.SessionFactoryImplementor

The following are top voted examples for showing how to use org.hibernate.engine.spi.SessionFactoryImplementor. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: lams   File: ConditionalParenthesisFunction.java   View source code 6 votes vote down vote up
@Override
public String render(Type firstArgumentType, List arguments, SessionFactoryImplementor sessionFactory) {
	final boolean hasArgs = !arguments.isEmpty();
	final StringBuilder buf = new StringBuilder( getName() );
	if ( hasArgs ) {
		buf.append( "(" );
		for ( int i = 0; i < arguments.size(); i++ ) {
			buf.append( arguments.get( i ) );
			if ( i < arguments.size() - 1 ) {
				buf.append( ", " );
			}
		}
		buf.append( ")" );
	}
	return buf.toString();
}
 
Example 2
Project: hibernate-ogm-ignite   File: IgniteTestHelper.java   View source code 6 votes vote down vote up
@Override
public long getNumberOfAssociations(SessionFactory sessionFactory) {
	int associationCount = 0;
	IgniteDatastoreProvider datastoreProvider = getProvider( sessionFactory );
	for ( CollectionPersister collectionPersister : ( (SessionFactoryImplementor) sessionFactory ).getCollectionPersisters().values() ) {
		AssociationKeyMetadata associationKeyMetadata = ( (OgmCollectionPersister) collectionPersister ).getAssociationKeyMetadata();
		if ( associationKeyMetadata.getAssociationKind() == AssociationKind.ASSOCIATION ) {
			IgniteCache<Object, BinaryObject> associationCache = getAssociationCache( sessionFactory, associationKeyMetadata );
			StringBuilder query = new StringBuilder( "SELECT " )
										.append( StringHelper.realColumnName( associationKeyMetadata.getColumnNames()[0] ) )
										.append( " FROM " ).append( associationKeyMetadata.getTable() );
			SqlFieldsQuery sqlQuery = datastoreProvider.createSqlFieldsQueryWithLog( query.toString(), null );
			Iterable<List<?>> queryResult = associationCache.query( sqlQuery );
			Set<Object> uniqs = new HashSet<>();
			for ( List<?> row : queryResult ) {
				Object value = row.get( 0 );
				if ( value != null ) {
					uniqs.add( value );
				}
			}
			associationCount += uniqs.size();
		}
	}
	return associationCount;
}
 
Example 3
Project: lams   File: HibernateTraversableResolver.java   View source code 6 votes vote down vote up
private void addAssociationsToTheSetForOneProperty(String name, Type type, String prefix, SessionFactoryImplementor factory) {

		if ( type.isCollectionType() ) {
			CollectionType collType = (CollectionType) type;
			Type assocType = collType.getElementType( factory );
			addAssociationsToTheSetForOneProperty(name, assocType, prefix, factory);
		}
		//ToOne association
		else if ( type.isEntityType() || type.isAnyType() ) {
			associations.add( prefix + name );
		} else if ( type.isComponentType() ) {
			CompositeType componentType = (CompositeType) type;
			addAssociationsToTheSetForAllProperties(
					componentType.getPropertyNames(),
					componentType.getSubtypes(),
					(prefix.equals( "" ) ? name : prefix + name) + ".",
					factory);
		}
	}
 
Example 4
Project: lams   File: CollectionType.java   View source code 6 votes vote down vote up
@Override
public String getAssociatedEntityName(SessionFactoryImplementor factory)
		throws MappingException {
	try {
		
		QueryableCollection collectionPersister = (QueryableCollection) factory
				.getCollectionPersister( role );
		
		if ( !collectionPersister.getElementType().isEntityType() ) {
			throw new MappingException( 
					"collection was not an association: " + 
					collectionPersister.getRole() 
				);
		}
		
		return collectionPersister.getElementPersister().getEntityName();
		
	}
	catch (ClassCastException cce) {
		throw new MappingException( "collection role is not queryable " + role );
	}
}
 
Example 5
Project: lams   File: ComponentType.java   View source code 6 votes vote down vote up
@Override
public String toLoggableString(Object value, SessionFactoryImplementor factory)
		throws HibernateException {
	if ( value == null ) {
		return "null";
	}

	if ( entityMode == null ) {
		throw new ClassCastException( value.getClass().getName() );
	}
	Map<String,String> result = new HashMap<String, String>();
	Object[] values = getPropertyValues( value, entityMode );
	for ( int i = 0; i < propertyTypes.length; i++ ) {
		result.put( propertyNames[i], propertyTypes[i].toLoggableString( values[i], factory ) );
	}
	return StringHelper.unqualify( getName() ) + result.toString();
}
 
Example 6
Project: lams   File: AbstractEmptinessExpression.java   View source code 6 votes vote down vote up
@Override
public final String toSqlString(Criteria criteria, CriteriaQuery criteriaQuery) throws HibernateException {
	final String entityName = criteriaQuery.getEntityName( criteria, propertyName );
	final String actualPropertyName = criteriaQuery.getPropertyName( propertyName );
	final String sqlAlias = criteriaQuery.getSQLAlias( criteria, propertyName );

	final SessionFactoryImplementor factory = criteriaQuery.getFactory();
	final QueryableCollection collectionPersister = getQueryableCollection( entityName, actualPropertyName, factory );

	final String[] collectionKeys = collectionPersister.getKeyColumnNames();
	final String[] ownerKeys = ( (Loadable) factory.getEntityPersister( entityName ) ).getIdentifierColumnNames();

	final String innerSelect = "(select 1 from " + collectionPersister.getTableName() + " where "
			+ new ConditionFragment().setTableAlias( sqlAlias ).setCondition( ownerKeys, collectionKeys ).toFragmentString()
			+ ")";

	return excludeEmpty()
			? "exists " + innerSelect
			: "not exists " + innerSelect;
}
 
Example 7
Project: lams   File: CastFunction.java   View source code 6 votes vote down vote up
@Override
public String render(Type columnType, List args, SessionFactoryImplementor factory) throws QueryException {
	if ( args.size()!=2 ) {
		throw new QueryException( "cast() requires two arguments; found : " + args.size() );
	}
	final String type = (String) args.get( 1 );
	final int[] sqlTypeCodes = factory.getTypeResolver().heuristicType( type ).sqlTypes( factory );
	if ( sqlTypeCodes.length!=1 ) {
		throw new QueryException("invalid Hibernate type for cast()");
	}
	String sqlType = factory.getDialect().getCastTypeName( sqlTypeCodes[0] );
	if ( sqlType == null ) {
		//TODO: never reached, since getExplicitHibernateTypeName() actually throws an exception!
		sqlType = type;
	}
	return "cast(" + args.get( 0 ) + " as " + sqlType + ')';
}
 
Example 8
Project: lams   File: SubqueryExpression.java   View source code 6 votes vote down vote up
/**
 * Creates the inner query used to extract some useful information about types, since it is needed in both methods.
 *
 * @param criteriaQuery The criteria query
 * @param factory The session factory.
 */
private void createAndSetInnerQuery(CriteriaQuery criteriaQuery, SessionFactoryImplementor factory) {
	if ( innerQuery == null ) {
		//with two-deep subqueries, the same alias would get generated for
		//both using the old method (criteriaQuery.generateSQLAlias()), so
		//that is now used as a fallback if the main criteria alias isn't set
		String alias;
		if ( this.criteriaImpl.getAlias() == null ) {
			alias = criteriaQuery.generateSQLAlias();
		}
		else {
			alias = this.criteriaImpl.getAlias() + "_";
		}

		innerQuery = new CriteriaQueryTranslator(
				factory,
				criteriaImpl,
				criteriaImpl.getEntityOrClassName(),
				alias,
				criteriaQuery
			);

		params = innerQuery.getQueryParameters();
		types = innerQuery.getProjectedTypes();
	}
}
 
Example 9
Project: lams   File: JoinedSubclassEntityPersister.java   View source code 6 votes vote down vote up
private void associateSubclassNamesToSubclassTableIndexes(
		PersistentClass persistentClass,
		Set<String> classNames,
		String[][] mapping,
		SessionFactoryImplementor factory) {

	final String tableName = persistentClass.getTable().getQualifiedName(
			factory.getDialect(),
			factory.getSettings().getDefaultCatalogName(),
			factory.getSettings().getDefaultSchemaName()
	);

	associateSubclassNamesToSubclassTableIndex( tableName, classNames, mapping );

	Iterator itr = persistentClass.getJoinIterator();
	while ( itr.hasNext() ) {
		final Join join = (Join) itr.next();
		final String secondaryTableName = join.getTable().getQualifiedName(
				factory.getDialect(),
				factory.getSettings().getDefaultCatalogName(),
				factory.getSettings().getDefaultSchemaName()
		);
		associateSubclassNamesToSubclassTableIndex( secondaryTableName, classNames, mapping );
	}
}
 
Example 10
Project: hibernate-ogm-ignite   File: IgniteTestHelper.java   View source code 6 votes vote down vote up
@Override
public Map<String, Object> extractEntityTuple(Session session, EntityKey key) {
	SessionFactoryImplementor sessionFactory = (SessionFactoryImplementor) session.getSessionFactory();
	IgniteCache<Object, BinaryObject> cache = getEntityCache( sessionFactory, key.getMetadata() );
	Object cacheKey = getProvider( sessionFactory ).createKeyObject( key );

	Map<String, Object> result = new HashMap<>();
	BinaryObject po = cache.get( cacheKey );

	TupleSnapshot snapshot = new IgniteTupleSnapshot( cacheKey, po, key.getMetadata() );
	for ( String fieldName : snapshot.getColumnNames() ) {
		result.put( fieldName, snapshot.get( fieldName ) );
	}

	return result;
}
 
Example 11
Project: lams   File: BasicCollectionLoader.java   View source code 6 votes vote down vote up
protected BasicCollectionLoader(
		QueryableCollection collectionPersister,
		int batchSize,
		String subquery,
		SessionFactoryImplementor factory,
		LoadQueryInfluencers loadQueryInfluencers) throws MappingException {
	super( collectionPersister, factory, loadQueryInfluencers );

	JoinWalker walker = new BasicCollectionJoinWalker(
			collectionPersister,
			batchSize,
			subquery,
			factory,
			loadQueryInfluencers
	);
	initFromWalker( walker );

	postInstantiate();

	if ( LOG.isDebugEnabled() ) {
		LOG.debugf( "Static select for collection %s: %s", collectionPersister.getRole(), getSQLString() );
	}
}
 
Example 12
Project: lams   File: JoinHelper.java   View source code 6 votes vote down vote up
public JoinDefinedByMetadata createCollectionJoin(
		QuerySpace leftHandSide,
		String lhsPropertyName,
		CollectionQuerySpace rightHandSide,
		boolean rightHandSideRequired,
		CollectionType joinedPropertyType,
		SessionFactoryImplementor sessionFactory) {
	return new JoinImpl(
			leftHandSide,
			lhsPropertyName,
			rightHandSide,
			joinedPropertyType.getAssociatedJoinable( sessionFactory ).getKeyColumnNames(),
			joinedPropertyType,
			rightHandSideRequired
	);
}
 
Example 13
Project: lams   File: PositionSubstringFunction.java   View source code 6 votes vote down vote up
@Override
public String render(Type firstArgumentType, List args, SessionFactoryImplementor factory) throws QueryException {
	final boolean threeArgs = args.size() > 2;
	final Object pattern = args.get( 0 );
	final Object string = args.get( 1 );
	final Object start = threeArgs ? args.get( 2 ) : null;

	final StringBuilder buf = new StringBuilder();
	if (threeArgs) {
		buf.append( '(' );
	}
	buf.append( "position(" ).append( pattern ).append( " in " );
	if (threeArgs) {
		buf.append( "substring(");
	}
	buf.append( string );
	if (threeArgs) {
		buf.append( ", " ).append( start ).append( ')' );
	}
	buf.append( ')' );
	if (threeArgs) {
		buf.append( '+' ).append( start ).append( "-1)" );
	}
	return buf.toString();
}
 
Example 14
Project: lams   File: SessionFactoryServiceRegistryImpl.java   View source code 6 votes vote down vote up
@SuppressWarnings( {"unchecked"})
public SessionFactoryServiceRegistryImpl(
		ServiceRegistryImplementor parent,
		SessionFactoryImplementor sessionFactory,
		MetadataImplementor metadata) {
	super( parent );

	this.sessionFactory = sessionFactory;
	this.configuration = null;
	this.metadata = metadata;

	// for now, just use the standard initiator list
	for ( SessionFactoryServiceInitiator initiator : StandardSessionFactoryServiceInitiators.LIST ) {
		// create the bindings up front to help identify to which registry services belong
		createServiceBinding( initiator );
	}
}
 
Example 15
Project: lams   File: SelectLockingStrategy.java   View source code 6 votes vote down vote up
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.getSettings().isCommentsEnabled() ) {
		select.setComment( getLockMode() + " lock " + getLockable().getEntityName() );
	}
	return select.toStatementString();
}
 
Example 16
Project: lams   File: JoinedSubclassEntityPersister.java   View source code 6 votes vote down vote up
private Set<String> processPersistentClassHierarchy(
		PersistentClass persistentClass,
		boolean isBase,
		SessionFactoryImplementor factory,
		String[][] mapping) {

	// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	// collect all the class names that indicate that the "main table" of the given PersistentClass should be
	// included when one of the collected class names is used in TREAT
	final Set<String> classNames = new HashSet<String>();

	final Iterator itr = persistentClass.getDirectSubclasses();
	while ( itr.hasNext() ) {
		final Subclass subclass = (Subclass) itr.next();
		final Set<String> subclassSubclassNames = processPersistentClassHierarchy(
				subclass,
				false,
				factory,
				mapping
		);
		classNames.addAll( subclassSubclassNames );
	}

	classNames.add( persistentClass.getEntityName() );

	if ( ! isBase ) {
		MappedSuperclass msc = persistentClass.getSuperMappedSuperclass();
		while ( msc != null ) {
			classNames.add( msc.getMappedClass().getName() );
			msc = msc.getSuperMappedSuperclass();
		}

		associateSubclassNamesToSubclassTableIndexes( persistentClass, classNames, mapping, factory );
	}

	return classNames;
}
 
Example 17
Project: lams   File: UnionSubclassEntityPersister.java   View source code 6 votes vote down vote up
public UnionSubclassEntityPersister(
		final EntityBinding entityBinding,
		final EntityRegionAccessStrategy cacheAccessStrategy,
		final NaturalIdRegionAccessStrategy naturalIdRegionAccessStrategy,
		final SessionFactoryImplementor factory,
		final Mapping mapping) throws HibernateException {
	super(entityBinding, cacheAccessStrategy, naturalIdRegionAccessStrategy, factory );
	// TODO: implement!!! initializing final fields to null to make compiler happy.
	subquery = null;
	tableName = null;
	subclassClosure = null;
	spaces = null;
	subclassSpaces = null;
	discriminatorValue = null;
	discriminatorSQLValue = null;
	constraintOrderedTableNames = null;
	constraintOrderedKeyColumnNames = null;
}
 
Example 18
Project: lams   File: OneToManyLoadQueryDetails.java   View source code 6 votes vote down vote up
/**
 * Constructs a EntityLoadQueryDetails object from the given inputs.
 *
 * @param loadPlan The load plan
 * @param buildingParameters Any influencers that would affect the generated SQL (mostly we are concerned with those
 * that add additional joins here)
 * @param factory The SessionFactory
 *
 * @return The EntityLoadQueryDetails
 */
OneToManyLoadQueryDetails(
		LoadPlan loadPlan,
		AliasResolutionContextImpl aliasResolutionContext,
		CollectionReturn rootReturn,
		QueryBuildingParameters buildingParameters,
		SessionFactoryImplementor factory) {
	super(
			loadPlan,
			aliasResolutionContext,
			rootReturn,
			buildingParameters,
			factory
	);
	generate();
}
 
Example 19
Project: ipf-flow-manager   File: CustomEventRegistration.java   View source code 6 votes vote down vote up
@Override
public void integrate(Metadata metadata, SessionFactoryImplementor sessionFactory, SessionFactoryServiceRegistry serviceRegistry) {
    EventListenerRegistry service = serviceRegistry.getService(org.hibernate.event.service.spi.EventListenerRegistry.class);

    StandardPBEStringEncryptor encrypt = new StandardPBEStringEncryptor();
    encrypt.setPassword("test_password");
    RenderedMessageEncryptEventListener encryptListener = new RenderedMessageEncryptEventListener();
    encryptListener.setStringEncryptor(encrypt);

    RenderedMessageDecryptEventListener decryptListener = new RenderedMessageDecryptEventListener();
    decryptListener.setStringEncryptor(encrypt);

    FullTextIndexEventListener fullTextListener = new FullTextIndexEventListener();

    service.appendListeners(EventType.PRE_UPDATE, encryptListener);
    service.prependListeners(EventType.POST_UPDATE, decryptListener);
    service.appendListeners(EventType.PRE_INSERT, encryptListener);
    service.prependListeners(EventType.POST_INSERT, decryptListener);
    service.appendListeners(EventType.POST_LOAD, decryptListener);
}
 
Example 20
Project: lams   File: SubselectOneToManyLoader.java   View source code 6 votes vote down vote up
public SubselectOneToManyLoader(
		QueryableCollection persister, 
		String subquery,
		Collection entityKeys,
		QueryParameters queryParameters,
		Map<String, int[]> namedParameterLocMap,
		SessionFactoryImplementor factory, 
		LoadQueryInfluencers loadQueryInfluencers) throws MappingException {
	super( persister, 1, subquery, factory, loadQueryInfluencers );

	keys = new Serializable[ entityKeys.size() ];
	Iterator iter = entityKeys.iterator();
	int i=0;
	while ( iter.hasNext() ) {
		keys[i++] = ( (EntityKey) iter.next() ).getIdentifier();
	}
	
	this.namedParameters = queryParameters.getNamedParameters();
	this.types = queryParameters.getFilteredPositionalParameterTypes();
	this.values = queryParameters.getFilteredPositionalParameterValues();
	this.namedParameterLocMap = namedParameterLocMap;
}
 
Example 21
Project: hibernate-ogm-redis   File: RedisTestHelper.java   View source code 5 votes vote down vote up
private static RedisDatastoreProvider getProvider(SessionFactory sessionFactory) {
	DatastoreProvider provider = ( (SessionFactoryImplementor) sessionFactory ).getServiceRegistry().getService(
			DatastoreProvider.class
	);
	if ( !( RedisDatastoreProvider.class.isInstance( provider ) ) ) {
		throw new RuntimeException( "Not testing with RedisDatastoreProvider, cannot extract underlying map." );
	}

	return RedisDatastoreProvider.class.cast( provider );
}
 
Example 22
Project: lams   File: AbstractNullnessCheckNode.java   View source code 5 votes vote down vote up
@Override
public void initialize() {
	// TODO : this really needs to be delayed unitl after 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 );
	}
}
 
Example 23
Project: lams   File: AbstractCompositionAttribute.java   View source code 5 votes vote down vote up
protected AbstractCompositionAttribute(
		AttributeSource source,
		SessionFactoryImplementor sessionFactory,
		int entityBasedAttributeNumber,
		String attributeName,
		CompositeType attributeType,
		int columnStartPosition,
		BaselineAttributeInformation baselineInfo) {
	super( source, sessionFactory, entityBasedAttributeNumber, attributeName, attributeType, baselineInfo );
	this.columnStartPosition = columnStartPosition;
}
 
Example 24
Project: lams   File: PersisterFactoryImpl.java   View source code 5 votes vote down vote up
@Override
@SuppressWarnings( {"unchecked"})
public EntityPersister createEntityPersister(
		PersistentClass metadata,
		EntityRegionAccessStrategy cacheAccessStrategy,
		NaturalIdRegionAccessStrategy naturalIdRegionAccessStrategy,
		SessionFactoryImplementor factory,
		Mapping cfg) {
	Class<? extends EntityPersister> persisterClass = metadata.getEntityPersisterClass();
	if ( persisterClass == null ) {
		persisterClass = serviceRegistry.getService( PersisterClassResolver.class ).getEntityPersisterClass( metadata );
	}
	return create( persisterClass, ENTITY_PERSISTER_CONSTRUCTOR_ARGS, metadata, cacheAccessStrategy, naturalIdRegionAccessStrategy, factory, cfg );
}
 
Example 25
Project: hibernate-ogm-ignite   File: IgniteQueryParserServiceInitiator.java   View source code 5 votes vote down vote up
@Override
public QueryParserService initiateService(
		SessionFactoryImplementor sessionFactory,
		SessionFactoryOptions sessionFactoryOptions,
		ServiceRegistryImplementor registry) {
	return IgniteQueryParserService.INSTANCE;
}
 
Example 26
Project: lams   File: AnyType.java   View source code 5 votes vote down vote up
@Override
public String toLoggableString(Object value, SessionFactoryImplementor factory) throws HibernateException {
	//TODO: terrible implementation!
	return value == null
			? "null"
			: factory.getTypeHelper()
			.entity( HibernateProxyHelper.getClassWithoutInitializingProxy( value ) )
			.toLoggableString( value, factory );
}
 
Example 27
Project: lams   File: MessageHelper.java   View source code 5 votes vote down vote up
/**
 * Generate an info message string relating to a particular entity.
 *
 * @param persister The persister for the entity
 * @param id The entity id value
 * @param factory The session factory - Could be null!
 * @return An info string, in the form [FooBar#1]
 */
public static String infoString(
		EntityPersister persister,
		Object id, 
		SessionFactoryImplementor factory) {
	StringBuilder s = new StringBuilder();
	s.append( '[' );
	Type idType;
	if( persister == null ) {
		s.append( "<null EntityPersister>" );
		idType = null;
	}
	else {
		s.append( persister.getEntityName() );
		idType = persister.getIdentifierType();
	}
	s.append( '#' );

	if ( id == null ) {
		s.append( "<null>" );
	}
	else {
		if ( idType == null ) {
			s.append( id );
		}
		else {
			if ( factory != null ) {
				s.append( idType.toLoggableString( id, factory ) );
			}
			else {
				s.append( "<not loggable>" );
			}
		}
	}
	s.append( ']' );

	return s.toString();

}
 
Example 28
Project: lams   File: CollectionType.java   View source code 5 votes vote down vote up
@Override
public void setToXMLNode(Node node, Object value, SessionFactoryImplementor factory)
		throws HibernateException {
	if ( !isEmbeddedInXML ) {
		node.detach();
	}
	else {
		replaceNode( node, (Element) value );
	}
}
 
Example 29
Project: lams   File: AnyType.java   View source code 5 votes vote down vote up
@Override
public String getOnCondition(
		String alias,
		SessionFactoryImplementor factory,
		Map enabledFilters,
		Set<String> treatAsDeclarations) {
	throw new UnsupportedOperationException();
}
 
Example 30
Project: lams   File: FilterHelper.java   View source code 5 votes vote down vote up
/**
 * The map of defined filters.  This is expected to be in format
 * where the filter names are the map keys, and the defined
 * conditions are the values.
 *
 * @param filters The map of defined filters.
 * @param factory The session factory
 */
public FilterHelper(List<FilterConfiguration> filters, SessionFactoryImplementor factory) {
	int filterCount = filters.size();
	filterNames = new String[filterCount];
	filterConditions = new String[filterCount];
	filterAutoAliasFlags = new boolean[filterCount];
	filterAliasTableMaps = new Map[filterCount];
	filterCount = 0;
	for ( final FilterConfiguration filter : filters ) {
		filterAutoAliasFlags[filterCount] = false;
		filterNames[filterCount] = filter.getName();
		filterConditions[filterCount] = filter.getCondition();
		filterAliasTableMaps[filterCount] = filter.getAliasTableMap( factory );
		if ( (filterAliasTableMaps[filterCount].isEmpty() || isTableFromPersistentClass( filterAliasTableMaps[filterCount] )) && filter
				.useAutoAliasInjection() ) {
			filterConditions[filterCount] = Template.renderWhereStringTemplate(
					filter.getCondition(),
					FilterImpl.MARKER,
					factory.getDialect(),
					factory.getSqlFunctionRegistry()
			);
			filterAutoAliasFlags[filterCount] = true;
		}
		filterConditions[filterCount] = StringHelper.replace(
				filterConditions[filterCount],
				":",
				":" + filterNames[filterCount] + "."
		);
		filterCount++;
	}
}
 
Example 31
Project: lams   File: ByteArrayBlobType.java   View source code 5 votes vote down vote up
@Override
public boolean isEqual(Object x, Object y, SessionFactoryImplementor factory) {
	if ( x == y ) return true;
	if ( x == null || y == null ) return false;
	if ( x instanceof Byte[] ) {
		Object[] o1 = (Object[]) x;
		Object[] o2 = (Object[]) y;
		return ArrayHelper.isEquals( o1, o2 );
	}
	else {
		byte[] c1 = (byte[]) x;
		byte[] c2 = (byte[]) y;
		return ArrayHelper.isEquals( c1, c2 );
	}
}
 
Example 32
Project: lams   File: CollectionCacheInvalidator.java   View source code 5 votes vote down vote up
private void integrate(SessionFactoryServiceRegistry serviceRegistry, SessionFactoryImplementor sessionFactory) {
	if ( !sessionFactory.getSettings().isAutoEvictCollectionCache() ) {
		// feature is disabled
		return;
	}
	if ( !sessionFactory.getSettings().isSecondLevelCacheEnabled() ) {
		// Nothing to do, if caching is disabled
		return;
	}
	EventListenerRegistry eventListenerRegistry = serviceRegistry.getService( EventListenerRegistry.class );
	eventListenerRegistry.appendListeners( EventType.POST_INSERT, this );
	eventListenerRegistry.appendListeners( EventType.POST_DELETE, this );
	eventListenerRegistry.appendListeners( EventType.POST_UPDATE, this );
}
 
Example 33
Project: lams   File: PropertyFactory.java   View source code 5 votes vote down vote up
/**
 * Generates a VersionProperty representation for an entity mapping given its
 * version mapping Property.
 *
 * @param property The version mapping Property.
 * @param lazyAvailable Is property lazy loading currently available.
 * @return The appropriate VersionProperty definition.
 */
public static VersionProperty buildVersionProperty(
		EntityPersister persister,
		SessionFactoryImplementor sessionFactory,
		int attributeNumber,
		Property property,
		boolean lazyAvailable) {
	String mappedUnsavedValue = ( (KeyValue) property.getValue() ).getNullValue();
	
	VersionValue unsavedValue = UnsavedValueFactory.getUnsavedVersionValue(
			mappedUnsavedValue,
			getGetter( property ),
			(VersionType) property.getType(),
			getConstructor( property.getPersistentClass() )
	);

	boolean lazy = lazyAvailable && property.isLazy();

	return new VersionProperty(
			persister,
			sessionFactory,
			attributeNumber,
	        property.getName(),
	        property.getValue().getType(),
			new BaselineAttributeInformation.Builder()
					.setLazy( lazy )
					.setInsertable( property.isInsertable() )
					.setUpdateable( property.isUpdateable() )
					.setValueGenerationStrategy( property.getValueGenerationStrategy() )
					.setNullable( property.isOptional() )
					.setDirtyCheckable( property.isUpdateable() && !lazy )
					.setVersionable( property.isOptimisticLocked() )
					.setCascadeStyle( property.getCascadeStyle() )
					.createInformation(),
	        unsavedValue
		);
}
 
Example 34
Project: lams   File: BatchingEntityLoaderBuilder.java   View source code 5 votes vote down vote up
public static BatchingEntityLoaderBuilder getBuilder(SessionFactoryImplementor factory) {
		switch ( factory.getSettings().getBatchFetchStyle() ) {
			case PADDED: {
				return PaddedBatchingEntityLoaderBuilder.INSTANCE;
			}
			case DYNAMIC: {
				return DynamicBatchingEntityLoaderBuilder.INSTANCE;
			}
			default: {
				return org.hibernate.loader.entity.plan.LegacyBatchingEntityLoaderBuilder.INSTANCE;
//				return LegacyBatchingEntityLoaderBuilder.INSTANCE;
			}
		}
	}
 
Example 35
Project: lams   File: BatchingEntityLoaderBuilder.java   View source code 5 votes vote down vote up
/**
 * Builds a batch-fetch capable loader based on the given persister, lock-mode, etc.
 *
 * @param persister The entity persister
 * @param batchSize The maximum number of ids to batch-fetch at once
 * @param lockMode The lock mode
 * @param factory The SessionFactory
 * @param influencers Any influencers that should affect the built query
 *
 * @return The loader.
 */
public UniqueEntityLoader buildLoader(
		OuterJoinLoadable persister,
		int batchSize,
		LockMode lockMode,
		SessionFactoryImplementor factory,
		LoadQueryInfluencers influencers) {
	if ( batchSize <= 1 ) {
		// no batching
		return buildNonBatchingLoader( persister, lockMode, factory, influencers );
	}
	return buildBatchingLoader( persister, batchSize, lockMode, factory, influencers );
}
 
Example 36
Project: lams   File: ClassicQueryTranslatorFactory.java   View source code 5 votes vote down vote up
/**
 * @see QueryTranslatorFactory#createQueryTranslator
 */
public QueryTranslator createQueryTranslator(
		String queryIdentifier,
        String queryString,
        Map filters,
        SessionFactoryImplementor factory,
        EntityGraphQueryHint entityGraphQueryHint) {
	if (entityGraphQueryHint != null) {
		throw new QueryException( "EntityGraphs cannot be applied queries using the classic QueryTranslator!" );
	}
	return new QueryTranslatorImpl( queryIdentifier, queryString, filters, factory );
}
 
Example 37
Project: lams   File: Template.java   View source code 5 votes vote down vote up
public static String renderOrderByStringTemplate(
		String orderByFragment,
		final ColumnMapper columnMapper,
		final SessionFactoryImplementor sessionFactory,
		final Dialect dialect,
		final SQLFunctionRegistry functionRegistry) {
	return translateOrderBy(
			orderByFragment,
			columnMapper,
			sessionFactory,
			dialect,
			functionRegistry
	).injectAliases( LEGACY_ORDER_BY_ALIAS_RESOLVER );
}
 
Example 38
Project: lams   File: EntityBasedAssociationAttribute.java   View source code 5 votes vote down vote up
public EntityBasedAssociationAttribute(
		EntityPersister source,
		SessionFactoryImplementor sessionFactory,
		int attributeNumber,
		String attributeName,
		AssociationType attributeType,
		BaselineAttributeInformation baselineInfo) {
	super( source, sessionFactory, attributeNumber, attributeName, attributeType, baselineInfo );
}
 
Example 39
Project: hibernate-ogm-ignite   File: IgniteTestHelper.java   View source code 5 votes vote down vote up
@Override
public long getNumberOfEntities(SessionFactory sessionFactory) {
	int entityCount = 0;
	Set<IgniteCache<?, ?>> processedCaches = Collections.newSetFromMap( new IdentityHashMap<IgniteCache<?, ?>, Boolean>() );
	for ( EntityPersister entityPersister : ( (SessionFactoryImplementor) sessionFactory ).getEntityPersisters().values() ) {
		IgniteCache<?, ?> entityCache = getEntityCache( sessionFactory, ( (OgmEntityPersister) entityPersister ).getEntityKeyMetadata() );
		if ( !processedCaches.contains( entityCache ) ) {
			entityCount += entityCache.size( CachePeekMode.ALL );
			processedCaches.add( entityCache );
		}
	}
	return entityCount;
}
 
Example 40
Project: lams   File: EntityLoader.java   View source code 5 votes vote down vote up
public EntityLoader(
		OuterJoinLoadable persister,
		LockOptions lockOptions,
		SessionFactoryImplementor factory,
		LoadQueryInfluencers loadQueryInfluencers) throws MappingException {
	this( persister, 1, lockOptions, factory, loadQueryInfluencers );
}