Java Code Examples for org.hibernate.persister.entity.EntityPersister#getVersionProperty()

The following examples show how to use org.hibernate.persister.entity.EntityPersister#getVersionProperty() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Example.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public TypedValue[] getTypedValues(Criteria criteria, CriteriaQuery criteriaQuery) {
	final EntityPersister meta = criteriaQuery.getFactory().getEntityPersister(
			criteriaQuery.getEntityName( criteria )
	);
	final String[] propertyNames = meta.getPropertyNames();
	final Type[] propertyTypes = meta.getPropertyTypes();

	final Object[] values = meta.getPropertyValues( exampleEntity );
	final List<TypedValue> list = new ArrayList<TypedValue>();
	for ( int i=0; i<propertyNames.length; i++ ) {
		final Object value = values[i];
		final Type type = propertyTypes[i];
		final String name = propertyNames[i];

		final boolean isVersionProperty = i == meta.getVersionProperty();

		if ( ! isVersionProperty && isPropertyIncluded( value, name, type ) ) {
			if ( propertyTypes[i].isComponentType() ) {
				addComponentTypedValues( name, value, (CompositeType) type, list, criteria, criteriaQuery );
			}
			else {
				addPropertyTypedValue( value, type, list );
			}
		}
	}

	return list.toArray( new TypedValue[ list.size() ] );
}
 
Example 2
Source File: Example.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
public String toSqlString(Criteria criteria, CriteriaQuery criteriaQuery)
	throws HibernateException {

	StringBuffer buf = new StringBuffer().append('(');
	EntityPersister meta = criteriaQuery.getFactory().getEntityPersister( criteriaQuery.getEntityName(criteria) );
	String[] propertyNames = meta.getPropertyNames();
	Type[] propertyTypes = meta.getPropertyTypes();
	//TODO: get all properties, not just the fetched ones!
	Object[] propertyValues = meta.getPropertyValues( entity, getEntityMode(criteria, criteriaQuery) );
	for (int i=0; i<propertyNames.length; i++) {
		Object propertyValue = propertyValues[i];
		String propertyName = propertyNames[i];

		boolean isPropertyIncluded = i!=meta.getVersionProperty() &&
			isPropertyIncluded( propertyValue, propertyName, propertyTypes[i] );
		if (isPropertyIncluded) {
			if ( propertyTypes[i].isComponentType() ) {
				appendComponentCondition(
					propertyName,
					propertyValue,
					(AbstractComponentType) propertyTypes[i],
					criteria,
					criteriaQuery,
					buf
				);
			}
			else {
				appendPropertyCondition(
					propertyName,
					propertyValue,
					criteria,
					criteriaQuery,
					buf
				);
			}
		}
	}
	if ( buf.length()==1 ) buf.append("1=1"); //yuck!
	return buf.append(')').toString();
}
 
Example 3
Source File: Example.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
public TypedValue[] getTypedValues(Criteria criteria, CriteriaQuery criteriaQuery)
throws HibernateException {

	EntityPersister meta = criteriaQuery.getFactory()
			.getEntityPersister( criteriaQuery.getEntityName(criteria) );
	String[] propertyNames = meta.getPropertyNames();
	Type[] propertyTypes = meta.getPropertyTypes();
	 //TODO: get all properties, not just the fetched ones!
	Object[] values = meta.getPropertyValues( entity, getEntityMode(criteria, criteriaQuery) );
	List list = new ArrayList();
	for (int i=0; i<propertyNames.length; i++) {
		Object value = values[i];
		Type type = propertyTypes[i];
		String name = propertyNames[i];

		boolean isPropertyIncluded = i!=meta.getVersionProperty() &&
			isPropertyIncluded(value, name, type);

		if (isPropertyIncluded) {
			if ( propertyTypes[i].isComponentType() ) {
				addComponentTypedValues(name, value, (AbstractComponentType) type, list, criteria, criteriaQuery);
			}
			else {
				addPropertyTypedValue(value, type, list);
			}
		}
	}
	return (TypedValue[]) list.toArray(TYPED_VALUES);
}
 
Example 4
Source File: Example.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
@Override
public String toSqlString(Criteria criteria, CriteriaQuery criteriaQuery) {
	final StringBuilder buf = new StringBuilder().append( '(' );
	final EntityPersister meta = criteriaQuery.getFactory().getEntityPersister(
			criteriaQuery.getEntityName( criteria )
	);
	final String[] propertyNames = meta.getPropertyNames();
	final Type[] propertyTypes = meta.getPropertyTypes();

	final Object[] propertyValues = meta.getPropertyValues( exampleEntity );
	for ( int i=0; i<propertyNames.length; i++ ) {
		final Object propertyValue = propertyValues[i];
		final String propertyName = propertyNames[i];

		final boolean isVersionProperty = i == meta.getVersionProperty();
		if ( ! isVersionProperty && isPropertyIncluded( propertyValue, propertyName, propertyTypes[i] ) ) {
			if ( propertyTypes[i].isComponentType() ) {
				appendComponentCondition(
					propertyName,
					propertyValue,
					(CompositeType) propertyTypes[i],
					criteria,
					criteriaQuery,
					buf
				);
			}
			else {
				appendPropertyCondition(
					propertyName,
					propertyValue,
					criteria,
					criteriaQuery,
					buf
				);
			}
		}
	}

	if ( buf.length()==1 ) {
		buf.append( "1=1" );
	}

	return buf.append( ')' ).toString();
}
 
Example 5
Source File: Versioning.java    From lams with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Inject the optimistic locking value into the entity state snapshot.
 *
 * @param fields The state snapshot
 * @param version The optimistic locking value
 * @param persister The entity persister
 */
public static void setVersion(Object[] fields, Object version, EntityPersister persister) {
	if ( !persister.isVersioned() ) {
		return;
	}
	fields[ persister.getVersionProperty() ] = version;
}
 
Example 6
Source File: Versioning.java    From lams with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Extract the optimistic locking value out of the entity state snapshot.
 *
 * @param fields The state snapshot
 * @param persister The entity persister
 * @return The extracted optimistic locking value
 */
public static Object getVersion(Object[] fields, EntityPersister persister) {
	if ( !persister.isVersioned() ) {
		return null;
	}
	return fields[ persister.getVersionProperty() ];
}
 
Example 7
Source File: Versioning.java    From cacheonix-core with GNU Lesser General Public License v2.1 3 votes vote down vote up
/**
 * Inject the optimisitc locking value into the entity state snapshot.
 *
 * @param fields The state snapshot
 * @param version The optimisitc locking value
 * @param persister The entity persister
 */
public static void setVersion(Object[] fields, Object version, EntityPersister persister) {
	if ( !persister.isVersioned() ) {
		return;
	}
	fields[ persister.getVersionProperty() ] = version;
}
 
Example 8
Source File: Versioning.java    From cacheonix-core with GNU Lesser General Public License v2.1 3 votes vote down vote up
/**
 * Extract the optimisitc locking value out of the entity state snapshot.
 *
 * @param fields The state snapshot
 * @param persister The entity persister
 * @return The extracted optimisitc locking value
 */
public static Object getVersion(Object[] fields, EntityPersister persister) {
	if ( !persister.isVersioned() ) {
		return null;
	}
	return fields[ persister.getVersionProperty() ];
}