HHH-6294 use enum instead of constant

This commit is contained in:
Strong Liu 2011-06-07 00:16:33 +08:00
parent 1320208baf
commit 72aedc8682
46 changed files with 576 additions and 542 deletions

View File

@ -1,10 +1,10 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2008, Red Hat Middleware LLC or third-party contributors as
* Copyright (c) 2011, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Middleware LLC.
* distributed under license by Red Hat Inc..
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
@ -23,78 +23,58 @@
*
*/
package org.hibernate;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
/**
* Controls how the session interacts with the second-level
* cache and query cache.
*
* @see Session#setCacheMode(CacheMode)
* @author Gavin King
* @author Strong Liu
* @see Session#setCacheMode(CacheMode)
*/
public final class CacheMode implements Serializable {
private final String name;
private final boolean isPutEnabled;
private final boolean isGetEnabled;
private static final Map INSTANCES = new HashMap();
public enum CacheMode {
private CacheMode(String name, boolean isPutEnabled, boolean isGetEnabled) {
this.name=name;
this.isPutEnabled = isPutEnabled;
this.isGetEnabled = isGetEnabled;
}
public String toString() {
return name;
}
public boolean isPutEnabled() {
return isPutEnabled;
}
public boolean isGetEnabled() {
return isGetEnabled;
}
/**
* The session may read items from the cache, and add items to the cache
*/
public static final CacheMode NORMAL = new CacheMode("NORMAL", true, true);
NORMAL( true, true),
/**
* The session will never interact with the cache, except to invalidate
* cache items when updates occur
*/
public static final CacheMode IGNORE = new CacheMode("IGNORE", false, false);
IGNORE( false, false),
/**
* The session may read items from the cache, but will not add items,
* The session may read items from the cache, but will not add items,
* except to invalidate items when updates occur
*/
public static final CacheMode GET = new CacheMode("GET", false, true);
GET( false, true),
/**
* The session will never read items from the cache, but will add items
* to the cache as it reads them from the database.
*/
public static final CacheMode PUT = new CacheMode("PUT", true, false);
PUT( true, false),
/**
* The session will never read items from the cache, but will add items
* to the cache as it reads them from the database. In this mode, the
* effect of <tt>hibernate.cache.use_minimal_puts</tt> is bypassed, in
* order to <em>force</em> a cache refresh
*/
public static final CacheMode REFRESH = new CacheMode("REFRESH", true, false);
static {
INSTANCES.put( NORMAL.name, NORMAL );
INSTANCES.put( IGNORE.name, IGNORE );
INSTANCES.put( GET.name, GET );
INSTANCES.put( PUT.name, PUT );
INSTANCES.put( REFRESH.name, REFRESH );
REFRESH( true, false);
private final boolean isPutEnabled;
private final boolean isGetEnabled;
CacheMode( boolean isPutEnabled, boolean isGetEnabled) {
this.isPutEnabled = isPutEnabled;
this.isGetEnabled = isGetEnabled;
}
private Object readResolve() {
return INSTANCES.get( name );
public boolean isGetEnabled() {
return isGetEnabled;
}
public static CacheMode parse(String name) {
return ( CacheMode ) INSTANCES.get( name );
public boolean isPutEnabled() {
return isPutEnabled;
}
}

View File

@ -23,7 +23,8 @@
*
*/
package org.hibernate;
import java.io.Serializable;
import java.util.EnumSet;
/**
* Defines the various policies by which Hibernate might release its underlying
@ -31,7 +32,7 @@ import java.io.Serializable;
*
* @author Steve Ebersole
*/
public class ConnectionReleaseMode implements Serializable {
public enum ConnectionReleaseMode{
/**
* Indicates that JDBC connection should be aggressively released after each
@ -39,7 +40,7 @@ public class ConnectionReleaseMode implements Serializable {
* explicitly close all iterators and scrollable results. This mode may
* only be used with a JTA datasource.
*/
public static final ConnectionReleaseMode AFTER_STATEMENT = new ConnectionReleaseMode( "after_statement" );
AFTER_STATEMENT("after_statement"),
/**
* Indicates that JDBC connections should be released after each transaction
@ -48,52 +49,19 @@ public class ConnectionReleaseMode implements Serializable {
* <p/>
* This is the default mode starting in 3.1; was previously {@link #ON_CLOSE}.
*/
public static final ConnectionReleaseMode AFTER_TRANSACTION = new ConnectionReleaseMode( "after_transaction" );
AFTER_TRANSACTION("after_transaction"),
/**
* Indicates that connections should only be released when the Session is explicitly closed
* or disconnected; this is the legacy (Hibernate2 and pre-3.1) behavior.
*/
public static final ConnectionReleaseMode ON_CLOSE = new ConnectionReleaseMode( "on_close" );
ON_CLOSE("on_close");
private String name;
private ConnectionReleaseMode(String name) {
private final String name;
ConnectionReleaseMode(String name){
this.name = name;
}
/**
* Override of Object.toString(). Returns the release mode name.
*
* @return The release mode name.
*/
public String toString() {
return name;
}
/**
* Determine the correct ConnectionReleaseMode instance based on the given
* name.
*
* @param modeName The release mode name.
* @return The appropriate ConnectionReleaseMode instance
* @throws HibernateException Indicates the modeName param did not match any known modes.
*/
public static ConnectionReleaseMode parse(String modeName) throws HibernateException {
if ( AFTER_STATEMENT.name.equals( modeName ) ) {
return AFTER_STATEMENT;
}
else if ( AFTER_TRANSACTION.name.equals( modeName ) ) {
return AFTER_TRANSACTION;
}
else if ( ON_CLOSE.name.equals( modeName ) ) {
return ON_CLOSE;
}
throw new HibernateException( "could not determine appropriate connection release mode [" + modeName + "]" );
}
private Object readResolve() {
return parse( name );
public static ConnectionReleaseMode parse(String name){
return ConnectionReleaseMode.valueOf( name.toUpperCase() );
}
}

View File

@ -28,6 +28,7 @@ import org.hibernate.criterion.CriteriaSpecification;
import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Projection;
import org.hibernate.sql.JoinType;
import org.hibernate.transform.ResultTransformer;
/**
@ -163,8 +164,8 @@ public interface Criteria extends CriteriaSpecification {
/**
* Join an association, assigning an alias to the joined association.
* <p/>
* Functionally equivalent to {@link #createAlias(String, String, int)} using
* {@link #INNER_JOIN} for the joinType.
* Functionally equivalent to {@link #createAlias(String, String, JoinType )} using
* {@link JoinType#INNER_JOIN} for the joinType.
*
* @param associationPath A dot-seperated property path
* @param alias The alias to assign to the joined association (for later reference).
@ -175,6 +176,23 @@ public interface Criteria extends CriteriaSpecification {
*/
public Criteria createAlias(String associationPath, String alias) throws HibernateException;
/**
* Join an association using the specified join-type, assigning an alias
* to the joined association.
* <p/>
* The joinType is expected to be one of {@link JoinType#INNER_JOIN} (the default),
* {@link JoinType#FULL_JOIN}, or {@link JoinType#LEFT_OUTER_JOIN}.
*
* @param associationPath A dot-seperated property path
* @param alias The alias to assign to the joined association (for later reference).
* @param joinType The type of join to use.
*
* @return this (for method chaining)
*
* @throws HibernateException Indicates a problem creating the sub criteria
*/
public Criteria createAlias(String associationPath, String alias, JoinType joinType) throws HibernateException;
/**
* Join an association using the specified join-type, assigning an alias
* to the joined association.
@ -189,9 +207,29 @@ public interface Criteria extends CriteriaSpecification {
* @return this (for method chaining)
*
* @throws HibernateException Indicates a problem creating the sub criteria
* @deprecated use {@link #createAlias(String, String, org.hibernate.sql.JoinType)}
*/
@Deprecated
public Criteria createAlias(String associationPath, String alias, int joinType) throws HibernateException;
/**
* Join an association using the specified join-type, assigning an alias
* to the joined association.
* <p/>
* The joinType is expected to be one of {@link JoinType#INNER_JOIN} (the default),
* {@link JoinType#FULL_JOIN}, or {@link JoinType#LEFT_OUTER_JOIN}.
*
* @param associationPath A dot-seperated property path
* @param alias The alias to assign to the joined association (for later reference).
* @param joinType The type of join to use.
* @param withClause The criteria to be added to the join condition (<tt>ON</tt> clause)
*
* @return this (for method chaining)
*
* @throws HibernateException Indicates a problem creating the sub criteria
*/
public Criteria createAlias(String associationPath, String alias, JoinType joinType, Criterion withClause) throws HibernateException;
/**
* Join an association using the specified join-type, assigning an alias
* to the joined association.
@ -207,14 +245,16 @@ public interface Criteria extends CriteriaSpecification {
* @return this (for method chaining)
*
* @throws HibernateException Indicates a problem creating the sub criteria
* @deprecated use {@link #createAlias(String, String, JoinType, Criterion}
*/
@Deprecated
public Criteria createAlias(String associationPath, String alias, int joinType, Criterion withClause) throws HibernateException;
/**
* Create a new <tt>Criteria</tt>, "rooted" at the associated entity.
* <p/>
* Functionally equivalent to {@link #createCriteria(String, int)} using
* {@link #INNER_JOIN} for the joinType.
* Functionally equivalent to {@link #createCriteria(String, org.hibernate.sql.JoinType)} using
* {@link JoinType#INNER_JOIN} for the joinType.
*
* @param associationPath A dot-seperated property path
*
@ -235,14 +275,29 @@ public interface Criteria extends CriteriaSpecification {
*
* @throws HibernateException Indicates a problem creating the sub criteria
*/
public Criteria createCriteria(String associationPath, JoinType joinType) throws HibernateException;
/**
* Create a new <tt>Criteria</tt>, "rooted" at the associated entity, using the
* specified join type.
*
* @param associationPath A dot-seperated property path
* @param joinType The type of join to use.
*
* @return the created "sub criteria"
*
* @throws HibernateException Indicates a problem creating the sub criteria
* @deprecated use {@link #createAlias(String, String, org.hibernate.sql.JoinType)}
*/
@Deprecated
public Criteria createCriteria(String associationPath, int joinType) throws HibernateException;
/**
* Create a new <tt>Criteria</tt>, "rooted" at the associated entity,
* assigning the given alias.
* <p/>
* Functionally equivalent to {@link #createCriteria(String, String, int)} using
* {@link #INNER_JOIN} for the joinType.
* Functionally equivalent to {@link #createCriteria(String, String, org.hibernate.sql.JoinType)} using
* {@link JoinType#INNER_JOIN} for the joinType.
*
* @param associationPath A dot-seperated property path
* @param alias The alias to assign to the joined association (for later reference).
@ -265,8 +320,25 @@ public interface Criteria extends CriteriaSpecification {
*
* @throws HibernateException Indicates a problem creating the sub criteria
*/
public Criteria createCriteria(String associationPath, String alias, JoinType joinType) throws HibernateException;
/**
* Create a new <tt>Criteria</tt>, "rooted" at the associated entity,
* assigning the given alias and using the specified join type.
*
* @param associationPath A dot-seperated property path
* @param alias The alias to assign to the joined association (for later reference).
* @param joinType The type of join to use.
*
* @return the created "sub criteria"
*
* @throws HibernateException Indicates a problem creating the sub criteria
* @deprecated use {@link #createCriteria(String, org.hibernate.sql.JoinType)}
*/
@Deprecated
public Criteria createCriteria(String associationPath, String alias, int joinType) throws HibernateException;
/**
* Create a new <tt>Criteria</tt>, "rooted" at the associated entity,
* assigning the given alias and using the specified join type.
@ -280,6 +352,23 @@ public interface Criteria extends CriteriaSpecification {
*
* @throws HibernateException Indicates a problem creating the sub criteria
*/
public Criteria createCriteria(String associationPath, String alias, JoinType joinType, Criterion withClause) throws HibernateException;
/**
* Create a new <tt>Criteria</tt>, "rooted" at the associated entity,
* assigning the given alias and using the specified join type.
*
* @param associationPath A dot-seperated property path
* @param alias The alias to assign to the joined association (for later reference).
* @param joinType The type of join to use.
* @param withClause The criteria to be added to the join condition (<tt>ON</tt> clause)
*
* @return the created "sub criteria"
*
* @throws HibernateException Indicates a problem creating the sub criteria
* @deprecated use {@link #createCriteria(String, String, org.hibernate.sql.JoinType, org.hibernate.criterion.Criterion)}
*/
@Deprecated
public Criteria createCriteria(String associationPath, String alias, int joinType, Criterion withClause) throws HibernateException;
/**

View File

@ -23,49 +23,35 @@
*
*/
package org.hibernate;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
/**
* Defines the representation modes available for entities.
*
* @author Steve Ebersole
*/
public class EntityMode implements Serializable {
private static final Map INSTANCES = new HashMap();
public static final EntityMode POJO = new EntityMode( "pojo" );
public static final EntityMode DOM4J = new EntityMode( "dom4j" );
public static final EntityMode MAP = new EntityMode( "dynamic-map" );
static {
INSTANCES.put( POJO.name, POJO );
INSTANCES.put( DOM4J.name, DOM4J );
INSTANCES.put( MAP.name, MAP );
}
public enum EntityMode {
POJO("pojo"),
DOM4J("dom4j"),
MAP("dynamic-map");
private final String name;
public EntityMode(String name) {
EntityMode(String name) {
this.name = name;
}
@Override
public String toString() {
return name;
}
private Object readResolve() {
return INSTANCES.get( name );
public static EntityMode parse(String entityMode) {
if(entityMode == null){
return POJO;
}
entityMode = entityMode.toUpperCase();
if ( entityMode.equals( "DYNAMIC-MAP" ) ) {
return MAP;
}
return valueOf( entityMode );
}
public static EntityMode parse(String name) {
EntityMode rtn = ( EntityMode ) INSTANCES.get( name );
if ( rtn == null ) {
// default is POJO
rtn = POJO;
}
return rtn;
}
}

View File

@ -23,9 +23,6 @@
*
*/
package org.hibernate;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
/**
* Represents an association fetching strategy. This is used
@ -37,30 +34,21 @@ import java.util.Map;
* @see Criteria#setFetchMode(java.lang.String, FetchMode)
* @author Gavin King
*/
public final class FetchMode implements Serializable {
private final String name;
private static final Map INSTANCES = new HashMap();
private FetchMode(String name) {
this.name=name;
}
public String toString() {
return name;
}
public enum FetchMode {
/**
* Default to the setting configured in the mapping file.
*/
public static final FetchMode DEFAULT = new FetchMode("DEFAULT");
DEFAULT,
/**
* Fetch using an outer join. Equivalent to <tt>fetch="join"</tt>.
*/
public static final FetchMode JOIN = new FetchMode("JOIN");
JOIN,
/**
* Fetch eagerly, using a separate select. Equivalent to
* <tt>fetch="select"</tt>.
*/
public static final FetchMode SELECT = new FetchMode("SELECT");
SELECT;
/**
* Fetch lazily. Equivalent to <tt>outer-join="false"</tt>.
@ -73,17 +61,6 @@ public final class FetchMode implements Serializable {
* @deprecated use <tt>FetchMode.JOIN</tt>
*/
public static final FetchMode EAGER = JOIN;
static {
INSTANCES.put( JOIN.name, JOIN );
INSTANCES.put( SELECT.name, SELECT );
INSTANCES.put( DEFAULT.name, DEFAULT );
}
private Object readResolve() {
return INSTANCES.get(name);
}
}

View File

@ -23,9 +23,6 @@
*
*/
package org.hibernate;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
/**
* Represents a flushing strategy. The flush process synchronizes
@ -38,77 +35,53 @@ import java.util.Map;
*
* @author Gavin King
*/
public final class FlushMode implements Serializable {
private static final Map INSTANCES = new HashMap();
private final int level;
private final String name;
private FlushMode(int level, String name) {
this.level = level;
this.name = name;
}
public String toString() {
return name;
}
/**
public enum FlushMode {
/**
* The {@link Session} is never flushed unless {@link Session#flush}
* is explicitly called by the application. This mode is very
* efficient for read only transactions.
*
* @deprecated use {@link #MANUAL} instead.
*/
public static final FlushMode NEVER = new FlushMode( 0, "NEVER" );
NEVER ( 0 ),
/**
* The {@link Session} is only ever flushed when {@link Session#flush}
* is explicitly called by the application. This mode is very
* efficient for read only transactions.
*/
public static final FlushMode MANUAL = new FlushMode( 0, "MANUAL" );
MANUAL( 0 ),
/**
* The {@link Session} is flushed when {@link Transaction#commit}
* is called.
*/
public static final FlushMode COMMIT = new FlushMode(5, "COMMIT");
COMMIT(5 ),
/**
* The {@link Session} is sometimes flushed before query execution
* in order to ensure that queries never return stale state. This
* is the default flush mode.
*/
public static final FlushMode AUTO = new FlushMode(10, "AUTO");
AUTO(10 ),
/**
* The {@link Session} is flushed before every query. This is
* almost always unnecessary and inefficient.
*/
public static final FlushMode ALWAYS = new FlushMode(20, "ALWAYS");
ALWAYS(20 );
private final int level;
private FlushMode(int level) {
this.level = level;
}
public boolean lessThan(FlushMode other) {
return this.level<other.level;
}
static {
INSTANCES.put( NEVER.name, NEVER );
INSTANCES.put( MANUAL.name, MANUAL );
INSTANCES.put( AUTO.name, AUTO );
INSTANCES.put( ALWAYS.name, ALWAYS );
INSTANCES.put( COMMIT.name, COMMIT );
}
public static boolean isManualFlushMode(FlushMode mode) {
return MANUAL.level == mode.level;
}
private Object readResolve() {
return INSTANCES.get( name );
}
public static FlushMode parse(String name) {
return ( FlushMode ) INSTANCES.get( name );
}
}

View File

@ -23,9 +23,6 @@
*
*/
package org.hibernate;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
/**
* Instances represent a lock mode for a row of a relational
@ -35,39 +32,10 @@ import java.util.Map;
* Some "advanced" users may wish to explicitly specify lock
* levels.
*
* @see Session#lock(Object,LockMode)
* @author Gavin King
* @see Session#lock(Object, LockMode)
*/
public final class LockMode implements Serializable {
private final int level;
private final String name;
private static final Map INSTANCES = new HashMap();
private LockMode(int level, String name) {
this.level=level;
this.name=name;
}
public String toString() {
return name;
}
/**
* Check if this lock mode is more restrictive than the given lock mode.
*
* @param mode LockMode to check
* @return true if this lock mode is more restrictive than given lock mode
*/
public boolean greaterThan(LockMode mode) {
return level > mode.level;
}
/**
* Check if this lock mode is less restrictive than the given lock mode.
*
* @param mode LockMode to check
* @return true if this lock mode is less restrictive than given lock mode
*/
public boolean lessThan(LockMode mode) {
return level < mode.level;
}
public enum LockMode {
/**
* No lock required. If an object is requested with this lock
* mode, a <tt>READ</tt> lock will be obtained if it is
@ -76,40 +44,42 @@ public final class LockMode implements Serializable {
* <br>
* This is the "default" lock mode.
*/
public static final LockMode NONE = new LockMode(0, "NONE");
NONE( 0 ),
/**
* A shared lock. Objects in this lock mode were read from
* the database in the current transaction, rather than being
* pulled from a cache.
*/
public static final LockMode READ = new LockMode(5, "READ");
READ( 5 ),
/**
* An upgrade lock. Objects loaded in this lock mode are
* materialized using an SQL <tt>select ... for update</tt>.
*
* @deprecated instead use PESSIMISTIC_WRITE
*/
public static final LockMode UPGRADE = new LockMode(10, "UPGRADE");
UPGRADE( 10 ),
/**
* Attempt to obtain an upgrade lock, using an Oracle-style
* <tt>select for update nowait</tt>. The semantics of
* this lock mode, once obtained, are the same as
* <tt>UPGRADE</tt>.
*/
public static final LockMode UPGRADE_NOWAIT = new LockMode(10, "UPGRADE_NOWAIT");
UPGRADE_NOWAIT( 10 ),
/**
* A <tt>WRITE</tt> lock is obtained when an object is updated
* or inserted. This lock mode is for internal use only and is
* not a valid mode for <tt>load()</tt> or <tt>lock()</tt> (both
* of which throw exceptions if WRITE is specified).
*/
public static final LockMode WRITE = new LockMode(10, "WRITE");
WRITE( 10 ),
/**
* Similiar to {@link #UPGRADE} except that, for versioned entities,
* it results in a forced version increment.
*
* @deprecated instead use PESSIMISTIC_FORCE_INCREMENT
*/
public static final LockMode FORCE = new LockMode( 15, "FORCE" );
FORCE( 15 ),
/**
* start of javax.persistence.LockModeType equivalent modes
@ -117,56 +87,59 @@ public final class LockMode implements Serializable {
/**
* Optimisticly assume that transaction will not experience contention for
* entities. The entity version will be verified near the transaction end.
* entities. The entity version will be verified near the transaction end.
*/
public static final LockMode OPTIMISTIC = new LockMode( 3, "OPTIMISTIC");
OPTIMISTIC( 3 ),
/**
* Optimisticly assume that transaction will not experience contention for entities.
* The entity version will be verified and incremented near the transaction end.
* The entity version will be verified and incremented near the transaction end.
*/
public static final LockMode OPTIMISTIC_FORCE_INCREMENT = new LockMode( 4, "OPTIMISTIC_FORCE_INCREMENT");
OPTIMISTIC_FORCE_INCREMENT( 4 ),
/**
* Implemented as PESSIMISTIC_WRITE.
* TODO: introduce separate support for PESSIMISTIC_READ
*/
public static final LockMode PESSIMISTIC_READ = new LockMode( 12, "PESSIMISTIC_READ");
PESSIMISTIC_READ( 12 ),
/**
* Transaction will obtain a database lock immediately.
* TODO: add PESSIMISTIC_WRITE_NOWAIT
*/
public static final LockMode PESSIMISTIC_WRITE = new LockMode( 13, "PESSIMISTIC_WRITE");
PESSIMISTIC_WRITE( 13 ),
/**
* Transaction will immediately increment the entity version.
*/
public static final LockMode PESSIMISTIC_FORCE_INCREMENT = new LockMode( 17, "PESSIMISTIC_FORCE_INCREMENT");
PESSIMISTIC_FORCE_INCREMENT( 17 );
private final int level;
private LockMode(int level) {
this.level = level;
}
/**
* end of javax.persistence.LockModeType modes
* Check if this lock mode is more restrictive than the given lock mode.
*
* @param mode LockMode to check
*
* @return true if this lock mode is more restrictive than given lock mode
*/
static {
INSTANCES.put( NONE.name, NONE );
INSTANCES.put( READ.name, READ );
INSTANCES.put( UPGRADE.name, UPGRADE );
INSTANCES.put( UPGRADE_NOWAIT.name, UPGRADE_NOWAIT );
INSTANCES.put( WRITE.name, WRITE );
INSTANCES.put( FORCE.name, FORCE );
INSTANCES.put( OPTIMISTIC.name, OPTIMISTIC);
INSTANCES.put( OPTIMISTIC_FORCE_INCREMENT.name, OPTIMISTIC_FORCE_INCREMENT);
INSTANCES.put( PESSIMISTIC_READ. name, PESSIMISTIC_READ);
INSTANCES.put( PESSIMISTIC_WRITE.name, PESSIMISTIC_WRITE);
INSTANCES.put( PESSIMISTIC_FORCE_INCREMENT.name, PESSIMISTIC_FORCE_INCREMENT);
public boolean greaterThan(LockMode mode) {
return level > mode.level;
}
private Object readResolve() {
return parse( name );
/**
* Check if this lock mode is less restrictive than the given lock mode.
*
* @param mode LockMode to check
*
* @return true if this lock mode is less restrictive than given lock mode
*/
public boolean lessThan(LockMode mode) {
return level < mode.level;
}
public static LockMode parse(String name) {
return ( LockMode ) INSTANCES.get(name);
}
}

View File

@ -23,72 +23,54 @@
*
*/
package org.hibernate;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
import org.hibernate.type.VersionType;
/**
* Represents a replication strategy.
*
* @see Session#replicate(Object, ReplicationMode)
* @author Gavin King
* @see Session#replicate(Object, ReplicationMode)
*/
public abstract class ReplicationMode implements Serializable {
private final String name;
private static final Map INSTANCES = new HashMap();
public ReplicationMode(String name) {
this.name=name;
}
public String toString() {
return name;
}
public abstract boolean shouldOverwriteCurrentVersion(Object entity, Object currentVersion, Object newVersion, VersionType versionType);
public enum ReplicationMode {
/**
* Throw an exception when a row already exists.
*/
public static final ReplicationMode EXCEPTION = new ReplicationMode("EXCEPTION") {
EXCEPTION {
public boolean shouldOverwriteCurrentVersion(Object entity, Object currentVersion, Object newVersion, VersionType versionType) {
throw new AssertionFailure("should not be called");
throw new AssertionFailure( "should not be called" );
}
};
},
/**
* Ignore replicated entities when a row already exists.
*/
public static final ReplicationMode IGNORE = new ReplicationMode("IGNORE") {
IGNORE {
public boolean shouldOverwriteCurrentVersion(Object entity, Object currentVersion, Object newVersion, VersionType versionType) {
return false;
}
};
},
/**
* Overwrite existing rows when a row already exists.
*/
public static final ReplicationMode OVERWRITE = new ReplicationMode("OVERWRITE") {
OVERWRITE {
public boolean shouldOverwriteCurrentVersion(Object entity, Object currentVersion, Object newVersion, VersionType versionType) {
return true;
}
};
},
/**
* When a row already exists, choose the latest version.
*/
public static final ReplicationMode LATEST_VERSION = new ReplicationMode("LATEST_VERSION") {
LATEST_VERSION {
public boolean shouldOverwriteCurrentVersion(Object entity, Object currentVersion, Object newVersion, VersionType versionType) {
if (versionType==null) return true; //always overwrite nonversioned data
return versionType.getComparator().compare(currentVersion, newVersion) <= 0;
if ( versionType == null ) {
return true; //always overwrite nonversioned data
}
return versionType.getComparator().compare( currentVersion, newVersion ) <= 0;
}
};
static {
INSTANCES.put( LATEST_VERSION.name, LATEST_VERSION );
INSTANCES.put( IGNORE.name, IGNORE );
INSTANCES.put( OVERWRITE.name, OVERWRITE );
INSTANCES.put( EXCEPTION.name, EXCEPTION );
}
public abstract boolean shouldOverwriteCurrentVersion(Object entity, Object currentVersion, Object newVersion, VersionType versionType);
private Object readResolve() {
return INSTANCES.get(name);
}
}

View File

@ -23,68 +23,56 @@
*
*/
package org.hibernate;
import java.io.Serializable;
import java.sql.ResultSet;
import java.util.HashMap;
import java.util.Map;
/**
* Specifies the type of JDBC scrollable result set to use
* underneath a <tt>ScrollableResults</tt>
*
* @author Gavin King
* @see Query#scroll(ScrollMode)
* @see ScrollableResults
* @author Gavin King
*/
public final class ScrollMode implements Serializable {
private final int resultSetType;
private final String name;
private static final Map INSTANCES = new HashMap();
public enum ScrollMode {
/**
* @see java.sql.ResultSet#TYPE_FORWARD_ONLY
*/
FORWARD_ONLY( ResultSet.TYPE_FORWARD_ONLY ),
private ScrollMode(int level, String name) {
this.resultSetType=level;
this.name=name;
/**
* @see java.sql.ResultSet#TYPE_SCROLL_SENSITIVE
*/
SCROLL_SENSITIVE(
ResultSet.TYPE_SCROLL_SENSITIVE
),
/**
* Note that since the Hibernate session acts as a cache, you
* might need to expicitly evict objects, if you need to see
* changes made by other transactions.
*
* @see java.sql.ResultSet#TYPE_SCROLL_INSENSITIVE
*/
SCROLL_INSENSITIVE(
ResultSet.TYPE_SCROLL_INSENSITIVE
);
private final int resultSetType;
private ScrollMode(int level) {
this.resultSetType = level;
}
public String toString() {
return name;
}
/**
* @return the JDBC result set type code
*/
public int toResultSetType() {
return resultSetType;
}
/**
* @see java.sql.ResultSet.TYPE_FORWARD_ONLY
*/
public static final ScrollMode FORWARD_ONLY = new ScrollMode(ResultSet.TYPE_FORWARD_ONLY, "FORWARD_ONLY");
/**
* @see java.sql.ResultSet.TYPE_SCROLL_SENSITIVE
*/
public static final ScrollMode SCROLL_SENSITIVE = new ScrollMode(ResultSet.TYPE_SCROLL_SENSITIVE, "SCROLL_SENSITIVE");
/**
* Note that since the Hibernate session acts as a cache, you
* might need to expicitly evict objects, if you need to see
* changes made by other transactions.
* @see java.sql.ResultSet.TYPE_SCROLL_INSENSITIVE
*/
public static final ScrollMode SCROLL_INSENSITIVE = new ScrollMode(ResultSet.TYPE_SCROLL_INSENSITIVE, "SCROLL_INSENSITIVE");
public boolean lessThan(ScrollMode other) {
return this.resultSetType<other.resultSetType;
}
static {
INSTANCES.put( FORWARD_ONLY.name, FORWARD_ONLY );
INSTANCES.put( SCROLL_INSENSITIVE.name, SCROLL_INSENSITIVE );
INSTANCES.put( SCROLL_SENSITIVE.name, SCROLL_SENSITIVE );
}
private Object readResolve() {
return INSTANCES.get(name);
return this.resultSetType < other.resultSetType;
}
}

View File

@ -21,13 +21,15 @@
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.annotations;
package org.hibernate.annotations;
import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.ElementType.TYPE;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
import java.lang.annotation.Retention;
import org.hibernate.EntityMode;
/**
* Define a tuplizer for an entity or a component
* @author Emmanuel Bernard
@ -37,6 +39,11 @@ import java.lang.annotation.Retention;
public @interface Tuplizer {
/** tuplizer implementation */
Class impl();
/** either pojo, dynamic-map or dom4j<34> */
/**
* either pojo, dynamic-map or dom4j
* @deprecated should use #entityModeType instead
*/
@Deprecated
String entityMode() default "pojo";
EntityMode entityModeType() default EntityMode.POJO;
}

View File

@ -2557,12 +2557,14 @@ public final class AnnotationBinder {
if ( property.isAnnotationPresent( Tuplizers.class ) ) {
for ( Tuplizer tuplizer : property.getAnnotation( Tuplizers.class ).value() ) {
EntityMode mode = EntityMode.parse( tuplizer.entityMode() );
//todo tuplizer.entityModeType
component.addTuplizer( mode, tuplizer.impl().getName() );
}
}
if ( property.isAnnotationPresent( Tuplizer.class ) ) {
Tuplizer tuplizer = property.getAnnotation( Tuplizer.class );
EntityMode mode = EntityMode.parse( tuplizer.entityMode() );
//todo tuplizer.entityModeType
component.addTuplizer( mode, tuplizer.impl().getName() );
}
}

View File

@ -321,12 +321,14 @@ public class EntityBinder {
if ( annotatedClass.isAnnotationPresent( Tuplizers.class ) ) {
for (Tuplizer tuplizer : annotatedClass.getAnnotation( Tuplizers.class ).value()) {
EntityMode mode = EntityMode.parse( tuplizer.entityMode() );
//todo tuplizer.entityModeType
persistentClass.addTuplizer( mode, tuplizer.impl().getName() );
}
}
if ( annotatedClass.isAnnotationPresent( Tuplizer.class ) ) {
Tuplizer tuplizer = annotatedClass.getAnnotation( Tuplizer.class );
EntityMode mode = EntityMode.parse( tuplizer.entityMode() );
//todo tuplizer.entityModeType
persistentClass.addTuplizer( mode, tuplizer.impl().getName() );
}

View File

@ -23,6 +23,7 @@
*
*/
package org.hibernate.criterion;
import org.hibernate.sql.JoinType;
import org.hibernate.transform.AliasToEntityMapResultTransformer;
import org.hibernate.transform.DistinctRootEntityResultTransformer;
import org.hibernate.transform.PassThroughResultTransformer;
@ -61,17 +62,24 @@ public interface CriteriaSpecification {
/**
* Specifies joining to an entity based on an inner join.
* @deprecated use {@link JoinType#INNER_JOIN}
*/
@Deprecated
public static final int INNER_JOIN = org.hibernate.sql.JoinFragment.INNER_JOIN;
/**
* Specifies joining to an entity based on a full join.
* @deprecated use {@link JoinType#FULL_JOIN}
*/
@Deprecated
public static final int FULL_JOIN = org.hibernate.sql.JoinFragment.FULL_JOIN;
/**
* Specifies joining to an entity based on a left outer join.
* @deprecated use {@link JoinType#LEFT_OUTER_JOIN}
*/
@Deprecated
public static final int LEFT_JOIN = org.hibernate.sql.JoinFragment.LEFT_OUTER_JOIN;
}

View File

@ -24,6 +24,8 @@
*/
package org.hibernate.criterion;
import java.io.Serializable;
import javax.persistence.criteria.Join;
import org.hibernate.Criteria;
import org.hibernate.FetchMode;
import org.hibernate.HibernateException;
@ -31,6 +33,7 @@ import org.hibernate.LockMode;
import org.hibernate.Session;
import org.hibernate.engine.spi.SessionImplementor;
import org.hibernate.internal.CriteriaImpl;
import org.hibernate.sql.JoinType;
import org.hibernate.transform.ResultTransformer;
/**
@ -144,27 +147,63 @@ public class DetachedCriteria implements CriteriaSpecification, Serializable {
return impl;
}
public DetachedCriteria createAlias(String associationPath, String alias, int joinType) throws HibernateException {
public DetachedCriteria createAlias(String associationPath, String alias, JoinType joinType) throws HibernateException {
criteria.createAlias(associationPath, alias, joinType);
return this;
}
public DetachedCriteria createAlias(String associationPath, String alias, int joinType, Criterion withClause) throws HibernateException {
public DetachedCriteria createAlias(String associationPath, String alias, JoinType joinType, Criterion withClause) throws HibernateException {
criteria.createAlias(associationPath, alias, joinType, withClause);
return this;
}
public DetachedCriteria createCriteria(String associationPath, int joinType) throws HibernateException {
public DetachedCriteria createCriteria(String associationPath, JoinType joinType) throws HibernateException {
return new DetachedCriteria(impl, criteria.createCriteria(associationPath, joinType));
}
public DetachedCriteria createCriteria(String associationPath, String alias, int joinType) throws HibernateException {
public DetachedCriteria createCriteria(String associationPath, String alias, JoinType joinType) throws HibernateException {
return new DetachedCriteria(impl, criteria.createCriteria(associationPath, alias, joinType));
}
public DetachedCriteria createCriteria(String associationPath, String alias, int joinType, Criterion withClause) throws HibernateException {
public DetachedCriteria createCriteria(String associationPath, String alias, JoinType joinType, Criterion withClause) throws HibernateException {
return new DetachedCriteria(impl, criteria.createCriteria(associationPath, alias, joinType, withClause));
}
/**
* @deprecated use {@link #createAlias(String, String, JoinType)}
*/
@Deprecated
public DetachedCriteria createAlias(String associationPath, String alias, int joinType) throws HibernateException {
return createAlias( associationPath, alias, JoinType.parse( joinType ) );
}
/**
* @deprecated use {@link #createAlias(String, String, JoinType, Criterion)}
*/
@Deprecated
public DetachedCriteria createAlias(String associationPath, String alias, int joinType, Criterion withClause) throws HibernateException {
return createAlias( associationPath, alias, JoinType.parse( joinType ), withClause );
}
/**
* @deprecated use {@link #createCriteria(String, JoinType)}
*/
@Deprecated
public DetachedCriteria createCriteria(String associationPath, int joinType) throws HibernateException {
return createCriteria( associationPath, JoinType.parse( joinType ) );
}
/**
* @deprecated use {@link #createCriteria(String, String, JoinType)}
*/
@Deprecated
public DetachedCriteria createCriteria(String associationPath, String alias, int joinType) throws HibernateException {
return createCriteria( associationPath, alias, JoinType.parse( joinType ) );
}
/**
* @deprecated use {@link #createCriteria(String, String, JoinType, Criterion)}
*/
@Deprecated
public DetachedCriteria createCriteria(String associationPath, String alias, int joinType, Criterion withClause) throws HibernateException {
return createCriteria( associationPath, alias, JoinType.parse( joinType ), withClause );
}
public DetachedCriteria setComment(String comment) {
criteria.setComment(comment);

View File

@ -23,74 +23,51 @@
*
*/
package org.hibernate.criterion;
import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
/**
* Represents an strategy for matching strings using "like".
*
* @see Example#enableLike(MatchMode)
* @author Gavin King
* @see Example#enableLike(MatchMode)
*/
public abstract class MatchMode implements Serializable {
private final String name;
private static final Map INSTANCES = new HashMap();
protected MatchMode(String name) {
this.name=name;
}
public String toString() {
return name;
}
public enum MatchMode {
/**
* Match the entire string to the pattern
*/
public static final MatchMode EXACT = new MatchMode("EXACT") {
EXACT {
public String toMatchString(String pattern) {
return pattern;
}
};
},
/**
* Match the start of the string to the pattern
*/
public static final MatchMode START = new MatchMode("START") {
START {
public String toMatchString(String pattern) {
return pattern + '%';
}
};
},
/**
* Match the end of the string to the pattern
*/
public static final MatchMode END = new MatchMode("END") {
END {
public String toMatchString(String pattern) {
return '%' + pattern;
}
};
},
/**
* Match the pattern anywhere in the string
*/
public static final MatchMode ANYWHERE = new MatchMode("ANYWHERE") {
ANYWHERE {
public String toMatchString(String pattern) {
return '%' + pattern + '%';
}
};
static {
INSTANCES.put( EXACT.name, EXACT );
INSTANCES.put( END.name, END );
INSTANCES.put( START.name, START );
INSTANCES.put( ANYWHERE.name, ANYWHERE );
}
private Object readResolve() {
return INSTANCES.get(name);
}
/**
* convert the pattern, by appending/prepending "%"
*/

View File

@ -34,6 +34,7 @@ import org.hibernate.internal.util.collections.CollectionHelper;
import org.hibernate.persister.collection.QueryableCollection;
import org.hibernate.persister.entity.Joinable;
import org.hibernate.sql.JoinFragment;
import org.hibernate.sql.JoinType;
import org.hibernate.sql.QueryJoinFragment;
import org.hibernate.type.AssociationType;
@ -43,7 +44,7 @@ import org.hibernate.type.AssociationType;
public class JoinSequence {
private final SessionFactoryImplementor factory;
private final List joins = new ArrayList();
private final List<Join> joins = new ArrayList<Join>();
private boolean useThetaStyle = false;
private final StringBuffer conditions = new StringBuffer();
private String rootAlias;
@ -54,7 +55,7 @@ public class JoinSequence {
@Override
public String toString() {
StringBuffer buf = new StringBuffer();
StringBuilder buf = new StringBuilder();
buf.append( "JoinSequence{" );
if ( rootJoinable != null ) {
buf.append( rootJoinable )
@ -72,11 +73,11 @@ public class JoinSequence {
private final AssociationType associationType;
private final Joinable joinable;
private final int joinType;
private final JoinType joinType;
private final String alias;
private final String[] lhsColumns;
Join(AssociationType associationType, String alias, int joinType, String[] lhsColumns)
Join(AssociationType associationType, String alias, JoinType joinType, String[] lhsColumns)
throws MappingException {
this.associationType = associationType;
this.joinable = associationType.getAssociatedJoinable( factory );
@ -97,7 +98,7 @@ public class JoinSequence {
return joinable;
}
public int getJoinType() {
public JoinType getJoinType() {
return joinType;
}
@ -140,7 +141,7 @@ public class JoinSequence {
return copy;
}
public JoinSequence addJoin(AssociationType associationType, String alias, int joinType, String[] referencingKey)
public JoinSequence addJoin(AssociationType associationType, String alias, JoinType joinType, String[] referencingKey)
throws MappingException {
joins.add( new Join( associationType, alias, joinType, referencingKey ) );
return this;
@ -174,8 +175,7 @@ public class JoinSequence {
Joinable last = rootJoinable;
for ( int i = 0; i < joins.size(); i++ ) {
Join join = ( Join ) joins.get( i );
for ( Join join: joins ) {
String on = join.getAssociationType().getOnCondition( join.getAlias(), factory, enabledFilters );
String condition = null;
if ( last != null &&
@ -209,7 +209,7 @@ public class JoinSequence {
condition
);
if (includeExtraJoins) { //TODO: not quite sure about the full implications of this!
addExtraJoins( joinFragment, join.getAlias(), join.getJoinable(), join.joinType == JoinFragment.INNER_JOIN );
addExtraJoins( joinFragment, join.getAlias(), join.getJoinable(), join.joinType == JoinType.INNER_JOIN );
}
last = join.getJoinable();
}

View File

@ -53,9 +53,9 @@ public class Fetch {
* require major changes to the subselect loading code (which is
* needed for other things as well anyway).
*/
public static class Style {
public static final Style JOIN = new Style( "join" );
public static final Style SELECT = new Style( "select" );
public enum Style {
JOIN( "join" ),
SELECT( "select" );
private final String name;

View File

@ -387,7 +387,7 @@ public final class EntityEntry implements Serializable {
( Object[] ) ois.readObject(),
( Object[] ) ois.readObject(),
ois.readObject(),
LockMode.parse( (String) ois.readObject() ),
LockMode.valueOf( (String) ois.readObject() ),
ois.readBoolean(),
ois.readBoolean(),
ois.readBoolean()

View File

@ -91,7 +91,7 @@ import org.hibernate.param.PositionalParameterSpecification;
import org.hibernate.param.VersionTypeSeedParameterSpecification;
import org.hibernate.persister.collection.QueryableCollection;
import org.hibernate.persister.entity.Queryable;
import org.hibernate.sql.JoinFragment;
import org.hibernate.sql.JoinType;
import org.hibernate.type.AssociationType;
import org.hibernate.type.ComponentType;
import org.hibernate.type.DbTimestampType;
@ -148,7 +148,7 @@ public class HqlSqlWalker extends HqlSqlBaseWalker implements ErrorReporter, Par
private ArrayList assignmentSpecifications = new ArrayList();
private int impliedJoinType;
private JoinType impliedJoinType = JoinType.INNER_JOIN;
/**
* Create a new tree transformer.
@ -342,7 +342,7 @@ public class HqlSqlWalker extends HqlSqlBaseWalker implements ErrorReporter, Par
if ( !persister.isOneToMany() ) {
join.addJoin( ( AssociationType ) persister.getElementType(),
fromElement.getTableAlias(),
JoinFragment.INNER_JOIN,
JoinType.INNER_JOIN,
persister.getElementColumnNames( fkTableAlias ) );
}
join.addCondition( fkTableAlias, keyColumnNames, " = ?" );
@ -369,7 +369,7 @@ public class HqlSqlWalker extends HqlSqlBaseWalker implements ErrorReporter, Par
throw new SemanticException( "Path expected for join!" );
}
DotNode dot = ( DotNode ) path;
int hibernateJoinType = JoinProcessor.toHibernateJoinType( joinType );
JoinType hibernateJoinType = JoinProcessor.toHibernateJoinType( joinType );
dot.setJoinType( hibernateJoinType ); // Tell the dot node about the join type.
dot.setFetch( fetch );
// Generate an explicit join for the root dot node. The implied joins will be collected and passed up
@ -548,7 +548,7 @@ public class HqlSqlWalker extends HqlSqlBaseWalker implements ErrorReporter, Par
impliedJoinType = JoinProcessor.toHibernateJoinType( joinType );
}
public int getImpliedJoinType() {
public JoinType getImpliedJoinType() {
return impliedJoinType;
}

View File

@ -35,6 +35,7 @@ import org.hibernate.internal.util.StringHelper;
import org.hibernate.persister.collection.QueryableCollection;
import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.sql.JoinFragment;
import org.hibernate.sql.JoinType;
import org.hibernate.type.CollectionType;
import org.hibernate.type.EntityType;
import org.hibernate.type.Type;
@ -100,7 +101,7 @@ public class DotNode extends FromReferenceNode implements DisplayableNode, Selec
/**
* The type of join to create. Default is an inner join.
*/
private int joinType = JoinFragment.INNER_JOIN;
private JoinType joinType = JoinType.INNER_JOIN;
/**
* Fetch join or not.
@ -120,7 +121,7 @@ public class DotNode extends FromReferenceNode implements DisplayableNode, Selec
* @param joinType The type of join to use.
* @see JoinFragment
*/
public void setJoinType(int joinType) {
public void setJoinType(JoinType joinType) {
this.joinType = joinType;
}
@ -135,7 +136,7 @@ public class DotNode extends FromReferenceNode implements DisplayableNode, Selec
@Override
public String getDisplayText() {
StringBuffer buf = new StringBuffer();
StringBuilder buf = new StringBuilder();
FromElement fromElement = getFromElement();
buf.append( "{propertyName=" ).append( propertyName );
buf.append( ",dereferenceType=" ).append( getWalker().getASTPrinter().getTokenTypeName( dereferenceType ) );

View File

@ -37,6 +37,7 @@ import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.persister.entity.Joinable;
import org.hibernate.persister.entity.Queryable;
import org.hibernate.sql.JoinFragment;
import org.hibernate.sql.JoinType;
import org.hibernate.type.AssociationType;
import org.hibernate.type.CollectionType;
import org.hibernate.type.ComponentType;
@ -182,7 +183,7 @@ public class FromElementFactory implements SqlTokenTypes {
FromElement createCollection(
QueryableCollection queryableCollection,
String role,
int joinType,
JoinType joinType,
boolean fetchFlag,
boolean indexed)
throws SemanticException {
@ -330,7 +331,7 @@ public class FromElementFactory implements SqlTokenTypes {
AssociationType elementAssociationType = sfh.getElementAssociationType( type );
// Create the join element under the from element.
int joinType = JoinFragment.INNER_JOIN;
JoinType joinType = JoinType.INNER_JOIN;
JoinSequence joinSequence = sfh.createJoinSequence( implied, elementAssociationType, tableAlias, joinType, targetColumns );
elem = initializeJoin( path, destination, joinSequence, targetColumns, origin, false );
elem.setUseFromFragment( true ); // The associated entity is implied, but it must be included in the FROM.
@ -366,7 +367,7 @@ public class FromElementFactory implements SqlTokenTypes {
private FromElement createEntityAssociation(
String role,
String roleAlias,
int joinType) throws SemanticException {
JoinType joinType) throws SemanticException {
FromElement elem;
Queryable entityPersister = ( Queryable ) queryableCollection.getElementPersister();
String associatedEntityName = entityPersister.getEntityName();
@ -412,7 +413,7 @@ public class FromElementFactory implements SqlTokenTypes {
String roleAlias,
Queryable entityPersister,
EntityType type,
int joinType) throws SemanticException {
JoinType joinType) throws SemanticException {
FromElement elem;
SessionFactoryHelper sfh = fromClause.getSessionFactoryHelper();
if ( inElementsFunction /*implied*/ ) {
@ -435,7 +436,7 @@ public class FromElementFactory implements SqlTokenTypes {
return elem;
}
private JoinSequence createJoinSequence(String roleAlias, int joinType) {
private JoinSequence createJoinSequence(String roleAlias, JoinType joinType) {
SessionFactoryHelper sessionFactoryHelper = fromClause.getSessionFactoryHelper();
String[] joinColumns = getColumns();
if ( collectionType == null ) {

View File

@ -33,6 +33,7 @@ import org.hibernate.internal.util.StringHelper;
import org.hibernate.persister.collection.QueryableCollection;
import org.hibernate.persister.entity.Queryable;
import org.hibernate.sql.JoinFragment;
import org.hibernate.sql.JoinType;
import org.hibernate.type.CollectionType;
import org.hibernate.type.Type;
import antlr.SemanticException;
@ -77,7 +78,7 @@ public class IdentNode extends FromReferenceNode implements SelectExpression {
String alias = null; // DotNode uses null here...
String columnTableAlias = getFromElement().getTableAlias();
int joinType = JoinFragment.INNER_JOIN;
JoinType joinType = JoinType.INNER_JOIN;
boolean fetch = false;
FromElementFactory factory = new FromElementFactory(

View File

@ -48,6 +48,7 @@ import org.hibernate.internal.util.StringHelper;
import org.hibernate.internal.util.collections.ArrayHelper;
import org.hibernate.param.DynamicFilterParameterSpecification;
import org.hibernate.sql.JoinFragment;
import org.hibernate.sql.JoinType;
import org.hibernate.type.Type;
import org.jboss.logging.Logger;
@ -83,14 +84,14 @@ public class JoinProcessor implements SqlTokenTypes {
* @see JoinFragment
* @see SqlTokenTypes
*/
public static int toHibernateJoinType(int astJoinType) {
public static JoinType toHibernateJoinType(int astJoinType) {
switch ( astJoinType ) {
case LEFT_OUTER:
return JoinFragment.LEFT_OUTER_JOIN;
return JoinType.LEFT_OUTER_JOIN;
case INNER:
return JoinFragment.INNER_JOIN;
return JoinType.INNER_JOIN;
case RIGHT_OUTER:
return JoinFragment.RIGHT_OUTER_JOIN;
return JoinType.RIGHT_OUTER_JOIN;
default:
throw new AssertionFailure( "undefined join type " + astJoinType );
}

View File

@ -40,6 +40,7 @@ import org.hibernate.persister.collection.QueryableCollection;
import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.persister.entity.PropertyMapping;
import org.hibernate.persister.entity.Queryable;
import org.hibernate.sql.JoinType;
import org.hibernate.type.AssociationType;
import org.hibernate.type.CollectionType;
import org.hibernate.type.EntityType;
@ -266,7 +267,7 @@ public class SessionFactoryHelper {
* @param columns The columns making up the condition of the join.
* @return The generated join sequence.
*/
public JoinSequence createJoinSequence(boolean implicit, AssociationType associationType, String tableAlias, int joinType, String[] columns) {
public JoinSequence createJoinSequence(boolean implicit, AssociationType associationType, String tableAlias, JoinType joinType, String[] columns) {
JoinSequence joinSequence = createJoinSequence();
joinSequence.setUseThetaStyle( implicit ); // Implicit joins use theta style (WHERE pk = fk), explicit joins use JOIN (after from)
joinSequence.addJoin( associationType, tableAlias, joinType, columns );

View File

@ -28,7 +28,7 @@ import java.util.Map;
import org.hibernate.QueryException;
import org.hibernate.hql.spi.QueryTranslator;
import org.hibernate.persister.entity.Queryable;
import org.hibernate.sql.JoinFragment;
import org.hibernate.sql.JoinType;
/**
* Parses the from clause of a hibernate query, looking for tables and
@ -47,7 +47,7 @@ public class FromParser implements Parser {
private boolean expectingIn;
private boolean expectingAs;
private boolean afterJoinType;
private int joinType;
private JoinType joinType = JoinType.INNER_JOIN;
private boolean afterFetch;
//support collection member declarations
@ -57,15 +57,13 @@ public class FromParser implements Parser {
private boolean afterMemberDeclarations;
private String collectionName;
private static final int NONE = -666;
private static final Map JOIN_TYPES = new HashMap();
private static final Map<String,JoinType> JOIN_TYPES = new HashMap<String,JoinType>();
static {
JOIN_TYPES.put( "left", JoinFragment.LEFT_OUTER_JOIN );
JOIN_TYPES.put( "right", JoinFragment.RIGHT_OUTER_JOIN );
JOIN_TYPES.put( "full", JoinFragment.FULL_JOIN );
JOIN_TYPES.put( "inner", JoinFragment.INNER_JOIN );
JOIN_TYPES.put( "left", JoinType.LEFT_OUTER_JOIN );
JOIN_TYPES.put( "right", JoinType.RIGHT_OUTER_JOIN );
JOIN_TYPES.put( "full", JoinType.FULL_JOIN );
JOIN_TYPES.put( "inner", JoinType.INNER_JOIN );
}
public void token(String token, QueryTranslatorImpl q) throws QueryException {
@ -81,7 +79,7 @@ public class FromParser implements Parser {
if ( !afterJoinType ) {
if ( !( expectingJoin | expectingAs ) ) throw new QueryException( "unexpected token: join" );
// inner joins can be abbreviated to 'join'
joinType = JoinFragment.INNER_JOIN;
joinType = JoinType.INNER_JOIN;
expectingJoin = false;
expectingAs = false;
}
@ -91,8 +89,8 @@ public class FromParser implements Parser {
}
else if ( lcToken.equals( "fetch" ) ) {
if ( q.isShallowQuery() ) throw new QueryException( QueryTranslator.ERROR_CANNOT_FETCH_WITH_ITERATE );
if ( joinType == NONE ) throw new QueryException( "unexpected token: fetch" );
if ( joinType == JoinFragment.FULL_JOIN || joinType == JoinFragment.RIGHT_OUTER_JOIN ) {
if ( joinType == JoinType.NONE ) throw new QueryException( "unexpected token: fetch" );
if ( joinType == JoinType.FULL_JOIN || joinType == JoinType.RIGHT_OUTER_JOIN ) {
throw new QueryException( "fetch may only be used with inner join or left outer join" );
}
afterFetch = true;
@ -100,21 +98,21 @@ public class FromParser implements Parser {
else if ( lcToken.equals( "outer" ) ) {
// 'outer' is optional and is ignored
if ( !afterJoinType ||
( joinType != JoinFragment.LEFT_OUTER_JOIN && joinType != JoinFragment.RIGHT_OUTER_JOIN )
( joinType != JoinType.LEFT_OUTER_JOIN && joinType != JoinType.RIGHT_OUTER_JOIN )
) {
throw new QueryException( "unexpected token: outer" );
}
}
else if ( JOIN_TYPES.containsKey( lcToken ) ) {
if ( !( expectingJoin | expectingAs ) ) throw new QueryException( "unexpected token: " + token );
joinType = ( ( Integer ) JOIN_TYPES.get( lcToken ) ).intValue();
joinType = JOIN_TYPES.get( lcToken );
afterJoinType = true;
expectingJoin = false;
expectingAs = false;
}
else if ( lcToken.equals( "class" ) ) {
if ( !afterIn ) throw new QueryException( "unexpected token: class" );
if ( joinType != NONE ) throw new QueryException( "outer or full join must be followed by path expression" );
if ( joinType != JoinType.NONE ) throw new QueryException( "outer or full join must be followed by path expression" );
afterClass = true;
}
else if ( lcToken.equals( "in" ) ) {
@ -187,7 +185,7 @@ public class FromParser implements Parser {
if ( alias == null ) throw new QueryException( "alias not specified for: " + token );
if ( joinType != NONE ) throw new QueryException( "outer or full join must be followed by path expression" );
if ( joinType != JoinType.NONE ) throw new QueryException( "outer or full join must be followed by path expression" );
if ( afterClass ) {
// treat it as a classname
@ -197,7 +195,7 @@ public class FromParser implements Parser {
}
else {
// treat it as a path expression
peParser.setJoinType( JoinFragment.INNER_JOIN );
peParser.setJoinType( JoinType.INNER_JOIN );
peParser.setUseThetaStyleJoin( true );
ParserHelper.parse( peParser, q.unalias( token ), ParserHelper.PATH_SEPARATORS, q );
if ( !peParser.isCollectionValued() ) throw new QueryException( "path expression did not resolve to collection: " + token );
@ -212,7 +210,7 @@ public class FromParser implements Parser {
}
else if( memberDeclarations && expectingPathExpression ){
expectingAs = true;
peParser.setJoinType( JoinFragment.INNER_JOIN );
peParser.setJoinType( JoinType.INNER_JOIN );
peParser.setUseThetaStyleJoin( false );
ParserHelper.parse( peParser, q.unalias( token ), ParserHelper.PATH_SEPARATORS, q );
if ( !peParser.isCollectionValued() ) throw new QueryException( "path expression did not resolve to collection: " + token );
@ -230,7 +228,7 @@ public class FromParser implements Parser {
Queryable p = q.getEntityPersisterUsingImports( token );
if ( p != null ) {
// starts with the name of a mapped class (new style)
if ( joinType != NONE ) throw new QueryException( "outer or full join must be followed by path expression" );
if ( joinType != JoinType.NONE ) throw new QueryException( "outer or full join must be followed by path expression" );
entityName = q.createNameFor( p.getEntityName() );
q.addFromClass( entityName, p );
expectingAs = true;
@ -249,19 +247,19 @@ public class FromParser implements Parser {
//if (joinType==NONE) throw new QueryException("path expression must be preceded by full, left, right or inner join");
//allow ODMG OQL style: from Person p, p.cars c
if ( joinType != NONE ) {
if ( joinType != JoinType.NONE ) {
peParser.setJoinType( joinType );
}
else {
peParser.setJoinType( JoinFragment.INNER_JOIN );
peParser.setJoinType( JoinType.INNER_JOIN );
}
peParser.setUseThetaStyleJoin( q.isSubquery() );
ParserHelper.parse( peParser, q.unalias( token ), ParserHelper.PATH_SEPARATORS, q );
entityName = peParser.addFromAssociation( q );
joinType = NONE;
peParser.setJoinType( JoinFragment.INNER_JOIN );
joinType = JoinType.NONE;
peParser.setJoinType( JoinType.INNER_JOIN );
if ( afterFetch ) {
peParser.fetch( q, entityName );
@ -289,7 +287,7 @@ public class FromParser implements Parser {
memberDeclarations = false;
expectingPathExpression = false;
afterMemberDeclarations = false;
joinType = NONE;
joinType = JoinType.NONE;
}
public void end(QueryTranslatorImpl q) {

View File

@ -34,7 +34,7 @@ import org.hibernate.persister.collection.QueryableCollection;
import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.persister.entity.PropertyMapping;
import org.hibernate.persister.entity.Queryable;
import org.hibernate.sql.JoinFragment;
import org.hibernate.sql.JoinType;
import org.hibernate.type.AssociationType;
import org.hibernate.type.CollectionType;
import org.hibernate.type.EntityType;
@ -69,7 +69,7 @@ public class PathExpressionParser implements Parser {
private final StringBuffer path = new StringBuffer();
private boolean ignoreInitialJoin;
private boolean continuation;
private int joinType = JoinFragment.INNER_JOIN; //default mode
private JoinType joinType = JoinType.INNER_JOIN; //default mode
private boolean useThetaStyleJoin = true;
private PropertyMapping currentPropertyMapping;
private JoinSequence joinSequence;
@ -77,7 +77,7 @@ public class PathExpressionParser implements Parser {
private boolean expectingCollectionIndex;
private LinkedList collectionElements = new LinkedList();
void setJoinType(int joinType) {
void setJoinType(JoinType joinType) {
this.joinType = joinType;
}

View File

@ -66,6 +66,7 @@ import org.hibernate.persister.entity.Loadable;
import org.hibernate.persister.entity.PropertyMapping;
import org.hibernate.persister.entity.Queryable;
import org.hibernate.sql.JoinFragment;
import org.hibernate.sql.JoinType;
import org.hibernate.sql.QuerySelect;
import org.hibernate.transform.ResultTransformer;
import org.hibernate.type.AssociationType;
@ -908,7 +909,7 @@ public class QueryTranslatorImpl extends BasicLoader implements FilterTranslator
try {
join.addJoin( ( AssociationType ) persister.getElementType(),
elementName,
JoinFragment.INNER_JOIN,
JoinType.INNER_JOIN,
persister.getElementColumnNames(collectionName) );
}
catch ( MappingException me ) {

View File

@ -42,6 +42,7 @@ import org.hibernate.criterion.NaturalIdentifier;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Projection;
import org.hibernate.engine.spi.SessionImplementor;
import org.hibernate.sql.JoinType;
import org.hibernate.transform.ResultTransformer;
import org.hibernate.internal.util.StringHelper;
@ -194,39 +195,66 @@ public class CriteriaImpl implements Criteria, Serializable {
}
public Criteria createAlias(String associationPath, String alias) {
return createAlias( associationPath, alias, INNER_JOIN );
return createAlias( associationPath, alias, JoinType.INNER_JOIN );
}
public Criteria createAlias(String associationPath, String alias, int joinType) {
public Criteria createAlias(String associationPath, String alias, JoinType joinType) {
new Subcriteria( this, associationPath, alias, joinType );
return this;
}
public Criteria createAlias(String associationPath, String alias, int joinType, Criterion withClause) {
@Override
public Criteria createAlias(String associationPath, String alias, int joinType) throws HibernateException {
return createAlias( associationPath, alias, JoinType.parse( joinType ) );
}
public Criteria createAlias(String associationPath, String alias, JoinType joinType, Criterion withClause) {
new Subcriteria( this, associationPath, alias, joinType, withClause );
return this;
}
public Criteria createCriteria(String associationPath) {
return createCriteria( associationPath, INNER_JOIN );
@Override
public Criteria createAlias(String associationPath, String alias, int joinType, Criterion withClause)
throws HibernateException {
return createAlias( associationPath, alias, JoinType.parse( joinType ), withClause );
}
public Criteria createCriteria(String associationPath, int joinType) {
public Criteria createCriteria(String associationPath) {
return createCriteria( associationPath, JoinType.INNER_JOIN );
}
public Criteria createCriteria(String associationPath, JoinType joinType) {
return new Subcriteria( this, associationPath, joinType );
}
public Criteria createCriteria(String associationPath, String alias) {
return createCriteria( associationPath, alias, INNER_JOIN );
@Override
public Criteria createCriteria(String associationPath, int joinType) throws HibernateException {
return createCriteria(associationPath, JoinType.parse( joinType ));
}
public Criteria createCriteria(String associationPath, String alias, int joinType) {
public Criteria createCriteria(String associationPath, String alias) {
return createCriteria( associationPath, alias, JoinType.INNER_JOIN );
}
public Criteria createCriteria(String associationPath, String alias, JoinType joinType) {
return new Subcriteria( this, associationPath, alias, joinType );
}
public Criteria createCriteria(String associationPath, String alias, int joinType, Criterion withClause) {
@Override
public Criteria createCriteria(String associationPath, String alias, int joinType) throws HibernateException {
return createCriteria( associationPath, alias, JoinType.parse( joinType ) );
}
public Criteria createCriteria(String associationPath, String alias, JoinType joinType, Criterion withClause) {
return new Subcriteria( this, associationPath, alias, joinType, withClause );
}
@Override
public Criteria createCriteria(String associationPath, String alias, int joinType, Criterion withClause)
throws HibernateException {
return createCriteria( associationPath, alias, JoinType.parse( joinType ), withClause );
}
public ResultTransformer getResultTransformer() {
return resultTransformer;
}
@ -412,13 +440,13 @@ public class CriteriaImpl implements Criteria, Serializable {
private String path;
private Criteria parent;
private LockMode lockMode;
private int joinType;
private JoinType joinType = JoinType.INNER_JOIN;
private Criterion withClause;
private boolean hasRestriction;
// Constructors ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
private Subcriteria(Criteria parent, String path, String alias, int joinType, Criterion withClause) {
private Subcriteria(Criteria parent, String path, String alias, JoinType joinType, Criterion withClause) {
this.alias = alias;
this.path = path;
this.parent = parent;
@ -428,11 +456,11 @@ public class CriteriaImpl implements Criteria, Serializable {
CriteriaImpl.this.subcriteriaList.add( this );
}
private Subcriteria(Criteria parent, String path, String alias, int joinType) {
private Subcriteria(Criteria parent, String path, String alias, JoinType joinType) {
this( parent, path, alias, joinType, null );
}
private Subcriteria(Criteria parent, String path, int joinType) {
private Subcriteria(Criteria parent, String path, JoinType joinType) {
this( parent, path, null, joinType );
}
@ -471,7 +499,7 @@ public class CriteriaImpl implements Criteria, Serializable {
return this;
}
public int getJoinType() {
public JoinType getJoinType() {
return joinType;
}
@ -497,39 +525,66 @@ public class CriteriaImpl implements Criteria, Serializable {
}
public Criteria createAlias(String associationPath, String alias) {
return createAlias( associationPath, alias, INNER_JOIN );
return createAlias( associationPath, alias, JoinType.INNER_JOIN );
}
public Criteria createAlias(String associationPath, String alias, int joinType) throws HibernateException {
public Criteria createAlias(String associationPath, String alias, JoinType joinType) throws HibernateException {
new Subcriteria( this, associationPath, alias, joinType );
return this;
}
public Criteria createAlias(String associationPath, String alias, int joinType, Criterion withClause) throws HibernateException {
@Override
public Criteria createAlias(String associationPath, String alias, int joinType) throws HibernateException {
return createAlias( associationPath, alias, JoinType.parse( joinType ) );
}
public Criteria createAlias(String associationPath, String alias, JoinType joinType, Criterion withClause) throws HibernateException {
new Subcriteria( this, associationPath, alias, joinType, withClause );
return this;
}
public Criteria createCriteria(String associationPath) {
return createCriteria( associationPath, INNER_JOIN );
@Override
public Criteria createAlias(String associationPath, String alias, int joinType, Criterion withClause)
throws HibernateException {
return createAlias( associationPath, alias, JoinType.parse( joinType ), withClause );
}
public Criteria createCriteria(String associationPath, int joinType) throws HibernateException {
public Criteria createCriteria(String associationPath) {
return createCriteria( associationPath, JoinType.INNER_JOIN );
}
public Criteria createCriteria(String associationPath, JoinType joinType) throws HibernateException {
return new Subcriteria( Subcriteria.this, associationPath, joinType );
}
public Criteria createCriteria(String associationPath, String alias) {
return createCriteria( associationPath, alias, INNER_JOIN );
@Override
public Criteria createCriteria(String associationPath, int joinType) throws HibernateException {
return createCriteria( associationPath, JoinType.parse( joinType ) );
}
public Criteria createCriteria(String associationPath, String alias, int joinType) throws HibernateException {
public Criteria createCriteria(String associationPath, String alias) {
return createCriteria( associationPath, alias, JoinType.INNER_JOIN );
}
public Criteria createCriteria(String associationPath, String alias, JoinType joinType) throws HibernateException {
return new Subcriteria( Subcriteria.this, associationPath, alias, joinType );
}
public Criteria createCriteria(String associationPath, String alias, int joinType, Criterion withClause) throws HibernateException {
@Override
public Criteria createCriteria(String associationPath, String alias, int joinType) throws HibernateException {
return createCriteria( associationPath, alias, JoinType.parse( joinType ) );
}
public Criteria createCriteria(String associationPath, String alias, JoinType joinType, Criterion withClause) throws HibernateException {
return new Subcriteria( this, associationPath, alias, joinType, withClause );
}
@Override
public Criteria createCriteria(String associationPath, String alias, int joinType, Criterion withClause)
throws HibernateException {
return createCriteria( associationPath, alias, JoinType.parse( joinType ), withClause );
}
public boolean isReadOnly() {
return CriteriaImpl.this.isReadOnly();
}

View File

@ -678,6 +678,7 @@ public final class SessionFactoryImpl
Map errors = new HashMap();
// Check named HQL queries
if(LOG.isDebugEnabled())
LOG.debugf("Checking %s named HQL queries", namedQueries.size());
Iterator itr = namedQueries.entrySet().iterator();
while ( itr.hasNext() ) {
@ -697,7 +698,7 @@ public final class SessionFactoryImpl
errors.put( queryName, e );
}
}
if(LOG.isDebugEnabled())
LOG.debugf("Checking %s named SQL queries", namedSqlQueries.size());
itr = namedSqlQueries.entrySet().iterator();
while ( itr.hasNext() ) {

View File

@ -1983,8 +1983,8 @@ public final class SessionImpl
entityMode = EntityMode.parse( ( String ) ois.readObject() );
autoClear = ois.readBoolean();
autoJoinTransactions = ois.readBoolean();
flushMode = FlushMode.parse( ( String ) ois.readObject() );
cacheMode = CacheMode.parse( ( String ) ois.readObject() );
flushMode = FlushMode.valueOf( ( String ) ois.readObject() );
cacheMode = CacheMode.valueOf( ( String ) ois.readObject() );
flushBeforeCompletionEnabled = ois.readBoolean();
autoCloseSessionEnabled = ois.readBoolean();
interceptor = ( Interceptor ) ois.readObject();
@ -2043,7 +2043,7 @@ public final class SessionImpl
oos.writeBoolean( autoClear );
oos.writeBoolean( autoJoinTransactions );
oos.writeObject( flushMode.toString() );
oos.writeObject( cacheMode.toString() );
oos.writeObject( cacheMode.name() );
oos.writeBoolean( flushBeforeCompletionEnabled );
oos.writeBoolean( autoCloseSessionEnabled );
// we need to writeObject() on this since interceptor is user defined

View File

@ -39,6 +39,7 @@ import org.hibernate.engine.spi.LoadQueryInfluencers;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.internal.util.StringHelper;
import org.hibernate.internal.util.collections.ArrayHelper;
import org.hibernate.mapping.Join;
import org.hibernate.persister.collection.CollectionPersister;
import org.hibernate.persister.collection.QueryableCollection;
import org.hibernate.persister.entity.EntityPersister;
@ -49,6 +50,7 @@ import org.hibernate.sql.ConditionFragment;
import org.hibernate.sql.DisjunctionFragment;
import org.hibernate.sql.InFragment;
import org.hibernate.sql.JoinFragment;
import org.hibernate.sql.JoinType;
import org.hibernate.type.AssociationType;
import org.hibernate.type.CompositeType;
import org.hibernate.type.EntityType;
@ -192,8 +194,8 @@ public class JoinWalker {
final String alias,
final PropertyPath path,
int currentDepth,
final int joinType) throws MappingException {
if ( joinType >= 0 ) {
final JoinType joinType) throws MappingException {
if ( joinType != JoinType.NONE ) {
addAssociationToJoinTree(
type,
aliasedLhsColumns,
@ -223,7 +225,7 @@ public class JoinWalker {
final String alias,
final PropertyPath path,
final int currentDepth,
final int joinType) throws MappingException {
final JoinType joinType) throws MappingException {
Joinable joinable = type.getAssociatedJoinable( getFactory() );
@ -329,7 +331,7 @@ public class JoinWalker {
// many-to-many collection itself. Here, it is alright to use
// an inner join...
boolean useInnerJoin = currentDepth == 0;
final int joinType = getJoinType(
final JoinType joinType = getJoinType(
associationType,
persister.getFetchMode(),
path,
@ -394,7 +396,7 @@ public class JoinWalker {
String lhsTable = JoinHelper.getLHSTableName(associationType, propertyNumber, persister);
PropertyPath subPath = path.append( persister.getSubclassPropertyName(propertyNumber) );
int joinType = getJoinType(
JoinType joinType = getJoinType(
persister,
subPath,
propertyNumber,
@ -430,11 +432,11 @@ public class JoinWalker {
* @param lhsColumns The owner join columns
* @param nullable Is the association nullable.
* @param currentDepth Current join depth
* @return type of join to use ({@link JoinFragment#INNER_JOIN},
* {@link JoinFragment#LEFT_OUTER_JOIN}, or -1 to indicate no joining.
* @return type of join to use ({@link org.hibernate.sql.JoinType#INNER_JOIN},
* {@link org.hibernate.sql.JoinType#LEFT_OUTER_JOIN}, or -1 to indicate no joining.
* @throws MappingException ??
*/
protected int getJoinType(
protected JoinType getJoinType(
OuterJoinLoadable persister,
final PropertyPath path,
int propertyNumber,
@ -469,11 +471,11 @@ public class JoinWalker {
* @param nullable Is the association nullable.
* @param currentDepth Current join depth
* @param cascadeStyle The metadata-defined cascade style.
* @return type of join to use ({@link JoinFragment#INNER_JOIN},
* {@link JoinFragment#LEFT_OUTER_JOIN}, or -1 to indicate no joining.
* @return type of join to use ({@link org.hibernate.sql.JoinType#INNER_JOIN},
* {@link org.hibernate.sql.JoinType#LEFT_OUTER_JOIN}, or -1 to indicate no joining.
* @throws MappingException ??
*/
protected int getJoinType(
protected JoinType getJoinType(
AssociationType associationType,
FetchMode config,
PropertyPath path,
@ -483,13 +485,13 @@ public class JoinWalker {
int currentDepth,
CascadeStyle cascadeStyle) throws MappingException {
if ( !isJoinedFetchEnabled( associationType, config, cascadeStyle ) ) {
return -1;
return JoinType.NONE;
}
if ( isTooDeep(currentDepth) || ( associationType.isCollectionType() && isTooManyCollections() ) ) {
return -1;
return JoinType.NONE;
}
if ( isDuplicateAssociation( lhsTable, lhsColumns, associationType ) ) {
return -1;
return JoinType.NONE;
}
return getJoinType( nullable, currentDepth );
}
@ -576,7 +578,7 @@ public class JoinWalker {
final PropertyPath subPath = path.append( propertyNames[i] );
final boolean[] propertyNullability = componentType.getPropertyNullability();
final int joinType = getJoinType(
final JoinType joinType = getJoinType(
persister,
subPath,
propertyNumber,
@ -642,7 +644,7 @@ public class JoinWalker {
final PropertyPath subPath = path.append( propertyNames[i] );
final boolean[] propertyNullability = compositeType.getPropertyNullability();
final int joinType = getJoinType(
final JoinType joinType = getJoinType(
associationType,
compositeType.getFetchMode(i),
subPath,
@ -681,15 +683,15 @@ public class JoinWalker {
* Use an inner join if it is a non-null association and this
* is the "first" join in a series
*/
protected int getJoinType(boolean nullable, int currentDepth) {
protected JoinType getJoinType(boolean nullable, int currentDepth) {
//TODO: this is too conservative; if all preceding joins were
// also inner joins, we could use an inner join here
//
// IMPL NOTE : currentDepth might be less-than zero if this is the
// root of a many-to-many collection initializer
return !nullable && currentDepth <= 0
? JoinFragment.INNER_JOIN
: JoinFragment.LEFT_OUTER_JOIN;
? JoinType.INNER_JOIN
: JoinType.LEFT_OUTER_JOIN;
}
protected boolean isTooDeep(int currentDepth) {
@ -795,18 +797,18 @@ public class JoinWalker {
* Should we join this association?
*/
protected boolean isJoinable(
final int joinType,
final JoinType joinType,
final Set visitedAssociationKeys,
final String lhsTable,
final String[] lhsColumnNames,
final AssociationType type,
final int depth) {
if ( joinType < 0 ) {
if ( joinType == JoinType.NONE ) {
return false;
}
if ( joinType == JoinFragment.INNER_JOIN ) {
if ( joinType == JoinType.INNER_JOIN ) {
return true;
}
@ -882,7 +884,7 @@ public class JoinWalker {
Iterator iter = associations.iterator();
while ( iter.hasNext() ) {
OuterJoinableAssociation oj = (OuterJoinableAssociation) iter.next();
if ( oj.getJoinType()==JoinFragment.LEFT_OUTER_JOIN &&
if ( oj.getJoinType()==JoinType.LEFT_OUTER_JOIN &&
oj.getJoinable().isCollection() &&
! oj.hasRestriction() ) {
result++;
@ -901,7 +903,7 @@ public class JoinWalker {
OuterJoinableAssociation last = null;
while ( iter.hasNext() ) {
OuterJoinableAssociation oj = (OuterJoinableAssociation) iter.next();
if ( oj.getJoinType() == JoinFragment.LEFT_OUTER_JOIN ) { // why does this matter?
if ( oj.getJoinType() == JoinType.LEFT_OUTER_JOIN ) { // why does this matter?
if ( oj.getJoinable().isCollection() ) {
final QueryableCollection queryableCollection = (QueryableCollection) oj.getJoinable();
if ( queryableCollection.hasOrdering() ) {
@ -1019,7 +1021,7 @@ public class JoinWalker {
else {
QueryableCollection collPersister = (QueryableCollection) oj.getJoinable();
if ( oj.getJoinType()==JoinFragment.LEFT_OUTER_JOIN && ! oj.hasRestriction() ) {
if ( oj.getJoinType()==JoinType.LEFT_OUTER_JOIN && ! oj.hasRestriction() ) {
//it must be a collection fetch
collectionPersisters[j] = collPersister;
collectionOwners[j] = oj.getOwner(associations);
@ -1072,13 +1074,13 @@ public class JoinWalker {
join.getRHSAlias(),
entitySuffix,
collectionSuffix,
join.getJoinType()==JoinFragment.LEFT_OUTER_JOIN
join.getJoinType()==JoinType.LEFT_OUTER_JOIN
);
if (selectFragment.trim().length() > 0) {
buf.append(", ").append(selectFragment);
}
if ( joinable.consumesEntityAlias() ) entityAliasCount++;
if ( joinable.consumesCollectionAlias() && join.getJoinType()==JoinFragment.LEFT_OUTER_JOIN ) collectionAliasCount++;
if ( joinable.consumesCollectionAlias() && join.getJoinType()==JoinType.LEFT_OUTER_JOIN ) collectionAliasCount++;
}
return buf.toString();
}

View File

@ -30,6 +30,7 @@ import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.persister.collection.QueryableCollection;
import org.hibernate.persister.entity.Joinable;
import org.hibernate.sql.JoinFragment;
import org.hibernate.sql.JoinType;
import org.hibernate.type.AssociationType;
import org.hibernate.type.EntityType;
import org.hibernate.internal.util.collections.CollectionHelper;
@ -48,7 +49,7 @@ public final class OuterJoinableAssociation {
private final String[] lhsColumns; // belong to other persister
private final String rhsAlias;
private final String[] rhsColumns;
private final int joinType;
private final JoinType joinType;
private final String on;
private final Map enabledFilters;
private final boolean hasRestriction;
@ -63,7 +64,7 @@ public final class OuterJoinableAssociation {
null,
null,
alias,
JoinFragment.LEFT_OUTER_JOIN,
JoinType.LEFT_OUTER_JOIN,
null,
false,
factory,
@ -77,7 +78,7 @@ public final class OuterJoinableAssociation {
String lhsAlias,
String[] lhsColumns,
String rhsAlias,
int joinType,
JoinType joinType,
String withClause,
boolean hasRestriction,
SessionFactoryImplementor factory,
@ -100,7 +101,7 @@ public final class OuterJoinableAssociation {
return propertyPath;
}
public int getJoinType() {
public JoinType getJoinType() {
return joinType;
}

View File

@ -38,6 +38,7 @@ import org.hibernate.loader.PropertyPath;
import org.hibernate.persister.collection.QueryableCollection;
import org.hibernate.persister.entity.OuterJoinLoadable;
import org.hibernate.sql.JoinFragment;
import org.hibernate.sql.JoinType;
import org.hibernate.sql.Select;
import org.hibernate.type.AssociationType;
import org.hibernate.internal.util.StringHelper;
@ -138,7 +139,7 @@ public class BasicCollectionJoinWalker extends CollectionJoinWalker {
sql = select.toStatementString();
}
protected int getJoinType(
protected JoinType getJoinType(
OuterJoinLoadable persister,
PropertyPath path,
int propertyNumber,
@ -149,7 +150,7 @@ public class BasicCollectionJoinWalker extends CollectionJoinWalker {
String[] lhsColumns,
boolean nullable,
int currentDepth) throws MappingException {
int joinType = super.getJoinType(
JoinType joinType = super.getJoinType(
persister,
path,
propertyNumber,
@ -162,8 +163,8 @@ public class BasicCollectionJoinWalker extends CollectionJoinWalker {
currentDepth
);
//we can use an inner join for the many-to-many
if ( joinType==JoinFragment.LEFT_OUTER_JOIN && path.isRoot() ) {
joinType=JoinFragment.INNER_JOIN;
if ( joinType==JoinType.LEFT_OUTER_JOIN && path.isRoot() ) {
joinType=JoinType.INNER_JOIN;
}
return joinType;
}

View File

@ -41,6 +41,7 @@ import org.hibernate.persister.entity.Joinable;
import org.hibernate.persister.entity.OuterJoinLoadable;
import org.hibernate.persister.entity.Queryable;
import org.hibernate.persister.collection.CollectionPersister;
import org.hibernate.sql.JoinType;
import org.hibernate.type.AssociationType;
import org.hibernate.type.Type;
import org.hibernate.internal.util.collections.ArrayHelper;
@ -129,7 +130,7 @@ public class CriteriaJoinWalker extends AbstractEntityJoinWalker {
}
}
protected int getJoinType(
protected JoinType getJoinType(
OuterJoinLoadable persister,
final PropertyPath path,
int propertyNumber,
@ -145,7 +146,7 @@ public class CriteriaJoinWalker extends AbstractEntityJoinWalker {
}
else {
if ( translator.hasProjection() ) {
return -1;
return JoinType.NONE;
}
else {
FetchMode fetchMode = translator.getRootCriteria().getFetchMode( path.getFullPath() );
@ -174,14 +175,14 @@ public class CriteriaJoinWalker extends AbstractEntityJoinWalker {
return getJoinType( nullable, currentDepth );
}
else {
return -1;
return JoinType.NONE;
}
}
}
}
}
protected int getJoinType(
protected JoinType getJoinType(
AssociationType associationType,
FetchMode config,
PropertyPath path,

View File

@ -54,6 +54,7 @@ import org.hibernate.internal.util.collections.ArrayHelper;
import org.hibernate.persister.entity.Loadable;
import org.hibernate.persister.entity.PropertyMapping;
import org.hibernate.persister.entity.Queryable;
import org.hibernate.sql.JoinType;
import org.hibernate.type.AssociationType;
import org.hibernate.type.CollectionType;
import org.hibernate.type.StringRepresentableType;
@ -79,7 +80,7 @@ public class CriteriaQueryTranslator implements CriteriaQuery {
private final Map criteriaSQLAliasMap = new HashMap();
private final Map aliasCriteriaMap = new HashMap();
private final Map associationPathCriteriaMap = new LinkedHashMap();
private final Map associationPathJoinTypesMap = new LinkedHashMap();
private final Map<String,JoinType> associationPathJoinTypesMap = new LinkedHashMap<String,JoinType>();
private final Map withClauseMap = new HashMap();
private final SessionFactoryImplementor sessionFactory;
@ -127,9 +128,9 @@ public class CriteriaQueryTranslator implements CriteriaQuery {
return associationPathCriteriaMap.containsKey( path );
}
public int getJoinType(String path) {
Integer result = ( Integer ) associationPathJoinTypesMap.get( path );
return ( result == null ? Criteria.INNER_JOIN : result.intValue() );
public JoinType getJoinType(String path) {
JoinType result = associationPathJoinTypesMap.get( path );
return ( result == null ? JoinType.INNER_JOIN : result );
}
public Criteria getCriteria(String path) {
@ -169,7 +170,7 @@ public class CriteriaQueryTranslator implements CriteriaQuery {
if ( old != null ) {
throw new QueryException( "duplicate association path: " + wholeAssociationPath );
}
int joinType = crit.getJoinType();
JoinType joinType = crit.getJoinType();
old = associationPathJoinTypesMap.put( wholeAssociationPath, joinType );
if ( old != null ) {
// TODO : not so sure this is needed...

View File

@ -86,7 +86,7 @@ public class SQLQueryParser {
// don't get'em'all we throw an exception! Way better than trial and error ;)
private String substituteBrackets(String sqlQuery) throws QueryException {
StringBuffer result = new StringBuffer( sqlQuery.length() + 20 );
StringBuilder result = new StringBuilder( sqlQuery.length() + 20 );
int left, right;
// replace {....} with corresponding column aliases
@ -294,7 +294,7 @@ public class SQLQueryParser {
}
public static class ParameterSubstitutionRecognizer implements ParameterParser.Recognizer {
StringBuffer result = new StringBuffer();
StringBuilder result = new StringBuilder();
Map namedParameterBindPoints = new HashMap();
int parameterCount = 0;

View File

@ -38,6 +38,7 @@ import org.hibernate.loader.PropertyPath;
import org.hibernate.persister.collection.QueryableCollection;
import org.hibernate.persister.entity.EntityPersister;
import org.hibernate.persister.entity.OuterJoinLoadable;
import org.hibernate.sql.JoinType;
import org.hibernate.type.AssociationType;
import org.hibernate.type.CompositeType;
import org.hibernate.type.EntityType;
@ -93,7 +94,7 @@ public class EntityJoinWalker extends AbstractEntityJoinWalker {
this.compositeKeyManyToOneTargetIndices = callback.resolve();
}
protected int getJoinType(
protected JoinType getJoinType(
OuterJoinLoadable persister,
PropertyPath path,
int propertyNumber,
@ -108,18 +109,18 @@ public class EntityJoinWalker extends AbstractEntityJoinWalker {
// fetch profiles.
// TODO : how to best handle criteria queries?
if ( lockOptions.getLockMode().greaterThan( LockMode.READ ) ) {
return -1;
return JoinType.NONE;
}
if ( isTooDeep( currentDepth )
|| ( associationType.isCollectionType() && isTooManyCollections() ) ) {
return -1;
return JoinType.NONE;
}
if ( !isJoinedFetchEnabledInMapping( metadataFetchMode, associationType )
&& !isJoinFetchEnabledByProfile( persister, path, propertyNumber ) ) {
return -1;
return JoinType.NONE;
}
if ( isDuplicateAssociation( lhsTable, lhsColumns, associationType ) ) {
return -1;
return JoinType.NONE;
}
return getJoinType( nullable, currentDepth );
}

View File

@ -98,6 +98,7 @@ import org.hibernate.sql.Alias;
import org.hibernate.sql.Delete;
import org.hibernate.sql.Insert;
import org.hibernate.sql.JoinFragment;
import org.hibernate.sql.JoinType;
import org.hibernate.sql.Select;
import org.hibernate.sql.SelectFragment;
import org.hibernate.sql.SimpleSelect;
@ -2999,8 +3000,8 @@ public abstract class AbstractEntityPersister
idCols,
getSubclassTableKeyColumns( j ),
innerJoin && isClassOrSuperclassTable( j ) && !isInverseTable( j ) && !isNullableTable( j ) ?
JoinFragment.INNER_JOIN : //we can inner join to superclass tables (the row MUST be there)
JoinFragment.LEFT_OUTER_JOIN //we can never inner join to subclass tables
JoinType.INNER_JOIN : //we can inner join to superclass tables (the row MUST be there)
JoinType.LEFT_OUTER_JOIN //we can never inner join to subclass tables
);
}
}
@ -3017,8 +3018,8 @@ public abstract class AbstractEntityPersister
keyCols,
getSubclassTableKeyColumns( j ),
isInverseSubclassTable( j ) || isNullableSubclassTable( j ) ?
JoinFragment.LEFT_OUTER_JOIN :
JoinFragment.INNER_JOIN );
JoinType.LEFT_OUTER_JOIN :
JoinType.INNER_JOIN );
}
return jf;
}

View File

@ -35,11 +35,11 @@ public class ANSIJoinFragment extends JoinFragment {
private StringBuffer buffer = new StringBuffer();
private StringBuffer conditions = new StringBuffer();
public void addJoin(String tableName, String alias, String[] fkColumns, String[] pkColumns, int joinType) {
public void addJoin(String tableName, String alias, String[] fkColumns, String[] pkColumns, JoinType joinType) {
addJoin(tableName, alias, fkColumns, pkColumns, joinType, null);
}
public void addJoin(String tableName, String alias, String[] fkColumns, String[] pkColumns, int joinType, String on) {
public void addJoin(String tableName, String alias, String[] fkColumns, String[] pkColumns, JoinType joinType, String on) {
String joinString;
switch (joinType) {
case INNER_JOIN:

View File

@ -22,7 +22,7 @@
* Boston, MA 02110-1301 USA
*
*/
package org.hibernate.sql;
package org.hibernate.sql;
import org.hibernate.AssertionFailure;
/**
@ -34,8 +34,8 @@ import org.hibernate.AssertionFailure;
*/
public class CacheJoinFragment extends ANSIJoinFragment {
public void addJoin(String tableName, String alias, String[] fkColumns, String[] pkColumns, int joinType, String on) {
if ( joinType == FULL_JOIN ) {
public void addJoin(String tableName, String alias, String[] fkColumns, String[] pkColumns, JoinType joinType, String on) {
if ( joinType == JoinType.FULL_JOIN ) {
throw new AssertionFailure( "Cache does not support full outer joins" );
}
super.addJoin( tableName, alias, fkColumns, pkColumns, joinType, on );

View File

@ -33,9 +33,9 @@ import org.hibernate.internal.util.StringHelper;
*/
public abstract class JoinFragment {
public abstract void addJoin(String tableName, String alias, String[] fkColumns, String[] pkColumns, int joinType);
public abstract void addJoin(String tableName, String alias, String[] fkColumns, String[] pkColumns, JoinType joinType);
public abstract void addJoin(String tableName, String alias, String[] fkColumns, String[] pkColumns, int joinType, String on);
public abstract void addJoin(String tableName, String alias, String[] fkColumns, String[] pkColumns, JoinType joinType, String on);
public abstract void addCrossJoin(String tableName, String alias);
@ -53,11 +53,26 @@ public abstract class JoinFragment {
public abstract JoinFragment copy();
/**
* @deprecated use {@link JoinType#INNER_JOIN} instead.
*/
@Deprecated
public static final int INNER_JOIN = 0;
/**
* @deprecated use {@link JoinType#FULL_JOIN} instead.
*/
@Deprecated
public static final int FULL_JOIN = 4;
/**
* @deprecated use {@link JoinType#LEFT_OUTER_JOIN} instead.
*/
@Deprecated
public static final int LEFT_OUTER_JOIN = 1;
/**
* @deprecated use {@link JoinType#RIGHT_OUTER_JOIN} instead.
*/
@Deprecated
public static final int RIGHT_OUTER_JOIN = 2;
private boolean hasFilterCondition = false;
private boolean hasThetaJoins = false;

View File

@ -36,7 +36,7 @@ public class OracleJoinFragment extends JoinFragment {
private StringBuffer afterFrom = new StringBuffer();
private StringBuffer afterWhere = new StringBuffer();
public void addJoin(String tableName, String alias, String[] fkColumns, String[] pkColumns, int joinType) {
public void addJoin(String tableName, String alias, String[] fkColumns, String[] pkColumns, JoinType joinType) {
addCrossJoin( tableName, alias );
@ -44,12 +44,12 @@ public class OracleJoinFragment extends JoinFragment {
setHasThetaJoins( true );
afterWhere.append( " and " )
.append( fkColumns[j] );
if ( joinType == RIGHT_OUTER_JOIN || joinType == FULL_JOIN ) afterWhere.append( "(+)" );
if ( joinType == JoinType.RIGHT_OUTER_JOIN || joinType == JoinType.FULL_JOIN ) afterWhere.append( "(+)" );
afterWhere.append( '=' )
.append( alias )
.append( '.' )
.append( pkColumns[j] );
if ( joinType == LEFT_OUTER_JOIN || joinType == FULL_JOIN ) afterWhere.append( "(+)" );
if ( joinType == JoinType.LEFT_OUTER_JOIN || joinType == JoinType.FULL_JOIN ) afterWhere.append( "(+)" );
}
}
@ -103,13 +103,13 @@ public class OracleJoinFragment extends JoinFragment {
afterFrom.append( fromFragmentString );
}
public void addJoin(String tableName, String alias, String[] fkColumns, String[] pkColumns, int joinType, String on) {
public void addJoin(String tableName, String alias, String[] fkColumns, String[] pkColumns, JoinType joinType, String on) {
//arbitrary on clause ignored!!
addJoin( tableName, alias, fkColumns, pkColumns, joinType );
if ( joinType == JoinFragment.INNER_JOIN ) {
if ( joinType == JoinType.INNER_JOIN ) {
addCondition( on );
}
else if ( joinType == JoinFragment.LEFT_OUTER_JOIN ) {
else if ( joinType == JoinType.LEFT_OUTER_JOIN ) {
addLeftOuterJoinCondition( on );
}
else {

View File

@ -42,16 +42,16 @@ public class QueryJoinFragment extends JoinFragment {
this.useThetaStyleInnerJoins = useThetaStyleInnerJoins;
}
public void addJoin(String tableName, String alias, String[] fkColumns, String[] pkColumns, int joinType) {
public void addJoin(String tableName, String alias, String[] fkColumns, String[] pkColumns, JoinType joinType) {
addJoin( tableName, alias, alias, fkColumns, pkColumns, joinType, null );
}
public void addJoin(String tableName, String alias, String[] fkColumns, String[] pkColumns, int joinType, String on) {
public void addJoin(String tableName, String alias, String[] fkColumns, String[] pkColumns, JoinType joinType, String on) {
addJoin( tableName, alias, alias, fkColumns, pkColumns, joinType, on );
}
private void addJoin(String tableName, String alias, String concreteAlias, String[] fkColumns, String[] pkColumns, int joinType, String on) {
if ( !useThetaStyleInnerJoins || joinType != INNER_JOIN ) {
private void addJoin(String tableName, String alias, String concreteAlias, String[] fkColumns, String[] pkColumns, JoinType joinType, String on) {
if ( !useThetaStyleInnerJoins || joinType != JoinType.INNER_JOIN ) {
JoinFragment jf = dialect.createOuterJoinFragment();
jf.addJoin( tableName, alias, fkColumns, pkColumns, joinType, on );
addFragment( jf );

View File

@ -37,21 +37,21 @@ public class Sybase11JoinFragment extends JoinFragment {
private StringBuffer afterFrom = new StringBuffer();
private StringBuffer afterWhere = new StringBuffer();
public void addJoin(String tableName, String alias, String[] fkColumns, String[] pkColumns, int joinType) {
public void addJoin(String tableName, String alias, String[] fkColumns, String[] pkColumns, JoinType joinType) {
addCrossJoin(tableName, alias);
for ( int j=0; j<fkColumns.length; j++) {
//full joins are not supported.. yet!
if (joinType==JoinFragment.FULL_JOIN ) throw new UnsupportedOperationException();
if (joinType==JoinType.FULL_JOIN ) throw new UnsupportedOperationException();
afterWhere.append(" and ")
.append( fkColumns[j] )
.append( " " );
if (joinType==LEFT_OUTER_JOIN ) afterWhere.append("*");
if (joinType==JoinType.LEFT_OUTER_JOIN ) afterWhere.append("*");
afterWhere.append('=');
if (joinType==RIGHT_OUTER_JOIN ) afterWhere.append("*");
if (joinType==JoinType.RIGHT_OUTER_JOIN ) afterWhere.append("*");
afterWhere.append (" ")
.append(alias)
@ -113,7 +113,7 @@ public class Sybase11JoinFragment extends JoinFragment {
}
public void addJoin(String tableName, String alias, String[] fkColumns, String[] pkColumns, int joinType, String on) {
public void addJoin(String tableName, String alias, String[] fkColumns, String[] pkColumns, JoinType joinType, String on) {
addJoin(tableName, alias, fkColumns, pkColumns, joinType);
addCondition(on);
}

View File

@ -66,7 +66,7 @@ public abstract class ConfigurationHelper {
return null;
}
flushMode = flushMode.toUpperCase();
return FlushMode.parse( flushMode );
return FlushMode.valueOf( flushMode );
}
private static FlushMode getFlushMode(FlushModeType flushMode) {
@ -103,7 +103,7 @@ public abstract class ConfigurationHelper {
return (CacheMode) value;
}
else {
return CacheMode.parse( (String) value );
return CacheMode.valueOf( (String) value );
}
}
}

View File

@ -98,7 +98,7 @@ public class LockModeTypeHelper {
}
else if ( String.class.isInstance( value ) ) {
// first try LockMode name
LockMode lockMode = LockMode.parse( (String) value );
LockMode lockMode = LockMode.valueOf( (String) value );
if ( lockMode == null ) {
try {
lockMode = getLockMode( LockModeType.valueOf( (String) value ) );