Hibernate SVN: r19411 - in core/trunk/core/src: main/java/org/hibernate/sql and 1 other directories.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2010-05-07 16:53:34 -0400 (Fri, 07 May 2010)
New Revision: 19411
Modified:
core/trunk/core/src/main/java/org/hibernate/mapping/Column.java
core/trunk/core/src/main/java/org/hibernate/sql/Template.java
core/trunk/core/src/test/java/org/hibernate/sql/TemplateTest.java
Log:
HHH-5135 - "Ambiguous column" exception thrown with columns having the same name as a function registered with the dialect (e.g. to_date, floor)
Modified: core/trunk/core/src/main/java/org/hibernate/mapping/Column.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/mapping/Column.java 2010-05-07 18:07:24 UTC (rev 19410)
+++ core/trunk/core/src/main/java/org/hibernate/mapping/Column.java 2010-05-07 20:53:34 UTC (rev 19411)
@@ -61,7 +61,8 @@
private String customWrite;
private String customRead;
- public Column() { };
+ public Column() {
+ }
public Column(String columnName) {
setName(columnName);
@@ -262,12 +263,17 @@
}
public String getTemplate(Dialect dialect, SQLFunctionRegistry functionRegistry) {
- String expr = getReadExpr(dialect);
- return Template.renderWhereStringTemplate(expr, dialect, functionRegistry);
+ return hasCustomRead()
+ ? Template.renderWhereStringTemplate( customRead, dialect, functionRegistry )
+ : Template.TEMPLATE + '.' + getQuotedName( dialect );
}
+ public boolean hasCustomRead() {
+ return ( customRead != null && customRead.length() > 0 );
+ }
+
public String getReadExpr(Dialect dialect) {
- return ( customRead != null && customRead.length() > 0 ) ? customRead : getQuotedName(dialect);
+ return hasCustomRead() ? customRead : getQuotedName( dialect );
}
public String getWriteExpr() {
Modified: core/trunk/core/src/main/java/org/hibernate/sql/Template.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/sql/Template.java 2010-05-07 18:07:24 UTC (rev 19410)
+++ core/trunk/core/src/main/java/org/hibernate/sql/Template.java 2010-05-07 20:53:34 UTC (rev 19411)
@@ -24,9 +24,13 @@
*/
package org.hibernate.sql;
+import java.util.ArrayList;
import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
import java.util.StringTokenizer;
+import org.hibernate.HibernateException;
import org.hibernate.dialect.Dialect;
import org.hibernate.dialect.function.SQLFunction;
import org.hibernate.dialect.function.SQLFunctionRegistry;
@@ -43,9 +47,9 @@
*/
public final class Template {
- private static final java.util.Set KEYWORDS = new HashSet();
- private static final java.util.Set BEFORE_TABLE_KEYWORDS = new HashSet();
- private static final java.util.Set FUNCTION_KEYWORDS = new HashSet();
+ private static final Set<String> KEYWORDS = new HashSet<String>();
+ private static final Set<String> BEFORE_TABLE_KEYWORDS = new HashSet<String>();
+ private static final Set<String> FUNCTION_KEYWORDS = new HashSet<String>();
static {
KEYWORDS.add("and");
KEYWORDS.add("or");
@@ -109,13 +113,14 @@
*
* @deprecated Only intended for annotations usage; use {@link #renderWhereStringTemplate(String, String, Dialect, SQLFunctionRegistry)} instead
*/
+ @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 ) );
}
/**
- * Takes the where condition provided in the mapping attribute and interpolates the alias.
- * Handles subselects, quoted identifiers, quoted strings, expressions, SQL functions,
+ * Takes the where condition provided in the mapping attribute and interpolates the alias.
+ * Handles sub-selects, quoted identifiers, quoted strings, expressions, SQL functions,
* named parameters.
*
* @param sqlWhereString The string into which to interpolate the placeholder value
@@ -125,51 +130,55 @@
* @return The rendered sql fragment
*/
public static String renderWhereStringTemplate(String sqlWhereString, String placeholder, Dialect dialect, SQLFunctionRegistry functionRegistry ) {
- //TODO: make this a bit nicer
+
+ // IMPL NOTE : The basic process here is to tokenize the incoming string and to iterate over each token
+ // in turn. As we process each token, we set a series of flags used to indicate the type of context in
+ // which the tokens occur. Depending on the state of those flags we decide whether we need to qualify
+ // identifier references.
+
String symbols = new StringBuffer()
- .append("=><!+-*/()',|&`")
- .append(StringHelper.WHITESPACE)
- .append( dialect.openQuote() )
- .append( dialect.closeQuote() )
- .toString();
- StringTokenizer tokens = new StringTokenizer(sqlWhereString, symbols, true);
-
+ .append( "=><!+-*/()',|&`" )
+ .append( StringHelper.WHITESPACE )
+ .append( dialect.openQuote() )
+ .append( dialect.closeQuote() )
+ .toString();
+ StringTokenizer tokens = new StringTokenizer( sqlWhereString, symbols, true );
StringBuffer result = new StringBuffer();
+
boolean quoted = false;
boolean quotedIdentifier = false;
boolean beforeTable = false;
boolean inFromClause = false;
boolean afterFromTable = false;
-
+
boolean hasMore = tokens.hasMoreTokens();
String nextToken = hasMore ? tokens.nextToken() : null;
- while (hasMore) {
+ while ( hasMore ) {
String token = nextToken;
String lcToken = token.toLowerCase();
hasMore = tokens.hasMoreTokens();
nextToken = hasMore ? tokens.nextToken() : null;
-
+
boolean isQuoteCharacter = false;
-
+
if ( !quotedIdentifier && "'".equals(token) ) {
quoted = !quoted;
isQuoteCharacter = true;
}
-
+
if ( !quoted ) {
-
boolean isOpenQuote;
if ( "`".equals(token) ) {
isOpenQuote = !quotedIdentifier;
- token = lcToken = isOpenQuote ?
- new Character( dialect.openQuote() ).toString() :
- new Character( dialect.closeQuote() ).toString();
- quotedIdentifier = isOpenQuote;
+ token = lcToken = isOpenQuote
+ ? Character.toString( dialect.openQuote() )
+ : Character.toString( dialect.closeQuote() );
+ quotedIdentifier = isOpenQuote;
isQuoteCharacter = true;
}
else if ( !quotedIdentifier && ( dialect.openQuote()==token.charAt(0) ) ) {
isOpenQuote = true;
- quotedIdentifier = true;
+ quotedIdentifier = true;
isQuoteCharacter = true;
}
else if ( quotedIdentifier && ( dialect.closeQuote()==token.charAt(0) ) ) {
@@ -180,40 +189,120 @@
else {
isOpenQuote = false;
}
-
- if (isOpenQuote) {
- result.append(placeholder).append('.');
+
+ if ( isOpenQuote ) {
+ result.append( placeholder ).append( '.' );
}
-
}
-
- boolean quotedOrWhitespace = quoted ||
- quotedIdentifier ||
- isQuoteCharacter ||
- Character.isWhitespace( token.charAt(0) );
-
- if (quotedOrWhitespace) {
- result.append(token);
+
+ // Special processing for ANSI SQL EXTRACT function
+ if ( "extract".equals( lcToken ) && "(".equals( nextToken ) ) {
+ final String field = extractUntil( tokens, "from" );
+ final String source = renderWhereStringTemplate(
+ extractUntil( tokens, ")" ),
+ placeholder,
+ dialect,
+ functionRegistry
+ );
+ result.append( "extract(" ).append( field ).append( " from " ).append( source ).append( ')' );
+
+ hasMore = tokens.hasMoreTokens();
+ nextToken = hasMore ? tokens.nextToken() : null;
+
+ continue;
}
- else if (beforeTable) {
- result.append(token);
+
+ // Special processing for ANSI SQL TRIM function
+ if ( "trim".equals( lcToken ) && "(".equals( nextToken ) ) {
+ List<String> operands = new ArrayList<String>();
+ StringBuilder builder = new StringBuilder();
+
+ boolean hasMoreOperands = true;
+ String operandToken = tokens.nextToken();
+ boolean quotedOperand = false;
+ while ( hasMoreOperands ) {
+ final boolean isQuote = "'".equals( operandToken );
+ if ( isQuote ) {
+ quotedOperand = !quotedOperand;
+ if ( !quotedOperand ) {
+ operands.add( builder.append( '\'' ).toString() );
+ builder.setLength( 0 );
+ }
+ else {
+ builder.append( '\'' );
+ }
+ }
+ else if ( quotedOperand ) {
+ builder.append( operandToken );
+ }
+ else if ( operandToken.length() == 1 && Character.isWhitespace( operandToken.charAt( 0 ) ) ) {
+ // do nothing
+ }
+ else {
+ operands.add( operandToken );
+ }
+ operandToken = tokens.nextToken();
+ hasMoreOperands = tokens.hasMoreTokens() && ! ")".equals( operandToken );
+ }
+
+ TrimOperands trimOperands = new TrimOperands( operands );
+ result.append( "trim(" );
+ if ( trimOperands.trimSpec != null ) {
+ result.append( trimOperands.trimSpec ).append( ' ' );
+ }
+ if ( trimOperands.trimChar != null ) {
+ if ( trimOperands.trimChar.startsWith( "'" ) && trimOperands.trimChar.endsWith( "'" ) ) {
+ result.append( trimOperands.trimChar );
+ }
+ else {
+ result.append(
+ renderWhereStringTemplate( trimOperands.trimSpec, placeholder, dialect, functionRegistry )
+ );
+ }
+ result.append( ' ' );
+ }
+ if ( trimOperands.from != null ) {
+ result.append( trimOperands.from ).append( ' ' );
+ }
+ else if ( trimOperands.trimSpec != null || trimOperands.trimChar != null ) {
+ // I think ANSI SQL says that the 'from' is not optional if either trim-spec or trim-char are specified
+ result.append( "from " );
+ }
+
+ result.append( renderWhereStringTemplate( trimOperands.trimSource, placeholder, dialect, functionRegistry ) )
+ .append( ')' );
+
+ hasMore = tokens.hasMoreTokens();
+ nextToken = hasMore ? tokens.nextToken() : null;
+
+ continue;
+ }
+
+ boolean quotedOrWhitespace = quoted || quotedIdentifier || isQuoteCharacter
+ || Character.isWhitespace( token.charAt(0) );
+
+ if ( quotedOrWhitespace ) {
+ result.append( token );
+ }
+ else if ( beforeTable ) {
+ result.append( token );
beforeTable = false;
afterFromTable = true;
}
- else if (afterFromTable) {
- if ( !"as".equals(lcToken) ) afterFromTable = false;
+ else if ( afterFromTable ) {
+ if ( !"as".equals(lcToken) ) {
+ afterFromTable = false;
+ }
result.append(token);
}
else if ( isNamedParameter(token) ) {
result.append(token);
}
- else if (
- isIdentifier(token, dialect) &&
- !isFunctionOrKeyword(lcToken, nextToken, dialect , functionRegistry)
- ) {
+ else if ( isIdentifier(token, dialect)
+ && !isFunctionOrKeyword(lcToken, nextToken, dialect , functionRegistry) ) {
result.append(placeholder)
- .append('.')
- .append( dialect.quote(token) );
+ .append('.')
+ .append( dialect.quote(token) );
}
else {
if ( BEFORE_TABLE_KEYWORDS.contains(lcToken) ) {
@@ -225,19 +314,313 @@
}
result.append(token);
}
-
- if ( //Yuck:
- inFromClause &&
- KEYWORDS.contains(lcToken) && //"as" is not in KEYWORDS
- !BEFORE_TABLE_KEYWORDS.contains(lcToken)
- ) {
+
+ //Yuck:
+ if ( inFromClause
+ && KEYWORDS.contains( lcToken ) //"as" is not in KEYWORDS
+ && !BEFORE_TABLE_KEYWORDS.contains( lcToken ) ) {
inFromClause = false;
}
+ }
- }
return result.toString();
}
+// /**
+// * Takes the where condition provided in the mapping attribute and interpolates the alias.
+// * Handles sub-selects, quoted identifiers, quoted strings, expressions, SQL functions,
+// * named parameters.
+// *
+// * @param sqlWhereString The string into which to interpolate the placeholder value
+// * @param placeholder The value to be interpolated into the the sqlWhereString
+// * @param dialect The dialect to apply
+// * @param functionRegistry The registry of all sql functions
+// *
+// * @return The rendered sql fragment
+// */
+// public static String renderWhereStringTemplate(
+// String sqlWhereString,
+// String placeholder,
+// Dialect dialect,
+// SQLFunctionRegistry functionRegistry) {
+//
+// // IMPL NOTE : The basic process here is to tokenize the incoming string and to iterate over each token
+// // in turn. As we process each token, we set a series of flags used to indicate the type of context in
+// // which the tokens occur. Depending on the state of those flags we decide whether we need to qualify
+// // identifier references.
+//
+// final String dialectOpenQuote = Character.toString( dialect.openQuote() );
+// final String dialectCloseQuote = Character.toString( dialect.closeQuote() );
+//
+// String symbols = new StringBuilder()
+// .append( "=><!+-*/()',|&`" )
+// .append( StringHelper.WHITESPACE )
+// .append( dialect.openQuote() )
+// .append( dialect.closeQuote() )
+// .toString();
+// StringTokenizer tokens = new StringTokenizer( sqlWhereString, symbols, true );
+// ProcessingState state = new ProcessingState();
+//
+// StringBuilder quotedBuffer = new StringBuilder();
+// StringBuilder result = new StringBuilder();
+//
+// boolean hasMore = tokens.hasMoreTokens();
+// String nextToken = hasMore ? tokens.nextToken() : null;
+// while ( hasMore ) {
+// String token = nextToken;
+// String lcToken = token.toLowerCase();
+// hasMore = tokens.hasMoreTokens();
+// nextToken = hasMore ? tokens.nextToken() : null;
+//
+// // First, determine quoting which might be based on either:
+// // 1) back-tick
+// // 2) single quote (ANSI SQL standard)
+// // 3) or dialect defined quote character(s)
+// QuotingCharacterDisposition quotingCharacterDisposition = QuotingCharacterDisposition.NONE;
+// if ( "`".equals( token ) ) {
+// state.quoted = !state.quoted;
+// quotingCharacterDisposition = state.quoted
+// ? QuotingCharacterDisposition.OPEN
+// : QuotingCharacterDisposition.CLOSE;
+// // replace token with the appropriate dialect quoting char
+// token = lcToken = ( quotingCharacterDisposition == QuotingCharacterDisposition.OPEN )
+// ? dialectOpenQuote
+// : dialectCloseQuote;
+// }
+// else if ( "'".equals( token ) ) {
+// state.quoted = !state.quoted;
+// quotingCharacterDisposition = state.quoted
+// ? QuotingCharacterDisposition.OPEN
+// : QuotingCharacterDisposition.CLOSE;
+// }
+// else if ( !state.quoted && dialectOpenQuote.equals( token ) ) {
+// state.quoted = true;
+// quotingCharacterDisposition = QuotingCharacterDisposition.OPEN;
+// }
+// else if ( state.quoted && dialectCloseQuote.equals( token ) ) {
+// state.quoted = false;
+// quotingCharacterDisposition = QuotingCharacterDisposition.CLOSE;
+// }
+//
+// if ( state.quoted ) {
+// quotedBuffer.append( token );
+// continue;
+// }
+//
+// // if we were previously processing quoted state and just encountered the close quote, then handle that
+// // quoted text
+// if ( quotingCharacterDisposition == QuotingCharacterDisposition.CLOSE ) {
+// token = quotedBuffer.toString();
+// quotedBuffer.setLength( 0 );
+// result.append( placeholder ).append( '.' )
+// .append( dialectOpenQuote ).append( token ).append( dialectCloseQuote );
+// continue;
+// }
+//
+// // Special processing for ANSI SQL EXTRACT function
+// if ( "extract".equals( lcToken ) && "(".equals( nextToken ) ) {
+// final String field = extractUntil( tokens, "from" );
+// final String source = renderWhereStringTemplate(
+// extractUntil( tokens, ")" ),
+// placeholder,
+// dialect,
+// functionRegistry
+// );
+// result.append( "extract(" ).append( field ).append( " from " ).append( source ).append( ')' );
+//
+// hasMore = tokens.hasMoreTokens();
+// nextToken = hasMore ? tokens.nextToken() : null;
+//
+// continue;
+// }
+//
+// // Special processing for ANSI SQL TRIM function
+// if ( "trim".equals( lcToken ) && "(".equals( nextToken ) ) {
+// List<String> operands = new ArrayList<String>();
+// StringBuilder builder = new StringBuilder();
+//
+// boolean hasMoreOperands = true;
+// String operandToken = tokens.nextToken();
+// boolean quoted = false;
+// while ( hasMoreOperands ) {
+// final boolean isQuote = "'".equals( operandToken );
+// if ( isQuote ) {
+// quoted = !quoted;
+// if ( !quoted ) {
+// operands.add( builder.append( '\'' ).toString() );
+// builder.setLength( 0 );
+// }
+// else {
+// builder.append( '\'' );
+// }
+// }
+// else if ( quoted ) {
+// builder.append( operandToken );
+// }
+// else if ( operandToken.length() == 1 && Character.isWhitespace( operandToken.charAt( 0 ) ) ) {
+// // do nothing
+// }
+// else {
+// operands.add( operandToken );
+// }
+// operandToken = tokens.nextToken();
+// hasMoreOperands = tokens.hasMoreTokens() && ! ")".equals( operandToken );
+// }
+//
+// TrimOperands trimOperands = new TrimOperands( operands );
+// result.append( "trim(" );
+// if ( trimOperands.trimSpec != null ) {
+// result.append( trimOperands.trimSpec ).append( ' ' );
+// }
+// if ( trimOperands.trimChar != null ) {
+// if ( trimOperands.trimChar.startsWith( "'" ) && trimOperands.trimChar.endsWith( "'" ) ) {
+// result.append( trimOperands.trimChar );
+// }
+// else {
+// result.append(
+// renderWhereStringTemplate( trimOperands.trimSpec, placeholder, dialect, functionRegistry )
+// );
+// }
+// result.append( ' ' );
+// }
+// if ( trimOperands.from != null ) {
+// result.append( trimOperands.from ).append( ' ' );
+// }
+// else if ( trimOperands.trimSpec != null || trimOperands.trimChar != null ) {
+// // I think ANSI SQL says that the 'from' is not optional if either trim-spec or trim-char are specified
+// result.append( "from " );
+// }
+//
+// result.append( renderWhereStringTemplate( trimOperands.trimSource, placeholder, dialect, functionRegistry ) )
+// .append( ')' );
+//
+// hasMore = tokens.hasMoreTokens();
+// nextToken = hasMore ? tokens.nextToken() : null;
+//
+// continue;
+// }
+//
+//
+// // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+//
+// if ( Character.isWhitespace( token.charAt( 0 ) ) ) {
+// result.append( token );
+// }
+// else if ( state.beforeTable ) {
+// result.append( token );
+// state.beforeTable = false;
+// state.afterFromTable = true;
+// }
+// else if ( state.afterFromTable ) {
+// if ( !"as".equals(lcToken) ) {
+// state.afterFromTable = false;
+// }
+// result.append(token);
+// }
+// else if ( isNamedParameter(token) ) {
+// result.append(token);
+// }
+// else if ( isIdentifier(token, dialect)
+// && !isFunctionOrKeyword(lcToken, nextToken, dialect , functionRegistry) ) {
+// result.append(placeholder)
+// .append('.')
+// .append( dialect.quote(token) );
+// }
+// else {
+// if ( BEFORE_TABLE_KEYWORDS.contains(lcToken) ) {
+// state.beforeTable = true;
+// state.inFromClause = true;
+// }
+// else if ( state.inFromClause && ",".equals(lcToken) ) {
+// state.beforeTable = true;
+// }
+// result.append(token);
+// }
+//
+// //Yuck:
+// if ( state.inFromClause
+// && KEYWORDS.contains( lcToken ) //"as" is not in KEYWORDS
+// && !BEFORE_TABLE_KEYWORDS.contains( lcToken ) ) {
+// state.inFromClause = false;
+// }
+// }
+//
+// return result.toString();
+// }
+//
+// private static class ProcessingState {
+// boolean quoted = false;
+// boolean quotedIdentifier = false;
+// boolean beforeTable = false;
+// boolean inFromClause = false;
+// boolean afterFromTable = false;
+// }
+//
+// private static enum QuotingCharacterDisposition { NONE, OPEN, CLOSE }
+
+ private static class TrimOperands {
+ private final String trimSpec;
+ private final String trimChar;
+ private final String from;
+ private final String trimSource;
+
+ private TrimOperands(List<String> operands) {
+ if ( operands.size() == 1 ) {
+ trimSpec = null;
+ trimChar = null;
+ from = null;
+ trimSource = operands.get(0);
+ }
+ else if ( operands.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() );
+ }
+
+ // trim-source will always be the last operand
+ trimSource = operands.get( operands.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 ) );
+ }
+ from = operands.get( operands.size() - 2 );
+
+ // trim-spec, if there is one will always be the first operand
+ if ( "leading".equalsIgnoreCase( operands.get(0) )
+ || "trailing".equalsIgnoreCase( operands.get(0) )
+ || "both".equalsIgnoreCase( operands.get(0) ) ) {
+ trimSpec = operands.get(0);
+ trimChar = null;
+ }
+ else {
+ trimSpec = null;
+ if ( operands.size() - 2 == 0 ) {
+ trimChar = null;
+ }
+ else {
+ trimChar = operands.get( 0 );
+ }
+ }
+ }
+ }
+ }
+
+ private static String extractUntil(StringTokenizer tokens, String delimiter) {
+ StringBuilder valueBuilder = new StringBuilder();
+ String token = tokens.nextToken();
+ while ( ! delimiter.equalsIgnoreCase( token ) ) {
+ valueBuilder.append( token );
+ token = tokens.nextToken();
+ }
+ return valueBuilder.toString().trim();
+ }
+
public static class NoOpColumnMapper implements ColumnMapper {
public static final NoOpColumnMapper INSTANCE = new NoOpColumnMapper();
public String[] map(String reference) {
@@ -254,8 +637,8 @@
* @param functionRegistry The SQL function registry
*
* @return The rendered <tt>ORDER BY</tt> template.
- *
- * @see #renderOrderByStringTemplate(String,ColumnMapper,SessionFactoryImplementor,Dialect,SQLFunctionRegistry)
+ *
+ * @deprecated Use {@link #renderOrderByStringTemplate(String,ColumnMapper,SessionFactoryImplementor,Dialect,SQLFunctionRegistry)} instead
*/
public static String renderOrderByStringTemplate(
String orderByFragment,
@@ -348,5 +731,4 @@
);
}
-
}
Modified: core/trunk/core/src/test/java/org/hibernate/sql/TemplateTest.java
===================================================================
--- core/trunk/core/src/test/java/org/hibernate/sql/TemplateTest.java 2010-05-07 18:07:24 UTC (rev 19410)
+++ core/trunk/core/src/test/java/org/hibernate/sql/TemplateTest.java 2010-05-07 20:53:34 UTC (rev 19411)
@@ -85,6 +85,43 @@
private static final SQLFunctionRegistry FUNCTION_REGISTRY = new SQLFunctionRegistry( DIALECT, Collections.EMPTY_MAP );
+ public void testSqlExtractFunction() {
+ String fragment = "extract( year from col )";
+ String template = Template.renderWhereStringTemplate( fragment, Template.TEMPLATE, DIALECT, FUNCTION_REGISTRY );
+
+ assertEquals( "extract(year from " + Template.TEMPLATE + ".col)", template );
+ }
+
+ public void testSqlTrimFunction() {
+ String fragment = "trim( col )";
+ String template = Template.renderWhereStringTemplate( fragment, Template.TEMPLATE, DIALECT, FUNCTION_REGISTRY );
+ assertEquals( "trim(" + Template.TEMPLATE + ".col)", template );
+
+ fragment = "trim( from col )";
+ template = Template.renderWhereStringTemplate( fragment, Template.TEMPLATE, DIALECT, FUNCTION_REGISTRY );
+ assertEquals( "trim(from " + Template.TEMPLATE + ".col)", template );
+
+ fragment = "trim( both from col )";
+ template = Template.renderWhereStringTemplate( fragment, Template.TEMPLATE, DIALECT, FUNCTION_REGISTRY );
+ assertEquals( "trim(both from " + Template.TEMPLATE + ".col)", template );
+
+ fragment = "trim( leading from col )";
+ template = Template.renderWhereStringTemplate( fragment, Template.TEMPLATE, DIALECT, FUNCTION_REGISTRY );
+ assertEquals( "trim(leading from " + Template.TEMPLATE + ".col)", template );
+
+ fragment = "trim( TRAILING from col )";
+ template = Template.renderWhereStringTemplate( fragment, Template.TEMPLATE, DIALECT, FUNCTION_REGISTRY );
+ assertEquals( "trim(TRAILING from " + Template.TEMPLATE + ".col)", template );
+
+ fragment = "trim( 'b' from col )";
+ template = Template.renderWhereStringTemplate( fragment, Template.TEMPLATE, DIALECT, FUNCTION_REGISTRY );
+ assertEquals( "trim('b' from " + Template.TEMPLATE + ".col)", template );
+
+ fragment = "trim( both 'b' from col )";
+ template = Template.renderWhereStringTemplate( fragment, Template.TEMPLATE, DIALECT, FUNCTION_REGISTRY );
+ assertEquals( "trim(both 'b' from " + Template.TEMPLATE + ".col)", template );
+ }
+
public void testSQLReferences() {
String fragment = "sql asc, sql desc";
String template = doStandardRendering( fragment );
14 years, 7 months
Hibernate SVN: r19410 - core/branches/Branch_3_3_2_GA_CP/parent.
by hibernate-commits@lists.jboss.org
Author: stliu
Date: 2010-05-07 14:07:24 -0400 (Fri, 07 May 2010)
New Revision: 19410
Modified:
core/branches/Branch_3_3_2_GA_CP/parent/pom.xml
Log:
JBPAPP-4253 update db driver version
Modified: core/branches/Branch_3_3_2_GA_CP/parent/pom.xml
===================================================================
--- core/branches/Branch_3_3_2_GA_CP/parent/pom.xml 2010-05-07 17:55:04 UTC (rev 19409)
+++ core/branches/Branch_3_3_2_GA_CP/parent/pom.xml 2010-05-07 18:07:24 UTC (rev 19410)
@@ -464,7 +464,7 @@
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
- <version>5.0.5</version>
+ <version>5.0.8</version>
</dependency>
</dependencies>
<properties>
@@ -483,7 +483,7 @@
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
- <version>5.0.5</version>
+ <version>5.1.12</version>
<scope>test</scope>
</dependency>
</dependencies>
@@ -624,8 +624,7 @@
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc14</artifactId>
- <!-- use the 10g drivers which are surprisingly largely bug free -->
- <version>10.0.2.0</version>
+ <version>10.0.2.4</version>
</dependency>
</dependencies>
<properties>
@@ -645,7 +644,7 @@
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc5</artifactId>
- <version>11.1.0.7.0</version>
+ <version>11.2.0.1.0</version>
<scope>test</scope>
</dependency>
</dependencies>
@@ -685,7 +684,7 @@
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc5</artifactId>
- <version>11.1.0.7.0</version>
+ <version>11.2.0.1.0</version>
<scope>test</scope>
</dependency>
</dependencies>
@@ -744,7 +743,7 @@
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>msjdbc</artifactId>
- <version>1.1</version>
+ <version>2.0.1008.2</version>
</dependency>
</dependencies>
<properties>
14 years, 7 months
Hibernate SVN: r19409 - core/branches/Branch_3_3.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2010-05-07 13:55:04 -0400 (Fri, 07 May 2010)
New Revision: 19409
Modified:
core/branches/Branch_3_3/
Log:
updated svnignore entries to add .idea
Property changes on: core/branches/Branch_3_3
___________________________________________________________________
Name: svn:ignore
- target
local
bin
*.ipr
*.iws
*.iml
.classpath
.project
.settings
.nbattrs
*.log
*.properties
.clover
atlassian-ide-plugin.xml
+ target
local
.idea
*.ipr
*.iws
*.iml
atlassian-ide-plugin.xml
.classpath
.project
.settings
.nbattrs
*.log
*.properties
.clover
14 years, 7 months
Hibernate SVN: r19408 - core/branches/Branch_3_3_2_GA_CP/testsuite/src/test/java/org/hibernate/test/sql/hand/query.
by hibernate-commits@lists.jboss.org
Author: stliu
Date: 2010-05-07 12:49:25 -0400 (Fri, 07 May 2010)
New Revision: 19408
Modified:
core/branches/Branch_3_3_2_GA_CP/testsuite/src/test/java/org/hibernate/test/sql/hand/query/NativeSQLQueries.hbm.xml
Log:
JBPAPP-2860 HHH-3892 - Improve support for mapping SQL LONGVARCHAR and CLOB to Java String, SQL LONGVARBINARY and BLOB to Java byte[]
Modified: core/branches/Branch_3_3_2_GA_CP/testsuite/src/test/java/org/hibernate/test/sql/hand/query/NativeSQLQueries.hbm.xml
===================================================================
--- core/branches/Branch_3_3_2_GA_CP/testsuite/src/test/java/org/hibernate/test/sql/hand/query/NativeSQLQueries.hbm.xml 2010-05-07 15:36:30 UTC (rev 19407)
+++ core/branches/Branch_3_3_2_GA_CP/testsuite/src/test/java/org/hibernate/test/sql/hand/query/NativeSQLQueries.hbm.xml 2010-05-07 16:49:25 UTC (rev 19408)
@@ -116,14 +116,14 @@
<property name="length" column="flength"/>
</class>
- <class name="TextHolder">
+ <class name="TextHolder" table="TEXTHOLDER">
<id name="id" column="id">
<generator class="increment"/>
</id>
<property name="description" type="text" length="15000"/>
</class>
- <class name="ImageHolder">
+ <class name="ImageHolder" table="IMAGEHOLDER">
<id name="id" column="id">
<generator class="increment"/>
</id>
14 years, 7 months
Hibernate SVN: r19407 - core/trunk/documentation/manual/src/main/docbook/en-US/content.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2010-05-07 11:36:30 -0400 (Fri, 07 May 2010)
New Revision: 19407
Modified:
core/trunk/documentation/manual/src/main/docbook/en-US/content/basic_mapping.xml
Log:
HHH-5149 documentation for versioning
Modified: core/trunk/documentation/manual/src/main/docbook/en-US/content/basic_mapping.xml
===================================================================
--- core/trunk/documentation/manual/src/main/docbook/en-US/content/basic_mapping.xml 2010-05-07 15:13:09 UTC (rev 19406)
+++ core/trunk/documentation/manual/src/main/docbook/en-US/content/basic_mapping.xml 2010-05-07 15:36:30 UTC (rev 19407)
@@ -2962,8 +2962,20 @@
for good scalability and works particularly well in read-often
write-sometimes situations.</para>
+ <para>You can use two approaches: a dedicated version number or a
+ timestamp.</para>
+
+ <para>A version or timestamp property should never be null for a
+ detached instance. Hibernate will detect any instance with a null
+ version or timestamp as transient, irrespective of what other
+ <literal>unsaved-value</literal> strategies are specified.
+ <emphasis>Declaring a nullable version or timestamp property is an easy
+ way to avoid problems with transitive reattachment in Hibernate. It is
+ especially useful for people using assigned identifiers or composite
+ keys</emphasis>.</para>
+
<section id="entity-mapping-entity-version">
- <title>Versioning for optimistic locking</title>
+ <title>Version number</title>
<para>You can add optimistic locking capability to an entity using the
<literal>@Version</literal> annotation:</para>
@@ -2981,9 +2993,8 @@
to detect conflicting updates (preventing lost updates you might
otherwise see with the last-commit-wins strategy).</para>
- <para>The version column may be a numeric (the recommended solution)
- or a timestamp. Hibernate supports any kind of type provided that you
- define and implement the appropriate
+ <para>The version column may be a numeric. Hibernate supports any kind
+ of type provided that you define and implement the appropriate
<classname>UserVersionType</classname>.</para>
<para>The application must not alter the version number set up by
@@ -2991,15 +3002,12 @@
check in Hibernate Entity Manager's reference documentation
<literal>LockModeType.OPTIMISTIC_FORCE_INCREMENT</literal> or
<literal>LockModeType.PESSIMISTIC_FORCE_INCREMENT</literal>.</para>
- </section>
- <section id="mapping-declaration-version" revision="4">
- <title>Version</title>
+ <para>If the version number is generated by the database (via a
+ trigger for example), make sure to use
+ <code>@org.hibernate.annotations.Generated(GenerationTime.ALWAYS).</code></para>
- <para>The <literal><version></literal> element is optional and
- indicates that the table contains versioned data. This is particularly
- useful if you plan to use <emphasis>long transactions</emphasis>. See
- below for more information:</para>
+ <para>To declare a version property in hbm.xml, use:</para>
<programlistingco role="XML">
<areaspec>
@@ -3080,31 +3088,33 @@
</callout>
</calloutlist>
</programlistingco>
-
- <para>Version numbers can be of Hibernate type
- <literal>long</literal>, <literal>integer</literal>,
- <literal>short</literal>, <literal>timestamp</literal> or
- <literal>calendar</literal>.</para>
-
- <para>A version or timestamp property should never be null for a
- detached instance. Hibernate will detect any instance with a null
- version or timestamp as transient, irrespective of what other
- <literal>unsaved-value</literal> strategies are specified.
- <emphasis>Declaring a nullable version or timestamp property is an
- easy way to avoid problems with transitive reattachment in Hibernate.
- It is especially useful for people using assigned identifiers or
- composite keys</emphasis>.</para>
</section>
<section id="mapping-declaration-timestamp" revision="4">
- <title>Timestamp (optional)</title>
+ <title>Timestamp</title>
- <para>The optional <literal><timestamp></literal> element
- indicates that the table contains timestamped data. This provides an
- alternative to versioning. Timestamps are a less safe implementation
- of optimistic locking. However, sometimes the application might use
- the timestamps in other ways.</para>
+ <para>Alternatively, you can use a timestamp. Timestamps are a less
+ safe implementation of optimistic locking. However, sometimes the
+ application might use the timestamps in other ways.</para>
+ <para>Simply mark a property of type <classname>Date</classname> or
+ <classname>Calendar</classname> as
+ <classname>@Version</classname>.</para>
+
+ <programlisting language="JAVA" role="JAVA">@Entity
+public class Flight implements Serializable {
+...
+ @Version
+ public Date getLastUpdate() { ... }
+} </programlisting>
+
+ <para>Like version numbers, the timestamp can be generated by the
+ database instead of Hibernate. To do that, use
+ <code>@org.hibernate.annotations.Generated(GenerationTime.ALWAYS).</code></para>
+
+ <para>In hbm.xml, use the <literal><timestamp></literal>
+ element:</para>
+
<programlistingco role="XML">
<areaspec>
<area coords="2" id="timestamp1" />
14 years, 7 months
Hibernate SVN: r19406 - in core/trunk: annotations/src/test/java/org/hibernate/test/annotations/lob and 4 other directories.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2010-05-07 11:13:09 -0400 (Fri, 07 May 2010)
New Revision: 19406
Added:
core/trunk/testing/src/main/java/org/hibernate/junit/DialectChecks.java
Modified:
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/id/sequences/IdTest.java
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/lob/LobTest.java
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/manytoone/referencedcolumnname/ManyToOneReferencedColumnNameTest.java
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/xml/hbm/HbmWithIdentityTest.java
core/trunk/testing/src/main/java/org/hibernate/junit/RequiresDialectFeature.java
core/trunk/testing/src/main/java/org/hibernate/test/annotations/HibernateTestCase.java
Log:
HHH-5204
Modified: core/trunk/annotations/src/test/java/org/hibernate/test/annotations/id/sequences/IdTest.java
===================================================================
--- core/trunk/annotations/src/test/java/org/hibernate/test/annotations/id/sequences/IdTest.java 2010-05-07 13:46:32 UTC (rev 19405)
+++ core/trunk/annotations/src/test/java/org/hibernate/test/annotations/id/sequences/IdTest.java 2010-05-07 15:13:09 UTC (rev 19406)
@@ -1,10 +1,34 @@
//$Id$
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2010, Red Hat Inc. or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Inc.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
package org.hibernate.test.annotations.id.sequences;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.hibernate.cfg.AnnotationConfiguration;
import org.hibernate.cfg.Configuration;
+import org.hibernate.junit.DialectChecks;
import org.hibernate.junit.RequiresDialectFeature;
import org.hibernate.mapping.Column;
import org.hibernate.test.annotations.TestCase;
@@ -30,7 +54,7 @@
* @author Emmanuel Bernard
*/
@SuppressWarnings("unchecked")
-@RequiresDialectFeature("supportsSequences")
+(a)RequiresDialectFeature(DialectChecks.SupportsSequences.class)
public class IdTest extends TestCase {
public void testGenericGenerator() throws Exception {
Session s = openSession();
Modified: core/trunk/annotations/src/test/java/org/hibernate/test/annotations/lob/LobTest.java
===================================================================
--- core/trunk/annotations/src/test/java/org/hibernate/test/annotations/lob/LobTest.java 2010-05-07 13:46:32 UTC (rev 19405)
+++ core/trunk/annotations/src/test/java/org/hibernate/test/annotations/lob/LobTest.java 2010-05-07 15:13:09 UTC (rev 19406)
@@ -1,15 +1,39 @@
//$Id$
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2010, Red Hat Inc. or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Inc.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
package org.hibernate.test.annotations.lob;
import org.hibernate.Session;
import org.hibernate.Transaction;
+import org.hibernate.junit.DialectChecks;
import org.hibernate.junit.RequiresDialectFeature;
import org.hibernate.test.annotations.TestCase;
/**
* @author Emmanuel Bernard
*/
-@RequiresDialectFeature("supportsExpectedLobUsagePattern")
+(a)RequiresDialectFeature(DialectChecks.SupportsExpectedLobUsagePattern.class)
public class LobTest extends TestCase {
public void testSerializableToBlob() throws Exception {
Book book = new Book();
Property changes on: core/trunk/annotations/src/test/java/org/hibernate/test/annotations/lob/LobTest.java
___________________________________________________________________
Name: svn:keywords
- Date Revision Author Id
+ Id
Modified: core/trunk/annotations/src/test/java/org/hibernate/test/annotations/manytoone/referencedcolumnname/ManyToOneReferencedColumnNameTest.java
===================================================================
--- core/trunk/annotations/src/test/java/org/hibernate/test/annotations/manytoone/referencedcolumnname/ManyToOneReferencedColumnNameTest.java 2010-05-07 13:46:32 UTC (rev 19405)
+++ core/trunk/annotations/src/test/java/org/hibernate/test/annotations/manytoone/referencedcolumnname/ManyToOneReferencedColumnNameTest.java 2010-05-07 15:13:09 UTC (rev 19406)
@@ -1,9 +1,33 @@
// $Id$
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2010, Red Hat Inc. or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Inc.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
package org.hibernate.test.annotations.manytoone.referencedcolumnname;
import java.math.BigDecimal;
import org.hibernate.Session;
+import org.hibernate.junit.DialectChecks;
import org.hibernate.junit.RequiresDialectFeature;
import org.hibernate.test.annotations.TestCase;
@@ -11,7 +35,7 @@
* @author Emmanuel Bernard
*/
public class ManyToOneReferencedColumnNameTest extends TestCase {
- @RequiresDialectFeature("supportsIdentityColumns")
+ @RequiresDialectFeature(DialectChecks.SupportsIdentityColumns.class)
public void testReoverableExceptionInFkOrdering() throws Exception {
//SF should not blow up
Vendor v = new Vendor();
@@ -34,7 +58,6 @@
s.flush();
s.getTransaction().rollback();
s.close();
-
}
protected Class[] getAnnotatedClasses() {
Modified: core/trunk/annotations/src/test/java/org/hibernate/test/annotations/xml/hbm/HbmWithIdentityTest.java
===================================================================
--- core/trunk/annotations/src/test/java/org/hibernate/test/annotations/xml/hbm/HbmWithIdentityTest.java 2010-05-07 13:46:32 UTC (rev 19405)
+++ core/trunk/annotations/src/test/java/org/hibernate/test/annotations/xml/hbm/HbmWithIdentityTest.java 2010-05-07 15:13:09 UTC (rev 19406)
@@ -2,6 +2,7 @@
package org.hibernate.test.annotations.xml.hbm;
import org.hibernate.Session;
+import org.hibernate.junit.DialectChecks;
import org.hibernate.junit.RequiresDialectFeature;
import org.hibernate.test.annotations.TestCase;
@@ -10,7 +11,7 @@
*/
public class HbmWithIdentityTest extends TestCase {
- @RequiresDialectFeature("supportsIdentityColumns")
+ @RequiresDialectFeature(DialectChecks.SupportsIdentityColumns.class)
public void testManyToOneAndInterface() throws Exception {
Session s = openSession();
s.getTransaction().begin();
Added: core/trunk/testing/src/main/java/org/hibernate/junit/DialectChecks.java
===================================================================
--- core/trunk/testing/src/main/java/org/hibernate/junit/DialectChecks.java (rev 0)
+++ core/trunk/testing/src/main/java/org/hibernate/junit/DialectChecks.java 2010-05-07 15:13:09 UTC (rev 19406)
@@ -0,0 +1,59 @@
+// $Id$
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2010, Red Hat Inc. or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Inc.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+package org.hibernate.junit;
+
+import org.hibernate.dialect.Dialect;
+
+/**
+ * Container class for different implementation of the {@code DialectCheck} interface.
+ *
+ * @author Hardy Ferentschik
+ */
+abstract public class DialectChecks {
+
+ abstract public boolean include(Dialect dialect);
+
+ public static class SupportsSequences extends DialectChecks {
+ public boolean include(Dialect dialect) {
+ return dialect.supportsSequences();
+ }
+ }
+
+ public static class SupportsExpectedLobUsagePattern extends DialectChecks {
+ public boolean include(Dialect dialect) {
+ return dialect.supportsExpectedLobUsagePattern();
+ }
+ }
+
+ public static class SupportsIdentityColumns extends DialectChecks {
+ public boolean include(Dialect dialect) {
+ return dialect.supportsIdentityColumns();
+ }
+ }
+
+
+}
+
+
Property changes on: core/trunk/testing/src/main/java/org/hibernate/junit/DialectChecks.java
___________________________________________________________________
Name: svn:keywords
+ Id
Modified: core/trunk/testing/src/main/java/org/hibernate/junit/RequiresDialectFeature.java
===================================================================
--- core/trunk/testing/src/main/java/org/hibernate/junit/RequiresDialectFeature.java 2010-05-07 13:46:32 UTC (rev 19405)
+++ core/trunk/testing/src/main/java/org/hibernate/junit/RequiresDialectFeature.java 2010-05-07 15:13:09 UTC (rev 19406)
@@ -1,3 +1,4 @@
+// $Id$
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
@@ -40,5 +41,5 @@
/**
* @return The name of the dialect feature.
*/
- String value();
+ Class<? extends DialectChecks> value();
}
\ No newline at end of file
Modified: core/trunk/testing/src/main/java/org/hibernate/test/annotations/HibernateTestCase.java
===================================================================
--- core/trunk/testing/src/main/java/org/hibernate/test/annotations/HibernateTestCase.java 2010-05-07 13:46:32 UTC (rev 19405)
+++ core/trunk/testing/src/main/java/org/hibernate/test/annotations/HibernateTestCase.java 2010-05-07 15:13:09 UTC (rev 19406)
@@ -38,6 +38,7 @@
import org.hibernate.cfg.Configuration;
import org.hibernate.dialect.Dialect;
import org.hibernate.jdbc.Work;
+import org.hibernate.junit.DialectChecks;
import org.hibernate.junit.FailureExpected;
import org.hibernate.junit.RequiresDialect;
import org.hibernate.junit.RequiresDialectFeature;
@@ -192,15 +193,9 @@
// then check against a dialect feature
RequiresDialectFeature requiresDialectFeatureAnn = locateAnnotation( RequiresDialectFeature.class, runMethod );
if ( requiresDialectFeatureAnn != null ) {
- String feature = requiresDialectFeatureAnn.value();
- boolean skip = false;
- try {
- Method m = dialect.getClass().getMethod( feature );
- skip = (Boolean) m.invoke( dialect );
- }
- catch ( NoSuchMethodException e ) {
- fail( "Dialect does not have a method: " + feature );
- }
+ Class<? extends DialectChecks> checkClass = requiresDialectFeatureAnn.value();
+ DialectChecks check = checkClass.newInstance();
+ boolean skip = check.include( dialect );
if ( skip ) {
return buildSkip( dialect, null, null );
}
14 years, 7 months
Hibernate SVN: r19405 - in core/trunk: annotations/src/test/java/org/hibernate/test/annotations/lob and 4 other directories.
by hibernate-commits@lists.jboss.org
Author: hardy.ferentschik
Date: 2010-05-07 09:46:32 -0400 (Fri, 07 May 2010)
New Revision: 19405
Added:
core/trunk/testing/src/main/java/org/hibernate/junit/RequiresDialectFeature.java
Modified:
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/id/sequences/IdTest.java
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/lob/LobTest.java
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/manytoone/referencedcolumnname/ManyToOneReferencedColumnNameTest.java
core/trunk/annotations/src/test/java/org/hibernate/test/annotations/xml/hbm/HbmWithIdentityTest.java
core/trunk/testing/src/main/java/org/hibernate/test/annotations/HibernateTestCase.java
Log:
HHH-5204
Modified: core/trunk/annotations/src/test/java/org/hibernate/test/annotations/id/sequences/IdTest.java
===================================================================
--- core/trunk/annotations/src/test/java/org/hibernate/test/annotations/id/sequences/IdTest.java 2010-05-07 12:25:26 UTC (rev 19404)
+++ core/trunk/annotations/src/test/java/org/hibernate/test/annotations/id/sequences/IdTest.java 2010-05-07 13:46:32 UTC (rev 19405)
@@ -5,6 +5,7 @@
import org.hibernate.Transaction;
import org.hibernate.cfg.AnnotationConfiguration;
import org.hibernate.cfg.Configuration;
+import org.hibernate.junit.RequiresDialectFeature;
import org.hibernate.mapping.Column;
import org.hibernate.test.annotations.TestCase;
import org.hibernate.test.annotations.id.sequences.entities.Ball;
@@ -29,27 +30,28 @@
* @author Emmanuel Bernard
*/
@SuppressWarnings("unchecked")
+@RequiresDialectFeature("supportsSequences")
public class IdTest extends TestCase {
public void testGenericGenerator() throws Exception {
Session s = openSession();
Transaction tx = s.beginTransaction();
SoundSystem system = new SoundSystem();
- system.setBrand("Genelec");
- system.setModel("T234");
+ system.setBrand( "Genelec" );
+ system.setModel( "T234" );
Furniture fur = new Furniture();
- s.persist(system);
- s.persist(fur);
+ s.persist( system );
+ s.persist( fur );
tx.commit();
s.close();
s = openSession();
tx = s.beginTransaction();
- system = (SoundSystem) s.get(SoundSystem.class, system.getId());
- fur = (Furniture) s.get(Furniture.class, fur.getId());
- assertNotNull(system);
- assertNotNull(fur);
- s.delete(system);
- s.delete(fur);
+ system = ( SoundSystem ) s.get( SoundSystem.class, system.getId() );
+ fur = ( Furniture ) s.get( Furniture.class, fur.getId() );
+ assertNotNull( system );
+ assertNotNull( fur );
+ s.delete( system );
+ s.delete( fur );
tx.commit();
s.close();
@@ -59,13 +61,14 @@
* Ensures that GenericGenerator annotations wrapped inside a
* GenericGenerators holder are bound correctly
*/
+
public void testGenericGenerators() throws Exception {
Session s = openSession();
Transaction tx = s.beginTransaction();
Monkey monkey = new Monkey();
- s.persist(monkey);
+ s.persist( monkey );
s.flush();
- assertNotNull(monkey.getId());
+ assertNotNull( monkey.getId() );
tx.rollback();
s.close();
}
@@ -77,21 +80,23 @@
Ball b = new Ball();
Dog d = new Dog();
Computer c = new Computer();
- s.persist(b);
- s.persist(d);
- s.persist(c);
+ s.persist( b );
+ s.persist( d );
+ s.persist( c );
tx.commit();
s.close();
- assertEquals("table id not generated", new Integer(1), b.getId());
- assertEquals("generator should not be shared", new Integer(1), d
- .getId());
- assertEquals("default value should work", new Long(1), c.getId());
+ assertEquals( "table id not generated", new Integer( 1 ), b.getId() );
+ assertEquals(
+ "generator should not be shared", new Integer( 1 ), d
+ .getId()
+ );
+ assertEquals( "default value should work", new Long( 1 ), c.getId() );
s = openSession();
tx = s.beginTransaction();
- s.delete(s.get(Ball.class, new Integer(1)));
- s.delete(s.get(Dog.class, new Integer(1)));
- s.delete(s.get(Computer.class, new Long(1)));
+ s.delete( s.get( Ball.class, new Integer( 1 ) ) );
+ s.delete( s.get( Dog.class, new Integer( 1 ) ) );
+ s.delete( s.get( Computer.class, new Long( 1 ) ) );
tx.commit();
s.close();
}
@@ -100,14 +105,14 @@
Session s = openSession();
Transaction tx = s.beginTransaction();
Shoe b = new Shoe();
- s.persist(b);
+ s.persist( b );
tx.commit();
s.close();
- assertNotNull(b.getId());
+ assertNotNull( b.getId() );
s = openSession();
tx = s.beginTransaction();
- s.delete(s.get(Shoe.class, b.getId()));
+ s.delete( s.get( Shoe.class, b.getId() ) );
tx.commit();
s.close();
}
@@ -116,14 +121,14 @@
Session s = openSession();
Transaction tx = s.beginTransaction();
Store b = new Store();
- s.persist(b);
+ s.persist( b );
tx.commit();
s.close();
- assertNotNull(b.getId());
+ assertNotNull( b.getId() );
s = openSession();
tx = s.beginTransaction();
- s.delete(s.get(Store.class, b.getId()));
+ s.delete( s.get( Store.class, b.getId() ) );
tx.commit();
s.close();
}
@@ -132,14 +137,14 @@
Session s = openSession();
Transaction tx = s.beginTransaction();
Department b = new Department();
- s.persist(b);
+ s.persist( b );
tx.commit();
s.close();
- assertNotNull(b.getId());
+ assertNotNull( b.getId() );
s = openSession();
tx = s.beginTransaction();
- s.delete(s.get(Department.class, b.getId()));
+ s.delete( s.get( Department.class, b.getId() ) );
tx.commit();
s.close();
}
@@ -150,16 +155,16 @@
s = openSession();
tx = s.beginTransaction();
Home h = new Home();
- s.persist(h);
+ s.persist( h );
tx.commit();
s.close();
- assertNotNull(h.getId());
+ assertNotNull( h.getId() );
s = openSession();
tx = s.beginTransaction();
- Home reloadedHome = (Home) s.get(Home.class, h.getId());
- assertEquals(h.getId(), reloadedHome.getId());
- s.delete(reloadedHome);
+ Home reloadedHome = ( Home ) s.get( Home.class, h.getId() );
+ assertEquals( h.getId(), reloadedHome.getId() );
+ s.delete( reloadedHome );
tx.commit();
s.close();
}
@@ -170,16 +175,16 @@
s = openSession();
tx = s.beginTransaction();
Home h = new Home();
- s.persist(h);
+ s.persist( h );
tx.commit();
s.close();
- assertNotNull(h.getId());
+ assertNotNull( h.getId() );
s = openSession();
tx = s.beginTransaction();
- Home reloadedHome = (Home) s.get(Home.class, h.getId());
- assertEquals(h.getId(), reloadedHome.getId());
- s.delete(reloadedHome);
+ Home reloadedHome = ( Home ) s.get( Home.class, h.getId() );
+ assertEquals( h.getId(), reloadedHome.getId() );
+ s.delete( reloadedHome );
tx.commit();
s.close();
}
@@ -190,13 +195,13 @@
s = openSession();
tx = s.beginTransaction();
FirTree chrismasTree = new FirTree();
- s.persist(chrismasTree);
+ s.persist( chrismasTree );
tx.commit();
s.clear();
tx = s.beginTransaction();
- chrismasTree = (FirTree) s.get(FirTree.class, chrismasTree.getId());
- assertNotNull(chrismasTree);
- s.delete(chrismasTree);
+ chrismasTree = ( FirTree ) s.get( FirTree.class, chrismasTree.getId() );
+ assertNotNull( chrismasTree );
+ s.delete( chrismasTree );
tx.commit();
s.close();
}
@@ -206,55 +211,58 @@
Transaction tx;
s = openSession();
tx = s.beginTransaction();
- Footballer fb = new Footballer("David", "Beckam", "Arsenal");
- GoalKeeper keeper = new GoalKeeper("Fabien", "Bartez", "OM");
- s.persist(fb);
- s.persist(keeper);
+ Footballer fb = new Footballer( "David", "Beckam", "Arsenal" );
+ GoalKeeper keeper = new GoalKeeper( "Fabien", "Bartez", "OM" );
+ s.persist( fb );
+ s.persist( keeper );
tx.commit();
s.clear();
// lookup by id
tx = s.beginTransaction();
- FootballerPk fpk = new FootballerPk("David", "Beckam");
- fb = (Footballer) s.get(Footballer.class, fpk);
- FootballerPk fpk2 = new FootballerPk("Fabien", "Bartez");
- keeper = (GoalKeeper) s.get(GoalKeeper.class, fpk2);
- assertNotNull(fb);
- assertNotNull(keeper);
- assertEquals("Beckam", fb.getLastname());
- assertEquals("Arsenal", fb.getClub());
- assertEquals(1, s.createQuery(
- "from Footballer f where f.firstname = 'David'").list().size());
+ FootballerPk fpk = new FootballerPk( "David", "Beckam" );
+ fb = ( Footballer ) s.get( Footballer.class, fpk );
+ FootballerPk fpk2 = new FootballerPk( "Fabien", "Bartez" );
+ keeper = ( GoalKeeper ) s.get( GoalKeeper.class, fpk2 );
+ assertNotNull( fb );
+ assertNotNull( keeper );
+ assertEquals( "Beckam", fb.getLastname() );
+ assertEquals( "Arsenal", fb.getClub() );
+ assertEquals(
+ 1, s.createQuery(
+ "from Footballer f where f.firstname = 'David'"
+ ).list().size()
+ );
tx.commit();
// reattach by merge
tx = s.beginTransaction();
- fb.setClub("Bimbo FC");
- s.merge(fb);
+ fb.setClub( "Bimbo FC" );
+ s.merge( fb );
tx.commit();
// reattach by saveOrUpdate
tx = s.beginTransaction();
- fb.setClub("Bimbo FC SA");
- s.saveOrUpdate(fb);
+ fb.setClub( "Bimbo FC SA" );
+ s.saveOrUpdate( fb );
tx.commit();
// clean up
s.clear();
tx = s.beginTransaction();
- fpk = new FootballerPk("David", "Beckam");
- fb = (Footballer) s.get(Footballer.class, fpk);
- assertEquals("Bimbo FC SA", fb.getClub());
- s.delete(fb);
- s.delete(keeper);
+ fpk = new FootballerPk( "David", "Beckam" );
+ fb = ( Footballer ) s.get( Footballer.class, fpk );
+ assertEquals( "Bimbo FC SA", fb.getClub() );
+ s.delete( fb );
+ s.delete( keeper );
tx.commit();
s.close();
}
public void testColumnDefinition() {
- Column idCol = (Column) getCfg().getClassMapping(Ball.class.getName())
+ Column idCol = ( Column ) getCfg().getClassMapping( Ball.class.getName() )
.getIdentifierProperty().getValue().getColumnIterator().next();
- assertEquals("ball_id", idCol.getName());
+ assertEquals( "ball_id", idCol.getName() );
}
public void testLowAllocationSize() throws Exception {
@@ -264,42 +272,39 @@
tx = s.beginTransaction();
int size = 4;
BreakDance[] bds = new BreakDance[size];
- for (int i = 0; i < size; i++) {
+ for ( int i = 0; i < size; i++ ) {
bds[i] = new BreakDance();
- s.persist(bds[i]);
+ s.persist( bds[i] );
}
s.flush();
- for (int i = 0; i < size; i++) {
- assertEquals(i + 1, bds[i].id.intValue());
+ for ( int i = 0; i < size; i++ ) {
+ assertEquals( i + 1, bds[i].id.intValue() );
}
tx.rollback();
s.close();
}
-
-
-
- @Override
- protected boolean runForCurrentDialect() {
- return super.runForCurrentDialect() && getDialect().supportsSequences();
- }
/**
* @see org.hibernate.test.annotations.TestCase#getAnnotatedClasses()
*/
protected Class[] getAnnotatedClasses() {
- return new Class[] { Ball.class, Shoe.class, Store.class,
+ return new Class[] {
+ Ball.class, Shoe.class, Store.class,
Department.class, Dog.class, Computer.class, Home.class,
Phone.class, Tree.class, FirTree.class, Footballer.class,
SoundSystem.class, Furniture.class, GoalKeeper.class,
- BreakDance.class, Monkey.class};
+ BreakDance.class, Monkey.class
+ };
}
-
+
/**
* @see org.hibernate.test.annotations.TestCase#getAnnotatedPackages()
*/
protected String[] getAnnotatedPackages() {
- return new String[] { "org.hibernate.test.annotations",
- "org.hibernate.test.annotations.id" };
+ return new String[] {
+ "org.hibernate.test.annotations",
+ "org.hibernate.test.annotations.id"
+ };
}
@Override
Modified: core/trunk/annotations/src/test/java/org/hibernate/test/annotations/lob/LobTest.java
===================================================================
--- core/trunk/annotations/src/test/java/org/hibernate/test/annotations/lob/LobTest.java 2010-05-07 12:25:26 UTC (rev 19404)
+++ core/trunk/annotations/src/test/java/org/hibernate/test/annotations/lob/LobTest.java 2010-05-07 13:46:32 UTC (rev 19405)
@@ -3,12 +3,13 @@
import org.hibernate.Session;
import org.hibernate.Transaction;
-import org.hibernate.dialect.Dialect;
+import org.hibernate.junit.RequiresDialectFeature;
import org.hibernate.test.annotations.TestCase;
/**
* @author Emmanuel Bernard
*/
+@RequiresDialectFeature("supportsExpectedLobUsagePattern")
public class LobTest extends TestCase {
public void testSerializableToBlob() throws Exception {
Book book = new Book();
@@ -118,11 +119,6 @@
super( x );
}
- @Override
- protected boolean runForCurrentDialect() {
- return super.runForCurrentDialect() && getDialect().supportsExpectedLobUsagePattern();
- }
-
protected Class[] getAnnotatedClasses() {
return new Class[] {
Book.class,
Modified: core/trunk/annotations/src/test/java/org/hibernate/test/annotations/manytoone/referencedcolumnname/ManyToOneReferencedColumnNameTest.java
===================================================================
--- core/trunk/annotations/src/test/java/org/hibernate/test/annotations/manytoone/referencedcolumnname/ManyToOneReferencedColumnNameTest.java 2010-05-07 12:25:26 UTC (rev 19404)
+++ core/trunk/annotations/src/test/java/org/hibernate/test/annotations/manytoone/referencedcolumnname/ManyToOneReferencedColumnNameTest.java 2010-05-07 13:46:32 UTC (rev 19405)
@@ -1,29 +1,31 @@
-//$
+// $Id$
package org.hibernate.test.annotations.manytoone.referencedcolumnname;
import java.math.BigDecimal;
-import org.hibernate.test.annotations.TestCase;
import org.hibernate.Session;
+import org.hibernate.junit.RequiresDialectFeature;
+import org.hibernate.test.annotations.TestCase;
/**
* @author Emmanuel Bernard
*/
public class ManyToOneReferencedColumnNameTest extends TestCase {
+ @RequiresDialectFeature("supportsIdentityColumns")
public void testReoverableExceptionInFkOrdering() throws Exception {
//SF should not blow up
Vendor v = new Vendor();
Item i = new Item();
ZItemCost ic = new ZItemCost();
- ic.setCost( new BigDecimal(2) );
+ ic.setCost( new BigDecimal( 2 ) );
ic.setItem( i );
ic.setVendor( v );
WarehouseItem wi = new WarehouseItem();
wi.setDefaultCost( ic );
wi.setItem( i );
wi.setVendor( v );
- wi.setQtyInStock( new BigDecimal(2) );
- Session s = openSession( );
+ wi.setQtyInStock( new BigDecimal( 2 ) );
+ Session s = openSession();
s.getTransaction().begin();
s.save( i );
s.save( v );
@@ -32,16 +34,9 @@
s.flush();
s.getTransaction().rollback();
s.close();
-
+
}
-
- @Override
- protected boolean runForCurrentDialect() {
- return super.runForCurrentDialect() && getDialect().supportsIdentityColumns();
- }
-
-
protected Class[] getAnnotatedClasses() {
return new Class[] {
Item.class,
Modified: core/trunk/annotations/src/test/java/org/hibernate/test/annotations/xml/hbm/HbmWithIdentityTest.java
===================================================================
--- core/trunk/annotations/src/test/java/org/hibernate/test/annotations/xml/hbm/HbmWithIdentityTest.java 2010-05-07 12:25:26 UTC (rev 19404)
+++ core/trunk/annotations/src/test/java/org/hibernate/test/annotations/xml/hbm/HbmWithIdentityTest.java 2010-05-07 13:46:32 UTC (rev 19405)
@@ -2,6 +2,7 @@
package org.hibernate.test.annotations.xml.hbm;
import org.hibernate.Session;
+import org.hibernate.junit.RequiresDialectFeature;
import org.hibernate.test.annotations.TestCase;
/**
@@ -9,6 +10,7 @@
*/
public class HbmWithIdentityTest extends TestCase {
+ @RequiresDialectFeature("supportsIdentityColumns")
public void testManyToOneAndInterface() throws Exception {
Session s = openSession();
s.getTransaction().begin();
@@ -23,11 +25,6 @@
s.close();
}
- @Override
- protected boolean runForCurrentDialect() {
- return super.runForCurrentDialect() && getDialect().supportsIdentityColumns();
- }
-
protected Class[] getAnnotatedClasses() {
return new Class[] {
Sky.class,
Copied: core/trunk/testing/src/main/java/org/hibernate/junit/RequiresDialectFeature.java (from rev 19404, core/trunk/testing/src/main/java/org/hibernate/junit/RequiresDialect.java)
===================================================================
--- core/trunk/testing/src/main/java/org/hibernate/junit/RequiresDialectFeature.java (rev 0)
+++ core/trunk/testing/src/main/java/org/hibernate/junit/RequiresDialectFeature.java 2010-05-07 13:46:32 UTC (rev 19405)
@@ -0,0 +1,44 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2010, Red Hat Inc. or third-party contributors as
+ * indicated by the @author tags or express copyright attribution
+ * statements applied by the authors. All third-party contributions are
+ * distributed under license by Red Hat Inc.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify,
+ * copy, or redistribute it subject to the terms and conditions of the GNU
+ * Lesser General Public License, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this distribution; if not, write to:
+ * Free Software Foundation, Inc.
+ * 51 Franklin Street, Fifth Floor
+ * Boston, MA 02110-1301 USA
+ */
+package org.hibernate.junit;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+/**
+ * Annotation used to indicate that a test should be run only when the current dialect suppports the
+ * specified feature.
+ *
+ * @author Hardy Ferentschik
+ */
+@Target({ ElementType.METHOD, ElementType.TYPE })
+(a)Retention(RetentionPolicy.RUNTIME)
+public @interface RequiresDialectFeature {
+ /**
+ * @return The name of the dialect feature.
+ */
+ String value();
+}
\ No newline at end of file
Modified: core/trunk/testing/src/main/java/org/hibernate/test/annotations/HibernateTestCase.java
===================================================================
--- core/trunk/testing/src/main/java/org/hibernate/test/annotations/HibernateTestCase.java 2010-05-07 12:25:26 UTC (rev 19404)
+++ core/trunk/testing/src/main/java/org/hibernate/test/annotations/HibernateTestCase.java 2010-05-07 13:46:32 UTC (rev 19405)
@@ -1,4 +1,4 @@
-// $Id:$
+// $Id$
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
@@ -30,8 +30,6 @@
import java.lang.reflect.Modifier;
import java.sql.Connection;
import java.sql.SQLException;
-import java.util.HashSet;
-import java.util.Set;
import junit.framework.TestCase;
import org.slf4j.Logger;
@@ -42,6 +40,7 @@
import org.hibernate.jdbc.Work;
import org.hibernate.junit.FailureExpected;
import org.hibernate.junit.RequiresDialect;
+import org.hibernate.junit.RequiresDialectFeature;
import org.hibernate.junit.SkipForDialect;
import org.hibernate.junit.SkipLog;
import org.hibernate.tool.hbm2ddl.SchemaExport;
@@ -60,23 +59,6 @@
protected static Configuration cfg;
private static Class<?> lastTestClass;
-
- /**
- * Flag indicating whether the test should be run or skipped.
- */
- private boolean runTest = true;
-
- /**
- * List of required dialect for the current {@code runMethod}. If the list is empty any dialect is allowed.
- * Otherwise the current dialect or a superclass of the current dialect must be in the list.
- */
- private final Set<Class<? extends Dialect>> requiredDialectList = new HashSet<Class<? extends Dialect>>();
-
- /**
- * List of dialects for which the current {@code runMethod} should be skipped.
- */
- private final Set<Class<? extends Dialect>> skipForDialectList = new HashSet<Class<? extends Dialect>>();
-
public HibernateTestCase() {
super();
}
@@ -172,7 +154,7 @@
}
}
- protected final Skip determineSkipByDialect(Dialect dialect, Method runMethod) {
+ protected final Skip determineSkipByDialect(Dialect dialect, Method runMethod) throws Exception {
// skips have precedence, so check them first
SkipForDialect skipForDialectAnn = locateAnnotation( SkipForDialect.class, runMethod );
if ( skipForDialectAnn != null ) {
@@ -195,18 +177,34 @@
if ( requiresDialectAnn != null ) {
for ( Class<? extends Dialect> dialectClass : requiresDialectAnn.value() ) {
if ( requiresDialectAnn.strictMatching() ) {
- if ( dialectClass.equals( dialect.getClass() ) ) {
+ if ( !dialectClass.equals( dialect.getClass() ) ) {
return buildSkip( dialect, null, null );
}
}
else {
- if ( dialectClass.isInstance( dialect ) ) {
+ if ( !dialectClass.isInstance( dialect ) ) {
return buildSkip( dialect, null, null );
}
}
}
}
+ // then check against a dialect feature
+ RequiresDialectFeature requiresDialectFeatureAnn = locateAnnotation( RequiresDialectFeature.class, runMethod );
+ if ( requiresDialectFeatureAnn != null ) {
+ String feature = requiresDialectFeatureAnn.value();
+ boolean skip = false;
+ try {
+ Method m = dialect.getClass().getMethod( feature );
+ skip = (Boolean) m.invoke( dialect );
+ }
+ catch ( NoSuchMethodException e ) {
+ fail( "Dialect does not have a method: " + feature );
+ }
+ if ( skip ) {
+ return buildSkip( dialect, null, null );
+ }
+ }
return null;
}
@@ -244,30 +242,6 @@
return this.getClass().getName() + "#" + this.getName();
}
- protected boolean runForCurrentDialect() {
- boolean runTestForCurrentDialect = true;
-
- // check whether the current dialect is assignableFrom from any of the specified required dialects.
- for ( Class<? extends Dialect> dialect : requiredDialectList ) {
- if ( dialect.isAssignableFrom( Dialect.getDialect().getClass() ) ) {
- runTestForCurrentDialect = true;
- break;
- }
- runTestForCurrentDialect = false;
- }
-
- // check whether the current dialect is assignableFrom from any of the specified skip for dialects.
- for ( Class<? extends Dialect> dialect : skipForDialectList ) {
- if ( dialect.isAssignableFrom( Dialect.getDialect().getClass() ) ) {
- runTestForCurrentDialect = false;
- break;
- }
- runTestForCurrentDialect = true;
- }
-
- return runTestForCurrentDialect;
- }
-
private Method findTestMethod() {
String fName = getName();
assertNotNull( fName );
@@ -289,7 +263,7 @@
protected abstract Class<?>[] getAnnotatedClasses();
protected String[] getMappings() {
- return new String[]{};
+ return new String[] { };
}
protected abstract void handleUnclosedResources();
14 years, 7 months
Hibernate SVN: r19404 - in annotations/branches/v3_4_0_GA_CP/src/test/java/org/hibernate/test/annotations: lob and 2 other directories.
by hibernate-commits@lists.jboss.org
Author: stliu
Date: 2010-05-07 08:25:26 -0400 (Fri, 07 May 2010)
New Revision: 19404
Modified:
annotations/branches/v3_4_0_GA_CP/src/test/java/org/hibernate/test/annotations/id/sequences/IdTest.java
annotations/branches/v3_4_0_GA_CP/src/test/java/org/hibernate/test/annotations/lob/LobTest.java
annotations/branches/v3_4_0_GA_CP/src/test/java/org/hibernate/test/annotations/manytoone/referencedcolumnname/ManyToOneReferencedColumnNameTest.java
annotations/branches/v3_4_0_GA_CP/src/test/java/org/hibernate/test/annotations/xml/hbm/HbmWithIdentityTest.java
Log:
JBPAPP-4235 HHH-4822 Add @FailureExpected annotation to annotations and entitymananger modules to allow the skipping of tests
Modified: annotations/branches/v3_4_0_GA_CP/src/test/java/org/hibernate/test/annotations/id/sequences/IdTest.java
===================================================================
--- annotations/branches/v3_4_0_GA_CP/src/test/java/org/hibernate/test/annotations/id/sequences/IdTest.java 2010-05-07 12:23:49 UTC (rev 19403)
+++ annotations/branches/v3_4_0_GA_CP/src/test/java/org/hibernate/test/annotations/id/sequences/IdTest.java 2010-05-07 12:25:26 UTC (rev 19404)
@@ -3,6 +3,7 @@
import org.hibernate.Session;
import org.hibernate.Transaction;
+import org.hibernate.dialect.Dialect;
import org.hibernate.mapping.Column;
import org.hibernate.test.annotations.TestCase;
import org.hibernate.test.annotations.id.sequences.entities.Ball;
@@ -277,8 +278,8 @@
@Override
- protected boolean runForCurrentDialect() {
- return super.runForCurrentDialect() && getDialect().supportsSequences();
+ protected boolean runForCurrentDialect( Dialect dialect ) {
+ return dialect.supportsSequences();
}
/**
Modified: annotations/branches/v3_4_0_GA_CP/src/test/java/org/hibernate/test/annotations/lob/LobTest.java
===================================================================
--- annotations/branches/v3_4_0_GA_CP/src/test/java/org/hibernate/test/annotations/lob/LobTest.java 2010-05-07 12:23:49 UTC (rev 19403)
+++ annotations/branches/v3_4_0_GA_CP/src/test/java/org/hibernate/test/annotations/lob/LobTest.java 2010-05-07 12:25:26 UTC (rev 19404)
@@ -3,6 +3,9 @@
import org.hibernate.Session;
import org.hibernate.Transaction;
+import org.hibernate.dialect.Dialect;
+import org.hibernate.dialect.PostgreSQLDialect;
+import org.hibernate.junit.SkipForDialect;
import org.hibernate.test.annotations.TestCase;
/**
@@ -65,6 +68,7 @@
s.close();
}
+ @SkipForDialect(jiraKey="HHH-4876",value={PostgreSQLDialect.class})
public void testBlob() throws Exception {
Session s;
Transaction tx;
@@ -115,8 +119,8 @@
}
@Override
- protected boolean runForCurrentDialect() {
- return super.runForCurrentDialect() && getDialect().supportsExpectedLobUsagePattern();
+ protected boolean runForCurrentDialect( Dialect dialect ) {
+ return dialect.supportsExpectedLobUsagePattern();
}
public LobTest(String x) {
Modified: annotations/branches/v3_4_0_GA_CP/src/test/java/org/hibernate/test/annotations/manytoone/referencedcolumnname/ManyToOneReferencedColumnNameTest.java
===================================================================
--- annotations/branches/v3_4_0_GA_CP/src/test/java/org/hibernate/test/annotations/manytoone/referencedcolumnname/ManyToOneReferencedColumnNameTest.java 2010-05-07 12:23:49 UTC (rev 19403)
+++ annotations/branches/v3_4_0_GA_CP/src/test/java/org/hibernate/test/annotations/manytoone/referencedcolumnname/ManyToOneReferencedColumnNameTest.java 2010-05-07 12:25:26 UTC (rev 19404)
@@ -4,6 +4,7 @@
import java.math.BigDecimal;
import org.hibernate.Session;
+import org.hibernate.dialect.Dialect;
import org.hibernate.test.annotations.TestCase;
/**
@@ -38,8 +39,8 @@
@Override
- protected boolean runForCurrentDialect() {
- return super.runForCurrentDialect() && getDialect().supportsIdentityColumns();
+ protected boolean runForCurrentDialect( Dialect dialect ) {
+ return dialect.supportsIdentityColumns();
}
Modified: annotations/branches/v3_4_0_GA_CP/src/test/java/org/hibernate/test/annotations/xml/hbm/HbmWithIdentityTest.java
===================================================================
--- annotations/branches/v3_4_0_GA_CP/src/test/java/org/hibernate/test/annotations/xml/hbm/HbmWithIdentityTest.java 2010-05-07 12:23:49 UTC (rev 19403)
+++ annotations/branches/v3_4_0_GA_CP/src/test/java/org/hibernate/test/annotations/xml/hbm/HbmWithIdentityTest.java 2010-05-07 12:25:26 UTC (rev 19404)
@@ -2,6 +2,7 @@
package org.hibernate.test.annotations.xml.hbm;
import org.hibernate.Session;
+import org.hibernate.dialect.Dialect;
import org.hibernate.test.annotations.TestCase;
/**
@@ -26,8 +27,8 @@
@Override
- protected boolean runForCurrentDialect() {
- return super.runForCurrentDialect() && getDialect().supportsIdentityColumns();
+ protected boolean runForCurrentDialect( Dialect dialect ) {
+ return dialect.supportsIdentityColumns();
}
14 years, 7 months
Hibernate SVN: r19403 - core/branches/Branch_3_3_2_GA_CP/testing/src/main/java/org/hibernate/test/annotations.
by hibernate-commits@lists.jboss.org
Author: stliu
Date: 2010-05-07 08:23:49 -0400 (Fri, 07 May 2010)
New Revision: 19403
Modified:
core/branches/Branch_3_3_2_GA_CP/testing/src/main/java/org/hibernate/test/annotations/HibernateTestCase.java
Log:
JBPAPP-4235 HHH-4822 Add @FailureExpected annotation to annotations and entitymananger modules to allow the skipping of tests
Modified: core/branches/Branch_3_3_2_GA_CP/testing/src/main/java/org/hibernate/test/annotations/HibernateTestCase.java
===================================================================
--- core/branches/Branch_3_3_2_GA_CP/testing/src/main/java/org/hibernate/test/annotations/HibernateTestCase.java 2010-05-07 12:00:31 UTC (rev 19402)
+++ core/branches/Branch_3_3_2_GA_CP/testing/src/main/java/org/hibernate/test/annotations/HibernateTestCase.java 2010-05-07 12:23:49 UTC (rev 19403)
@@ -60,23 +60,6 @@
protected static Configuration cfg;
private static Class<?> lastTestClass;
-
- /**
- * Flag indicating whether the test should be run or skipped.
- */
- private boolean runTest = true;
-
- /**
- * List of required dialect for the current {@code runMethod}. If the list is empty any dialect is allowed.
- * Otherwise the current dialect or a superclass of the current dialect must be in the list.
- */
- private final Set<Class<? extends Dialect>> requiredDialectList = new HashSet<Class<? extends Dialect>>();
-
- /**
- * List of dialects for which the current {@code runMethod} should be skipped.
- */
- private final Set<Class<? extends Dialect>> skipForDialectList = new HashSet<Class<? extends Dialect>>();
-
public HibernateTestCase() {
super();
}
@@ -206,7 +189,10 @@
}
}
}
-
+ // finally check against runForCurrentDialect
+ if ( !runForCurrentDialect( dialect )){
+ return buildSkip( dialect, null, null );
+ }
return null;
}
@@ -244,28 +230,8 @@
return this.getClass().getName() + "#" + this.getName();
}
- protected boolean runForCurrentDialect() {
- boolean runTestForCurrentDialect = true;
-
- // check whether the current dialect is assignableFrom from any of the specified required dialects.
- for ( Class<? extends Dialect> dialect : requiredDialectList ) {
- if ( dialect.isAssignableFrom( Dialect.getDialect().getClass() ) ) {
- runTestForCurrentDialect = true;
- break;
- }
- runTestForCurrentDialect = false;
- }
-
- // check whether the current dialect is assignableFrom from any of the specified skip for dialects.
- for ( Class<? extends Dialect> dialect : skipForDialectList ) {
- if ( dialect.isAssignableFrom( Dialect.getDialect().getClass() ) ) {
- runTestForCurrentDialect = false;
- break;
- }
- runTestForCurrentDialect = true;
- }
-
- return runTestForCurrentDialect;
+ protected boolean runForCurrentDialect( Dialect dialect ) {
+ return true;
}
private Method findTestMethod() {
14 years, 7 months
Hibernate SVN: r19402 - core/branches/Branch_3_3_2_GA_CP/testing/src/main/java/org/hibernate/test/annotations.
by hibernate-commits@lists.jboss.org
Author: stliu
Date: 2010-05-07 08:00:31 -0400 (Fri, 07 May 2010)
New Revision: 19402
Modified:
core/branches/Branch_3_3_2_GA_CP/testing/src/main/java/org/hibernate/test/annotations/HibernateTestCase.java
Log:
JBPAPP-4235 HHH-4822 Add @FailureExpected annotation to annotations and entitymananger modules to allow the skipping of tests
Modified: core/branches/Branch_3_3_2_GA_CP/testing/src/main/java/org/hibernate/test/annotations/HibernateTestCase.java
===================================================================
--- core/branches/Branch_3_3_2_GA_CP/testing/src/main/java/org/hibernate/test/annotations/HibernateTestCase.java 2010-05-07 10:58:10 UTC (rev 19401)
+++ core/branches/Branch_3_3_2_GA_CP/testing/src/main/java/org/hibernate/test/annotations/HibernateTestCase.java 2010-05-07 12:00:31 UTC (rev 19402)
@@ -195,12 +195,12 @@
if ( requiresDialectAnn != null ) {
for ( Class<? extends Dialect> dialectClass : requiresDialectAnn.value() ) {
if ( requiresDialectAnn.strictMatching() ) {
- if ( dialectClass.equals( dialect.getClass() ) ) {
+ if ( !dialectClass.equals( dialect.getClass() ) ) {
return buildSkip( dialect, null, null );
}
}
else {
- if ( dialectClass.isInstance( dialect ) ) {
+ if ( !dialectClass.isInstance( dialect ) ) {
return buildSkip( dialect, null, null );
}
}
14 years, 7 months