Java Code Examples for org.hibernate.EntityMode#POJO

The following examples show how to use org.hibernate.EntityMode#POJO . These examples are extracted from open source projects. 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 Project: lams   File: Property.java    License: GNU General Public License v2.0 6 votes vote down vote up
public PropertyAccessStrategy getPropertyAccessStrategy(Class clazz) throws MappingException {
	String accessName = getPropertyAccessorName();
	if ( accessName == null ) {
		if ( clazz == null || java.util.Map.class.equals( clazz ) ) {
			accessName = "map";
		}
		else {
			accessName = "property";
		}
	}

	final EntityMode entityMode = clazz == null || java.util.Map.class.equals( clazz )
			? EntityMode.MAP
			: EntityMode.POJO;

	return resolveServiceRegistry().getService( PropertyAccessStrategyResolver.class ).resolvePropertyAccessStrategy(
			clazz,
			accessName,
			entityMode
	);
}
 
Example 2
@Override
public Object nullSafeGet(
		ResultSet rs,
		String name,
		SharedSessionContractImplementor session,
		Object owner) throws HibernateException, SQLException {
	final Object discriminatorValue = underlyingType.nullSafeGet( rs, name, session, owner );
	final String entityName = persister.getSubclassForDiscriminatorValue( discriminatorValue );
	if ( entityName == null ) {
		throw new HibernateException( "Unable to resolve discriminator value [" + discriminatorValue + "] to entity name" );
	}
	final EntityPersister entityPersister = session.getEntityPersister( entityName, null );
	return ( EntityMode.POJO == entityPersister.getEntityMode() ) ? entityPersister.getMappedClass() : entityName;
}
 
Example 3
private ComponentMetamodel(Component component, ComponentTuplizerFactory componentTuplizerFactory){
	this.role = component.getRoleName();
	this.isKey = component.isKey();
	propertySpan = component.getPropertySpan();
	properties = new StandardProperty[propertySpan];
	Iterator itr = component.getPropertyIterator();
	int i = 0;
	while ( itr.hasNext() ) {
		Property property = ( Property ) itr.next();
		properties[i] = PropertyFactory.buildStandardProperty( property, false );
		propertyIndexes.put( property.getName(), i );
		i++;
	}

	entityMode = component.hasPojoRepresentation() ? EntityMode.POJO : EntityMode.MAP;

	// todo : move this to SF per HHH-3517; also see HHH-1907 and ComponentMetamodel
	final String tuplizerClassName = component.getTuplizerImplClassName( entityMode );
	this.componentTuplizer = tuplizerClassName == null ? componentTuplizerFactory.constructDefaultTuplizer(
			entityMode,
			component
	) : componentTuplizerFactory.constructTuplizer( tuplizerClassName, component );

	final ConfigurationService cs = component.getMetadata().getMetadataBuildingOptions().getServiceRegistry()
			.getService(ConfigurationService.class);

	this.createEmptyCompositesEnabled = ConfigurationHelper.getBoolean(
			Environment.CREATE_EMPTY_COMPOSITES_ENABLED,
			cs.getSettings(),
			false
	);
}
 
Example 4
public TypedValue[] getTypedValues(Criteria criteria, CriteriaQuery criteriaQuery) 
throws HibernateException {
	TypedValue[] superTv = super.getTypedValues(criteria, criteriaQuery);
	TypedValue[] result = new TypedValue[superTv.length+1];
	System.arraycopy(superTv, 0, result, 1, superTv.length);
	result[0] = new TypedValue( getTypes()[0], value, EntityMode.POJO );
	return result;
}
 
Example 5
public TypedValue[] getTypedValues(Criteria criteria, CriteriaQuery criteriaQuery) 
throws HibernateException {
	Type[] types = params.getPositionalParameterTypes();
	Object[] values = params.getPositionalParameterValues();
	TypedValue[] tv = new TypedValue[types.length];
	for ( int i=0; i<types.length; i++ ) {
		tv[i] = new TypedValue( types[i], values[i], EntityMode.POJO );
	}
	return tv;
}
 
Example 6
protected SQLCriterion(String sql, Object[] values, Type[] types) {
	this.sql = sql;
	typedValues = new TypedValue[values.length];
	for ( int i=0; i<typedValues.length; i++ ) {
		typedValues[i] = new TypedValue( types[i], values[i], EntityMode.POJO );
	}
}
 
Example 7
public TypedValue getTypedIdentifierValue(Criteria subcriteria, Object value) {
	final Loadable loadable = ( Loadable ) getPropertyMapping( getEntityName( subcriteria ) );
	return new TypedValue(
			loadable.getIdentifierType(),
	        value,
	        EntityMode.POJO
	);
}
 
Example 8
/**
 * Get the a typed value for the given property value.
 */
