org.hibernate.persister.entity.AbstractPropertyMapping Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of hibernate Show documentation
Show all versions of hibernate Show documentation
Relational Persistence for Java
//$Id: AbstractPropertyMapping.java 10851 2006-11-21 17:38:43Z [email protected] $
package org.hibernate.persister.entity;
import java.util.HashMap;
import java.util.Map;
import org.hibernate.MappingException;
import org.hibernate.QueryException;
import org.hibernate.engine.Mapping;
import org.hibernate.sql.Template;
import org.hibernate.type.AbstractComponentType;
import org.hibernate.type.AssociationType;
import org.hibernate.type.EntityType;
import org.hibernate.type.Type;
import org.hibernate.util.ArrayHelper;
import org.hibernate.util.StringHelper;
/**
* Base implementation of a PropertyMapping
*
* @author Gavin King
*/
public abstract class AbstractPropertyMapping implements PropertyMapping {
private final Map typesByPropertyPath = new HashMap();
private final Map columnsByPropertyPath = new HashMap();
private final Map formulaTemplatesByPropertyPath = new HashMap();
public String[] getIdentifierColumnNames() {
throw new UnsupportedOperationException("one-to-one is not supported here");
}
protected abstract String getEntityName();
public Type toType(String propertyName) throws QueryException {
Type type = (Type) typesByPropertyPath.get(propertyName);
if ( type == null ) {
throw propertyException( propertyName );
}
return type;
}
protected final QueryException propertyException(String propertyName) {
return new QueryException( "could not resolve property: " + propertyName + " of: " + getEntityName() );
}
public String[] getColumnNames(String propertyName) {
String[] cols = (String[]) columnsByPropertyPath.get(propertyName);
if (cols==null) {
throw new MappingException("unknown property: " + propertyName);
}
return cols;
}
public String[] toColumns(String alias, String propertyName) throws QueryException {
//TODO: *two* hashmap lookups here is one too many...
String[] columns = (String[]) columnsByPropertyPath.get(propertyName);
if ( columns == null ) {
throw propertyException( propertyName );
}
String[] templates = (String[]) formulaTemplatesByPropertyPath.get(propertyName);
String[] result = new String[columns.length];
for ( int i=0; i