From 660a7cbef1eadfd1c2a6da5b853fa752e9cc26af Mon Sep 17 00:00:00 2001 From: Strong Liu Date: Thu, 4 Aug 2011 00:04:43 +0800 Subject: [PATCH] simple code format --- .../java/org/hibernate/dialect/Dialect.java | 87 ++++++++----------- .../hibernate/engine/spi/IdentifierValue.java | 4 +- .../annotations/EntityHierarchyBuilder.java | 7 +- 3 files changed, 40 insertions(+), 58 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/dialect/Dialect.java b/hibernate-core/src/main/java/org/hibernate/dialect/Dialect.java index 67374c124e..b8a0dce080 100644 --- a/hibernate-core/src/main/java/org/hibernate/dialect/Dialect.java +++ b/hibernate-core/src/main/java/org/hibernate/dialect/Dialect.java @@ -1101,22 +1101,20 @@ public abstract class Dialect { * @since 3.2 */ public LockingStrategy getLockingStrategy(Lockable lockable, LockMode lockMode) { - if ( lockMode==LockMode.PESSIMISTIC_FORCE_INCREMENT) { - return new PessimisticForceIncrementLockingStrategy( lockable, lockMode); - } - else if ( lockMode==LockMode.PESSIMISTIC_WRITE) { - return new PessimisticWriteSelectLockingStrategy( lockable, lockMode); - } - else if ( lockMode==LockMode.PESSIMISTIC_READ) { - return new PessimisticReadSelectLockingStrategy( lockable, lockMode); - } - else if ( lockMode==LockMode.OPTIMISTIC) { - return new OptimisticLockingStrategy( lockable, lockMode); - } - else if ( lockMode==LockMode.OPTIMISTIC_FORCE_INCREMENT) { - return new OptimisticForceIncrementLockingStrategy( lockable, lockMode); - } - return new SelectLockingStrategy( lockable, lockMode ); + switch ( lockMode ) { + case PESSIMISTIC_FORCE_INCREMENT: + return new PessimisticForceIncrementLockingStrategy( lockable, lockMode ); + case PESSIMISTIC_WRITE: + return new PessimisticWriteSelectLockingStrategy( lockable, lockMode ); + case PESSIMISTIC_READ: + return new PessimisticReadSelectLockingStrategy( lockable, lockMode ); + case OPTIMISTIC: + return new OptimisticLockingStrategy( lockable, lockMode ); + case OPTIMISTIC_FORCE_INCREMENT: + return new OptimisticForceIncrementLockingStrategy( lockable, lockMode ); + default: + return new SelectLockingStrategy( lockable, lockMode ); + } } /** @@ -1126,27 +1124,27 @@ public abstract class Dialect { * @return The appropriate for update fragment. */ public String getForUpdateString(LockOptions lockOptions) { - LockMode lockMode = lockOptions.getLockMode(); - if ( lockMode==LockMode.UPGRADE) { - return getForUpdateString(); - } - else if( lockMode==LockMode.PESSIMISTIC_READ ) { - return getReadLockString(lockOptions.getTimeOut()); - } - else if( lockMode==LockMode.PESSIMISTIC_WRITE ) { - return getWriteLockString(lockOptions.getTimeOut()); - } - else if ( lockMode==LockMode.UPGRADE_NOWAIT ) { - return getForUpdateNowaitString(); - } - else if ( lockMode==LockMode.FORCE || lockMode==LockMode.PESSIMISTIC_FORCE_INCREMENT) { - return getForUpdateNowaitString(); - } - else { - return ""; - } + LockMode lockMode = lockOptions.getLockMode(); + return getForUpdateString( lockMode, lockOptions.getTimeOut() ); } + private String getForUpdateString(LockMode lockMode, int timeout){ + switch ( lockMode ) { + case UPGRADE: + return getForUpdateString(); + case PESSIMISTIC_READ: + return getReadLockString( timeout ); + case PESSIMISTIC_WRITE: + return getWriteLockString( timeout ); + case UPGRADE_NOWAIT: + case FORCE: + case PESSIMISTIC_FORCE_INCREMENT: + return getForUpdateNowaitString(); + default: + return ""; + } + } + /** * Given a lock mode, determine the appropriate for update fragment to use. * @@ -1154,24 +1152,7 @@ public abstract class Dialect { * @return The appropriate for update fragment. */ public String getForUpdateString(LockMode lockMode) { - if ( lockMode==LockMode.UPGRADE ) { - return getForUpdateString(); - } - else if( lockMode==LockMode.PESSIMISTIC_READ ) { - return getReadLockString(LockOptions.WAIT_FOREVER); - } - else if( lockMode==LockMode.PESSIMISTIC_WRITE ) { - return getWriteLockString(LockOptions.WAIT_FOREVER); - } - else if ( lockMode==LockMode.UPGRADE_NOWAIT ) { - return getForUpdateNowaitString(); - } - else if ( lockMode==LockMode.FORCE || lockMode==LockMode.PESSIMISTIC_FORCE_INCREMENT) { - return getForUpdateNowaitString(); - } - else { - return ""; - } + return getForUpdateString( lockMode, LockOptions.WAIT_FOREVER ); } /** diff --git a/hibernate-core/src/main/java/org/hibernate/engine/spi/IdentifierValue.java b/hibernate-core/src/main/java/org/hibernate/engine/spi/IdentifierValue.java index 4113f7c240..4345af2845 100755 --- a/hibernate-core/src/main/java/org/hibernate/engine/spi/IdentifierValue.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/spi/IdentifierValue.java @@ -89,7 +89,7 @@ public class IdentifierValue implements UnsavedValueStrategy { @Override public final Boolean isUnsaved(Object id) { LOG.trace("ID unsaved-value strategy NULL"); - return id==null ? Boolean.TRUE : Boolean.FALSE; + return id==null; } @Override public Serializable getDefaultValue(Object currentValue) { @@ -137,7 +137,7 @@ public class IdentifierValue implements UnsavedValueStrategy { */ public Boolean isUnsaved(Object id) { LOG.trace("ID unsaved-value: " + value); - return id==null || id.equals(value) ? Boolean.TRUE : Boolean.FALSE; + return id==null || id.equals(value); } public Serializable getDefaultValue(Object currentValue) { diff --git a/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/EntityHierarchyBuilder.java b/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/EntityHierarchyBuilder.java index 38a2611847..c909bff76d 100644 --- a/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/EntityHierarchyBuilder.java +++ b/hibernate-core/src/main/java/org/hibernate/metamodel/source/annotations/EntityHierarchyBuilder.java @@ -39,6 +39,7 @@ import org.jboss.jandex.Index; import org.jboss.jandex.MethodInfo; import org.hibernate.AnnotationException; +import org.hibernate.internal.util.collections.CollectionHelper; import org.hibernate.metamodel.binding.InheritanceType; import org.hibernate.metamodel.source.annotations.entity.EntityClass; import org.hibernate.metamodel.source.annotations.entity.RootEntitySourceImpl; @@ -158,7 +159,7 @@ public class EntityHierarchyBuilder { /** * Finds the root entity starting at the entity given by {@code info}. The root entity is not the highest superclass - * in a java type sense, but the highest superclass which is also an entity (annotated w/ {@code @Index}. + * in a java type sense, but the highest superclass which is also an entity (annotated w/ {@code @Entity}. * * @param index the annotation repository * @param info the class info representing an entity @@ -329,10 +330,10 @@ public class EntityHierarchyBuilder { List idAnnotations = info.annotations().get( JPADotNames.ID ); List embeddedIdAnnotations = info.annotations().get( JPADotNames.EMBEDDED_ID ); - if ( embeddedIdAnnotations != null && !embeddedIdAnnotations.isEmpty() ) { + if ( CollectionHelper.isNotEmpty( embeddedIdAnnotations ) ) { accessTypeByEmbeddedIdPlacement = determineAccessTypeByIdPlacement( embeddedIdAnnotations ); } - if ( idAnnotations != null && !idAnnotations.isEmpty() ) { + if ( CollectionHelper.isNotEmpty( idAnnotations ) ) { accessTypeByIdPlacement = determineAccessTypeByIdPlacement( idAnnotations ); } }