From 71adfabca89cff01e758137078a0f479e339345f Mon Sep 17 00:00:00 2001 From: Strong Liu Date: Mon, 15 Aug 2011 14:55:06 +0800 Subject: [PATCH] simple code refact --- .../hibernate/engine/spi/VersionValue.java | 8 +++---- .../id/IdentifierGeneratorHelper.java | 2 +- .../org/hibernate/proxy/LazyInitializer.java | 6 ++--- .../source/annotations/entity/MapsIdTest.java | 24 +++++++++++++++++++ 4 files changed, 32 insertions(+), 8 deletions(-) diff --git a/hibernate-core/src/main/java/org/hibernate/engine/spi/VersionValue.java b/hibernate-core/src/main/java/org/hibernate/engine/spi/VersionValue.java index 6288f866f7..59d59c9e57 100755 --- a/hibernate-core/src/main/java/org/hibernate/engine/spi/VersionValue.java +++ b/hibernate-core/src/main/java/org/hibernate/engine/spi/VersionValue.java @@ -50,7 +50,7 @@ public class VersionValue implements UnsavedValueStrategy { @Override public final Boolean isUnsaved(Object version) { LOG.trace("Version unsaved-value strategy NULL"); - return version==null ? Boolean.TRUE : Boolean.FALSE; + return version==null; } @Override public Object getDefaultValue(Object currentValue) { @@ -69,7 +69,7 @@ public class VersionValue implements UnsavedValueStrategy { @Override public final Boolean isUnsaved(Object version) { LOG.trace("Version unsaved-value strategy UNDEFINED"); - return version==null ? Boolean.TRUE : null; + return version==null; } @Override public Object getDefaultValue(Object currentValue) { @@ -90,7 +90,7 @@ public class VersionValue implements UnsavedValueStrategy { public final Boolean isUnsaved(Object version) throws MappingException { LOG.trace("Version unsaved-value strategy NEGATIVE"); if (version==null) return Boolean.TRUE; - if (version instanceof Number) return ((Number)version).longValue() < 0l ? Boolean.TRUE : Boolean.FALSE; + if (version instanceof Number) return ((Number)version).longValue() < 0l; throw new MappingException("unsaved-value NEGATIVE may only be used with short, int and long types"); } @Override @@ -121,7 +121,7 @@ public class VersionValue implements UnsavedValueStrategy { @Override public Boolean isUnsaved(Object version) throws MappingException { LOG.trace("Version unsaved-value: " + value); - return version==null || version.equals(value) ? Boolean.TRUE : Boolean.FALSE; + return version==null || version.equals(value); } @Override diff --git a/hibernate-core/src/main/java/org/hibernate/id/IdentifierGeneratorHelper.java b/hibernate-core/src/main/java/org/hibernate/id/IdentifierGeneratorHelper.java index ebdcaa2214..0d2c86f285 100644 --- a/hibernate-core/src/main/java/org/hibernate/id/IdentifierGeneratorHelper.java +++ b/hibernate-core/src/main/java/org/hibernate/id/IdentifierGeneratorHelper.java @@ -84,7 +84,7 @@ public final class IdentifierGeneratorHelper { if ( !rs.next() ) { throw new HibernateException( "The database returned no natively generated identity value" ); } - final Serializable id = IdentifierGeneratorHelper.get( rs, type ); + final Serializable id = get( rs, type ); LOG.debugf("Natively generated identity: %s", id); return id; } diff --git a/hibernate-core/src/main/java/org/hibernate/proxy/LazyInitializer.java b/hibernate-core/src/main/java/org/hibernate/proxy/LazyInitializer.java index 2baf741f35..5ab1ec6aff 100644 --- a/hibernate-core/src/main/java/org/hibernate/proxy/LazyInitializer.java +++ b/hibernate-core/src/main/java/org/hibernate/proxy/LazyInitializer.java @@ -42,14 +42,14 @@ public interface LazyInitializer { public void initialize() throws HibernateException; /** - * Retrieve the identifier value for the enity our owning proxy represents. + * Retrieve the identifier value for the entity our owning proxy represents. * * @return The identifier value. */ public Serializable getIdentifier(); /** - * Set the identifier value for the enity our owning proxy represents. + * Set the identifier value for the entity our owning proxy represents. * * @param id The identifier value. */ @@ -93,7 +93,7 @@ public interface LazyInitializer { * * @throws HibernateException Indicates problem locating the target. */ - public abstract Object getImplementation(SessionImplementor session) throws HibernateException; + public Object getImplementation(SessionImplementor session) throws HibernateException; /** * Initialize the proxy manually by injecting its target. diff --git a/hibernate-core/src/test/java/org/hibernate/metamodel/source/annotations/entity/MapsIdTest.java b/hibernate-core/src/test/java/org/hibernate/metamodel/source/annotations/entity/MapsIdTest.java index fc1cd83109..f97e61ef67 100644 --- a/hibernate-core/src/test/java/org/hibernate/metamodel/source/annotations/entity/MapsIdTest.java +++ b/hibernate-core/src/test/java/org/hibernate/metamodel/source/annotations/entity/MapsIdTest.java @@ -1,3 +1,27 @@ +/* + * Hibernate, Relational Persistence for Idiomatic Java + * + * 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 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 + * Lesser General Public License, as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License + * for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this distribution; if not, write to: + * Free Software Foundation, Inc. + * 51 Franklin Street, Fifth Floor + * Boston, MA 02110-1301 USA + */ + package org.hibernate.metamodel.source.annotations.entity; import javax.persistence.Embeddable;