simple improvement and code format

This commit is contained in:
Strong Liu 2012-12-24 03:10:38 +08:00
parent ceb96094f5
commit ada2a5327e
6 changed files with 29 additions and 20 deletions

View File

@ -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 @@ import org.hibernate.dialect.Dialect;
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 File

@ -39,6 +39,7 @@ import org.hibernate.internal.util.BytesHelper;
* @author Steve Ebersole
*/
public class CustomVersionOneStrategy implements UUIDGenerationStrategy {
@Override
public int getGeneratedVersion() {
return 1;
}
@ -58,7 +59,7 @@ public class CustomVersionOneStrategy implements UUIDGenerationStrategy {
mostSignificantBits = BytesHelper.asLong( hiBits );
}
@Override
public UUID generateUUID(SessionImplementor session) {
long leastSignificantBits = generateLeastSignificantBits( System.currentTimeMillis() );
return new UUID( mostSignificantBits, leastSignificantBits );

View File

@ -38,6 +38,7 @@ public class StandardRandomStrategy implements UUIDGenerationStrategy {
/**
* A variant 4 (random) strategy
*/
@Override
public int getGeneratedVersion() {
// a "random" strategy
return 4;
@ -46,6 +47,7 @@ public class StandardRandomStrategy implements UUIDGenerationStrategy {
/**
* Delegates to {@link UUID#randomUUID()}
*/
@Override
public UUID generateUUID(SessionImplementor session) {
return UUID.randomUUID();
}

View File

@ -625,7 +625,7 @@ public abstract class AbstractCollectionPersister
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 File

@ -866,7 +866,7 @@ public abstract class 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 File

@ -119,7 +119,12 @@ public final class Template {
@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 @@ public final class Template {
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 @@ public final class Template {
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 @@ public final class Template {
}
else {
trimSpec = null;
if ( operands.size() - 2 == 0 ) {
if ( size - 2 == 0 ) {
trimChar = null;
}
else {
@ -749,7 +755,7 @@ public final class Template {
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