Update of /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/loader
In directory sc8-pr-cvs1:/tmp/cvs-serv14211/src/net/sf/hibernate/loader
Modified Files:
AnsiOuterJoinGenerator.java CollectionInitializer.java
CollectionLoader.java EntityLoader.java Loader.java
OneToManyLoader.java OracleOuterJoinGenerator.java
OuterJoinGenerator.java OuterJoinLoader.java
SimpleEntityLoader.java UniqueEntityLoader.java
Log Message:
reformatted code with beautiful, shiny, happy TABS!
improved an exception
Index: AnsiOuterJoinGenerator.java
===================================================================
RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/loader/AnsiOuterJoinGenerator.java,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -C2 -d -r1.1.1.1 -r1.2
*** AnsiOuterJoinGenerator.java 1 Jan 2003 13:56:05 -0000 1.1.1.1
--- AnsiOuterJoinGenerator.java 4 Jan 2003 11:15:29 -0000 1.2
***************
*** 9,39 ****
*/
public class AnsiOuterJoinGenerator extends OuterJoinGenerator {
!
public final static String EMPTY_STRING = "";
!
public AnsiOuterJoinGenerator() {
}
!
public final String appendOuterJoinStringAfterFrom(StringBuffer buf, String tableName, String alias, String[] fkColumns, String[] pkColumns, boolean innerJoin) {
!
buf.append( innerJoin ? " INNER JOIN " : " LEFT OUTER JOIN ")
! .append(tableName)
! .append(' ')
! .append(alias)
! .append(" ON ");
//TODO: refactor onto Loadable .. this is repeated in two other places
for ( int j=0; j<fkColumns.length; j++) {
buf.append( fkColumns[j] )
! .append('=')
! .append(alias)
! .append('.')
! .append( pkColumns[j] );
if ( j<fkColumns.length-1 ) buf.append(" and ");
}
return buf.toString();
}
!
public final String appendOuterJoinStringAfterWhere(StringBuffer buf, String alias, String[] fkColumns, String[] pkColumns, boolean innerJoin) {
return EMPTY_STRING;
}
}
--- 9,42 ----
*/
public class AnsiOuterJoinGenerator extends OuterJoinGenerator {
!
public final static String EMPTY_STRING = "";
!
public AnsiOuterJoinGenerator() {
}
!
public final String appendOuterJoinStringAfterFrom(StringBuffer buf, String tableName, String alias, String[] fkColumns, String[] pkColumns, boolean innerJoin) {
!
buf.append( innerJoin ? " INNER JOIN " : " LEFT OUTER JOIN ")
! .append(tableName)
! .append(' ')
! .append(alias)
! .append(" ON ");
//TODO: refactor onto Loadable .. this is repeated in two other places
for ( int j=0; j<fkColumns.length; j++) {
buf.append( fkColumns[j] )
! .append('=')
! .append(alias)
! .append('.')
! .append( pkColumns[j] );
if ( j<fkColumns.length-1 ) buf.append(" and ");
}
return buf.toString();
}
!
public final String appendOuterJoinStringAfterWhere(StringBuffer buf, String alias, String[] fkColumns, String[] pkColumns, boolean innerJoin) {
return EMPTY_STRING;
}
}
+
+
+
Index: CollectionInitializer.java
===================================================================
RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/loader/CollectionInitializer.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** CollectionInitializer.java 3 Jan 2003 13:36:01 -0000 1.2
--- CollectionInitializer.java 4 Jan 2003 11:15:29 -0000 1.3
***************
*** 20,21 ****
--- 20,24 ----
public void initialize(Serializable id, PersistentCollection collection, Object owner, SessionImplementor session) throws SQLException, HibernateException;
}
+
+
+
Index: CollectionLoader.java
===================================================================
RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/loader/CollectionLoader.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** CollectionLoader.java 3 Jan 2003 13:36:01 -0000 1.2
--- CollectionLoader.java 4 Jan 2003 11:15:29 -0000 1.3
***************
*** 23,37 ****
private final Type idType;
private final boolean allowTwoPhaseLoad;
!
public CollectionLoader(CollectionPersister persister, SessionFactoryImplementor session) throws MappingException {
!
super( session.getDialect() );
allowTwoPhaseLoad = !persister.isSet();
!
idType = persister.getKeyType();
String alias = alias( persister.getQualifiedTableName(), 0 );
!
List associations = walkTree(persister, alias, session);
--- 23,37 ----
private final Type idType;
private final boolean allowTwoPhaseLoad;
!
public CollectionLoader(CollectionPersister persister, SessionFactoryImplementor session) throws MappingException {
!
super( session.getDialect() );
allowTwoPhaseLoad = !persister.isSet();
!
idType = persister.getKeyType();
String alias = alias( persister.getQualifiedTableName(), 0 );
!
List associations = walkTree(persister, alias, session);
***************
*** 54,59 ****
// ORDER BY CLAUSE
( persister.hasOrdering() ) ?
! persister.getSQLOrderByString(alias) :
! null
);
--- 54,59 ----
// ORDER BY CLAUSE
( persister.hasOrdering() ) ?
! persister.getSQLOrderByString(alias) :
! null
);
***************
*** 68,72 ****
public void initialize(Serializable id, PersistentCollection collection, Object owner, SessionImplementor session) throws SQLException, HibernateException {
! loadCollection(session, id, idType, owner, collection);
}
--- 68,72 ----
public void initialize(Serializable id, PersistentCollection collection, Object owner, SessionImplementor session) throws SQLException, HibernateException {
! loadCollection(session, id, idType, owner, collection);
}
***************
*** 74,77 ****
return allowTwoPhaseLoad;
}
!
}
--- 74,80 ----
return allowTwoPhaseLoad;
}
!
}
+
+
+
Index: EntityLoader.java
===================================================================
RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/loader/EntityLoader.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** EntityLoader.java 3 Jan 2003 13:36:01 -0000 1.2
--- EntityLoader.java 4 Jan 2003 11:15:29 -0000 1.3
***************
*** 24,41 ****
public EntityLoader(Loadable persister, SessionFactoryImplementor factory) throws MappingException {
!
super( factory.getDialect() );
!
idType = new Type[] { persister.getIdentifierType() };
this.persister = persister;
String alias = alias( persister.getClassName(), 0 );
!
List associations = walkTree(persister, alias, factory);
!
int joins=associations.size();
suffixes = new String[joins+1];
for ( int i=0; i<=joins; i++ ) suffixes[i] = (joins==0) ? "" : Integer.toString(i);
!
sql = sqlSelect(
//SELECT CLAUSE
--- 24,41 ----
public EntityLoader(Loadable persister, SessionFactoryImplementor factory) throws MappingException {
!
super( factory.getDialect() );
!
idType = new Type[] { persister.getIdentifierType() };
this.persister = persister;
String alias = alias( persister.getClassName(), 0 );
!
List associations = walkTree(persister, alias, factory);
!
int joins=associations.size();
suffixes = new String[joins+1];
for ( int i=0; i<=joins; i++ ) suffixes[i] = (joins==0) ? "" : Integer.toString(i);
!
sql = sqlSelect(
//SELECT CLAUSE
***************
*** 52,61 ****
persister.outerJoinsAfterWhere(alias, true)
);
!
classPersisters = new Loadable[joins+1];
for ( int i=0; i<joins; i++ ) classPersisters[i] = ( (OuterJoinableAssociation) associations.get(i) ).subpersister;
classPersisters[joins] = persister;
}
!
protected CollectionPersister getCollectionPersister() {
return null;
--- 52,61 ----
persister.outerJoinsAfterWhere(alias, true)
);
!
classPersisters = new Loadable[joins+1];
for ( int i=0; i<joins; i++ ) classPersisters[i] = ( (OuterJoinableAssociation) associations.get(i) ).subpersister;
classPersisters[joins] = persister;
}
!
protected CollectionPersister getCollectionPersister() {
return null;
***************
*** 75,78 ****
}
}
!
}
--- 75,81 ----
}
}
!
}
+
+
+
Index: Loader.java
===================================================================
RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/loader/Loader.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** Loader.java 3 Jan 2003 13:36:01 -0000 1.2
--- Loader.java 4 Jan 2003 11:15:29 -0000 1.3
***************
*** 29,33 ****
/**
* Abstract superclass of object loading (and querying) strategies. This class implements useful
! * common functionality that concrete loaders would delegate to. It is not intended that this
* functionality would be directly accessed by client code. (Hence, all methods of this class
* will eventually be declared <tt>protected</tt>.)
--- 29,33 ----
/**
* Abstract superclass of object loading (and querying) strategies. This class implements useful
! * common functionality that concrete loaders would delegate to. It is not intended that this
* functionality would be directly accessed by client code. (Hence, all methods of this class
* will eventually be declared <tt>protected</tt>.)
***************
*** 64,68 ****
}
/**
! * Are we allowed to do two-phase loading? (we aren't for some special cases
* like sets of entities ... actually only that one special case)
*/
--- 64,68 ----
}
/**
! * Are we allowed to do two-phase loading? (we aren't for some special cases
* like sets of entities ... actually only that one special case)
*/
***************
*** 91,103 ****
/**
* Execute an SQL query and attempt to instantiate instances of the class mapped by the given
! * persister from each row of the <tt>ResultSet</tt>. If an object is supplied, will attempt to
* initialize that object. If a collection is supplied, attempt to initialize that collection.
*/
private final List doFind(
final SessionImplementor session,
! final Object[] values,
final Type[] types,
! final Object optionalObject,
! final Serializable optionalID,
final PersistentCollection optionalCollection,
final Object optionalCollectionOwner,
--- 91,103 ----
/**
* Execute an SQL query and attempt to instantiate instances of the class mapped by the given
! * persister from each row of the <tt>ResultSet</tt>. If an object is supplied, will attempt to
* initialize that object. If a collection is supplied, attempt to initialize that collection.
*/
private final List doFind(
final SessionImplementor session,
! final Object[] values,
final Type[] types,
! final Object optionalObject,
! final Serializable optionalID,
final PersistentCollection optionalCollection,
final Object optionalCollectionOwner,
***************
*** 106,115 ****
final Map namedParams
) throws SQLException, HibernateException {
!
returnProxies = returnProxies && Environment.jvmSupportsProxies();
!
! int maxRows = (selection==null || selection.getMaxRows()==null) ?
! Integer.MAX_VALUE :
! selection.getMaxRows().intValue();
final Loadable[] persisters = getPersisters();
--- 106,115 ----
final Map namedParams
) throws SQLException, HibernateException {
!
returnProxies = returnProxies && Environment.jvmSupportsProxies();
!
! int maxRows = (selection==null || selection.getMaxRows()==null) ?
! Integer.MAX_VALUE :
! selection.getMaxRows().intValue();
final Loadable[] persisters = getPersisters();
***************
*** 118,127 ****
final boolean twoPhaseLoad = allowTwoPhaseLoad() && cols > 0;
final String[] suffixes = getSuffixes();
!
final ArrayList hydratedObjects = twoPhaseLoad ? new ArrayList() : null;
final Key optionalObjectKey;
//boolean success;
!
if (optionalObject!=null) {
optionalObjectKey = new Key( optionalID, session.getPersister(optionalObject) );
--- 118,127 ----
final boolean twoPhaseLoad = allowTwoPhaseLoad() && cols > 0;
final String[] suffixes = getSuffixes();
!
final ArrayList hydratedObjects = twoPhaseLoad ? new ArrayList() : null;
final Key optionalObjectKey;
//boolean success;
!
if (optionalObject!=null) {
optionalObjectKey = new Key( optionalID, session.getPersister(optionalObject) );
***************
*** 137,151 ****
final boolean scalars = hasScalarValues();
if (scalars) {
! returnTypes = getReturnTypes();
names = getScalarColumnNames();
}
!
final List results = new ArrayList(); //new net.sf.hibernate.collections.List(this);
final PreparedStatement st = prepareQueryStatement( getSQLString(), values, types, selection, false, session );
! final ResultSet rs = getResultSet(st, namedParams, selection, session);
try {
!
final Key[] keys = new Key[cols]; //we can reuse it each time
final boolean[] hydrate = new boolean[cols]; //we can reuse it each time
--- 137,151 ----
final boolean scalars = hasScalarValues();
if (scalars) {
! returnTypes = getReturnTypes();
names = getScalarColumnNames();
}
!
final List results = new ArrayList(); //new net.sf.hibernate.collections.List(this);
final PreparedStatement st = prepareQueryStatement( getSQLString(), values, types, selection, false, session );
! final ResultSet rs = getResultSet(st, namedParams, selection, session);
try {
!
final Key[] keys = new Key[cols]; //we can reuse it each time
final boolean[] hydrate = new boolean[cols]; //we can reuse it each time
***************
*** 163,167 ****
if ( hydrate[i] ) {
! // grab its state from the ResultSet and keep it in the Session
// (but don't yet initialize the object itself)
loadFromResultSet( rs, row[i], keys[i].getIdentifier(), suffixes[i], session );
--- 163,167 ----
if ( hydrate[i] ) {
! // grab its state from the ResultSet and keep it in the Session
// (but don't yet initialize the object itself)
loadFromResultSet( rs, row[i], keys[i].getIdentifier(), suffixes[i], session );
***************
*** 173,177 ****
else {
//materialize associations (and initialize the object) *now*
! session.initializeEntity( row[i] );
}
--- 173,177 ----
else {
//materialize associations (and initialize the object) *now*
! session.initializeEntity( row[i] );
}
***************
*** 193,204 ****
Object[] queryRow = new Object[queryCols];
for ( int i=0; i<queryCols; i++ )
! queryRow[i] = returnTypes[i].nullSafeGet( rs, names[i], session, null );
results.add(queryRow);
}
}
!
if (collection) optionalCollection.readFrom( rs, getCollectionPersister(), optionalCollectionOwner );
}
!
}
catch (SQLException sqle) {
--- 193,204 ----
Object[] queryRow = new Object[queryCols];
for ( int i=0; i<queryCols; i++ )
! queryRow[i] = returnTypes[i].nullSafeGet( rs, names[i], session, null );
results.add(queryRow);
}
}
!
if (collection) optionalCollection.readFrom( rs, getCollectionPersister(), optionalCollectionOwner );
}
!
}
catch (SQLException sqle) {
***************
*** 221,225 ****
return results;
!
}
--- 221,225 ----
return results;
!
}
***************
*** 228,233 ****
* method is side-effecty. If an <tt>id</tt> is given, don't bother going to the <tt>ResultSet</tt>.
*/
! private Key getKeyFromResultSet(Loadable persister, String suffix, Serializable id, ResultSet rs, SessionImplementor session)
! throws HibernateException, SQLException {
--- 228,233 ----
* method is side-effecty. If an <tt>id</tt> is given, don't bother going to the <tt>ResultSet</tt>.
*/
! private Key getKeyFromResultSet(Loadable persister, String suffix, Serializable id, ResultSet rs, SessionImplementor session)
! throws HibernateException, SQLException {
***************
*** 236,240 ****
String[] keyColNames = StringHelper.suffix( persister.getIdentifierColumnNames(), suffix );
StringHelper.unQuoteInPlace(keyColNames);
!
id = (Serializable) persister.getIdentifierType().nullSafeGet(rs, keyColNames, session, null);
}
--- 236,240 ----
String[] keyColNames = StringHelper.suffix( persister.getIdentifierColumnNames(), suffix );
StringHelper.unQuoteInPlace(keyColNames);
!
id = (Serializable) persister.getIdentifierType().nullSafeGet(rs, keyColNames, session, null);
}
***************
*** 251,257 ****
private Object[] getRow(
ResultSet rs,
! Loadable[] persisters,
! String[] suffixes,
! Key[] keys,
boolean[] hydrate, //RETURNS VALUES BY SIDE-EFFECT!!!!!!!!
Object optionalObject,
--- 251,257 ----
private Object[] getRow(
ResultSet rs,
! Loadable[] persisters,
! String[] suffixes,
! Key[] keys,
boolean[] hydrate, //RETURNS VALUES BY SIDE-EFFECT!!!!!!!!
Object optionalObject,
***************
*** 263,297 ****
Object[] rowResults = new Object[cols];
!
for ( int i=0; i<cols; i++ ) {
!
Object object=null;
Key key = keys[i];
!
if ( keys[i]==null ) {
hydrate[i] = false;
}
else {
!
//If the object is already loaded, return the loaded one
object = session.getEntity(key);
if (object!=null) {
!
//its already loaded so don't need to hydrate it
hydrate[i] = false;
!
if ( !persisters[i].getMappedClass().isAssignableFrom( object.getClass() ) )
! throw new WrongClassException( "loaded object was of wrong class", key.getIdentifier(), persisters[i].getMappedClass() );
!
}
else {
!
Class instanceClass = getInstanceClass( rs, persisters[i], suffixes[i], key.getIdentifier(), session );
!
if ( optionalObjectKey!=null && key.equals(optionalObjectKey) ) {
//its the given optional object
object=optionalObject;
//success=true;
!
}
else {
--- 263,297 ----
Object[] rowResults = new Object[cols];
!
for ( int i=0; i<cols; i++ ) {
!
Object object=null;
Key key = keys[i];
!
if ( keys[i]==null ) {
hydrate[i] = false;
}
else {
!
//If the object is already loaded, return the loaded one
object = session.getEntity(key);
if (object!=null) {
!
//its already loaded so don't need to hydrate it
hydrate[i] = false;
!
if ( !persisters[i].getMappedClass().isAssignableFrom( object.getClass() ) )
! throw new WrongClassException( "loaded object was of wrong class", key.getIdentifier(), persisters[i].getMappedClass() );
!
}
else {
!
Class instanceClass = getInstanceClass( rs, persisters[i], suffixes[i], key.getIdentifier(), session );
!
if ( optionalObjectKey!=null && key.equals(optionalObjectKey) ) {
//its the given optional object
object=optionalObject;
//success=true;
!
}
else {
***************
*** 299,312 ****
object = session.getFactory().getPersister(instanceClass).instantiate( key.getIdentifier() );
}
!
//need to hydrate it.
hydrate[i] = true;
!
// so that code is circular-reference safe:
session.addUninitializedEntity( key, object, getLockMode() );
}
!
}
!
rowResults[i]=object;
--- 299,312 ----
object = session.getFactory().getPersister(instanceClass).instantiate( key.getIdentifier() );
}
!
//need to hydrate it.
hydrate[i] = true;
!
// so that code is circular-reference safe:
session.addUninitializedEntity( key, object, getLockMode() );
}
!
}
!
rowResults[i]=object;
***************
*** 314,326 ****
return rowResults;
!
}
!
!
/**
* Hydrate an object from the SQL <tt>ResultSet</tt>
*/
private void loadFromResultSet(ResultSet rs, Object object, Serializable id, String suffix, SessionImplementor session) throws SQLException, HibernateException {
!
if ( log.isTraceEnabled() ) log.trace("Initializing object from ResultSet: " + id);
--- 314,326 ----
return rowResults;
!
}
!
!
/**
* Hydrate an object from the SQL <tt>ResultSet</tt>
*/
private void loadFromResultSet(ResultSet rs, Object object, Serializable id, String suffix, SessionImplementor session) throws SQLException, HibernateException {
!
if ( log.isTraceEnabled() ) log.trace("Initializing object from ResultSet: " + id);
***************
*** 338,344 ****
*/
private Class getInstanceClass(ResultSet rs, Loadable persister, String suffix, Serializable id, SessionImplementor session) throws HibernateException, SQLException {
!
Class topClass = persister.getMappedClass();
!
if ( persister.hasSubclasses() ) {
--- 338,344 ----
*/
private Class getInstanceClass(ResultSet rs, Loadable persister, String suffix, Serializable id, SessionImplementor session) throws HibernateException, SQLException {
!
Class topClass = persister.getMappedClass();
!
if ( persister.hasSubclasses() ) {
***************
*** 349,360 ****
// Code to handle subclasses of topClass
Object discriminatorValue = persister.getDiscriminatorType().nullSafeGet(rs, col, session, null);
!
Class result = persister.getSubclassForDiscriminatorValue(discriminatorValue);
!
if (result==null) throw new WrongClassException("Discriminator: " + discriminatorValue, id, topClass);
//woops we got an instance of another class heirarchy branch
!
return result;
!
}
else {
--- 349,360 ----
// Code to handle subclasses of topClass
Object discriminatorValue = persister.getDiscriminatorType().nullSafeGet(rs, col, session, null);
!
Class result = persister.getSubclassForDiscriminatorValue(discriminatorValue);
!
if (result==null) throw new WrongClassException("Discriminator: " + discriminatorValue, id, topClass);
//woops we got an instance of another class heirarchy branch
!
return result;
!
}
else {
***************
*** 363,367 ****
}
! /**
* Unmarshall the fields of a persistent instance from a result set
*/
--- 363,367 ----
}
! /**
* Unmarshall the fields of a persistent instance from a result set
*/
***************
*** 382,386 ****
return values;
}
!
/**
* Advance the cursor to the first required row of the <tt>ResultSet</tt>
--- 382,386 ----
return values;
}
!
/**
* Advance the cursor to the first required row of the <tt>ResultSet</tt>
***************
*** 405,409 ****
}
}
!
/**
* Obtain a <tt>PreparedStatement</tt> and bind JDBC-style <tt>?</tt> parameters
--- 405,409 ----
}
}
!
/**
* Obtain a <tt>PreparedStatement</tt> and bind JDBC-style <tt>?</tt> parameters
***************
*** 412,424 ****
boolean scrollable = selection!=null &&
! ( ( selection.getFirstRow()!=null && selection.getFirstRow().intValue()!=0 ) || scroll ) &&
! session.getFactory().useScrollableResultSets();
PreparedStatement st = session.getBatcher().prepareQueryStatement(sql, scrollable);
try {
!
if (selection!=null && selection.getTimeout()!=null) st.setQueryTimeout( selection.getTimeout().intValue() );
!
int col=1;
for ( int i=0; i<values.length; i++) {
--- 412,424 ----
boolean scrollable = selection!=null &&
! ( ( selection.getFirstRow()!=null && selection.getFirstRow().intValue()!=0 ) || scroll ) &&
! session.getFactory().useScrollableResultSets();
PreparedStatement st = session.getBatcher().prepareQueryStatement(sql, scrollable);
try {
!
if (selection!=null && selection.getTimeout()!=null) st.setQueryTimeout( selection.getTimeout().intValue() );
!
int col=1;
for ( int i=0; i<values.length; i++) {
***************
*** 437,441 ****
throw he;
}
!
return st;
}
--- 437,441 ----
throw he;
}
!
return st;
}
***************
*** 445,450 ****
*/
protected final void setMaxRows(PreparedStatement st,RowSelection selection) throws SQLException {
! if ( selection!=null && selection.getMaxRows()!=null ) st.setMaxRows(
! selection.getMaxRows().intValue() + ( (selection.getFirstRow()==null) ? 0 : selection.getFirstRow().intValue() )
);
}
--- 445,450 ----
*/
protected final void setMaxRows(PreparedStatement st,RowSelection selection) throws SQLException {
! if ( selection!=null && selection.getMaxRows()!=null ) st.setMaxRows(
! selection.getMaxRows().intValue() + ( (selection.getFirstRow()==null) ? 0 : selection.getFirstRow().intValue() )
);
}
***************
*** 477,481 ****
*/
protected void bindNamedParameters(PreparedStatement st, Map namedParams, SessionImplementor session) throws SQLException, HibernateException {}
!
/**
* Called by subclasses that load entities
--- 477,481 ----
*/
protected void bindNamedParameters(PreparedStatement st, Map namedParams, SessionImplementor session) throws SQLException, HibernateException {}
!
/**
* Called by subclasses that load entities
***************
*** 483,490 ****
protected final List loadEntity(
final SessionImplementor session,
! final Object[] values,
final Type[] types,
! final Object optionalObject,
! final Serializable optionalID,
boolean returnProxies
) throws SQLException, HibernateException {
--- 483,490 ----
protected final List loadEntity(
final SessionImplementor session,
! final Object[] values,
final Type[] types,
! final Object optionalObject,
! final Serializable optionalID,
boolean returnProxies
) throws SQLException, HibernateException {
***************
*** 497,501 ****
protected final List loadCollection(
final SessionImplementor session,
! final Serializable id,
final Type type,
final Object owner,
--- 497,501 ----
protected final List loadCollection(
final SessionImplementor session,
! final Serializable id,
final Type type,
final Object owner,
***************
*** 504,509 ****
return doFind(session, new Object[] {id}, new Type[] {type}, null, null, collection, owner, true, null, null);
}
!
!
/**
* Called by subclasses that implement queries
--- 504,509 ----
return doFind(session, new Object[] {id}, new Type[] {type}, null, null, collection, owner, true, null, null);
}
!
!
/**
* Called by subclasses that implement queries
***************
*** 511,515 ****
public final List find(
final SessionImplementor session,
! final Object[] values,
final Type[] types,
boolean returnProxies,
--- 511,515 ----
public final List find(
final SessionImplementor session,
! final Object[] values,
final Type[] types,
boolean returnProxies,
***************
*** 519,523 ****
return doFind(session, values, types, null, null, null, null, returnProxies, selection, namedParams);
}
!
/**
* Construct an SQL <tt>SELECT</tt> statement from the given clauses
--- 519,523 ----
return doFind(session, values, types, null, null, null, null, returnProxies, selection, namedParams);
}
!
/**
* Construct an SQL <tt>SELECT</tt> statement from the given clauses
***************
*** 531,542 ****
*/
protected static final String sqlSelect(String selectClause, String fromClause, String outerJoinsAfterFrom, String whereClause, String outerJoinsAfterWhere, String orderByClause) {
! StringBuffer buf = new StringBuffer(
selectClause.length() + fromClause.length() + outerJoinsAfterFrom.length() + whereClause.length() + outerJoinsAfterWhere.length() + 20
);
buf.append("SELECT ").append(selectClause)
! .append(" FROM ").append(fromClause)
! .append(outerJoinsAfterFrom)
! .append(" WHERE ").append(whereClause)
! .append(outerJoinsAfterWhere);
if (orderByClause!=null) buf.append(" ORDER BY ").append(orderByClause);
return buf.toString();
--- 531,542 ----
*/
protected static final String sqlSelect(String selectClause, String fromClause, String outerJoinsAfterFrom, String whereClause, String outerJoinsAfterWhere, String orderByClause) {
! StringBuffer buf = new StringBuffer(
selectClause.length() + fromClause.length() + outerJoinsAfterFrom.length() + whereClause.length() + outerJoinsAfterWhere.length() + 20
);
buf.append("SELECT ").append(selectClause)
! .append(" FROM ").append(fromClause)
! .append(outerJoinsAfterFrom)
! .append(" WHERE ").append(whereClause)
! .append(outerJoinsAfterWhere);
if (orderByClause!=null) buf.append(" ORDER BY ").append(orderByClause);
return buf.toString();
***************
*** 544,545 ****
--- 544,548 ----
}
+
+
+
Index: OneToManyLoader.java
===================================================================
RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/loader/OneToManyLoader.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** OneToManyLoader.java 3 Jan 2003 13:36:01 -0000 1.2
--- OneToManyLoader.java 4 Jan 2003 11:15:29 -0000 1.3
***************
*** 24,34 ****
private final Type idType;
private final boolean allowTwoPhaseLoad;
!
public OneToManyLoader(CollectionPersister collPersister, SessionFactoryImplementor session) throws MappingException {
!
super( session.getDialect() );
allowTwoPhaseLoad = !collPersister.isSet();
!
collectionPersister = collPersister;
--- 24,34 ----
private final Type idType;
private final boolean allowTwoPhaseLoad;
!
public OneToManyLoader(CollectionPersister collPersister, SessionFactoryImplementor session) throws MappingException {
!
super( session.getDialect() );
allowTwoPhaseLoad = !collPersister.isSet();
!
collectionPersister = collPersister;
***************
*** 65,88 ****
// ORDER BY CLAUSE
collPersister.hasOrdering() ?
! collPersister.getSQLOrderByString(collAlias) :
! null
);
!
classPersisters = new Loadable[joins+1];
for ( int i=0; i<joins; i++ ) classPersisters[i] = ( (OuterJoinableAssociation) associations.get(i) ).subpersister;
classPersisters[joins] = persister;
}
!
protected CollectionPersister getCollectionPersister() {
return collectionPersister;
}
!
public void initialize(Serializable id, PersistentCollection collection, Object owner, SessionImplementor session) throws SQLException, HibernateException {
! loadCollection(session, id, idType, owner, collection);
}
!
protected boolean allowTwoPhaseLoad() {
return allowTwoPhaseLoad;
}
!
}
--- 65,91 ----
// ORDER BY CLAUSE
collPersister.hasOrdering() ?
! collPersister.getSQLOrderByString(collAlias) :
! null
);
!
classPersisters = new Loadable[joins+1];
for ( int i=0; i<joins; i++ ) classPersisters[i] = ( (OuterJoinableAssociation) associations.get(i) ).subpersister;
classPersisters[joins] = persister;
}
!
protected CollectionPersister getCollectionPersister() {
return collectionPersister;
}
!
public void initialize(Serializable id, PersistentCollection collection, Object owner, SessionImplementor session) throws SQLException, HibernateException {
! loadCollection(session, id, idType, owner, collection);
}
!
protected boolean allowTwoPhaseLoad() {
return allowTwoPhaseLoad;
}
!
}
+
+
+
Index: OracleOuterJoinGenerator.java
===================================================================
RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/loader/OracleOuterJoinGenerator.java,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -C2 -d -r1.1.1.1 -r1.2
*** OracleOuterJoinGenerator.java 1 Jan 2003 13:56:08 -0000 1.1.1.1
--- OracleOuterJoinGenerator.java 4 Jan 2003 11:15:29 -0000 1.2
***************
*** 9,38 ****
*/
public class OracleOuterJoinGenerator extends OuterJoinGenerator {
!
public OracleOuterJoinGenerator() {
}
!
public final String appendOuterJoinStringAfterFrom(StringBuffer buf, String tableName, String alias, String[] fkColumns, String[] pkColumns, boolean innerJoin) {
!
buf.append(", ")
! .append(tableName)
! .append(' ')
! .append(alias);
return buf.toString();
}
!
public final String appendOuterJoinStringAfterWhere(StringBuffer buf, String alias, String[] fkColumns, String[] pkColumns, boolean innerJoin) {
!
for ( int j=0; j<fkColumns.length; j++) {
buf.append(" AND ")
! .append( fkColumns[j] )
! .append('=')
! .append(alias)
! .append('.')
! .append( pkColumns[j] );
if (!innerJoin) buf.append("(+)");
}
return buf.toString();
}
!
}
--- 9,41 ----
*/
public class OracleOuterJoinGenerator extends OuterJoinGenerator {
!
public OracleOuterJoinGenerator() {
}
!
public final String appendOuterJoinStringAfterFrom(StringBuffer buf, String tableName, String alias, String[] fkColumns, String[] pkColumns, boolean innerJoin) {
!
buf.append(", ")
! .append(tableName)
! .append(' ')
! .append(alias);
return buf.toString();
}
!
public final String appendOuterJoinStringAfterWhere(StringBuffer buf, String alias, String[] fkColumns, String[] pkColumns, boolean innerJoin) {
!
for ( int j=0; j<fkColumns.length; j++) {
buf.append(" AND ")
! .append( fkColumns[j] )
! .append('=')
! .append(alias)
! .append('.')
! .append( pkColumns[j] );
if (!innerJoin) buf.append("(+)");
}
return buf.toString();
}
!
}
+
+
+
Index: OuterJoinGenerator.java
===================================================================
RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/loader/OuterJoinGenerator.java,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -C2 -d -r1.1.1.1 -r1.2
*** OuterJoinGenerator.java 1 Jan 2003 13:56:10 -0000 1.1.1.1
--- OuterJoinGenerator.java 4 Jan 2003 11:15:29 -0000 1.2
***************
*** 11,18 ****
public abstract class OuterJoinGenerator {
!
/**
* Generate a list of <tt>LEFT OUTER JOIN</tt> clauses for the given associations.
! * This is the first insertion point of outer join logic into the sql.
*/
public final String outerJoinStringAfterFrom(List associations) {
--- 11,18 ----
public abstract class OuterJoinGenerator {
!
/**
* Generate a list of <tt>LEFT OUTER JOIN</tt> clauses for the given associations.
! * This is the first insertion point of outer join logic into the sql.
*/
public final String outerJoinStringAfterFrom(List associations) {
***************
*** 23,27 ****
appendOuterJoinStringAfterFrom(
buf,
! oj.subpersister.getTableName(),
oj.subalias,
oj.foreignKeyColumns,
--- 23,27 ----
appendOuterJoinStringAfterFrom(
buf,
! oj.subpersister.getTableName(),
oj.subalias,
oj.foreignKeyColumns,
***************
*** 33,40 ****
return buf.toString();
}
!
/**
* Generate a list of <tt>LEFT OUTER JOIN</tt> clauses for the given associations.
! * This is the second insertion point of outer join logic into the sql.
*/
public final String outerJoinStringAfterWhere(List associations) {
--- 33,40 ----
return buf.toString();
}
!
/**
* Generate a list of <tt>LEFT OUTER JOIN</tt> clauses for the given associations.
! * This is the second insertion point of outer join logic into the sql.
*/
public final String outerJoinStringAfterWhere(List associations) {
***************
*** 44,50 ****
OuterJoinLoader.OuterJoinableAssociation oj = (OuterJoinLoader.OuterJoinableAssociation) iter.next();
appendOuterJoinStringAfterWhere(
! buf,
! oj.subalias,
! oj.foreignKeyColumns,
oj.subpersister.getIdentifierColumnNames(),
false
--- 44,50 ----
OuterJoinLoader.OuterJoinableAssociation oj = (OuterJoinLoader.OuterJoinableAssociation) iter.next();
appendOuterJoinStringAfterWhere(
! buf,
! oj.subalias,
! oj.foreignKeyColumns,
oj.subpersister.getIdentifierColumnNames(),
false
***************
*** 54,58 ****
return buf.toString();
}
!
/**
* Generate a <tt>LEFT OUTER JOIN</tt> clause to the table of the entity class.
--- 54,58 ----
return buf.toString();
}
!
/**
* Generate a <tt>LEFT OUTER JOIN</tt> clause to the table of the entity class.
***************
*** 60,69 ****
*/
public abstract String appendOuterJoinStringAfterFrom(StringBuffer buf, String tableName, String alias, String[] fkColumns, String[] pkColumns, boolean innerJoin);
!
/**
* Generate a <tt>ON</tt> clause to the table of the entity class
* To be inserted after the FROM clause.
*/
! public abstract String appendOuterJoinStringAfterWhere(StringBuffer buf, String alias, String[] fkColumns, String[] pkColumns, boolean innerJoin);
!
}
--- 60,72 ----
*/
public abstract String appendOuterJoinStringAfterFrom(StringBuffer buf, String tableName, String alias, String[] fkColumns, String[] pkColumns, boolean innerJoin);
!
/**
* Generate a <tt>ON</tt> clause to the table of the entity class
* To be inserted after the FROM clause.
*/
! public abstract String appendOuterJoinStringAfterWhere(StringBuffer buf, String alias, String[] fkColumns, String[] pkColumns, boolean innerJoin);
!
}
+
+
+
Index: OuterJoinLoader.java
===================================================================
RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/loader/OuterJoinLoader.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** OuterJoinLoader.java 3 Jan 2003 13:36:01 -0000 1.2
--- OuterJoinLoader.java 4 Jan 2003 11:15:29 -0000 1.3
***************
*** 27,31 ****
public static final int AUTO = 0;
public static final int LAZY = -1;
!
protected static final Type[] NO_TYPES = new Type[0];
protected static final String[][] NO_STRINGARRAYS = new String[0][];
--- 27,31 ----
public static final int AUTO = 0;
public static final int LAZY = -1;
!
protected static final Type[] NO_TYPES = new Type[0];
protected static final String[][] NO_STRINGARRAYS = new String[0][];
***************
*** 36,45 ****
protected String[] suffixes;
protected final OuterJoinGenerator outerJoinGenerator;
!
public OuterJoinLoader(Dialect dialect)
{
outerJoinGenerator = dialect.getOuterJoinGenerator();
}
!
public static final class OuterJoinableAssociation {
//Object persister; // a class or collection persister!
--- 36,45 ----
protected String[] suffixes;
protected final OuterJoinGenerator outerJoinGenerator;
!
public OuterJoinLoader(Dialect dialect)
{
outerJoinGenerator = dialect.getOuterJoinGenerator();
}
!
public static final class OuterJoinableAssociation {
//Object persister; // a class or collection persister!
***************
*** 66,70 ****
if ( session.enableJoinedFetch() ) { //yick!
!
Type type = persister.getElementType();
String[] columns = StringHelper.prefix( persister.getElementColumnNames(), alias + '.' );
--- 66,70 ----
if ( session.enableJoinedFetch() ) { //yick!
!
Type type = persister.getElementType();
String[] columns = StringHelper.prefix( persister.getElementColumnNames(), alias + '.' );
***************
*** 126,131 ****
*/
private void walkTree(AbstractComponentType act, String[] cols, Object persister, String alias, List associations, Set classPersisters, SessionFactoryImplementor session) throws MappingException {
! if (
! !session.enableJoinedFetch() ||
persister instanceof MultiTableEntityPersister //TODO: remove this + enable outerjoin fetching
) return;
--- 126,131 ----
*/
private void walkTree(AbstractComponentType act, String[] cols, Object persister, String alias, List associations, Set classPersisters, SessionFactoryImplementor session) throws MappingException {
! if (
! !session.enableJoinedFetch() ||
persister instanceof MultiTableEntityPersister //TODO: remove this + enable outerjoin fetching
) return;
***************
*** 138,143 ****
if ( types[i].isEntityType() ) {
EntityType etype = (EntityType) types[i];
! if ( autoEager( act.enableJoinedFetch(i), etype, session ) )
! walkTree(etype, range, persister, alias, associations, classPersisters, session);
}
else if ( types[i].isComponentType() ) {
--- 138,143 ----
if ( types[i].isEntityType() ) {
EntityType etype = (EntityType) types[i];
! if ( autoEager( act.enableJoinedFetch(i), etype, session ) )
! walkTree(etype, range, persister, alias, associations, classPersisters, session);
}
else if ( types[i].isComponentType() ) {
***************
*** 154,158 ****
return !persister.hasProxy() || ( type.isOneToOne() && ( (OneToOneType) type ).isNullable() );
}
!
/**
* Add on association (one-to-one or many-to-one) to a list of associations be fetched by outerjoin (if necessary)
--- 154,158 ----
return !persister.hasProxy() || ( type.isOneToOne() && ( (OneToOneType) type ).isNullable() );
}
!
/**
* Add on association (one-to-one or many-to-one) to a list of associations be fetched by outerjoin (if necessary)
***************
*** 166,170 ****
if ( !classPersisters.contains(subpersister) ) { // to avoid navigating back up bidirectional associations (and circularities)
!
OuterJoinableAssociation assoc = new OuterJoinableAssociation();
associations.add(assoc);
--- 166,170 ----
if ( !classPersisters.contains(subpersister) ) { // to avoid navigating back up bidirectional associations (and circularities)
!
OuterJoinableAssociation assoc = new OuterJoinableAssociation();
associations.add(assoc);
***************
*** 219,232 ****
for ( int j=0; j<keyCols.length; j++) {
buf.append(alias)
! .append('.')
! .append( keyCols[j] )
! .append(" AS ")
! .append( aliasColumn( keyCols[j], suffix ) );
if ( j != keyCols.length-1 ) buf.append(", ");
}
buf.append( persister.propertySelectClauseFragment(alias, suffix) );
!
}
!
/**
* Generate a list of column conditions of the form <tt>x.foo = ?, x.bar = ?</tt>
--- 219,232 ----
for ( int j=0; j<keyCols.length; j++) {
buf.append(alias)
! .append('.')
! .append( keyCols[j] )
! .append(" AS ")
! .append( aliasColumn( keyCols[j], suffix ) );
if ( j != keyCols.length-1 ) buf.append(", ");
}
buf.append( persister.propertySelectClauseFragment(alias, suffix) );
!
}
!
/**
* Generate a list of column conditions of the form <tt>x.foo = ?, x.bar = ?</tt>
***************
*** 236,242 ****
for ( int i=0; i<columns.length; i++ ) {
buf.append(alias)
! .append('.')
! .append( columns[i] )
! .append( " = ?");
if (i<columns.length-1) buf.append(" and ");
}
--- 236,242 ----
for ( int i=0; i<columns.length; i++ ) {
buf.append(alias)
! .append('.')
! .append( columns[i] )
! .append( " = ?");
if (i<columns.length-1) buf.append(" and ");
}
***************
*** 252,257 ****
for ( int i=0; i<selectCols.length; i++ ) {
buf.append(alias)
! .append('.')
! .append( selectCols[i] );
if (i!=selectCols.length-1) buf.append(", ");
}
--- 252,257 ----
for ( int i=0; i<selectCols.length; i++ ) {
buf.append(alias)
! .append('.')
! .append( selectCols[i] );
if (i!=selectCols.length-1) buf.append(", ");
}
***************
*** 260,266 ****
for ( int i=0; i<indexCols.length; i++ ) {
buf.append(", ")
! .append(alias)
! .append('.')
! .append( indexCols[i] );
}
}
--- 260,266 ----
for ( int i=0; i<indexCols.length; i++ ) {
buf.append(", ")
! .append(alias)
! .append('.')
! .append( indexCols[i] );
}
}
***************
*** 271,308 ****
return suffixes;
}
-
- protected static String alias(String tableName, int n) {
-
- tableName = StringHelper.unqualify(tableName);
! return aliasCore(tableName.length() <=5 ?
! tableName :
! tableName.substring(0, 5),
! Integer.toString(n)
! );
! }
!
! protected static String aliasColumn(String columnName, String suffix) {
! return aliasCore(columnName, suffix);
! }
!
! //TODO: refactor! this is a duplicate of a method in the Loader heirarchy
! private static String aliasCore(String name, String suffix) {
! char quote = name.charAt(0);
! boolean nameEscaped = Dialect.QUOTE.indexOf(quote) > -1;
! if (nameEscaped) name = name.substring(1, name.length()-1);
- StringBuffer aliasBuilder = new StringBuffer(name.length());
- if (nameEscaped) aliasBuilder.append(quote);
- aliasBuilder.append(name);
- aliasBuilder.append(suffix);
- if (nameEscaped) aliasBuilder.append(quote);
- return aliasBuilder.toString();
- }
- }
--- 271,311 ----
return suffixes;
}
! protected static String alias(String tableName, int n) {
!
! tableName = StringHelper.unqualify(tableName);
!
! return aliasCore(tableName.length() <=5 ?
! tableName :
! tableName.substring(0, 5),
! Integer.toString(n)
! );
! }
! protected static String aliasColumn(String columnName, String suffix) {
! return aliasCore(columnName, suffix);
! }
! //TODO: refactor! this is a duplicate of a method in the Loader heirarchy
! private static String aliasCore(String name, String suffix) {
!
! char quote = name.charAt(0);
! boolean nameEscaped = Dialect.QUOTE.indexOf(quote) > -1;
!
! if (nameEscaped) name = name.substring(1, name.length()-1);
!
! StringBuffer aliasBuilder = new StringBuffer(name.length());
!
! if (nameEscaped) aliasBuilder.append(quote);
! aliasBuilder.append(name);
! aliasBuilder.append(suffix);
! if (nameEscaped) aliasBuilder.append(quote);
!
! return aliasBuilder.toString();
! }
! }
Index: SimpleEntityLoader.java
===================================================================
RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/loader/SimpleEntityLoader.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** SimpleEntityLoader.java 3 Jan 2003 13:36:01 -0000 1.2
--- SimpleEntityLoader.java 4 Jan 2003 11:15:29 -0000 1.3
***************
*** 30,42 ****
this.lockMode = lockMode;
}
!
public String getSQLString() {
return sql;
}
!
public Loadable[] getPersisters() {
return persister;
}
!
public CollectionPersister getCollectionPersister() {
return null;
--- 30,42 ----
this.lockMode = lockMode;
}
!
public String getSQLString() {
return sql;
}
!
public Loadable[] getPersisters() {
return persister;
}
!
public CollectionPersister getCollectionPersister() {
return null;
***************
*** 63,67 ****
}
}
- }
--- 63,70 ----
}
}
+
+
+ }
+
Index: UniqueEntityLoader.java
===================================================================
RCS file: /cvsroot/hibernate/Hibernate2/src/net/sf/hibernate/loader/UniqueEntityLoader.java,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -C2 -d -r1.1.1.1 -r1.2
*** UniqueEntityLoader.java 1 Jan 2003 13:56:11 -0000 1.1.1.1
--- UniqueEntityLoader.java 4 Jan 2003 11:15:29 -0000 1.2
***************
*** 15,16 ****
--- 15,19 ----
public Object load(SessionImplementor session, Serializable id, Object optionalObject) throws HibernateException, SQLException;
}
+
+
+
|