refactor, remove redundant type cast

This commit is contained in:
Strong Liu 2012-12-25 19:25:47 +08:00
parent ada2a5327e
commit 6c6df69535
66 changed files with 150 additions and 151 deletions

View File

@ -38,7 +38,7 @@ public enum ConnectionReleaseMode{
* 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 @@ public enum ConnectionReleaseMode{
* <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() );
}

View File

@ -75,21 +75,21 @@ public abstract class BulkAccessor implements Serializable {
* 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();
}
/**

View File

@ -1115,7 +1115,7 @@ public final class AnnotationBinder {
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 @@ public final class AnnotationBinder {
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" );

View File

@ -211,7 +211,7 @@ public class Ejb3JoinColumn extends Ejb3Column {
if ( actualColumns == null || actualColumns.length == 0 ) {
return new Ejb3JoinColumn[] {
buildJoinColumn(
(JoinColumn) null,
null,
mappedBy,
joins,
propertyHolder,
@ -356,8 +356,8 @@ public class Ejb3JoinColumn extends Ejb3Column {
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
);
}

View File

@ -121,7 +121,7 @@ public class ToOneFkSecondPass extends FkSecondPass {
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() );

View File

@ -112,8 +112,8 @@ public class ListBinder extends CollectionBinder {
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();

View File

@ -311,7 +311,7 @@ public class JPAOverriddenAnnotationReader implements AnnotationReader {
public <T extends Annotation> boolean isAnnotationPresent(Class<T> annotationType) {
initAnnotations();
return (T) annotationsMap.get( annotationType ) != null;
return annotationsMap.containsKey( annotationType );
}
public Annotation[] getAnnotations() {

View File

@ -52,8 +52,6 @@ public class PersistentList extends AbstractPersistentCollection implements List
@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() );

View File

@ -292,7 +292,7 @@ public class JoinSequence {
}
public Join getFirstJoin() {
return (Join) joins.get( 0 );
return joins.get( 0 );
}
public static interface Selector {

View File

@ -43,7 +43,7 @@ public class ColumnNameCache {
}
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();
}

View File

@ -26,6 +26,7 @@ package org.hibernate.engine.spi;
import java.io.Serializable;
import org.hibernate.EntityMode;
import org.hibernate.internal.util.ValueHolder;
import org.hibernate.type.Type;
/**
@ -37,16 +38,23 @@ import org.hibernate.type.Type;
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(Type type, Object value, EntityMode entityMode) {
public TypedValue(final Type type, final Object value) {
this.type = type;
this.value = value;
this.entityMode = entityMode;
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, value);
}
public Object getValue() {
@ -56,19 +64,15 @@ public final class TypedValue implements Serializable {
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;

View File

@ -193,6 +193,5 @@ public class TableBasedUpdateHandlerImpl
}
protected void handleAddedParametersOnUpdate(PreparedStatement ps, SessionImplementor session, int position) throws SQLException {
//To change body of created methods use File | Settings | File Templates.
}
}

View File

@ -65,7 +65,7 @@ public class FilterHelper {
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()){

View File

@ -66,7 +66,7 @@ class ComponentCollectionCriteriaInfoProvider implements CriteriaInfoProvider {
}
public PropertyMapping getPropertyMapping() {
return (PropertyMapping)persister;
return persister;
}
public Type getType(String relativePath) {

View File

@ -50,7 +50,7 @@ class EntityCriteriaInfoProvider implements CriteriaInfoProvider {
}
public PropertyMapping getPropertyMapping() {
return (PropertyMapping)persister;
return persister;
}
public Type getType(String relativePath) {

View File

@ -216,7 +216,7 @@ public class Table implements RelationalModel, Serializable {
}
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 class Table implements RelationalModel, Serializable {
}
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 class Table implements RelationalModel, Serializable {
}
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();

View File

@ -291,7 +291,7 @@ public abstract class AbstractEntitySourceImpl implements EntitySource {
@Override
public String getDiscriminatorMatchValue() {
return null; //To change body of implemented methods use File | Settings | File Templates.
return null;
}
@Override

View File

@ -134,7 +134,7 @@ public class ManyToManyPluralAttributeElementSourceImpl implements ManyToManyPlu
@Override
public FetchMode getFetchMode() {
return null; //To change body of implemented methods use File | Settings | File Templates.
return null;
}
@Override

View File

@ -62,7 +62,7 @@ public class NamedParameterSpecification extends AbstractExplicitParameterSpecif
*/
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() );
}

View File

@ -243,8 +243,8 @@ public abstract class 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();

View File

@ -59,7 +59,10 @@ public class BasicEntityPropertyMapping extends AbstractPropertyMapping {
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
);
}

View File

@ -84,7 +84,7 @@ public class JACCPermissions {
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 );
}
};

View File

