Java Code Examples for org.hibernate.type.EntityType#getIdentifierOrUniqueKeyPropertyName()

The following examples show how to use org.hibernate.type.EntityType#getIdentifierOrUniqueKeyPropertyName() . 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: AbstractPropertyMapping.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
protected void initIdentifierPropertyPaths(
		final String path,
		final EntityType etype,
		final String[] columns,
		final String[] columnReaders,
		final String[] columnReaderTemplates,
		final Mapping factory) throws MappingException {

	Type idtype = etype.getIdentifierOrUniqueKeyType( factory );
	String idPropName = etype.getIdentifierOrUniqueKeyPropertyName( factory );
	boolean hasNonIdentifierPropertyNamedId = hasNonIdentifierPropertyNamedId( etype, factory );

	if ( etype.isReferenceToPrimaryKey() ) {
		if ( !hasNonIdentifierPropertyNamedId ) {
			String idpath1 = extendPath( path, EntityPersister.ENTITY_ID );
			addPropertyPath( idpath1, idtype, columns, columnReaders, columnReaderTemplates, null, factory );
			initPropertyPaths( idpath1, idtype, columns, columnReaders, columnReaderTemplates, null, factory );
		}
	}

	if ( idPropName != null ) {
		String idpath2 = extendPath( path, idPropName );
		addPropertyPath( idpath2, idtype, columns, columnReaders, columnReaderTemplates, null, factory );
		initPropertyPaths( idpath2, idtype, columns, columnReaders, columnReaderTemplates, null, factory );
	}
}
 
Example 2
Source File: AbstractPropertyMapping.java    From cacheonix-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
protected void initIdentifierPropertyPaths(
		final String path, 
		final EntityType etype, 
		final String[] columns, 
		final Mapping factory) throws MappingException {

	Type idtype = etype.getIdentifierOrUniqueKeyType( factory );
	String idPropName = etype.getIdentifierOrUniqueKeyPropertyName(factory);
	boolean hasNonIdentifierPropertyNamedId = hasNonIdentifierPropertyNamedId( etype, factory );

	if ( etype.isReferenceToPrimaryKey() ) {
		if ( !hasNonIdentifierPropertyNamedId ) {
			String idpath1 = extendPath(path, EntityPersister.ENTITY_ID);
			addPropertyPath(idpath1, idtype, columns, null);
			initPropertyPaths(idpath1, idtype, columns, null, factory);
		}
	}

	if (idPropName!=null) {
		String idpath2 = extendPath(path, idPropName);
		addPropertyPath(idpath2, idtype, columns, null);
		initPropertyPaths(idpath2, idtype, columns, null, factory);
	}
}
 
Example 3
Source File: SessionFactoryHelper.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Determine the name of the property for the entity encapsulated by the
 * given type which represents the id or unique-key.
 *
 * @param entityType The type representing the entity.
 * @return The corresponding property name
 * @throws QueryException Indicates such a property could not be found.
 */
public String getIdentifierOrUniqueKeyPropertyName(EntityType entityType) {
	try {
		return entityType.getIdentifierOrUniqueKeyPropertyName( sfi );
	}
	catch ( MappingException me ) {
		throw new QueryException( me );
	}
}
 
Example 4
Source File: PathExpressionParser.java    From cacheonix-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private void dereferenceEntity(String propertyName, EntityType propertyType, QueryTranslatorImpl q)
		throws QueryException {
	//NOTE: we avoid joining to the next table if the named property is just the foreign key value

	//if its "id"
	boolean isIdShortcut = EntityPersister.ENTITY_ID.equals( propertyName ) &&
			propertyType.isReferenceToPrimaryKey();

	//or its the id property name
	final String idPropertyName;
	try {
		idPropertyName = propertyType.getIdentifierOrUniqueKeyPropertyName( q.getFactory() );
	}
	catch ( MappingException me ) {
		throw new QueryException( me );
	}
	boolean isNamedIdPropertyShortcut = idPropertyName != null
			&& idPropertyName.equals( propertyName )
			&& propertyType.isReferenceToPrimaryKey();

	if ( isIdShortcut || isNamedIdPropertyShortcut ) {
		// special shortcut for id properties, skip the join!
		// this must only occur at the _end_ of a path expression
		if ( componentPath.length() > 0 ) componentPath.append( '.' );
		componentPath.append( propertyName );
	}
	else {
		String entityClass = propertyType.getAssociatedEntityName();
		String name = q.createNameFor( entityClass );
		q.addType( name, entityClass );
		addJoin( name, propertyType );
		if ( propertyType.isOneToOne() ) oneToOneOwnerName = currentName;
		ownerAssociationType = propertyType;
		currentName = name;
		currentProperty = propertyName;
		q.addPathAliasAndJoin( path.substring( 0, path.toString().lastIndexOf( '.' ) ), name, joinSequence.copy() );
		componentPath.setLength( 0 );
		currentPropertyMapping = q.getEntityPersister( entityClass );
	}
}
 
Example 5
Source File: PathExpressionParser.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
private void dereferenceEntity(String propertyName, EntityType propertyType, QueryTranslatorImpl q)
		throws QueryException {
	//NOTE: we avoid joining to the next table if the named property is just the foreign key value

	//if its "id"
	boolean isIdShortcut = EntityPersister.ENTITY_ID.equals( propertyName )
			&& propertyType.isReferenceToPrimaryKey();

	//or its the id property name
	final String idPropertyName;
	try {
		idPropertyName = propertyType.getIdentifierOrUniqueKeyPropertyName( q.getFactory() );
	}
	catch ( MappingException me ) {
		throw new QueryException( me );
	}
	boolean isNamedIdPropertyShortcut = idPropertyName != null
			&& idPropertyName.equals( propertyName )
			&& propertyType.isReferenceToPrimaryKey();


	if ( isIdShortcut || isNamedIdPropertyShortcut ) {
		// special shortcut for id properties, skip the join!
		// this must only occur at the _end_ of a path expression
		if ( componentPath.length() > 0 ) {
			componentPath.append( '.' );
		}
		componentPath.append( propertyName );
	}
	else {
		String entityClass = propertyType.getAssociatedEntityName();
		String name = q.createNameFor( entityClass );
		q.addType( name, entityClass );
		addJoin( name, propertyType );
		if ( propertyType.isOneToOne() ) {
			oneToOneOwnerName = currentName;
		}
		ownerAssociationType = propertyType;
		currentName = name;
		currentProperty = propertyName;
		q.addPathAliasAndJoin( path.substring( 0, path.toString().lastIndexOf( '.' ) ), name, joinSequence.copy() );
		componentPath.setLength( 0 );
		currentPropertyMapping = q.getEntityPersister( entityClass );
	}
}
 
Example 6
Source File: SessionFactoryHelper.java    From lams with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Determine the name of the property for the entity encapsulated by the
 * given type which represents the id or unique-key.
 *
 * @param entityType The type representing the entity.
 *
 * @return The corresponding property name
 *
 * @throws QueryException Indicates such a property could not be found.
 */
public String getIdentifierOrUniqueKeyPropertyName(EntityType entityType) {
	try {
		return entityType.getIdentifierOrUniqueKeyPropertyName( sfi );
	}
	catch ( MappingException me ) {
		throw new QueryException( me );
	}
}