Author: d.plentz
Date: 2007-07-25 22:12:05 -0400 (Wed, 25 Jul 2007)
New Revision: 12822
Modified:
trunk/HibernateExt/annotations/src/java/org/hibernate/annotations/SQLDeleteAll.java
trunk/HibernateExt/annotations/src/java/org/hibernate/cfg/AnnotationBinder.java
trunk/HibernateExt/annotations/src/java/org/hibernate/cfg/AnnotationConfiguration.java
trunk/HibernateExt/annotations/src/java/org/hibernate/cfg/PropertyHolderBuilder.java
trunk/HibernateExt/annotations/src/java/org/hibernate/type/EnumType.java
Log:
Just some code cleanup.
Modified:
trunk/HibernateExt/annotations/src/java/org/hibernate/annotations/SQLDeleteAll.java
===================================================================
---
trunk/HibernateExt/annotations/src/java/org/hibernate/annotations/SQLDeleteAll.java 2007-07-26
01:32:22 UTC (rev 12821)
+++
trunk/HibernateExt/annotations/src/java/org/hibernate/annotations/SQLDeleteAll.java 2007-07-26
02:12:05 UTC (rev 12822)
@@ -1,14 +1,14 @@
//$Id: $
package org.hibernate.annotations;
-import java.lang.annotation.Target;
-import java.lang.annotation.Retention;
-import java.lang.annotation.ElementType;
-import java.lang.annotation.RetentionPolicy;
-import static java.lang.annotation.ElementType.TYPE;
import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.TYPE;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
/**
* SqlDelete Annotation for overwriting Hibernate default DELETE ALL method
*
Modified: trunk/HibernateExt/annotations/src/java/org/hibernate/cfg/AnnotationBinder.java
===================================================================
---
trunk/HibernateExt/annotations/src/java/org/hibernate/cfg/AnnotationBinder.java 2007-07-26
01:32:22 UTC (rev 12821)
+++
trunk/HibernateExt/annotations/src/java/org/hibernate/cfg/AnnotationBinder.java 2007-07-26
02:12:05 UTC (rev 12822)
@@ -475,7 +475,6 @@
}
if ( InheritanceType.SINGLE_TABLE.equals( inheritanceState.type ) ) {
- javax.persistence.Inheritance inhAnn = annotatedClass.getAnnotation(
javax.persistence.Inheritance.class );
javax.persistence.DiscriminatorColumn discAnn = annotatedClass.getAnnotation(
javax.persistence.DiscriminatorColumn.class
);
@@ -1587,8 +1586,8 @@
else {
//define whether the type is a component or not
boolean isComponent = false;
- Embeddable embeddableAnn = (Embeddable) returnedClass.getAnnotation( Embeddable.class
);
- Embedded embeddedAnn = (Embedded) property.getAnnotation( Embedded.class );
+ Embeddable embeddableAnn = returnedClass.getAnnotation( Embeddable.class );
+ Embedded embeddedAnn = property.getAnnotation( Embedded.class );
isComponent = embeddedAnn != null || embeddableAnn != null;
if ( isComponent ) {
Modified:
trunk/HibernateExt/annotations/src/java/org/hibernate/cfg/AnnotationConfiguration.java
===================================================================
---
trunk/HibernateExt/annotations/src/java/org/hibernate/cfg/AnnotationConfiguration.java 2007-07-26
01:32:22 UTC (rev 12821)
+++
trunk/HibernateExt/annotations/src/java/org/hibernate/cfg/AnnotationConfiguration.java 2007-07-26
02:12:05 UTC (rev 12822)
@@ -20,6 +20,7 @@
import java.util.SortedSet;
import java.util.StringTokenizer;
import java.util.TreeSet;
+
import javax.persistence.Entity;
import javax.persistence.MappedSuperclass;
@@ -317,7 +318,7 @@
}
super.secondPassCompile();
inSecondPass = false;
- Iterator tables = (Iterator<Map.Entry<Table, List<String[]>>>)
tableUniqueConstraints.entrySet().iterator();
+ Iterator tables = tableUniqueConstraints.entrySet().iterator();
Table table;
Map.Entry entry;
String keyName;
Modified:
trunk/HibernateExt/annotations/src/java/org/hibernate/cfg/PropertyHolderBuilder.java
===================================================================
---
trunk/HibernateExt/annotations/src/java/org/hibernate/cfg/PropertyHolderBuilder.java 2007-07-26
01:32:22 UTC (rev 12821)
+++
trunk/HibernateExt/annotations/src/java/org/hibernate/cfg/PropertyHolderBuilder.java 2007-07-26
02:12:05 UTC (rev 12822)
@@ -27,7 +27,7 @@
//Map<String, Join> joins,
ExtendedMappings mappings
) {
- return (PropertyHolder) new ClassPropertyHolder( persistentClass, clazzToProcess,
entityBinder, mappings );
+ return new ClassPropertyHolder( persistentClass, clazzToProcess, entityBinder, mappings
);
}
/**
@@ -42,7 +42,7 @@
Component component, String path, PropertyData inferredData, PropertyHolder parent,
ExtendedMappings mappings
) {
- return (PropertyHolder) new ComponentPropertyHolder( component, path, inferredData,
parent, mappings );
+ return new ComponentPropertyHolder( component, path, inferredData, parent, mappings );
}
/**
@@ -62,6 +62,6 @@
PersistentClass persistentClass, Map<String, Join> joins,
ExtendedMappings mappings
) {
- return (PropertyHolder) new ClassPropertyHolder( persistentClass, null, joins, mappings
);
+ return new ClassPropertyHolder( persistentClass, null, joins, mappings );
}
}
Modified: trunk/HibernateExt/annotations/src/java/org/hibernate/type/EnumType.java
===================================================================
--- trunk/HibernateExt/annotations/src/java/org/hibernate/type/EnumType.java 2007-07-26
01:32:22 UTC (rev 12821)
+++ trunk/HibernateExt/annotations/src/java/org/hibernate/type/EnumType.java 2007-07-26
02:12:05 UTC (rev 12822)
@@ -5,7 +5,6 @@
import java.io.ObjectInputStream;
import java.io.Serializable;
import java.lang.reflect.Method;
-import java.sql.DatabaseMetaData;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
@@ -131,115 +130,6 @@
}
}
- //TODO remove
- private void guessType(PreparedStatement statement, int index) {
- //TODO use SQLException wrapper?
- if ( ! guessed ) {
- try {
- sqlType = guessTypeFromMetaData( statement.getConnection().getMetaData() );
- }
- catch (SQLException e) {
- sqlType = guessTypeByParameter( statement, index, e );
- }
- catch (HibernateException e) {
- sqlType = guessTypeByParameter( statement, index, e );
- }
- guessed = true;
- }
- }
-
- //TODO remove
- private int guessTypeFromMetaData(DatabaseMetaData metadata) throws SQLException {
- ResultSet rs = null;
- try {
- String username = metadata.getUserName();
- int guessedType = Types.NULL;
- int numResults = 0;
- boolean nonNullType = false;
-
- // Try to find the column information up to three times. First with values as is in
case
- // the database ever stores mixed case identifiers, or the supplied identifiers match
- // perfectly. Then if the metadata is not found, try using lower and upper case
- // identifiers - but only if the datbaase reports it would use them.
- rs = metadata.getColumns( catalog, schema, table, column );
-
- boolean isValid;
-
- isValid = rs.next();
-
- if ( ! isValid && metadata.storesLowerCaseIdentifiers() ) {
- rs.close();
- rs = metadata.getColumns(
- catalog == null ? catalog : catalog.toLowerCase(),
- schema == null ? schema : schema.toLowerCase(),
- table.toLowerCase(), column.toLowerCase()
- );
- isValid = rs.next();
- }
-
- if ( ! isValid && metadata.storesUpperCaseIdentifiers() ) {
- rs.close();
- rs = metadata.getColumns(
- catalog == null ? catalog : catalog.toUpperCase(),
- schema == null ? schema : schema.toUpperCase(),
- table.toUpperCase(), column.toUpperCase()
- );
- isValid = rs.next();
- }
-
- // try to find
- while ( isValid ) {
- guessedType = rs.getInt( "DATA_TYPE" );
- if ( rs.wasNull() ) {
- continue; // TODO throw exception?
- }
- else {
- nonNullType = true;
- }
-
- numResults++;
- if ( username != null ) {
- String schema = rs.getString( "TABLE_SCHEM" );
- // if the username matches the schema, there's no better guess available...
- if ( username.equalsIgnoreCase( schema ) ) return guessedType;
- }
- else if ( numResults > 1 ) {
- // if there's no username and multiple results, there's no point in
continuing
- throw new HibernateException( "Several columns matching in metadata: " +
column );
- }
- isValid = rs.next();
- }
- if ( numResults == 0 ) throw new HibernateException( "Enum type column not found
in metadata: " + column );
- if ( numResults > 1 ) throw new HibernateException( "Several columns matching
in metadata: " + column );
- if ( !nonNullType ) throw new HibernateException( "Column without type in
metadata!: " + column );
- log.trace( "Enum type guessed from metadata: " + guessedType );
- return guessedType;
- }
- finally {
- try {
- if ( rs != null ) rs.close();
- }
- catch (SQLException e) {
- //swallow in purpose
- }
- }
- }
-
- //TODO remove
- private int guessTypeByParameter(PreparedStatement statement, int index, Exception e) {
- log.debug(
- "Unable to guess the column type for enum through conn.getMetadata(): "
- + e.getMessage()
- );
- try {
- return statement.getParameterMetaData().getParameterType( index );
- }
- catch (SQLException ee) {
- log.warn( "Unable to guess enum type, default to INTEGER", ee );
- return Types.INTEGER;
- }
- }
-
private boolean isOrdinal(int paramType) {
switch ( paramType ) {
case Types.INTEGER: