Permalink
Browse files

refactor, remove redundant type cast

  • Loading branch information...
1 parent ada2a53 commit 6c6df695350f917fe707b4f830e29c8c52c3f5d0 @stliu stliu committed Dec 25, 2012
Showing with 149 additions and 150 deletions.
  1. +3 −7 hibernate-core/src/main/java/org/hibernate/ConnectionReleaseMode.java
  2. +3 −3 hibernate-core/src/main/java/org/hibernate/bytecode/internal/javassist/BulkAccessor.java
  3. +2 −2 hibernate-core/src/main/java/org/hibernate/cfg/AnnotationBinder.java
  4. +3 −3 hibernate-core/src/main/java/org/hibernate/cfg/Ejb3JoinColumn.java
  5. +1 −1 hibernate-core/src/main/java/org/hibernate/cfg/ToOneFkSecondPass.java
  6. +2 −2 hibernate-core/src/main/java/org/hibernate/cfg/annotations/ListBinder.java
  7. +1 −1 ...te-core/src/main/java/org/hibernate/cfg/annotations/reflection/JPAOverriddenAnnotationReader.java
  8. +0 −2 hibernate-core/src/main/java/org/hibernate/collection/internal/PersistentList.java
  9. +1 −1 hibernate-core/src/main/java/org/hibernate/engine/internal/JoinSequence.java
  10. +1 −1 hibernate-core/src/main/java/org/hibernate/engine/jdbc/ColumnNameCache.java
  11. +19 −15 hibernate-core/src/main/java/org/hibernate/engine/spi/TypedValue.java
  12. +0 −1 hibernate-core/src/main/java/org/hibernate/hql/spi/TableBasedUpdateHandlerImpl.java
  13. +1 −1 hibernate-core/src/main/java/org/hibernate/internal/FilterHelper.java
  14. +1 −1 ...ate-core/src/main/java/org/hibernate/loader/criteria/ComponentCollectionCriteriaInfoProvider.java
  15. +1 −1 hibernate-core/src/main/java/org/hibernate/loader/criteria/EntityCriteriaInfoProvider.java
  16. +4 −4 hibernate-core/src/main/java/org/hibernate/mapping/Table.java
  17. +1 −1 hibernate-core/src/main/java/org/hibernate/metamodel/source/hbm/AbstractEntitySourceImpl.java
  18. +1 −1 .../src/main/java/org/hibernate/metamodel/source/hbm/ManyToManyPluralAttributeElementSourceImpl.java
  19. +1 −1 hibernate-core/src/main/java/org/hibernate/param/NamedParameterSpecification.java
  20. +2 −2 hibernate-core/src/main/java/org/hibernate/persister/collection/AbstractCollectionPersister.java
  21. +4 −1 hibernate-core/src/main/java/org/hibernate/persister/entity/BasicEntityPropertyMapping.java
  22. +1 −1 hibernate-core/src/main/java/org/hibernate/secure/internal/JACCPermissions.java
  23. +2 −2 hibernate-core/src/main/java/org/hibernate/tuple/entity/AbstractEntityTuplizer.java
  24. +1 −1 hibernate-core/src/main/java/org/hibernate/tuple/entity/EntityMetamodel.java
  25. +1 −1 hibernate-core/src/main/java/org/hibernate/type/CollectionType.java
  26. +2 −2 hibernate-core/src/main/java/org/hibernate/type/ComponentType.java
  27. +1 −1 hibernate-core/src/main/java/org/hibernate/type/descriptor/java/MutableMutabilityPlan.java
  28. +1 −1 ...te-core/src/test/java/org/hibernate/test/annotations/beanvalidation/BeanValidationGroupsTest.java
  29. +1 −1 .../hibernate/test/annotations/derivedidentities/e1/a/DerivedIdentitySimpleParentIdClassDepTest.java
  30. +2 −2 hibernate-core/src/test/java/org/hibernate/test/annotations/embedded/EmbeddedTest.java
  31. +1 −1 hibernate-core/src/test/java/org/hibernate/test/annotations/idmanytoone/ShoppingBasketsPK.java
  32. +1 −1 hibernate-core/src/test/java/org/hibernate/test/annotations/onetomany/OneToManyTest.java
  33. +3 −3 hibernate-core/src/test/java/org/hibernate/test/annotations/persister/PersisterTest.java
  34. +4 −4 hibernate-core/src/test/java/org/hibernate/test/batch/BatchTest.java
  35. +2 −2 hibernate-core/src/test/java/org/hibernate/test/cascade/circle/Route.java
  36. +1 −1 hibernate-core/src/test/java/org/hibernate/test/component/basic/ComponentTest.java
  37. +1 −1 hibernate-core/src/test/java/org/hibernate/test/compositeelement/CompositeElementTest.java
  38. +6 −6 hibernate-core/src/test/java/org/hibernate/test/criteria/CriteriaQueryTest.java
  39. +5 −5 hibernate-core/src/test/java/org/hibernate/test/criteria/OuterJoinCriteriaTest.java
  40. +1 −1 .../test/java/org/hibernate/test/event/collection/detached/DetachedMultipleCollectionChangeTest.java
  41. +1 −1 hibernate-core/src/test/java/org/hibernate/test/hql/ASTParserLoadingTest.java
  42. +1 −1 hibernate-core/src/test/java/org/hibernate/test/hqlfetchscroll/HQLScrollFetchTest.java
  43. +4 −4 ...ava/org/hibernate/test/immutable/entitywithmutablecollection/AbstractEntityWithOneToManyTest.java
  44. +0 −1 ...ore/src/test/java/org/hibernate/test/immutable/entitywithmutablecollection/ContractVariation.java
  45. +4 −4 hibernate-core/src/test/java/org/hibernate/test/legacy/FooBarTest.java
  46. +3 −3 hibernate-core/src/test/java/org/hibernate/test/legacy/MultiplicityType.java
  47. +4 −4 ...ate-core/src/test/java/org/hibernate/test/querycache/AbstractQueryCacheResultTransformerTest.java
  48. +12 −12 hibernate-core/src/test/java/org/hibernate/test/readonly/ReadOnlySessionLazyNonLazyTest.java
  49. +2 −2 hibernate-core/src/test/java/org/hibernate/test/util/SchemaUtil.java
  50. +1 −1 .../main/java/org/hibernate/cache/ehcache/management/impl/EhcacheHibernateMBeanRegistrationImpl.java
  51. +4 −3 hibernate-entitymanager/src/main/java/org/hibernate/jpa/HibernatePersistenceProvider.java
  52. +1 −2 hibernate-entitymanager/src/main/java/org/hibernate/jpa/criteria/path/PluralAttributePath.java
  53. +0 −1 ...rnate-entitymanager/src/main/java/org/hibernate/jpa/event/internal/jpa/CallbackProcessorImpl.java
  54. +3 −3 ...nager/src/main/java/org/hibernate/jpa/internal/instrument/InterceptFieldClassFileTransformer.java
  55. +1 −1 hibernate-entitymanager/src/main/java/org/hibernate/jpa/internal/util/PersistenceUtilHelper.java
  56. +1 −1 hibernate-entitymanager/src/main/java/org/hibernate/jpa/internal/util/XmlHelper.java
  57. +1 −1 ...nate-entitymanager/src/main/resources/META-INF/services/javax.persistence.spi.PersistenceProvider
  58. +1 −1 hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/callbacks/CallbackAndDirtyTest.java
  59. +3 −3 hibernate-entitymanager/src/test/java/org/hibernate/jpa/test/lock/LockTimeoutPropertyTest.java
  60. +1 −1 hibernate-envers/src/main/java/org/hibernate/envers/configuration/PersistentClassGraphDefiner.java
  61. +1 −1 hibernate-envers/src/main/java/org/hibernate/envers/configuration/RevisionInfoConfiguration.java
  62. +4 −3 ...ers/src/main/java/org/hibernate/envers/configuration/metadata/reader/AuditedPropertiesReader.java
  63. +1 −1 hibernate-envers/src/test/java/org/hibernate/envers/test/entities/PrimitiveTestEntity.java
  64. +1 −1 hibernate-envers/src/test/java/org/hibernate/envers/test/integration/data/DateTestEntity.java
  65. +4 −4 ...ate-envers/src/test/java/org/hibernate/envers/test/integration/query/RevisionConstraintQuery.java
  66. +1 −1 .../org/hibernate/test/cache/infinispan/functional/cluster/EntityCollectionInvalidationTestCase.java
