Skip to content
Browse files

simple improvement and code format

  • Loading branch information...
1 parent ceb9609 commit ada2a5327e6cc4433424b3c812791eaf867fd249 @stliu stliu committed Dec 24, 2012
View
10 hibernate-core/src/main/java/org/hibernate/dialect/function/SQLFunctionRegistry.java
@@ -22,6 +22,7 @@
* Boston, MA 02110-1301 USA
*/
package org.hibernate.dialect.function;
+
import java.util.HashMap;
import java.util.Map;
@@ -30,19 +31,18 @@
public class SQLFunctionRegistry {
private final Dialect dialect;
private final Map<String, SQLFunction> userFunctions;
-
+
public SQLFunctionRegistry(Dialect dialect, Map<String, SQLFunction> userFunctions) {
this.dialect = dialect;
- this.userFunctions = new HashMap<String, SQLFunction>();
- this.userFunctions.putAll( userFunctions );
+ this.userFunctions = new HashMap<String, SQLFunction>( userFunctions );
}
-
+
public SQLFunction findSQLFunction(String functionName) {
String name = functionName.toLowerCase();
SQLFunction userFunction = userFunctions.get( name );
return userFunction != null
? userFunction
- : (SQLFunction) dialect.getFunctions().get( name );
+ : dialect.getFunctions().get( name );
}
public boolean hasFunction(String functionName) {
View
3 hibernate-core/src/main/java/org/hibernate/id/uuid/CustomVersionOneStrategy.java
@@ -39,6 +39,7 @@
* @author Steve Ebersole
*/
public class CustomVersionOneStrategy implements UUIDGenerationStrategy {
+ @Override
public int getGeneratedVersion() {
return 1;
}
@@ -58,7 +59,7 @@ public CustomVersionOneStrategy() {
mostSignificantBits = BytesHelper.asLong( hiBits );
}
-
+ @Override
public UUID generateUUID(SessionImplementor session) {
long leastSignificantBits = generateLeastSignificantBits( System.currentTimeMillis() );
return new UUID( mostSignificantBits, leastSignificantBits );
View
2 hibernate-core/src/main/java/org/hibernate/id/uuid/StandardRandomStrategy.java
@@ -38,6 +38,7 @@
/**
* A variant 4 (random) strategy
*/
+ @Override
public int getGeneratedVersion() {
// a "random" strategy
return 4;
@@ -46,6 +47,7 @@ public int getGeneratedVersion() {
/**
* Delegates to {@link UUID#randomUUID()}
*/
+ @Override
public UUID generateUUID(SessionImplementor session) {
return UUID.randomUUID();
}
View
2 ...te-core/src/main/java/org/hibernate/persister/collection/AbstractCollectionPersister.java
@@ -625,7 +625,7 @@ else if ( !elementType.isEntityType() ) {
if ( columnName == null ) {
// if the column name is null, it indicates that this index in the property value mapping is
// actually represented by a formula.
- final int propertyIndex = elementPersister.getEntityMetamodel().getPropertyIndex( reference );
+// final int propertyIndex = elementPersister.getEntityMetamodel().getPropertyIndex( reference );
final String formulaTemplate = formulaTemplates[i];
result[i] = new FormulaReference() {
@Override
View
2 hibernate-core/src/main/java/org/hibernate/persister/entity/AbstractEntityPersister.java
@@ -866,7 +866,7 @@ public AbstractEntityPersister(
}
else {
rootTableKeyColumnReaders[i] = col.getReadFragment();
- rootTableKeyColumnReaderTemplates[i] = getTemplateFromString( col.getReadFragment(), factory );
+ rootTableKeyColumnReaderTemplates[i] = getTemplateFromString( rootTableKeyColumnReaders[i], factory );
}
identifierAliases[i] = col.getAlias( factory.getDialect() );
i++;
View
30 hibernate-core/src/main/java/org/hibernate/sql/Template.java
@@ -119,7 +119,12 @@ public static String renderWhereStringTemplate(String sqlWhereString, Dialect di
@Deprecated
@SuppressWarnings({ "JavaDoc" })
public static String renderWhereStringTemplate(String sqlWhereString, String placeholder, Dialect dialect) {
- return renderWhereStringTemplate( sqlWhereString, placeholder, dialect, new SQLFunctionRegistry( dialect, java.util.Collections.EMPTY_MAP ) );
+ return renderWhereStringTemplate(
+ sqlWhereString,
+ placeholder,
+ dialect,
+ new SQLFunctionRegistry( dialect, java.util.Collections.<String, SQLFunction>emptyMap() )
+ );
}
/**
@@ -302,7 +307,7 @@ else if ( afterFromTable ) {
else if ( isNamedParameter(token) ) {
result.append(token);
}
- else if ( isIdentifier(token, dialect)
+ else if ( isIdentifier(token)
&& !isFunctionOrKeyword(lcToken, nextToken, dialect , functionRegistry) ) {
result.append(placeholder)
.append('.')
@@ -569,31 +574,32 @@ else if ( inFromClause && ",".equals(lcToken) ) {
private final String trimSource;
private TrimOperands(List<String> operands) {
- if ( operands.size() == 1 ) {
+ final int size = operands.size();
+ if ( size == 1 ) {
trimSpec = null;
trimChar = null;
from = null;
trimSource = operands.get(0);
}
- else if ( operands.size() == 4 ) {
+ else if ( size == 4 ) {
trimSpec = operands.get(0);
trimChar = operands.get(1);
from = operands.get(2);
trimSource = operands.get(3);
}
else {
- if ( operands.size() < 1 || operands.size() > 4 ) {
- throw new HibernateException( "Unexpected number of trim function operands : " + operands.size() );
+ if ( size < 1 || size > 4 ) {
+ throw new HibernateException( "Unexpected number of trim function operands : " + size );
}
// trim-source will always be the last operand
- trimSource = operands.get( operands.size() - 1 );
+ trimSource = operands.get( size - 1 );
// ANSI SQL says that more than one operand means that the FROM is required
- if ( ! "from".equals( operands.get( operands.size() - 2 ) ) ) {
- throw new HibernateException( "Expecting FROM, found : " + operands.get( operands.size() - 2 ) );
+ if ( ! "from".equals( operands.get( size - 2 ) ) ) {
+ throw new HibernateException( "Expecting FROM, found : " + operands.get( size - 2 ) );
}
- from = operands.get( operands.size() - 2 );
+ from = operands.get( size - 2 );
// trim-spec, if there is one will always be the first operand
if ( "leading".equalsIgnoreCase( operands.get(0) )
@@ -604,7 +610,7 @@ else if ( operands.size() == 4 ) {
}
else {
trimSpec = null;
- if ( operands.size() - 2 == 0 ) {
+ if ( size - 2 == 0 ) {
trimChar = null;
}
else {
@@ -749,7 +755,7 @@ private static boolean isFunction(String lcToken, String nextToken, SQLFunctionR
return ! function.hasParenthesesIfNoArguments();
}
- private static boolean isIdentifier(String token, Dialect dialect) {
+ private static boolean isIdentifier(String token) {
return token.charAt(0)=='`' || ( //allow any identifier quoted with backtick
Character.isLetter( token.charAt(0) ) && //only recognizes identifiers beginning with a letter
token.indexOf('.') < 0

0 comments on commit ada2a53

Please sign in to comment.
Something went wrong with that request. Please try again.