Java Code Examples for org.hibernate.internal.util.StringHelper#root()

The following examples show how to use org.hibernate.internal.util.StringHelper#root() . 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: PersistentClass.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private Property getProperty(String propertyName, Iterator iterator) throws MappingException {
	if ( iterator.hasNext() ) {
		String root = StringHelper.root( propertyName );
		while ( iterator.hasNext() ) {
			Property prop = (Property) iterator.next();
			if ( prop.getName().equals( root ) ) {
				return prop;
			}
		}
	}
	throw new MappingException( "property [" + propertyName + "] not found on entity [" + getEntityName() + "]" );
}
 
Example 2
Source File: CriteriaQueryTranslator.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private String getWholeAssociationPath(CriteriaImpl.Subcriteria subcriteria) {
	String path = subcriteria.getPath();

	// some messy, complex stuff here, since createCriteria() can take an
	// aliased path, or a path rooted at the creating criteria instance
	Criteria parent = null;
	if ( path.indexOf( '.' ) > 0 ) {
		// if it is a compound path
		String testAlias = StringHelper.root( path );
		if ( !testAlias.equals( subcriteria.getAlias() ) ) {
			// and the qualifier is not the alias of this criteria
			// -> check to see if we belong to some criteria other
			//  than the one that created us
			parent = aliasCriteriaMap.get( testAlias );
		}
	}
	if ( parent == null ) {
		// otherwise assume the parent is the the criteria that created us
		parent = subcriteria.getParent();
	}
	else {
		path = StringHelper.unroot( path );
	}

	if ( parent.equals( rootCriteria ) ) {
		// if its the root criteria, we are done
		return path;
	}
	else {
		// otherwise, recurse
		return getWholeAssociationPath( ( CriteriaImpl.Subcriteria ) parent ) + '.' + path;
	}
}
 
Example 3
Source File: CriteriaQueryTranslator.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public String getEntityName(Criteria subcriteria, String propertyName) {
	if ( propertyName.indexOf( '.' ) > 0 ) {
		final String root = StringHelper.root( propertyName );
		final Criteria crit = getAliasedCriteria( root );
		if ( crit != null ) {
			return getEntityName( crit );
		}
	}
	return getEntityName( subcriteria );
}
 
Example 4
Source File: CriteriaQueryTranslator.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public String getSQLAlias(Criteria criteria, String propertyName) {
	if ( propertyName.indexOf( '.' ) > 0 ) {
		final String root = StringHelper.root( propertyName );
		final Criteria subcriteria = getAliasedCriteria( root );
		if ( subcriteria != null ) {
			return getSQLAlias( subcriteria );
		}
	}
	return getSQLAlias( criteria );
}
 
Example 5
Source File: CriteriaQueryTranslator.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
@Override
public String getPropertyName(String propertyName) {
	if ( propertyName.indexOf( '.' ) > 0 ) {
		final String root = StringHelper.root( propertyName );
		final Criteria criteria = getAliasedCriteria( root );
		if ( criteria != null ) {
			return propertyName.substring( root.length() + 1 );
		}
	}
	return propertyName;
}
 
Example 6
Source File: AbstractEntityPersister.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Warning:
 * When there are duplicated property names in the subclasses
 * of the class, this method may return the wrong table
 * number for the duplicated subclass property (note that
 * SingleTableEntityPersister defines an overloaded form
 * which takes the entity name.
 */
public int getSubclassPropertyTableNumber(String propertyPath) {
	String rootPropertyName = StringHelper.root( propertyPath );
	Type type = propertyMapping.toType( rootPropertyName );
	if ( type.isAssociationType() ) {
		AssociationType assocType = (AssociationType) type;
		if ( assocType.useLHSPrimaryKey() ) {
			// performance op to avoid the array search
			return 0;
		}
		else if ( type.isCollectionType() ) {
			// properly handle property-ref-based associations
			rootPropertyName = assocType.getLHSPropertyName();
		}
	}
	//Enable for HHH-440, which we don't like:
	/*if ( type.isComponentType() && !propertyName.equals(rootPropertyName) ) {
		String unrooted = StringHelper.unroot(propertyName);
		int idx = ArrayHelper.indexOf( getSubclassColumnClosure(), unrooted );
		if ( idx != -1 ) {
			return getSubclassColumnTableNumberClosure()[idx];
		}
	}*/
	int index = ArrayHelper.indexOf(
			getSubclassPropertyNameClosure(),
			rootPropertyName
	); //TODO: optimize this better!
	return index == -1 ? 0 : getSubclassPropertyTableNumber( index );
}
 
Example 7
Source File: QueryTranslatorImpl.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
String unalias(String path) {
	String alias = StringHelper.root( path );
	String name = getAliasName( alias );
	if ( name != null ) {
		return name + path.substring( alias.length() );
	}
	return path;
}
 
Example 8
Source File: PathHelper.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
public static String getAlias(String path) {
	return StringHelper.root( path );
}