@@ -38,7 +38,7 @@
* explicitly close all iterators and scrollable results. This mode may
* only be used with a JTA datasource.
*/
- AFTER_STATEMENT("after_statement"),
+ AFTER_STATEMENT,
/**
* Indicates that JDBC connections should be released after each transaction
@@ -47,18 +47,14 @@
* <p/>
* This is the default mode starting in 3.1; was previously {@link #ON_CLOSE}.
*/
- 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.
*/
- ON_CLOSE("on_close");
+ ON_CLOSE;
- private final String name;
- ConnectionReleaseMode(String name){
- this.name = name;
- }
public static ConnectionReleaseMode parse(String name){
return ConnectionReleaseMode.valueOf( name.toUpperCase() );
}
@@ -75,21 +75,21 @@ protected BulkAccessor() {
* Returns the types of properties.
*/
public Class[] getPropertyTypes() {
- return ( Class[] ) types.clone();
+ return types.clone();
}
/**
* Returns the setter names of properties.
*/
public String[] getGetters() {
- return ( String[] ) getters.clone();
+ return getters.clone();
}
/**
* Returns the getter names of the properties.
*/
public String[] getSetters() {
- return ( String[] ) setters.clone();
+ return setters.clone();
}
/**
@@ -1115,7 +1115,7 @@ else if ( InheritanceType.TABLE_PER_CLASS.equals( inheritanceState.getType() ) )
jcAnn = jcsAnn.value()[colIndex];
inheritanceJoinedColumns[colIndex] = Ejb3JoinColumn.buildJoinColumn(
jcAnn, null, superEntity.getIdentifier(),
- ( Map<String, Join> ) null, ( PropertyHolder ) null, mappings
+ null, null, mappings
);
}
}
@@ -1124,7 +1124,7 @@ else if ( InheritanceType.TABLE_PER_CLASS.equals( inheritanceState.getType() ) )
inheritanceJoinedColumns = new Ejb3JoinColumn[1];
inheritanceJoinedColumns[0] = Ejb3JoinColumn.buildJoinColumn(
jcAnn, null, superEntity.getIdentifier(),
- ( Map<String, Join> ) null, ( PropertyHolder ) null, mappings
+ null, null, mappings
);
}
LOG.trace( "Subclass joined column(s) created" );
@@ -211,7 +211,7 @@ public static Ejb3JoinColumn buildJoinFormula(
if ( actualColumns == null || actualColumns.length == 0 ) {
return new Ejb3JoinColumn[] {
buildJoinColumn(
- (JoinColumn) null,
+ null,
mappedBy,
joins,
propertyHolder,
@@ -356,8 +356,8 @@ public static Ejb3JoinColumn buildJoinColumn(
else {
defaultName = mappings.getObjectNameNormalizer().normalizeIdentifierQuoting( defaultName );
return new Ejb3JoinColumn(
- (String) null, defaultName,
- false, false, true, true, null, (String) null,
+ null, defaultName,
+ false, false, true, true, null, null,
joins, propertyHolder, null, null, true, mappings
);
}
@@ -121,7 +121,7 @@ public void doSecondPass(java.util.Map persistentClasses) throws MappingExceptio
if ( !manyToOne.isIgnoreNotFound() ) manyToOne.createPropertyRefConstraints( persistentClasses );
}
else if ( value instanceof OneToOne ) {
- ( (OneToOne) value ).createForeignKey();
+ value.createForeignKey();
}
else {
throw new AssertionFailure( "FkSecondPass for a wrong value type: " + value.getClass().getName() );
@@ -112,8 +112,8 @@ private void bindIndex(final Mappings mappings) {
PropertyHolder valueHolder = PropertyHolderBuilder.buildPropertyHolder(
this.collection,
StringHelper.qualify( this.collection.getRole(), "key" ),
- (XClass) null,
- (XProperty) null, propertyHolder, mappings
+ null,
+ null, propertyHolder, mappings
);
List list = (List) this.collection;
if ( !list.isOneToMany() ) indexColumn.forceNotNull();
@@ -311,7 +311,7 @@ else if ( propertyName.startsWith( "is" ) ) {
public <T extends Annotation> boolean isAnnotationPresent(Class<T> annotationType) {
initAnnotations();
- return (T) annotationsMap.get( annotationType ) != null;
+ return annotationsMap.containsKey( annotationType );
}
public Annotation[] getAnnotations() {
@@ -52,8 +52,6 @@
@Override
@SuppressWarnings( {"unchecked"})
public Serializable getSnapshot(CollectionPersister persister) throws HibernateException {
- final EntityMode entityMode = persister.getOwnerEntityPersister().getEntityMode();
-
ArrayList clonedList = new ArrayList( list.size() );
for ( Object element : list ) {
Object deepCopy = persister.getElementType().deepCopy( element, persister.getFactory() );
@@ -292,7 +292,7 @@ public Iterator iterateJoins() {
}
public Join getFirstJoin() {
- return (Join) joins.get( 0 );
+ return joins.get( 0 );
}
public static interface Selector {
@@ -43,7 +43,7 @@ public ColumnNameCache(int columnCount) {
}
public int getIndexForColumnName(String columnName, ResultSet rs) throws SQLException {
- Integer cached = ( Integer ) columnNameToIndexCache.get( columnName );
+ Integer cached = columnNameToIndexCache.get( columnName );
if ( cached != null ) {
return cached.intValue();
}
@@ -26,6 +26,7 @@
import java.io.Serializable;
import org.hibernate.EntityMode;
+import org.hibernate.internal.util.ValueHolder;
import org.hibernate.type.Type;
/**
@@ -37,16 +38,23 @@
public final class TypedValue implements Serializable {
private final Type type;
private final Object value;
- private final EntityMode entityMode;
+ private final ValueHolder<Integer> hashcode;
- public TypedValue(Type type, Object value) {
- this( type, value, EntityMode.POJO );
+ public TypedValue(final Type type, final Object value) {
+ this.type = type;
+ this.value = value;
+ this.hashcode = new ValueHolder<Integer>(
+ new ValueHolder.DeferredInitializer<Integer>() {
+ @Override
+ public Integer initialize() {
+ return value == null ? 0 : type.getHashCode( value );
+ }
+ }
+ );
}
-
+ @Deprecated
public TypedValue(Type type, Object value, EntityMode entityMode) {
- this.type = type;
- this.value=value;
- this.entityMode = entityMode;
+ this(type, value);
}
public Object getValue() {
@@ -56,19 +64,15 @@ public Object getValue() {
public Type getType() {
return type;
}
-
+ @Override
public String toString() {
return value==null ? "null" : value.toString();
}
-
+ @Override
public int hashCode() {
- //int result = 17;
- //result = 37 * result + type.hashCode();
- //result = 37 * result + ( value==null ? 0 : value.hashCode() );
- //return result;
- return value==null ? 0 : type.getHashCode(value );
+ return hashcode.getValue();
}
-
+ @Override
public boolean equals(Object other) {
if ( !(other instanceof TypedValue) ) return false;
TypedValue that = (TypedValue) other;
@@ -193,6 +193,5 @@ protected int handlePrependedParametersOnIdSelection(PreparedStatement ps, Sessi
}
protected void handleAddedParametersOnUpdate(PreparedStatement ps, SessionImplementor session, int position) throws SQLException {
- //To change body of created methods use File | Settings | File Templates.
}
}
@@ -65,7 +65,7 @@ public FilterHelper(List filters, SessionFactoryImplementor factory) {
while ( iter.hasNext() ) {
filterAutoAliasFlags[filterCount] = false;
final FilterConfiguration filter = (FilterConfiguration) iter.next();
- filterNames[filterCount] = (String) filter.getName();
+ filterNames[filterCount] = filter.getName();
filterConditions[filterCount] = filter.getCondition();
filterAliasTableMaps[filterCount] = filter.getAliasTableMap(factory);
if ((filterAliasTableMaps[filterCount].isEmpty() || isTableFromPersistentClass(filterAliasTableMaps[filterCount])) && filter.useAutoAliasInjection()){
@@ -66,7 +66,7 @@ public String getName() {
}
public PropertyMapping getPropertyMapping() {
- return (PropertyMapping)persister;
+ return persister;
}
public Type getType(String relativePath) {
@@ -50,7 +50,7 @@ public String getName() {
}
public PropertyMapping getPropertyMapping() {
- return (PropertyMapping)persister;
+ return persister;
}
public Type getType(String relativePath) {
@@ -216,7 +216,7 @@ public Column getColumn(int n) {
}
public void addColumn(Column column) {
- Column old = (Column) getColumn( column );
+ Column old = getColumn( column );
if ( old == null ) {
columns.put( column.getCanonicalName(), column );
column.uniqueInteger = columns.size();
@@ -622,7 +622,7 @@ public Index addIndex(Index index) {
}
public UniqueKey addUniqueKey(UniqueKey uniqueKey) {
- UniqueKey current = (UniqueKey) uniqueKeys.get( uniqueKey.getName() );
+ UniqueKey current = uniqueKeys.get( uniqueKey.getName() );
if ( current != null ) {
throw new MappingException( "UniqueKey " + uniqueKey.getName() + " already exists!" );
}
@@ -638,11 +638,11 @@ public UniqueKey createUniqueKey(List keyColumns) {
}
public UniqueKey getUniqueKey(String keyName) {
- return (UniqueKey) uniqueKeys.get( keyName );
+ return uniqueKeys.get( keyName );
}
public UniqueKey getOrCreateUniqueKey(String keyName) {
- UniqueKey uk = (UniqueKey) uniqueKeys.get( keyName );
+ UniqueKey uk = uniqueKeys.get( keyName );
if ( uk == null ) {
uk = new UniqueKey();
@@ -291,7 +291,7 @@ public void add(SubclassEntitySourceImpl subclassEntitySource) {
@Override
public String getDiscriminatorMatchValue() {
- return null; //To change body of implemented methods use File | Settings | File Templates.
+ return null;
}
@Override
@@ -134,7 +134,7 @@ public String getWhere() {
@Override
public FetchMode getFetchMode() {
- return null; //To change body of implemented methods use File | Settings | File Templates.
+ return null;
}
@Override
@@ -62,7 +62,7 @@ public NamedParameterSpecification(int sourceLine, int sourceColumn, String name
*/
public int bind(PreparedStatement statement, QueryParameters qp, SessionImplementor session, int position)
throws SQLException {
- TypedValue typedValue = ( TypedValue ) qp.getNamedParameters().get( name );
+ TypedValue typedValue = qp.getNamedParameters().get( name );
typedValue.getType().nullSafeSet( statement, typedValue.getValue(), position, session );
return typedValue.getType().getColumnSpan( session.getFactory() );
}
@@ -243,8 +243,8 @@ public AbstractCollectionPersister(
this.cacheAccessStrategy = cacheAccessStrategy;
if ( factory.getSettings().isStructuredCacheEntriesEnabled() ) {
cacheEntryStructure = collection.isMap() ?
- (CacheEntryStructure) new StructuredMapCacheEntry() :
- (CacheEntryStructure) new StructuredCollectionCacheEntry();
+ new StructuredMapCacheEntry() :
+ new StructuredCollectionCacheEntry();
}
else {
cacheEntryStructure = new UnstructuredCacheEntry();
@@ -59,7 +59,10 @@ public Type getType() {
public String[] toColumns(final String alias, final String propertyName) throws QueryException {
return super.toColumns(
- persister.generateTableAlias( alias, persister.getSubclassPropertyTableNumber(propertyName) ),
+ AbstractEntityPersister.generateTableAlias(
+ alias,
+ persister.getSubclassPropertyTableNumber( propertyName )
+ ),
propertyName
);
}
@@ -84,7 +84,7 @@ public static void checkPermission(Class clazz, String contextID, EJBMethodPermi
PolicyContextActions PRIVILEGED = new PolicyContextActions() {
private final PrivilegedExceptionAction exAction = new PrivilegedExceptionAction() {
public Object run() throws Exception {
- return (Subject) PolicyContext.getContext( SUBJECT_CONTEXT_KEY );
+ return PolicyContext.getContext( SUBJECT_CONTEXT_KEY );
}
};
@@ -417,8 +417,8 @@ private static MappedIdentifierValueMarshaller buildMappedIdentifierValueMarshal
}
return wereAllEquivalent
- ? (MappedIdentifierValueMarshaller) new NormalMappedIdentifierValueMarshaller( virtualIdComponent, mappedIdClassComponentType )
- : (MappedIdentifierValueMarshaller) new IncrediblySillyJpaMapsIdMappedIdentifierValueMarshaller( virtualIdComponent, mappedIdClassComponentType );
+ ? new NormalMappedIdentifierValueMarshaller( virtualIdComponent, mappedIdClassComponentType )
+ : new IncrediblySillyJpaMapsIdMappedIdentifierValueMarshaller( virtualIdComponent, mappedIdClassComponentType );
}
private static class NormalMappedIdentifierValueMarshaller implements MappedIdentifierValueMarshaller {
@@ -795,7 +795,7 @@ public int getPropertyIndex(String propertyName) {
}
public Integer getPropertyIndexOrNull(String propertyName) {
- return (Integer) propertyIndexes.get( propertyName );
+ return propertyIndexes.get( propertyName );
}
public boolean hasCollections() {
@@ -380,7 +380,7 @@ public Serializable getKeyOfOwner(Object owner, SessionImplementor session) {
// TODO: Fix this so it will work for non-POJO entity mode
Type keyType = getPersister( session ).getKeyType();
if ( !keyType.getReturnedClass().isInstance( id ) ) {
- id = (Serializable) keyType.semiResolve(
+ id = keyType.semiResolve(
entityEntry.getLoadedValue( foreignKeyPropertyName ),
session,
owner
@@ -105,15 +105,15 @@ public EntityMode getEntityMode() {
public ComponentTuplizer getComponentTuplizer() {
return componentTuplizer;
}
-
+ @Override
public int getColumnSpan(Mapping mapping) throws MappingException {
int span = 0;
for ( int i = 0; i < propertySpan; i++ ) {
span += propertyTypes[i].getColumnSpan( mapping );
}
return span;
}
-
+ @Override
public int[] sqlTypes(Mapping mapping) throws MappingException {
//Not called at runtime so doesn't matter if its slow :)
int[] sqlTypes = new int[getColumnSpan( mapping )];
@@ -44,7 +44,7 @@ public Serializable disassemble(T value) {
@Override
@SuppressWarnings({ "unchecked" })
public T assemble(Serializable cached) {
- return (T) deepCopy( (T) cached );
+ return deepCopy( (T) cached );
}
@Override
Oops, something went wrong.

0 comments on commit 6c6df69

Please sign in to comment.