@ -417,8 +417,8 @@ public abstract class AbstractEntityTuplizer implements EntityTuplizer {
}
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 {

View File

@ -795,7 +795,7 @@ public class EntityMetamodel implements Serializable {
}
public Integer getPropertyIndexOrNull(String propertyName) {
return (Integer) propertyIndexes.get( propertyName );
return propertyIndexes.get( propertyName );
}
public boolean hasCollections() {

View File

@ -380,7 +380,7 @@ public abstract class CollectionType extends AbstractType implements Association
// 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

View File

@ -105,7 +105,7 @@ public class ComponentType extends AbstractType implements CompositeType, Proced
public ComponentTuplizer getComponentTuplizer() {
return componentTuplizer;
}
@Override
public int getColumnSpan(Mapping mapping) throws MappingException {
int span = 0;
for ( int i = 0; i < propertySpan; i++ ) {
@ -113,7 +113,7 @@ public class ComponentType extends AbstractType implements CompositeType, Proced
}
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 )];

View File

@ -44,7 +44,7 @@ public abstract class MutableMutabilityPlan<T> implements MutabilityPlan<T> {
@Override
@SuppressWarnings({ "unchecked" })
public T assemble(Serializable cached) {
return (T) deepCopy( (T) cached );
return deepCopy( (T) cached );
}
@Override

View File

@ -71,7 +71,7 @@ public class BeanValidationGroupsTest extends BaseCoreFunctionalTestCase {
catch ( ConstraintViolationException e ) {
assertEquals( 1, e.getConstraintViolations().size() );
// TODO - seems this explicit case is necessary with JDK 5 (at least on Mac). With Java 6 there is no problem
Annotation annotation = (Annotation) e.getConstraintViolations()
Annotation annotation = e.getConstraintViolations()
.iterator()
.next()
.getConstraintDescriptor()

View File

@ -81,7 +81,7 @@ public class DerivedIdentitySimpleParentIdClassDepTest extends BaseCoreFunctiona
Query query = s.createQuery("Select d from Dependent d where d.name='LittleP' and d.emp.empName='Paula'");
List depList = query.list();
assertEquals( 1, depList.size() );
Object newDependent = (Dependent) depList.get(0);
Object newDependent = depList.get(0);
assertSame( d, newDependent );
s.getTransaction().rollback();
s.close();

View File

@ -104,7 +104,7 @@ public class EmbeddedTest extends BaseCoreFunctionalTestCase {
s = openSession();
tx = s.beginTransaction();
reg = (RegionalArticle) s.get( RegionalArticle.class, (Serializable) reg.getPk() );
reg = (RegionalArticle) s.get( RegionalArticle.class, reg.getPk() );
assertNotNull( reg );
assertNotNull( reg.getPk() );
assertEquals( "Je ne veux pes rester sage - Dolly", reg.getName() );
@ -396,7 +396,7 @@ public class EmbeddedTest extends BaseCoreFunctionalTestCase {
Set<Manager> topManagement = provider.getOwner().getTopManagement();
assertNotNull( "OneToMany not set", topManagement );
assertEquals( "Wrong number of elements", 1, topManagement.size() );
manager = (Manager) topManagement.iterator().next();
manager = topManagement.iterator().next();
assertEquals( "Wrong element", "Bill", manager.getName() );
s.delete( manager );
s.delete( provider );

View File

@ -33,7 +33,7 @@ public class ShoppingBasketsPK implements Serializable {
public int hashCode() {
int hashcode = 0;
if (getOwner() != null) {
hashcode = hashcode + (int) getOwner().getORMID();
hashcode = hashcode + getOwner().getORMID();
}
hashcode = hashcode + (getBasketDatetime() == null ? 0 : getBasketDatetime().hashCode());
return hashcode;

View File

@ -307,7 +307,7 @@ public class OneToManyTest extends BaseCoreFunctionalTestCase {
s = openSession();
tx = s.beginTransaction();
Troop troop = ( Troop ) s.get( Troop.class, disney.getId() );
Soldier soldier = ( Soldier ) troop.getSoldiers().iterator().next();
Soldier soldier = troop.getSoldiers().iterator().next();
tx.commit();
s.close();
troop.getSoldiers().clear();

View File

@ -39,7 +39,7 @@ public class PersisterTest extends BaseCoreFunctionalTestCase {
@Test
public void testEntityEntityPersisterAndPersisterSpecified() throws Exception {
//checks to see that the persister specified with the @Persister annotation takes precedence if a @Entity.persister() is also specified
PersistentClass persistentClass = (PersistentClass) configuration().getClassMapping( Deck.class.getName() );
PersistentClass persistentClass = configuration().getClassMapping( Deck.class.getName() );
assertEquals( "Incorrect Persister class for " + persistentClass.getMappedClass(), EntityPersister.class,
persistentClass.getEntityPersisterClass() );
}
@ -47,7 +47,7 @@ public class PersisterTest extends BaseCoreFunctionalTestCase {
@Test
public void testEntityEntityPersisterSpecified() throws Exception {
//tests the persister specified with an @Entity.persister()
PersistentClass persistentClass = (PersistentClass) configuration().getClassMapping( Card.class.getName() );
PersistentClass persistentClass = configuration().getClassMapping( Card.class.getName() );
assertEquals( "Incorrect Persister class for " + persistentClass.getMappedClass(),
SingleTableEntityPersister.class, persistentClass.getEntityPersisterClass() );
}
@ -55,7 +55,7 @@ public class PersisterTest extends BaseCoreFunctionalTestCase {
@Test
public void testCollectionPersisterSpecified() throws Exception {
//tests the persister specified by the @Persister annotation on a collection
Collection collection = (Collection) configuration().getCollectionMapping( Deck.class.getName() + ".cards" );
Collection collection = configuration().getCollectionMapping( Deck.class.getName() + ".cards" );
assertEquals( "Incorrect Persister class for collection " + collection.getRole(), CollectionPersister.class,
collection.getCollectionPersisterClass() );
}

View File

@ -64,27 +64,27 @@ public class BatchTest extends BaseCoreFunctionalTestCase {
final int N = 5000; //26 secs with batch flush, 26 without
//final int N = 100000; //53 secs with batch flush, OOME without
//final int N = 250000; //137 secs with batch flush, OOME without
int batchSize = ( ( SessionFactoryImplementor ) sessionFactory() ).getSettings().getJdbcBatchSize();
int batchSize = sessionFactory().getSettings().getJdbcBatchSize();
doBatchInsertUpdate( N, batchSize );
System.out.println( System.currentTimeMillis() - start );
}
@Test
public void testBatchInsertUpdateSizeEqJdbcBatchSize() {
int batchSize = ( ( SessionFactoryImplementor ) sessionFactory() ).getSettings().getJdbcBatchSize();
int batchSize = sessionFactory().getSettings().getJdbcBatchSize();
doBatchInsertUpdate( 50, batchSize );
}
@Test
public void testBatchInsertUpdateSizeLtJdbcBatchSize() {
int batchSize = ( ( SessionFactoryImplementor ) sessionFactory() ).getSettings().getJdbcBatchSize();
int batchSize = sessionFactory().getSettings().getJdbcBatchSize();
doBatchInsertUpdate( 50, batchSize - 1 );
}
@Test
public void testBatchInsertUpdateSizeGtJdbcBatchSize() {
long start = System.currentTimeMillis();
int batchSize = ( ( SessionFactoryImplementor ) sessionFactory() ).getSettings().getJdbcBatchSize();
int batchSize = sessionFactory().getSettings().getJdbcBatchSize();
doBatchInsertUpdate( 50, batchSize + 1 );
}

View File

@ -96,11 +96,11 @@ public class Route {
buffer.append("Route name: " + name + " id: " + routeID + " transientField: " + transientField + "\n");
for (Iterator it = nodes.iterator(); it.hasNext();) {
buffer.append("Node: " + (Node)it.next());
buffer.append("Node: " + it.next() );
}
for (Iterator it = vehicles.iterator(); it.hasNext();) {
buffer.append("Vehicle: " + (Vehicle)it.next());
buffer.append("Vehicle: " + it.next() );
}
return buffer.toString();

View File

@ -78,7 +78,7 @@ public class ComponentTest extends BaseCoreFunctionalTestCase {
Component component = ( Component ) personProperty.getValue();
Formula f = ( Formula ) component.getProperty( "yob" ).getValue().getColumnIterator().next();
SQLFunction yearFunction = ( SQLFunction ) dialect.getFunctions().get( "year" );
SQLFunction yearFunction = dialect.getFunctions().get( "year" );
if ( yearFunction == null ) {
// the dialect not know to support a year() function, so rely on the
// ANSI SQL extract function

View File

@ -56,7 +56,7 @@ public class CompositeElementTest extends BaseCoreFunctionalTestCase {
Component childComponents = ( Component ) children.getElement();
Formula f = ( Formula ) childComponents.getProperty( "bioLength" ).getValue().getColumnIterator().next();
SQLFunction lengthFunction = ( SQLFunction ) dialect.getFunctions().get( "length" );
SQLFunction lengthFunction = dialect.getFunctions().get( "length" );
if ( lengthFunction != null ) {
ArrayList args = new ArrayList();
args.add( "bio" );

View File

@ -1388,7 +1388,7 @@ public class CriteriaQueryTest extends BaseCoreFunctionalTestCase {
s.flush();
List enrolments = ( List ) s.createCriteria( Enrolment.class).setProjection( Projections.id() ).list();
List enrolments = s.createCriteria( Enrolment.class).setProjection( Projections.id() ).list();
t.rollback();
s.close();
}
@ -1405,7 +1405,7 @@ public class CriteriaQueryTest extends BaseCoreFunctionalTestCase {
s.save(course);
s.flush();
s.clear();
List data = ( List ) s.createCriteria( CourseMeeting.class).setProjection( Projections.id() ).list();
List data = s.createCriteria( CourseMeeting.class).setProjection( Projections.id() ).list();
t.commit();
s.close();
@ -1463,7 +1463,7 @@ public class CriteriaQueryTest extends BaseCoreFunctionalTestCase {
s.save(course);
s.flush();
List data = ( List ) s.createCriteria( CourseMeeting.class).setProjection( Projections.id().as( "id" ) ).list();
List data = s.createCriteria( CourseMeeting.class).setProjection( Projections.id().as( "id" ) ).list();
t.rollback();
s.close();
}
@ -1480,7 +1480,7 @@ public class CriteriaQueryTest extends BaseCoreFunctionalTestCase {
s.save( gaith );
s.flush();
List cityStates = ( List ) s.createCriteria( Student.class).setProjection( Projections.property( "cityState" ) ).list();
List cityStates = s.createCriteria( Student.class).setProjection( Projections.property( "cityState" ) ).list();
t.rollback();
s.close();
}
@ -1496,7 +1496,7 @@ public class CriteriaQueryTest extends BaseCoreFunctionalTestCase {
gaith.setCityState( new CityState( "Chicago", "Illinois" ) );
s.save(gaith);
s.flush();
List data = ( List ) s.createCriteria( Student.class)
List data = s.createCriteria( Student.class)
.setProjection( Projections.projectionList()
.add( Projections.property( "cityState" ) )
.add( Projections.property("name") ) )
@ -1545,7 +1545,7 @@ public class CriteriaQueryTest extends BaseCoreFunctionalTestCase {
gavin.getEnrolments().add(enrolment);
s.save(enrolment);
s.flush();
List data = ( List ) s.createCriteria( Enrolment.class)
List data = s.createCriteria( Enrolment.class)
.setProjection( Projections.projectionList()
.add( Projections.property( "semester" ) )
.add( Projections.property("year") )

View File

@ -289,11 +289,11 @@ public class OuterJoinCriteriaTest extends BaseCoreFunctionalTestCase {
Order o = (Order) it.next();
if ( order1.getOrderId() == o.getOrderId() ) {
assertEquals( 1, o.getLines().size() );
assertEquals( "3000", ( ( OrderLine ) o.getLines().iterator().next() ).getArticleId() );
assertEquals( "3000", o.getLines().iterator().next().getArticleId() );
}
else if ( order3.getOrderId() == o.getOrderId() ) {
assertEquals( 1, o.getLines().size() );
assertEquals( "3000", ( ( OrderLine ) o.getLines().iterator().next() ).getArticleId() );
assertEquals( "3000", o.getLines().iterator().next().getArticleId() );
}
else {
fail( "unknown order" );
@ -332,7 +332,7 @@ public class OuterJoinCriteriaTest extends BaseCoreFunctionalTestCase {
for ( Object order : orders ) {
Order o = (Order) order;
if ( order1.getOrderId() == o.getOrderId() ) {
assertEquals( "1000", ( ( OrderLine ) o.getLines().iterator().next() ).getArticleId() );
assertEquals( "1000", o.getLines().iterator().next().getArticleId() );
}
else if ( order2.getOrderId() == o.getOrderId() ) {
assertEquals( 0, o.getLines().size() );
@ -367,11 +367,11 @@ public class OuterJoinCriteriaTest extends BaseCoreFunctionalTestCase {
Order o = (Order) it.next();
if ( order1.getOrderId() == o.getOrderId() ) {
assertEquals( 1, o.getLines().size() );
assertEquals( "3000", ( ( OrderLine ) o.getLines().iterator().next() ).getArticleId() );
assertEquals( "3000", o.getLines().iterator().next().getArticleId() );
}
else if ( order3.getOrderId() == o.getOrderId() ) {
assertEquals( 1, o.getLines().size() );
assertEquals( "3000", ( ( OrderLine ) o.getLines().iterator().next() ).getArticleId() );
assertEquals( "3000", o.getLines().iterator().next().getArticleId() );
}
else {
fail( "unknown order" );

View File

@ -238,7 +238,7 @@ public class DetachedMultipleCollectionChangeTest extends BaseCoreFunctionalTest
org.hibernate.test.event.collection.Entity ownerExpected,
List<? extends org.hibernate.test.event.collection.Entity> expectedCollectionEntrySnapshot,
int index) {
AbstractCollectionEvent event = (AbstractCollectionEvent) listeners
AbstractCollectionEvent event = listeners
.getEvents().get(index);
assertSame(listenerExpected, listeners.getListenersCalled().get(index));

View File

@ -2431,7 +2431,7 @@ public class ASTParserLoadingTest extends BaseCoreFunctionalTestCase {
Zoo zooRead = ( Zoo ) results.get( 0 );
assertEquals( zoo, zooRead );
assertTrue( Hibernate.isInitialized( zooRead.getMammals() ) );
Mammal mammalRead = ( Mammal ) ( ( Map ) zooRead.getMammals() ).get( "zebra" );
Mammal mammalRead = ( Mammal ) zooRead.getMammals().get( "zebra" );
assertEquals( mammal, mammalRead );
session.delete( mammalRead );
session.delete( zooRead );

View File

@ -342,7 +342,7 @@ public class HQLScrollFetchTest extends BaseCoreFunctionalTestCase {
Transaction t = s.beginTransaction();
List list = s.createQuery( "from Parent" ).list();
for ( Iterator i = list.iterator(); i.hasNext(); ) {
s.delete( (Parent) i.next() );
s.delete( i.next() );
}
t.commit();
s.close();

View File

@ -66,23 +66,23 @@ public abstract class AbstractEntityWithOneToManyTest extends BaseCoreFunctional
protected void prepareTest() throws Exception {
super.prepareTest();
isContractPartiesInverse = ( ( SessionFactoryImpl ) sessionFactory() ).getCollectionPersister( Contract.class.getName() + ".parties" ).isInverse();
isContractPartiesInverse = sessionFactory().getCollectionPersister( Contract.class.getName() + ".parties" ).isInverse();
try {
( ( SessionFactoryImpl ) sessionFactory() ).getEntityPersister( Party.class.getName() ).getPropertyType( "contract" );
sessionFactory().getEntityPersister( Party.class.getName() ).getPropertyType( "contract" );
isContractPartiesBidirectional = true;
}
catch ( QueryException ex) {
isContractPartiesBidirectional = false;
}
try {
( ( SessionFactoryImpl ) sessionFactory() ).getEntityPersister( ContractVariation.class.getName() ).getPropertyType( "contract" );
sessionFactory().getEntityPersister( ContractVariation.class.getName() ).getPropertyType( "contract" );
isContractVariationsBidirectional = true;
}
catch ( QueryException ex) {
isContractVariationsBidirectional = false;
}
isContractVersioned = ( ( SessionFactoryImpl ) sessionFactory() ).getEntityPersister( Contract.class.getName() ).isVersioned();
isContractVersioned = sessionFactory().getEntityPersister( Contract.class.getName() ).isVersioned();
}
@Test

View File

@ -64,7 +64,6 @@ public class ContractVariation implements Serializable {
public ContractVariation(int version, Contract contract) {
this.contract = contract;
this.id = id;
contract.getVariations().add(this);
}

View File

@ -1531,7 +1531,7 @@ public class FooBarTest extends LegacyTestCase {
}
private boolean isOuterJoinFetchingDisabled() {
return new Integer(0).equals( ( (SessionFactoryImplementor) sessionFactory() ).getSettings().getMaximumFetchDepth() );
return new Integer(0).equals( sessionFactory().getSettings().getMaximumFetchDepth() );
}
@Test
@ -1689,7 +1689,7 @@ public class FooBarTest extends LegacyTestCase {
GlarchProxy g = new Glarch();
Multiplicity m = new Multiplicity();
m.count = 12;
m.glarch = (Glarch) g;
m.glarch = g;
g.setMultiple(m);
Session s = openSession();
@ -4864,8 +4864,8 @@ public class FooBarTest extends LegacyTestCase {
g2.setStrings(set);
Session s = openSession();
Transaction t = s.beginTransaction();
Serializable gid = (Serializable) s.save(g);
Serializable g2id = (Serializable) s.save(g2);
Serializable gid = s.save(g);
Serializable g2id = s.save(g2);
t.commit();
assertTrue( g.getVersion()==0 );
assertTrue( g2.getVersion()==0 );

View File

@ -57,8 +57,8 @@ public class MultiplicityType implements CompositeUserType {
public Object getPropertyValue(Object component, int property) {
Multiplicity o = (Multiplicity) component;
return property==0 ?
(Object) new Integer(o.count) :
(Object) o.glarch;
new Integer(o.count) :
o.glarch;
}
public void setPropertyValue(
@ -94,7 +94,7 @@ public class MultiplicityType implements CompositeUserType {
public Object nullSafeGet(ResultSet rs, String[] names, SessionImplementor session, Object owner)
throws HibernateException, SQLException {
Integer c = (Integer) IntegerType.INSTANCE.nullSafeGet( rs, names[0], session );
Integer c = IntegerType.INSTANCE.nullSafeGet( rs, names[0], session );
GlarchProxy g = (GlarchProxy) ( (Session) session ).getTypeHelper().entity( Glarch.class ).nullSafeGet(rs, names[1], session, owner);
Multiplicity m = new Multiplicity();
m.count = c==null ? 0 : c.intValue();

View File

@ -361,8 +361,8 @@ public abstract class AbstractQueryCacheResultTransformerTest extends BaseCoreFu
public void check(Object results) {
assertTrue( results instanceof Course );
assertEquals( courseExpected, results );
assertTrue( Hibernate.isInitialized( ((Course) courseExpected).getCourseMeetings() ) );
assertEquals( courseExpected.getCourseMeetings(), ((Course) courseExpected).getCourseMeetings() );
assertTrue( Hibernate.isInitialized( courseExpected.getCourseMeetings() ) );
assertEquals( courseExpected.getCourseMeetings(), courseExpected.getCourseMeetings() );
}
};
runTest( hqlExecutor, criteriaExecutor, checker, true );
@ -2219,7 +2219,7 @@ public abstract class AbstractQueryCacheResultTransformerTest extends BaseCoreFu
}
private Constructor getConstructor() {
Type studentNametype =
( ( SessionFactoryImpl ) sessionFactory() )
sessionFactory()
.getEntityPersister( Student.class.getName() )
.getPropertyType( "name" );
return ReflectHelper.getConstructor( Student.class, new Type[] {StandardBasicTypes.LONG, studentNametype} );
@ -2705,7 +2705,7 @@ public abstract class AbstractQueryCacheResultTransformerTest extends BaseCoreFu
}
protected void assertCount(int expected) {
int actual = ( int ) sessionFactory().getStatistics().getQueries().length;
int actual = sessionFactory().getStatistics().getQueries().length;
assertEquals( expected, actual );
}

View File

@ -1063,19 +1063,19 @@ public class ReadOnlySessionLazyNonLazyTest extends AbstractReadOnlyTest {
c.getNonLazySelectDataPoints().iterator().next()
)
);
List list = ( List ) s.createFilter( c.getLazyDataPoints(), "" )
List list = s.createFilter( c.getLazyDataPoints(), "" )
.setMaxResults(1)
.setReadOnly( false )
.list();
assertEquals( 1, list.size() );
assertFalse( s.isReadOnly( list.get( 0 ) ) );
list = ( List ) s.createFilter( c.getNonLazyJoinDataPoints(), "" )
list = s.createFilter( c.getNonLazyJoinDataPoints(), "" )
.setMaxResults(1)
.setReadOnly( false )
.list();
assertEquals( 1, list.size() );
assertTrue( s.isReadOnly( list.get( 0 ) ) );
list = ( List ) s.createFilter( c.getNonLazySelectDataPoints(), "" )
list = s.createFilter( c.getNonLazySelectDataPoints(), "" )
.setMaxResults(1)
.setReadOnly( false )
.list();
@ -1141,19 +1141,19 @@ public class ReadOnlySessionLazyNonLazyTest extends AbstractReadOnlyTest {
)
);
expectedReadOnlyObjects = new HashSet();
List list = ( List ) s.createFilter( c.getLazyDataPoints(), "" )
List list = s.createFilter( c.getLazyDataPoints(), "" )
.setMaxResults(1)
.setReadOnly( true )
.list();
assertEquals( 1, list.size() );
assertTrue( s.isReadOnly( list.get( 0 ) ) );
list = ( List ) s.createFilter( c.getNonLazyJoinDataPoints(), "" )
list = s.createFilter( c.getNonLazyJoinDataPoints(), "" )
.setMaxResults(1)
.setReadOnly( true )
.list();
assertEquals( 1, list.size() );
assertFalse( s.isReadOnly( list.get( 0 ) ) );
list = ( List ) s.createFilter( c.getNonLazySelectDataPoints(), "" )
list = s.createFilter( c.getNonLazySelectDataPoints(), "" )
.setMaxResults(1)
.setReadOnly( true )
.list();
@ -1233,17 +1233,17 @@ public class ReadOnlySessionLazyNonLazyTest extends AbstractReadOnlyTest {
c.getNonLazySelectDataPoints().iterator().next()
)
);
List list = ( List ) s.createFilter( c.getLazyDataPoints(), "" )
List list = s.createFilter( c.getLazyDataPoints(), "" )
.setMaxResults( 1 )
.list();
assertEquals( 1, list.size() );
assertTrue( s.isReadOnly( list.get( 0 ) ) );
list = ( List ) s.createFilter( c.getNonLazyJoinDataPoints(), "" )
list = s.createFilter( c.getNonLazyJoinDataPoints(), "" )
.setMaxResults( 1 )
.list();
assertEquals( 1, list.size() );
assertTrue( s.isReadOnly( list.get( 0 ) ) );
list = ( List ) s.createFilter( c.getNonLazySelectDataPoints(), "" )
list = s.createFilter( c.getNonLazySelectDataPoints(), "" )
.setMaxResults( 1 )
.list();
assertEquals( 1, list.size() );
@ -1308,17 +1308,17 @@ public class ReadOnlySessionLazyNonLazyTest extends AbstractReadOnlyTest {
)
);
expectedReadOnlyObjects = new HashSet();
List list = ( List ) s.createFilter( c.getLazyDataPoints(), "" )
List list = s.createFilter( c.getLazyDataPoints(), "" )
.setMaxResults( 1 )
.list();
assertEquals( 1, list.size() );
assertFalse( s.isReadOnly( list.get( 0 ) ) );
list = ( List ) s.createFilter( c.getNonLazyJoinDataPoints(), "" )
list = s.createFilter( c.getNonLazyJoinDataPoints(), "" )
.setMaxResults( 1 )
.list();
assertEquals( 1, list.size() );
assertFalse( s.isReadOnly( list.get( 0 ) ) );
list = ( List ) s.createFilter( c.getNonLazySelectDataPoints(), "" )
list = s.createFilter( c.getNonLazySelectDataPoints(), "" )
.setMaxResults( 1 )
.list();
assertEquals( 1, list.size() );

View File

@ -35,7 +35,7 @@ import org.hibernate.mapping.Table;
*/
public abstract class SchemaUtil {
public static boolean isColumnPresent(String tableName, String columnName, Configuration cfg) {
final Iterator<Table> tables = ( Iterator<Table> ) cfg.getTableMappings();
final Iterator<Table> tables = cfg.getTableMappings();
while (tables.hasNext()) {
Table table = tables.next();
if (tableName.equals( table.getName() ) ) {
@ -52,7 +52,7 @@ public abstract class SchemaUtil {
}
public static boolean isTablePresent(String tableName, Configuration cfg) {
final Iterator<Table> tables = ( Iterator<Table> ) cfg.getTableMappings();
final Iterator<Table> tables = cfg.getTableMappings();
while (tables.hasNext()) {
Table table = tables.next();
if (tableName.equals( table.getName() ) ) {

View File

@ -112,7 +112,7 @@ public class EhcacheHibernateMBeanRegistrationImpl
exception
);
}
status = status.STATUS_ALIVE;
status = Status.STATUS_ALIVE;
}
private MBeanServer getMBeanServer() {

View File

@ -104,14 +104,15 @@ public class HibernatePersistenceProvider implements PersistenceProvider {
}
private final ProviderUtil providerUtil = new ProviderUtil() {
@Override
public LoadState isLoadedWithoutReference(Object proxy, String property) {
return PersistenceUtilHelper.isLoadedWithoutReference( proxy, property, cache );
}
@Override
public LoadState isLoadedWithReference(Object proxy, String property) {
return PersistenceUtilHelper.isLoadedWithReference( proxy, property, cache );
}
@Override
public LoadState isLoaded(Object o) {
return PersistenceUtilHelper.isLoaded(o);
}

View File

@ -53,8 +53,7 @@ public class PluralAttributePath<X> extends AbstractPathImpl<X> implements Seria
}
private static CollectionPersister resolvePersister(CriteriaBuilderImpl criteriaBuilder, PluralAttribute attribute) {
SessionFactoryImplementor sfi = (SessionFactoryImplementor)
criteriaBuilder.getEntityManagerFactory().getSessionFactory();
SessionFactoryImplementor sfi = criteriaBuilder.getEntityManagerFactory().getSessionFactory();
return sfi.getCollectionPersister( resolveRole( attribute ) );
}

View File

@ -159,6 +159,5 @@ public class CallbackProcessorImpl implements CallbackProcessor {
@Override
public void release() {
//To change body of implemented methods use File | Settings | File Templates.
}
}

View File

@ -51,11 +51,11 @@ public class InterceptFieldClassFileTransformer implements javax.persistence.spi
},
//TODO change it to a static class to make it faster?
new FieldFilter() {
@Override
public boolean shouldInstrumentField(String className, String fieldName) {
return true;
}
@Override
public boolean shouldTransformFieldAccess(
String transformingClassName, String fieldOwnerClassName, String fieldName
) {
@ -64,7 +64,7 @@ public class InterceptFieldClassFileTransformer implements javax.persistence.spi
}
);
}
@Override
public byte[] transform(
ClassLoader loader,
String className,

View File

@ -55,7 +55,7 @@ public class PersistenceUtilHelper {
//it's ours so we know it's loaded
if (state == LoadState.UNKNOWN) state = LoadState.LOADED;
}
else if ( interceptor != null && (! isInitialized)) {
else if ( interceptor != null ) {
state = LoadState.NOT_LOADED;
}
else if ( sureFromUs ) { //interceptor == null

View File

@ -58,7 +58,7 @@ public final class XmlHelper {
Node currentChild = children.item( i );
if ( currentChild.getNodeType() == Node.ELEMENT_NODE &&
( (Element) currentChild ).getTagName().equals( tagName ) ) {
goodChildren.add( (Element) currentChild );
goodChildren.add( currentChild );
}
}
return goodChildren.iterator();

View File

@ -1 +1 @@
org.hibernate.ejb.HibernatePersistence
org.hibernate.jpa.HibernatePersistenceProvider

View File

@ -97,7 +97,7 @@ public class CallbackAndDirtyTest extends BaseEntityManagerFunctionalTestCase {
manager.getTransaction().begin();
mark = manager.find( Employee.class, new Long( ids[0] ) );
joe = (Customer) manager.find( Customer.class, new Long( ids[1] ) );
joe = manager.find( Customer.class, new Long( ids[1] ) );
yomomma = manager.find( Person.class, new Long( ids[2] ) );
mark.setZip( "30306" );

View File

@ -35,7 +35,7 @@ public class LockTimeoutPropertyTest extends BaseEntityManagerFunctionalTestCase
em.getTransaction().begin();
Query query = em.createNamedQuery( "getAll" );
query.setLockMode( LockModeType.PESSIMISTIC_READ );
int timeout = ((QueryImpl)(((org.hibernate.jpa.internal.QueryImpl)query).getHibernateQuery())).getLockOptions().getTimeOut();
int timeout = ((org.hibernate.jpa.internal.QueryImpl)query).getHibernateQuery().getLockOptions().getTimeOut();
assertEquals( 3000, timeout );
}
@ -50,14 +50,14 @@ public class LockTimeoutPropertyTest extends BaseEntityManagerFunctionalTestCase
int timeout = Integer.valueOf( em.getProperties().get( AvailableSettings.LOCK_TIMEOUT ).toString() );
assertEquals( 2000, timeout);
org.hibernate.jpa.internal.QueryImpl q = (org.hibernate.jpa.internal.QueryImpl) em.createQuery( "select u from UnversionedLock u" );
timeout = ((QueryImpl)q.getHibernateQuery()).getLockOptions().getTimeOut();
timeout = q.getHibernateQuery().getLockOptions().getTimeOut();
assertEquals( 2000, timeout );
Query query = em.createQuery( "select u from UnversionedLock u" );
query.setLockMode(LockModeType.PESSIMISTIC_WRITE);
query.setHint( AvailableSettings.LOCK_TIMEOUT, 3000 );
q = (org.hibernate.jpa.internal.QueryImpl)query;
timeout = ((QueryImpl)q.getHibernateQuery()).getLockOptions().getTimeOut();
timeout = q.getHibernateQuery().getLockOptions().getTimeOut();
assertEquals( 3000, timeout );
em.getTransaction().rollback();
em.close();

View File

@ -71,6 +71,6 @@ public class PersistentClassGraphDefiner implements GraphDefiner<PersistentClass
@SuppressWarnings({"unchecked"})
public List<PersistentClass> getValues() {
return Tools.iteratorToList((Iterator<PersistentClass>) cfg.getClassMappings());
return Tools.iteratorToList( cfg.getClassMappings() );
}
}

View File

@ -249,7 +249,7 @@ public class RevisionInfoConfiguration {
}
public RevisionInfoConfigurationResult configure(Configuration cfg, ReflectionManager reflectionManager) {
Iterator<PersistentClass> classes = (Iterator<PersistentClass>) cfg.getClassMappings();
Iterator<PersistentClass> classes = cfg.getClassMappings();
boolean revisionEntityFound = false;
RevisionInfoGenerator revisionInfoGenerator = null;

View File

@ -212,7 +212,7 @@ public class AuditedPropertiesReader {
private void readPersistentPropertiesAccess() {
Iterator<Property> propertyIter = persistentPropertiesSource.getPropertyIterator();
while (propertyIter.hasNext()) {
Property property = (Property) propertyIter.next();
Property property = propertyIter.next();
addPersistentProperty(property);
if ("embedded".equals(property.getPropertyAccessorName()) && property.getName().equals(property.getNodeName())) {
// If property name equals node name and embedded accessor type is used, processing component
@ -319,7 +319,7 @@ public class AuditedPropertiesReader {
// Marking component properties as placed directly in class (not inside another component).
componentData.setBeanName(null);
PersistentPropertiesSource componentPropertiesSource = new ComponentPropertiesSource((Component) propertyValue);
PersistentPropertiesSource componentPropertiesSource = new ComponentPropertiesSource( propertyValue );
AuditedPropertiesReader audPropReader = new AuditedPropertiesReader(
ModificationStore.FULL, componentPropertiesSource, componentData, globalCfg, reflectionManager,
propertyNamePrefix + MappingTools.createComponentPrefix(embeddedName)
@ -338,7 +338,8 @@ public class AuditedPropertiesReader {
allClassAudited);
PersistentPropertiesSource componentPropertiesSource = new ComponentPropertiesSource(
(Component) propertyValue);
propertyValue
);
ComponentAuditedPropertiesReader audPropReader = new ComponentAuditedPropertiesReader(
ModificationStore.FULL, componentPropertiesSource,

View File

@ -53,7 +53,7 @@ public class PrimitiveTestEntity {
public PrimitiveTestEntity(Integer id, int numVal1, int number2) {
this.id = id;
this.numVal1 = numVal1;
this.numVal2 = numVal2;
this.numVal2 = number2;
}
public Integer getId() {

View File

@ -50,7 +50,7 @@ public class DateTestEntity {
public DateTestEntity(Integer id, Date date) {
this.id = id;
this.dateValue = dateValue;
this.dateValue = date;
}
public Integer getId() {

View File

@ -159,10 +159,10 @@ public class RevisionConstraintQuery extends BaseEnversJPAFunctionalTestCase {
.add(AuditEntity.id().eq(id1))
.getSingleResult();
Assert.assertEquals(Integer.valueOf(4), (Integer) result[0]);
Assert.assertEquals(Long.valueOf(4), (Long) result[1]);
Assert.assertEquals(Integer.valueOf(4), result[0] );
Assert.assertEquals(Long.valueOf(4), result[1] );
Assert.assertEquals(Long.valueOf(4), result[2]);
Assert.assertEquals(Integer.valueOf(1), (Integer) result[3]);
Assert.assertEquals(Integer.valueOf(1), result[3] );
}
@Test
@ -186,7 +186,7 @@ public class RevisionConstraintQuery extends BaseEnversJPAFunctionalTestCase {
.add(AuditEntity.id().eq(id1))
.getSingleResult();
Assert.assertEquals(Long.valueOf(4), (Long) result);
Assert.assertEquals(Long.valueOf(4), result );
}
@Test

View File

@ -364,7 +364,7 @@ public class EntityCollectionInvalidationTestCase extends DualNodeTestCase {
if ( !event.isPre() ) {
CacheKey cacheKey = (CacheKey) event.getKey();
Integer primKey = (Integer) cacheKey.getKey();
String key = (String) cacheKey.getEntityOrRoleName() + '#' + primKey;
String key = cacheKey.getEntityOrRoleName() + '#' + primKey;
log.debug( "MyListener[" + name + "] - Visiting key " + key );
// String name = fqn.toString();
String token = ".functional.";