public TypedValue getTypedValue(Criteria subcriteria, String propertyName, Object value)
		throws HibernateException {
	// Detect discriminator values...
	if ( value instanceof Class ) {
		Class entityClass = ( Class ) value;
		Queryable q = SessionFactoryHelper.findQueryableUsingImports( sessionFactory, entityClass.getName() );
		if ( q != null ) {
			Type type = q.getDiscriminatorType();
			String stringValue = q.getDiscriminatorSQLValue();
			// Convert the string value into the proper type.
			if ( type instanceof NullableType ) {
				NullableType nullableType = ( NullableType ) type;
				value = nullableType.fromStringValue( stringValue );
			}
			else {
				throw new QueryException( "Unsupported discriminator type " + type );
			}
			return new TypedValue(
					type,
			        value,
			        EntityMode.POJO
			);
		}
	}
	// Otherwise, this is an ordinary value.
	return new TypedValue(
			getTypeUsingProjection( subcriteria, propertyName ),
	        value,
	        EntityMode.POJO
	);
}
 
Example 9
public void evictEntity(String entityName, Serializable id) throws HibernateException {
	EntityPersister p = getEntityPersister(entityName);
	if ( p.hasCache() ) {
		if ( log.isDebugEnabled() ) {
			log.debug( "evicting second-level cache: " + MessageHelper.infoString(p, id, this) );
		}
		CacheKey cacheKey = new CacheKey( id, p.getIdentifierType(), p.getRootEntityName(), EntityMode.POJO, this );
		p.getCache().remove( cacheKey );
	}
}
 
Example 10
public void evict(Class persistentClass, Serializable id) throws HibernateException {
	EntityPersister p = getEntityPersister( persistentClass.getName() );
	if ( p.hasCache() ) {
		if ( log.isDebugEnabled() ) {
			log.debug( "evicting second-level cache: " + MessageHelper.infoString(p, id, this) );
		}
		CacheKey cacheKey = new CacheKey( id, p.getIdentifierType(), p.getRootEntityName(), EntityMode.POJO, this );
		p.getCache().remove( cacheKey );
	}
}
 
Example 11
public void evictCollection(String roleName, Serializable id) throws HibernateException {
	CollectionPersister p = getCollectionPersister(roleName);
	if ( p.hasCache() ) {
		if ( log.isDebugEnabled() ) {
			log.debug( "evicting second-level cache: " + MessageHelper.collectionInfoString(p, id, this) );
		}
		CacheKey cacheKey = new CacheKey( id, p.getKeyType(), p.getRole(), EntityMode.POJO, this );
		p.getCache().remove( cacheKey );
	}
}
 
Example 12
public EntityMode guessEntityMode(Object object) {
	if ( !isInstance(object, EntityMode.POJO) ) {
		return null;
	}
	else {
		return EntityMode.POJO;
	}
}
 
Example 13
@Override
public EntityMode getEntityMode() {
	return EntityMode.POJO;
}
 
Example 14
public EntityMode getEntityMode() {
	return EntityMode.POJO;
}
 
Example 15
protected EntityMode determineEntityMode() {
	return StringHelper.isNotEmpty( entityNamingSource.getClassName() ) ? EntityMode.POJO : EntityMode.MAP;
}
 
Example 16
public TypedValue[] getTypedValues(Criteria criteria, CriteriaQuery criteriaQuery) 
throws HibernateException {
	return new TypedValue[] { 
		new TypedValue( Hibernate.INTEGER, new Integer(size), EntityMode.POJO ) 
	};
}
 
Example 17
public EntityMode getEntityMode() {
	return EntityMode.POJO;
}
 
Example 18
public EntityMode getEntityMode() {
	return EntityMode.POJO;
}
 
Example 19
private void checkEntityMode(EntityMode entityMode) {
	if ( EntityMode.POJO != entityMode ) {
		throw new IllegalArgumentException( "Unhandled EntityMode : " + entityMode );
	}
}
 
Example 20
/**
 * The callback from Hibernate in order to build an instance of the
 * entity represented by the given entity name.  Here, we build a
 * {@link Proxy} representing the entity.
 *
 * @param entityName The entity name for which to create an instance.  In our setup,
 * this is the interface name.
 * @param entityMode The entity mode in which to create an instance.  Here, we are only
 * interestes in custom behavior for the POJO entity mode.
 * @param id The identifier value for the given entity.
 * @return The instantiated instance.
 */
public Object instantiate(String entityName, EntityMode entityMode, Serializable id) {
	if ( entityMode == EntityMode.POJO ) {
		if ( Customer.class.getName().equals( entityName ) ) {
			return ProxyHelper.newCustomerProxy( id );
		}
		else if ( Company.class.getName().equals( entityName ) ) {
			return ProxyHelper.newCompanyProxy( id );
		}
	}
	return super.instantiate( entityName, entityMode, id );
}