Hibernate SVN: r18257 - core/trunk/entitymanager/src/main/java/org/hibernate/ejb/packaging.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2009-12-17 08:29:55 -0500 (Thu, 17 Dec 2009)
New Revision: 18257
Modified:
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/packaging/PersistenceMetadata.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/packaging/PersistenceXmlLoader.java
Log:
Remove now unneeded flag to avoid getMember population
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/packaging/PersistenceMetadata.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/packaging/PersistenceMetadata.java 2009-12-17 11:05:13 UTC (rev 18256)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/packaging/PersistenceMetadata.java 2009-12-17 13:29:55 UTC (rev 18257)
@@ -52,7 +52,16 @@
private Properties props = new Properties();
private boolean excludeUnlistedClasses = false;
private String validationMode;
+ private String version;
+ public String getVersion() {
+ return version;
+ }
+
+ public void setVersion(String version) {
+ this.version = version;
+ }
+
public String getSharedCacheMode() {
return sharedCacheMode;
}
@@ -176,7 +185,9 @@
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
- sb.append( "PersistenceMetadata [\n")
+ sb.append( "PersistenceMetadata(version=" )
+ .append( version )
+ .append(") [\n")
.append("\tname: ").append(name).append("\n")
.append("\tjtaDataSource: ").append(jtaDatasource).append("\n")
.append("\tnonJtaDataSource: ").append(nonJtaDatasource).append("\n")
@@ -212,8 +223,7 @@
}
sb.append( "\t]\n")
.append("\thbmfiles: ")
- .append( hbmfiles != null ? hbmfiles.size() : 0 ).append("\n")
- .append("\tproperties[\n");
+ .append( hbmfiles != null ? hbmfiles.size() : 0 ).append("\n");
if (validationMode != null) {
sb.append("\tvalidation-mode: ").append(validationMode).append("\n");
@@ -222,6 +232,8 @@
sb.append("\tshared-cache-mode: ").append(sharedCacheMode).append("\n");
}
+ sb.append("\tproperties[\n");
+
if (props != null) {
for ( Map.Entry elt : props.entrySet()) {
sb.append("\t\t").append( elt.getKey() ).append(": ").append( elt.getValue() ).append("\n");
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/packaging/PersistenceXmlLoader.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/packaging/PersistenceXmlLoader.java 2009-12-17 11:05:13 UTC (rev 18256)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/packaging/PersistenceXmlLoader.java 2009-12-17 13:29:55 UTC (rev 18257)
@@ -33,6 +33,12 @@
import javax.persistence.spi.PersistenceUnitTransactionType;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.transform.stream.StreamSource;
+import javax.xml.transform.dom.DOMSource;
+import javax.xml.validation.SchemaFactory;
+import javax.xml.validation.Schema;
+import javax.xml.validation.Validator;
+import javax.xml.validation.ValidatorHandler;
import org.hibernate.cfg.EJB3DTDEntityResolver;
import org.hibernate.ejb.HibernatePersistence;
@@ -71,30 +77,36 @@
if ( is == null ) {
throw new IOException( "Failed to obtain InputStream from url: " + configURL );
}
- List errors = new ArrayList();
- DocumentBuilderFactory docBuilderFactory = null;
- docBuilderFactory = DocumentBuilderFactory.newInstance();
- docBuilderFactory.setValidating( true );
+ DocumentBuilderFactory docBuilderFactory = DocumentBuilderFactory.newInstance();
docBuilderFactory.setNamespaceAware( true );
- try {
- //otherwise Xerces fails in validation
- docBuilderFactory.setAttribute( "http://apache.org/xml/features/validation/schema", true );
- }
- catch (IllegalArgumentException e) {
- docBuilderFactory.setValidating( false );
- docBuilderFactory.setNamespaceAware( false );
- }
+ final Schema v2Schema = SchemaFactory.newInstance( javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI )
+ .newSchema( new StreamSource( getStreamFromClasspath( "persistence_2_0.xsd" ) ) );
+ final Validator v2Validator = v2Schema.newValidator();
+ final Schema v1Schema = SchemaFactory.newInstance( javax.xml.XMLConstants.W3C_XML_SCHEMA_NS_URI )
+ .newSchema( new StreamSource( getStreamFromClasspath( "persistence_1_0.xsd" ) ) );
+ final Validator v1Validator = v2Schema.newValidator();
+
InputSource source = new InputSource( is );
DocumentBuilder docBuilder = docBuilderFactory.newDocumentBuilder();
docBuilder.setEntityResolver( resolver );
- docBuilder.setErrorHandler( new ErrorLogger( "XML InputStream", errors, resolver ) );
Document doc = docBuilder.parse( source );
+
+ List errors = new ArrayList();
+ v2Validator.setErrorHandler( new ErrorLogger( "XML InputStream", errors, resolver ) );
+ v2Validator.validate( new DOMSource( doc ) );
+
if ( errors.size() != 0 ) {
- throw new PersistenceException( "invalid persistence.xml", (Throwable) errors.get( 0 ) );
+ throw new PersistenceException( "Invlid persistence.xml. Check the error logs for parsing errors", (Throwable) errors.get( 0 ) );
}
return doc;
}
+ private static InputStream getStreamFromClasspath(String fileName) {
+ String path = "org/hibernate/ejb/" + fileName;
+ InputStream dtdStream = PersistenceXmlLoader.class.getClassLoader().getResourceAsStream( path );
+ return dtdStream;
+ }
+
/**
* Method used by JBoss AS 4.0.5 for parsing
*/
@@ -109,6 +121,9 @@
PersistenceUnitTransactionType defaultTransactionType) throws Exception {
Document doc = loadURL( url, resolver );
Element top = doc.getDocumentElement();
+ //version is mandatory
+ final String version = top.getAttribute( "version" );
+
NodeList children = top.getChildNodes();
ArrayList<PersistenceMetadata> units = new ArrayList<PersistenceMetadata>();
for ( int i = 0; i < children.getLength() ; i++ ) {
@@ -117,6 +132,7 @@
String tag = element.getTagName();
if ( tag.equals( "persistence-unit" ) ) {
PersistenceMetadata metadata = parsePersistenceUnit( element );
+ metadata.setVersion(version);
//override properties of metadata if needed
if ( overrides.containsKey( HibernatePersistence.PROVIDER ) ) {
String provider = (String) overrides.get( HibernatePersistence.PROVIDER );
@@ -270,20 +286,33 @@
}
public void error(SAXParseException error) {
- if ( resolver instanceof EJB3DTDEntityResolver ) {
- if ( ( (EJB3DTDEntityResolver) resolver ).isResolved() == false ) return;
- }
- log.error( "Error parsing XML: {}({}) {}", new Object[] { file, error.getLineNumber(), error.getMessage() } );
+// if ( resolver instanceof EJB3DTDEntityResolver ) {
+// if ( ( (EJB3DTDEntityResolver) resolver ).isResolved() == false ) return;
+// }
+
+ log.error( "Error parsing XML (line {}: column {}): {}",
+ new Object[] {
+ error.getLineNumber(),
+ error.getColumnNumber(),
+ error.getMessage() } );
errors.add( error );
}
public void fatalError(SAXParseException error) {
- log.error( "Error parsing XML: {}({}) {}", new Object[] { file, error.getLineNumber(), error.getMessage() } );
+ log.error( "Error parsing XML (line {}: column {}): {}",
+ new Object[] {
+ error.getLineNumber(),
+ error.getColumnNumber(),
+ error.getMessage() } );
errors.add( error );
}
public void warning(SAXParseException warn) {
- log.warn( "Warning parsing XML: {}({}) {}", new Object[] { file, warn.getLineNumber(), warn.getMessage() } );
+ log.warn( "Warning parsing XML (line {}: column {}): {}",
+ new Object[] {
+ warn.getLineNumber(),
+ warn.getColumnNumber(),
+ warn.getMessage() } );
}
}
14 years, 12 months
Hibernate SVN: r18256 - core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel.
by hibernate-commits@lists.jboss.org
Author: epbernard
Date: 2009-12-17 06:05:13 -0500 (Thu, 17 Dec 2009)
New Revision: 18256
Modified:
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/AttributeFactory.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/MetadataContext.java
Log:
Remove now unneeded flag to avoid getMember population
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/AttributeFactory.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/AttributeFactory.java 2009-12-17 08:49:02 UTC (rev 18255)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/AttributeFactory.java 2009-12-17 11:05:13 UTC (rev 18256)
@@ -58,19 +58,19 @@
}
@SuppressWarnings({ "unchecked" })
- public <X, Y> AttributeImplementor<X, Y> buildAttribute(AbstractManagedType<X> ownerType, Property property, boolean getMember) {
+ public <X, Y> AttributeImplementor<X, Y> buildAttribute(AbstractManagedType<X> ownerType, Property property) {
AttributeContext attrContext = getAttributeContext( property );
final AttributeImplementor<X, Y> attribute;
if ( attrContext.isCollection() ) {
- attribute = buildPluralAttribute( ownerType, property, attrContext, getMember );
+ attribute = buildPluralAttribute( ownerType, property, attrContext);
}
else {
- final Type<Y> attrType = getType( ownerType, attrContext.getElementTypeStatus(), attrContext.getElementValue(), getMember );
+ final Type<Y> attrType = getType( ownerType, attrContext.getElementTypeStatus(), attrContext.getElementValue() );
attribute = new SingularAttributeImpl<X,Y>(
property.getName(),
property.getType().getReturnedClass(),
ownerType,
- getMember ? determineStandardJavaMember( ownerType, property ) : null,
+ determineStandardJavaMember( ownerType, property ),
false,
false,
property.isOptional(),
@@ -82,15 +82,15 @@
}
@SuppressWarnings( "unchecked" )
- private <X, Y, V, K> AttributeImplementor<X, Y> buildPluralAttribute(AbstractManagedType<X> ownerType, Property property, AttributeContext attrContext, boolean getMember) {
+ private <X, Y, V, K> AttributeImplementor<X, Y> buildPluralAttribute(AbstractManagedType<X> ownerType, Property property, AttributeContext attrContext) {
AttributeImplementor<X, Y> attribute;
- final Type<V> attrType = getType( ownerType, attrContext.getElementTypeStatus(), attrContext.getElementValue(), getMember );
- final Member member = getMember ? determineStandardJavaMember( ownerType, property ) : null;
+ final Type<V> attrType = getType( ownerType, attrContext.getElementTypeStatus(), attrContext.getElementValue() );
+ final Member member = determineStandardJavaMember( ownerType, property );
final Class<Y> collectionClass = (Class<Y>) ( member instanceof Field
? ( ( Field ) member ).getType()
: ( ( Method ) member ).getReturnType() );
if ( java.util.Map.class.isAssignableFrom( collectionClass ) ) {
- final Type<K> keyType = getType( ownerType, attrContext.getKeyTypeStatus(), attrContext.getKeyValue(), getMember );
+ final Type<K> keyType = getType( ownerType, attrContext.getKeyTypeStatus(), attrContext.getKeyValue() );
attribute = PluralAttributeImpl.create( ownerType, attrType, collectionClass, keyType )
.member( member )
.property( property )
@@ -107,13 +107,13 @@
return attribute;
}
- private <X> Type<X> getType(AbstractManagedType owner, AttributeContext.TypeStatus elementTypeStatus, Value value, boolean getMember) {
+ private <X> Type<X> getType(AbstractManagedType owner, AttributeContext.TypeStatus elementTypeStatus, Value value) {
final org.hibernate.type.Type type = value.getType();
switch ( elementTypeStatus ) {
case BASIC:
return buildBasicType( type );
case EMBEDDABLE:
- return buildEmbeddableType( owner, value, type, getMember );
+ return buildEmbeddableType( owner, value, type );
case ENTITY:
return buildEntityType( type );
default:
@@ -135,7 +135,7 @@
}
@SuppressWarnings( "unchecked" )
- private <X> Type<X> buildEmbeddableType(AbstractManagedType owner, Value value, org.hibernate.type.Type type, boolean getMember) {
+ private <X> Type<X> buildEmbeddableType(AbstractManagedType owner, Value value, org.hibernate.type.Type type) {
//build embedable type
final Class<X> clazz = type.getReturnedClass();
final EmbeddableTypeImpl<X> embeddableType = new EmbeddableTypeImpl<X>( clazz, owner, (ComponentType) type );
@@ -144,22 +144,22 @@
final Iterator<Property> subProperties = component.getPropertyIterator();
while ( subProperties.hasNext() ) {
final Property property = subProperties.next();
- embeddableType.getBuilder().addAttribute( buildAttribute( embeddableType, property, getMember ) );
+ embeddableType.getBuilder().addAttribute( buildAttribute( embeddableType, property) );
}
embeddableType.lock();
return embeddableType;
}
@SuppressWarnings({ "unchecked" })
- public <X, Y> SingularAttributeImpl<X, Y> buildIdAttribute(AbstractIdentifiableType<X> ownerType, Property property, boolean getMember) {
+ public <X, Y> SingularAttributeImpl<X, Y> buildIdAttribute(AbstractIdentifiableType<X> ownerType, Property property) {
final AttributeContext attrContext = getAttributeContext( property );
- final Type<Y> attrType = getType( ownerType, attrContext.getElementTypeStatus(), attrContext.getElementValue(), getMember );
+ final Type<Y> attrType = getType( ownerType, attrContext.getElementTypeStatus(), attrContext.getElementValue() );
final Class<Y> idJavaType = property.getType().getReturnedClass();
return new SingularAttributeImpl.Identifier(
property.getName(),
idJavaType,
ownerType,
- getMember ? determineIdentifierJavaMember( ownerType, property ) : null,
+ determineIdentifierJavaMember( ownerType, property ),
attrType,
attrContext.getElementAttributeType()
);
@@ -259,15 +259,15 @@
}
@SuppressWarnings({ "unchecked" })
- public <X, Y> SingularAttributeImpl<X, Y> buildVersionAttribute(AbstractIdentifiableType<X> ownerType, Property property, boolean getMember) {
+ public <X, Y> SingularAttributeImpl<X, Y> buildVersionAttribute(AbstractIdentifiableType<X> ownerType, Property property) {
final AttributeContext attrContext = getAttributeContext( property );
final Class<Y> javaType = property.getType().getReturnedClass();
- final Type<Y> attrType = getType( ownerType, attrContext.getElementTypeStatus(), attrContext.getElementValue(), getMember );
+ final Type<Y> attrType = getType( ownerType, attrContext.getElementTypeStatus(), attrContext.getElementValue() );
return new SingularAttributeImpl.Version(
property.getName(),
javaType,
ownerType,
- getMember ? determineVersionJavaMember( ownerType, property ) : null,
+ determineVersionJavaMember( ownerType, property ),
attrType,
attrContext.getElementAttributeType()
);
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/MetadataContext.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/MetadataContext.java 2009-12-17 08:49:02 UTC (rev 18255)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/metamodel/MetadataContext.java 2009-12-17 11:05:13 UTC (rev 18256)
@@ -174,7 +174,7 @@
// #buildIdClassAttributes
continue;
}
- final Attribute attribute = attributeFactory.buildAttribute( jpa2Mapping, property, true );
+ final Attribute attribute = attributeFactory.buildAttribute( jpa2Mapping, property );
jpa2Mapping.getBuilder().addAttribute( attribute );
}
jpa2Mapping.lock();
@@ -191,7 +191,7 @@
Iterator<Property> properties = ( Iterator<Property> ) safeMapping.getDeclaredPropertyIterator();
while ( properties.hasNext() ) {
final Property property = properties.next();
- final Attribute attribute = attributeFactory.buildAttribute( jpa2Mapping, property, true );
+ final Attribute attribute = attributeFactory.buildAttribute( jpa2Mapping, property );
jpa2Mapping.getBuilder().addAttribute( attribute );
}
jpa2Mapping.lock();
@@ -213,7 +213,7 @@
final Property declaredIdentifierProperty = persistentClass.getDeclaredIdentifierProperty();
if (declaredIdentifierProperty != null) {
jpaEntityType.getBuilder().applyIdAttribute(
- attributeFactory.buildIdAttribute( jpaEntityType, declaredIdentifierProperty, true )
+ attributeFactory.buildIdAttribute( jpaEntityType, declaredIdentifierProperty )
);
}
}
@@ -227,7 +227,7 @@
final Property declaredIdentifierProperty = mappingType.getDeclaredIdentifierProperty();
if (declaredIdentifierProperty != null) {
jpaMappingType.getBuilder().applyIdAttribute(
- attributeFactory.buildIdAttribute( jpaMappingType, declaredIdentifierProperty, true )
+ attributeFactory.buildIdAttribute( jpaMappingType, declaredIdentifierProperty )
);
}
}
@@ -244,7 +244,7 @@
final Property declaredVersion = persistentClass.getDeclaredVersion();
if (declaredVersion != null) {
jpaEntityType.getBuilder().applyVersionAttribute(
- attributeFactory.buildVersionAttribute( jpaEntityType, declaredVersion, true )
+ attributeFactory.buildVersionAttribute( jpaEntityType, declaredVersion )
);
}
}
@@ -253,7 +253,7 @@
final Property declaredVersion = mappingType.getDeclaredVersion();
if ( declaredVersion != null ) {
jpaMappingType.getBuilder().applyVersionAttribute(
- attributeFactory.buildVersionAttribute( jpaMappingType, declaredVersion, true )
+ attributeFactory.buildVersionAttribute( jpaMappingType, declaredVersion )
);
}
}
@@ -265,7 +265,7 @@
@SuppressWarnings( "unchecked")
Iterator<Property> properties = persistentClass.getIdentifierMapper().getPropertyIterator();
while ( properties.hasNext() ) {
- attributes.add( attributeFactory.buildIdAttribute( jpaEntityType, properties.next(), true ) );
+ attributes.add( attributeFactory.buildIdAttribute( jpaEntityType, properties.next() ) );
}
return attributes;
}
@@ -277,7 +277,7 @@
@SuppressWarnings( "unchecked" )
Iterator<Property> properties = mappingType.getIdentifierMapper().getPropertyIterator();
while ( properties.hasNext() ) {
- attributes.add( attributeFactory.buildIdAttribute( jpaMappingType, properties.next(), true ) );
+ attributes.add( attributeFactory.buildIdAttribute( jpaMappingType, properties.next() ) );
}
return attributes;
}
14 years, 12 months
Hibernate SVN: r18254 - core/trunk/core/src/main/java/org/hibernate/dialect.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2009-12-17 00:51:20 -0500 (Thu, 17 Dec 2009)
New Revision: 18254
Modified:
core/trunk/core/src/main/java/org/hibernate/dialect/Cache71Dialect.java
core/trunk/core/src/main/java/org/hibernate/dialect/DB2Dialect.java
core/trunk/core/src/main/java/org/hibernate/dialect/HSQLDialect.java
core/trunk/core/src/main/java/org/hibernate/dialect/IngresDialect.java
core/trunk/core/src/main/java/org/hibernate/dialect/MckoiDialect.java
core/trunk/core/src/main/java/org/hibernate/dialect/MySQLDialect.java
core/trunk/core/src/main/java/org/hibernate/dialect/Oracle8iDialect.java
core/trunk/core/src/main/java/org/hibernate/dialect/Oracle9Dialect.java
core/trunk/core/src/main/java/org/hibernate/dialect/PostgreSQLDialect.java
core/trunk/core/src/main/java/org/hibernate/dialect/RDMSOS2200Dialect.java
Log:
HHH-4709 - registered length functions should return Integer
Modified: core/trunk/core/src/main/java/org/hibernate/dialect/Cache71Dialect.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/dialect/Cache71Dialect.java 2009-12-17 00:21:49 UTC (rev 18253)
+++ core/trunk/core/src/main/java/org/hibernate/dialect/Cache71Dialect.java 2009-12-17 05:51:20 UTC (rev 18254)
@@ -305,7 +305,6 @@
registerFunction( "lcase", new StandardJDBCEscapeFunction( "lcase", Hibernate.STRING ) );
registerFunction( "left", new StandardJDBCEscapeFunction( "left", Hibernate.STRING ) );
registerFunction( "len", new StandardSQLFunction( "len", Hibernate.INTEGER ) );
- registerFunction( "length", new StandardSQLFunction( "length", Hibernate.INTEGER ) );
registerFunction( "$length", new VarArgsSQLFunction( "$length(", ",", ")" ) );
// aggregate functions shouldn't be registered, right?
//registerFunction( "list", new StandardSQLFunction("list",Hibernate.STRING) );
Modified: core/trunk/core/src/main/java/org/hibernate/dialect/DB2Dialect.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/dialect/DB2Dialect.java 2009-12-17 00:21:49 UTC (rev 18253)
+++ core/trunk/core/src/main/java/org/hibernate/dialect/DB2Dialect.java 2009-12-17 05:51:20 UTC (rev 18254)
@@ -134,7 +134,6 @@
registerFunction("lower", new StandardSQLFunction("lower") );
registerFunction("ucase", new StandardSQLFunction("ucase") );
registerFunction("lcase", new StandardSQLFunction("lcase") );
- registerFunction("length", new StandardSQLFunction("length", Hibernate.LONG) );
registerFunction("ltrim", new StandardSQLFunction("ltrim") );
registerFunction("rtrim", new StandardSQLFunction("rtrim") );
registerFunction( "substr", new StandardSQLFunction( "substr", Hibernate.STRING ) );
Modified: core/trunk/core/src/main/java/org/hibernate/dialect/HSQLDialect.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/dialect/HSQLDialect.java 2009-12-17 00:21:49 UTC (rev 18253)
+++ core/trunk/core/src/main/java/org/hibernate/dialect/HSQLDialect.java 2009-12-17 05:51:20 UTC (rev 18254)
@@ -85,7 +85,6 @@
registerFunction( "ascii", new StandardSQLFunction( "ascii", Hibernate.INTEGER ) );
registerFunction( "char", new StandardSQLFunction( "char", Hibernate.CHARACTER ) );
- registerFunction( "length", new StandardSQLFunction( "length", Hibernate.LONG ) );
registerFunction( "lower", new StandardSQLFunction( "lower" ) );
registerFunction( "upper", new StandardSQLFunction( "upper" ) );
registerFunction( "lcase", new StandardSQLFunction( "lcase" ) );
Modified: core/trunk/core/src/main/java/org/hibernate/dialect/IngresDialect.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/dialect/IngresDialect.java 2009-12-17 00:21:49 UTC (rev 18253)
+++ core/trunk/core/src/main/java/org/hibernate/dialect/IngresDialect.java 2009-12-17 05:51:20 UTC (rev 18254)
@@ -100,7 +100,6 @@
registerFunction( "intextract", new StandardSQLFunction( "intextract", Hibernate.INTEGER ) );
registerFunction( "left", new StandardSQLFunction( "left", Hibernate.STRING ) );
registerFunction( "locate", new SQLFunctionTemplate( Hibernate.LONG, "locate(?1, ?2)" ) );
- registerFunction( "length", new StandardSQLFunction( "length", Hibernate.LONG ) );
registerFunction( "ln", new StandardSQLFunction( "ln", Hibernate.DOUBLE ) );
registerFunction( "log", new StandardSQLFunction( "log", Hibernate.DOUBLE ) );
registerFunction( "lower", new StandardSQLFunction( "lower" ) );
Modified: core/trunk/core/src/main/java/org/hibernate/dialect/MckoiDialect.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/dialect/MckoiDialect.java 2009-12-17 00:21:49 UTC (rev 18253)
+++ core/trunk/core/src/main/java/org/hibernate/dialect/MckoiDialect.java 2009-12-17 05:51:20 UTC (rev 18254)
@@ -64,7 +64,6 @@
registerFunction( "sqrt", new StandardSQLFunction("sqrt", Hibernate.DOUBLE) );
registerFunction( "abs", new StandardSQLFunction("abs") );
registerFunction( "sign", new StandardSQLFunction( "sign", Hibernate.INTEGER ) );
- registerFunction( "length", new StandardSQLFunction( "length", Hibernate.INTEGER ) );
registerFunction( "round", new StandardSQLFunction( "round", Hibernate.INTEGER ) );
registerFunction( "mod", new StandardSQLFunction( "mod", Hibernate.INTEGER ) );
registerFunction( "least", new StandardSQLFunction("least") );
Modified: core/trunk/core/src/main/java/org/hibernate/dialect/MySQLDialect.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/dialect/MySQLDialect.java 2009-12-17 00:21:49 UTC (rev 18253)
+++ core/trunk/core/src/main/java/org/hibernate/dialect/MySQLDialect.java 2009-12-17 05:51:20 UTC (rev 18254)
@@ -76,7 +76,6 @@
registerFunction("character_length", new StandardSQLFunction("character_length", Hibernate.LONG) );
registerFunction("lcase", new StandardSQLFunction("lcase") );
registerFunction("lower", new StandardSQLFunction("lower") );
- registerFunction("length", new StandardSQLFunction("length", Hibernate.LONG) );
registerFunction("ltrim", new StandardSQLFunction("ltrim") );
registerFunction("ord", new StandardSQLFunction("ord", Hibernate.INTEGER) );
registerFunction("quote", new StandardSQLFunction("quote") );
Modified: core/trunk/core/src/main/java/org/hibernate/dialect/Oracle8iDialect.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/dialect/Oracle8iDialect.java 2009-12-17 00:21:49 UTC (rev 18253)
+++ core/trunk/core/src/main/java/org/hibernate/dialect/Oracle8iDialect.java 2009-12-17 05:51:20 UTC (rev 18254)
@@ -138,7 +138,6 @@
registerFunction( "soundex", new StandardSQLFunction("soundex") );
registerFunction( "upper", new StandardSQLFunction("upper") );
registerFunction( "ascii", new StandardSQLFunction("ascii", Hibernate.INTEGER) );
- registerFunction( "length", new StandardSQLFunction("length", Hibernate.LONG) );
registerFunction( "to_char", new StandardSQLFunction("to_char", Hibernate.STRING) );
registerFunction( "to_date", new StandardSQLFunction("to_date", Hibernate.TIMESTAMP) );
Modified: core/trunk/core/src/main/java/org/hibernate/dialect/Oracle9Dialect.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/dialect/Oracle9Dialect.java 2009-12-17 00:21:49 UTC (rev 18253)
+++ core/trunk/core/src/main/java/org/hibernate/dialect/Oracle9Dialect.java 2009-12-17 05:51:20 UTC (rev 18254)
@@ -117,7 +117,6 @@
registerFunction( "soundex", new StandardSQLFunction("soundex") );
registerFunction( "upper", new StandardSQLFunction("upper") );
registerFunction( "ascii", new StandardSQLFunction("ascii", Hibernate.INTEGER) );
- registerFunction( "length", new StandardSQLFunction("length", Hibernate.LONG) );
registerFunction( "to_char", new StandardSQLFunction("to_char", Hibernate.STRING) );
registerFunction( "to_date", new StandardSQLFunction("to_date", Hibernate.TIMESTAMP) );
Modified: core/trunk/core/src/main/java/org/hibernate/dialect/PostgreSQLDialect.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/dialect/PostgreSQLDialect.java 2009-12-17 00:21:49 UTC (rev 18253)
+++ core/trunk/core/src/main/java/org/hibernate/dialect/PostgreSQLDialect.java 2009-12-17 05:51:20 UTC (rev 18254)
@@ -106,7 +106,6 @@
registerFunction( "quote_literal", new StandardSQLFunction("quote_literal", Hibernate.STRING) );
registerFunction( "md5", new StandardSQLFunction("md5") );
registerFunction( "ascii", new StandardSQLFunction("ascii", Hibernate.INTEGER) );
- registerFunction( "length", new StandardSQLFunction("length", Hibernate.LONG) );
registerFunction( "char_length", new StandardSQLFunction("char_length", Hibernate.LONG) );
registerFunction( "bit_length", new StandardSQLFunction("bit_length", Hibernate.LONG) );
registerFunction( "octet_length", new StandardSQLFunction("octet_length", Hibernate.LONG) );
Modified: core/trunk/core/src/main/java/org/hibernate/dialect/RDMSOS2200Dialect.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/dialect/RDMSOS2200Dialect.java 2009-12-17 00:21:49 UTC (rev 18253)
+++ core/trunk/core/src/main/java/org/hibernate/dialect/RDMSOS2200Dialect.java 2009-12-17 05:51:20 UTC (rev 18254)
@@ -73,7 +73,6 @@
registerFunction("ascii", new StandardSQLFunction("ascii", Hibernate.INTEGER) );
registerFunction("char_length", new StandardSQLFunction("char_length", Hibernate.INTEGER) );
registerFunction("character_length", new StandardSQLFunction("character_length", Hibernate.INTEGER) );
- registerFunction("length", new StandardSQLFunction("length", Hibernate.INTEGER) );
// The RDMS concat() function only supports 2 parameters
registerFunction( "concat", new SQLFunctionTemplate(Hibernate.STRING, "concat(?1, ?2)") );
14 years, 12 months
Hibernate SVN: r18253 - in core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria: expression and 2 other directories.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2009-12-16 19:21:49 -0500 (Wed, 16 Dec 2009)
New Revision: 18253
Added:
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/Renderable.java
Modified:
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/CriteriaQueryImpl.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/MapKeyHelpers.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/QueryStructure.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/BinaryArithmeticOperation.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/CoalesceExpression.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/CompoundSelectionImpl.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/ConcatExpression.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/ExpressionImpl.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/ExpressionImplementor.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/NullifExpression.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/SearchedCaseExpression.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/SimpleCaseExpression.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/SubqueryComparisonModifierExpression.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/UnaryArithmeticOperation.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/LocateFunction.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/ParameterizedFunctionExpression.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/SubstringFunction.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/TrimFunction.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/BetweenPredicate.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/BooleanExpressionPredicate.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/ComparisonPredicate.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/CompoundPredicate.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/ExistsPredicate.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/ExplicitTruthValueCheck.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/InPredicate.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/LikePredicate.java
core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/NullnessPredicate.java
Log:
HHH-4708 - Make CompoundSelectionImpl implement ExpressionImplementor
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/CriteriaQueryImpl.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/CriteriaQueryImpl.java 2009-12-16 23:15:01 UTC (rev 18252)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/CriteriaQueryImpl.java 2009-12-17 00:21:49 UTC (rev 18253)
@@ -38,8 +38,6 @@
import javax.persistence.criteria.Subquery;
import javax.persistence.metamodel.EntityType;
-import org.hibernate.ejb.criteria.expression.ExpressionImplementor;
-
/**
* The Hibernate implementation of the JPA {@link CriteriaQuery} contract. Mostly a set of delegation to its
* internal {@link QueryStructure}.
@@ -342,7 +340,7 @@
String sep = "";
for ( Order orderSpec : getOrderList() ) {
jpaqlQuery.append( sep )
- .append( ( ( ExpressionImplementor ) orderSpec.getExpression() ).render( renderingContext ) )
+ .append( ( ( Renderable ) orderSpec.getExpression() ).render( renderingContext ) )
.append( orderSpec.isAscending() ? " asc" : " desc" );
sep = ", ";
}
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/MapKeyHelpers.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/MapKeyHelpers.java 2009-12-16 23:15:01 UTC (rev 18252)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/MapKeyHelpers.java 2009-12-17 00:21:49 UTC (rev 18253)
@@ -27,19 +27,19 @@
import java.util.Map;
import java.util.Map.Entry;
import javax.persistence.criteria.Expression;
+import javax.persistence.criteria.From;
import javax.persistence.criteria.Join;
import javax.persistence.criteria.JoinType;
import javax.persistence.criteria.MapJoin;
import javax.persistence.criteria.Path;
-import javax.persistence.criteria.From;
import javax.persistence.metamodel.Attribute;
import javax.persistence.metamodel.ManagedType;
import javax.persistence.metamodel.MapAttribute;
import javax.persistence.metamodel.SingularAttribute;
import javax.persistence.metamodel.Type.PersistenceType;
+
import org.hibernate.ejb.criteria.JoinImplementors.JoinImplementor;
import org.hibernate.ejb.criteria.expression.ExpressionImpl;
-import org.hibernate.ejb.criteria.expression.ExpressionImplementor;
import org.hibernate.engine.SessionFactoryImplementor;
import org.hibernate.persister.collection.CollectionPersister;
import org.hibernate.type.Type;
@@ -293,7 +293,7 @@
private String path(CriteriaQueryCompiler.RenderingContext renderingContext) {
return origin.getPathIdentifier()
+ '.'
- + ( (ExpressionImplementor) getAttribute() ).renderProjection( renderingContext );
+ + ( (Renderable) getAttribute() ).renderProjection( renderingContext );
}
}
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/QueryStructure.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/QueryStructure.java 2009-12-16 23:15:01 UTC (rev 18252)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/QueryStructure.java 2009-12-17 00:21:49 UTC (rev 18253)
@@ -43,8 +43,6 @@
import javax.persistence.criteria.JoinType;
import javax.persistence.metamodel.EntityType;
-import org.hibernate.ejb.criteria.expression.ExpressionImplementor;
-
/**
* Models basic query structure. Used as a delegate in implementing both
* {@link org.hibernate.criterion.CriteriaQuery} and
@@ -214,10 +212,10 @@
if ( getSelection() == null ) {
// we should have only a single root (query validation should have checked this...)
final Root root = getRoots().iterator().next();
- jpaqlQuery.append( ( (ExpressionImplementor) root ).renderProjection( renderingContext) );
+ jpaqlQuery.append( ( (Renderable) root ).renderProjection( renderingContext) );
}
else {
- jpaqlQuery.append( ( (ExpressionImplementor) getSelection() ).renderProjection( renderingContext ) );
+ jpaqlQuery.append( ( (Renderable) getSelection() ).renderProjection( renderingContext ) );
}
jpaqlQuery.append( " from " );
@@ -236,7 +234,7 @@
if ( getRestriction() != null) {
jpaqlQuery.append( " where " )
- .append( ( (ExpressionImplementor) getRestriction() ).render( renderingContext ) );
+ .append( ( (Renderable) getRestriction() ).render( renderingContext ) );
}
if ( ! getGroupings().isEmpty() ) {
@@ -244,13 +242,13 @@
sep = "";
for ( Expression grouping : getGroupings() ) {
jpaqlQuery.append( sep )
- .append( ( (ExpressionImplementor) grouping ).render( renderingContext ) );
+ .append( ( (Renderable) grouping ).render( renderingContext ) );
sep = ", ";
}
if ( getHaving() != null ) {
jpaqlQuery.append( " having " )
- .append( ( (ExpressionImplementor) getHaving() ).render( renderingContext ) );
+ .append( ( (Renderable) getHaving() ).render( renderingContext ) );
}
}
}
Added: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/Renderable.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/Renderable.java (rev 0)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/Renderable.java 2009-12-17 00:21:49 UTC (rev 18253)
@@ -0,0 +1,34 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2009, 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.ejb.criteria;
+
+/**
+ * TODO : javadoc
+ *
+ * @author Steve Ebersole
+ */
+public interface Renderable {
+ public String render(CriteriaQueryCompiler.RenderingContext renderingContext);
+ public String renderProjection(CriteriaQueryCompiler.RenderingContext renderingContext);
+}
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/BinaryArithmeticOperation.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/BinaryArithmeticOperation.java 2009-12-16 23:15:01 UTC (rev 18252)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/BinaryArithmeticOperation.java 2009-12-17 00:21:49 UTC (rev 18253)
@@ -28,6 +28,7 @@
import org.hibernate.ejb.criteria.ParameterRegistry;
import org.hibernate.ejb.criteria.CriteriaBuilderImpl;
import org.hibernate.ejb.criteria.CriteriaQueryCompiler;
+import org.hibernate.ejb.criteria.Renderable;
/**
* Models standard arithmetc operations with two operands.
@@ -196,8 +197,8 @@
public String render(CriteriaQueryCompiler.RenderingContext renderingContext) {
return getOperator().apply(
- ( (ExpressionImplementor) getLeftHandOperand() ).render( renderingContext ),
- ( (ExpressionImplementor) getRightHandOperand() ).render( renderingContext )
+ ( (Renderable) getLeftHandOperand() ).render( renderingContext ),
+ ( (Renderable) getRightHandOperand() ).render( renderingContext )
);
}
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/CoalesceExpression.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/CoalesceExpression.java 2009-12-16 23:15:01 UTC (rev 18252)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/CoalesceExpression.java 2009-12-17 00:21:49 UTC (rev 18253)
@@ -30,6 +30,7 @@
import org.hibernate.ejb.criteria.ParameterRegistry;
import org.hibernate.ejb.criteria.CriteriaBuilderImpl;
import org.hibernate.ejb.criteria.CriteriaQueryCompiler;
+import org.hibernate.ejb.criteria.Renderable;
/**
* Models an ANSI SQL <tt>COALESCE</tt> expression. <tt>COALESCE</tt> is a specialized <tt>CASE</tt> statement.
@@ -85,7 +86,7 @@
String sep = "";
for ( Expression expression : getExpressions() ) {
buffer.append( sep )
- .append( ( (ExpressionImplementor) expression ).render( renderingContext ) );
+ .append( ( (Renderable) expression ).render( renderingContext ) );
sep = ", ";
}
return buffer.append( ")" ).toString();
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/CompoundSelectionImpl.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/CompoundSelectionImpl.java 2009-12-16 23:15:01 UTC (rev 18252)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/CompoundSelectionImpl.java 2009-12-17 00:21:49 UTC (rev 18253)
@@ -24,11 +24,14 @@
package org.hibernate.ejb.criteria.expression;
import java.util.List;
+import javax.persistence.Tuple;
import javax.persistence.criteria.CompoundSelection;
import javax.persistence.criteria.Selection;
+import org.hibernate.ejb.criteria.CriteriaQueryCompiler;
import org.hibernate.ejb.criteria.ParameterRegistry;
import org.hibernate.ejb.criteria.CriteriaBuilderImpl;
+import org.hibernate.ejb.criteria.Renderable;
/**
* The Hibernate implementation of the JPA {@link CompoundSelection}
@@ -36,7 +39,8 @@
*
* @author Steve Ebersole
*/
-public class CompoundSelectionImpl<X> extends SelectionImpl<X> implements CompoundSelection<X> {
+public class CompoundSelectionImpl<X> extends SelectionImpl<X> implements CompoundSelection<X>, Renderable {
+ private final boolean isConstructor;
private List<Selection<?>> selectionItems;
public CompoundSelectionImpl(
@@ -44,6 +48,7 @@
Class<X> javaType,
List<Selection<?>> selectionItems) {
super( criteriaBuilder, javaType );
+ this.isConstructor = !javaType.isArray() && !Tuple.class.isAssignableFrom( javaType );
this.selectionItems = selectionItems;
}
@@ -63,4 +68,24 @@
}
}
+ public String render(CriteriaQueryCompiler.RenderingContext renderingContext) {
+ StringBuilder buff = new StringBuilder();
+ if ( isConstructor ) {
+ buff.append( "new " ).append( getJavaType().getName() ).append( '(' );
+ }
+ String sep = "";
+ for ( Selection selection : selectionItems ) {
+ buff.append( sep )
+ .append( ( (Renderable) selection ).renderProjection( renderingContext ) );
+ sep = ", ";
+ }
+ if ( isConstructor ) {
+ buff.append( ')' );
+ }
+ return buff.toString();
+ }
+
+ public String renderProjection(CriteriaQueryCompiler.RenderingContext renderingContext) {
+ return render( renderingContext );
+ }
}
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/ConcatExpression.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/ConcatExpression.java 2009-12-16 23:15:01 UTC (rev 18252)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/ConcatExpression.java 2009-12-17 00:21:49 UTC (rev 18253)
@@ -27,6 +27,7 @@
import org.hibernate.ejb.criteria.ParameterRegistry;
import org.hibernate.ejb.criteria.CriteriaBuilderImpl;
import org.hibernate.ejb.criteria.CriteriaQueryCompiler;
+import org.hibernate.ejb.criteria.Renderable;
/**
* A string concatenation.
@@ -78,9 +79,9 @@
}
public String render(CriteriaQueryCompiler.RenderingContext renderingContext) {
- return ( (ExpressionImplementor) getString1() ).render( renderingContext )
+ return ( (Renderable) getString1() ).render( renderingContext )
+ " || "
- + ( (ExpressionImplementor) getString2() ).render( renderingContext );
+ + ( (Renderable) getString2() ).render( renderingContext );
}
public String renderProjection(CriteriaQueryCompiler.RenderingContext renderingContext) {
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/ExpressionImpl.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/ExpressionImpl.java 2009-12-16 23:15:01 UTC (rev 18252)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/ExpressionImpl.java 2009-12-17 00:21:49 UTC (rev 18253)
@@ -35,7 +35,9 @@
*
* @author Steve Ebersole
*/
-public abstract class ExpressionImpl<T> extends SelectionImpl<T> implements ExpressionImplementor<T> {
+public abstract class ExpressionImpl<T>
+ extends SelectionImpl<T>
+ implements ExpressionImplementor<T> {
public ExpressionImpl(CriteriaBuilderImpl criteriaBuilder, Class<T> javaType) {
super( criteriaBuilder, javaType );
}
@@ -43,6 +45,7 @@
/**
* {@inheritDoc}
*/
+ @SuppressWarnings({ "unchecked" })
public <X> Expression<X> as(Class<X> type) {
return type.equals( getJavaType() )
? (Expression<X>) this
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/ExpressionImplementor.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/ExpressionImplementor.java 2009-12-16 23:15:01 UTC (rev 18252)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/ExpressionImplementor.java 2009-12-17 00:21:49 UTC (rev 18253)
@@ -25,14 +25,12 @@
import javax.persistence.criteria.Expression;
-import org.hibernate.ejb.criteria.CriteriaQueryCompiler;
+import org.hibernate.ejb.criteria.Renderable;
/**
* TODO : javadoc
*
* @author Steve Ebersole
*/
-public interface ExpressionImplementor<T> extends Expression<T> {
- public String render(CriteriaQueryCompiler.RenderingContext renderingContext);
- public String renderProjection(CriteriaQueryCompiler.RenderingContext renderingContext);
+public interface ExpressionImplementor<T> extends Expression<T>, Renderable {
}
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/NullifExpression.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/NullifExpression.java 2009-12-16 23:15:01 UTC (rev 18252)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/NullifExpression.java 2009-12-17 00:21:49 UTC (rev 18253)
@@ -27,6 +27,7 @@
import org.hibernate.ejb.criteria.ParameterRegistry;
import org.hibernate.ejb.criteria.CriteriaBuilderImpl;
import org.hibernate.ejb.criteria.CriteriaQueryCompiler;
+import org.hibernate.ejb.criteria.Renderable;
/**
* Models an ANSI SQL <tt>NULLIF</tt> expression. <tt>NULLIF</tt> is a specialized <tt>CASE</tt> statement.
@@ -76,9 +77,9 @@
public String render(CriteriaQueryCompiler.RenderingContext renderingContext) {
return "nullif("
- + ( (ExpressionImplementor) getPrimaryExpression() ).render( renderingContext )
+ + ( (Renderable) getPrimaryExpression() ).render( renderingContext )
+ ','
- + ( (ExpressionImplementor) getSecondaryExpression() ).render( renderingContext )
+ + ( (Renderable) getSecondaryExpression() ).render( renderingContext )
+ ")";
}
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/SearchedCaseExpression.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/SearchedCaseExpression.java 2009-12-16 23:15:01 UTC (rev 18252)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/SearchedCaseExpression.java 2009-12-17 00:21:49 UTC (rev 18253)
@@ -30,6 +30,7 @@
import org.hibernate.ejb.criteria.ParameterRegistry;
import org.hibernate.ejb.criteria.CriteriaBuilderImpl;
import org.hibernate.ejb.criteria.CriteriaQueryCompiler;
+import org.hibernate.ejb.criteria.Renderable;
/**
* Models what ANSI SQL terms a <tt>searched case expression</tt>. This is a <tt>CASE</tt> expression
@@ -129,12 +130,12 @@
StringBuilder caseStatement = new StringBuilder( "case" );
for ( WhenClause whenClause : getWhenClauses() ) {
caseStatement.append( " when " )
- .append( ( (ExpressionImplementor) whenClause.getCondition() ).render( renderingContext ) )
+ .append( ( (Renderable) whenClause.getCondition() ).render( renderingContext ) )
.append( " then " )
- .append( ( (ExpressionImplementor) whenClause.getResult() ).render( renderingContext ) );
+ .append( ( (Renderable) whenClause.getResult() ).render( renderingContext ) );
}
caseStatement.append( " else " )
- .append( ( (ExpressionImplementor) getOtherwiseResult() ).render( renderingContext ) )
+ .append( ( (Renderable) getOtherwiseResult() ).render( renderingContext ) )
.append( " end" );
return caseStatement.toString();
}
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/SimpleCaseExpression.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/SimpleCaseExpression.java 2009-12-16 23:15:01 UTC (rev 18252)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/SimpleCaseExpression.java 2009-12-17 00:21:49 UTC (rev 18253)
@@ -30,6 +30,7 @@
import org.hibernate.ejb.criteria.ParameterRegistry;
import org.hibernate.ejb.criteria.CriteriaBuilderImpl;
import org.hibernate.ejb.criteria.CriteriaQueryCompiler;
+import org.hibernate.ejb.criteria.Renderable;
/**
* Models what ANSI SQL terms a simple case statement. This is a <tt>CASE</tt> expression in the form<pre>
@@ -136,15 +137,15 @@
public String render(CriteriaQueryCompiler.RenderingContext renderingContext) {
StringBuilder caseExpr = new StringBuilder();
caseExpr.append( "case " )
- .append( ( (ExpressionImplementor) getExpression() ).render( renderingContext ) )
+ .append( ( (Renderable) getExpression() ).render( renderingContext ) )
.append( ' ' );
for ( WhenClause whenClause : getWhenClauses() ) {
- caseExpr.append( ( (ExpressionImplementor) whenClause.getCondition() ).render( renderingContext ) )
+ caseExpr.append( ( (Renderable) whenClause.getCondition() ).render( renderingContext ) )
.append( " then " )
- .append( ( (ExpressionImplementor) whenClause.getResult() ).render( renderingContext ) );
+ .append( ( (Renderable) whenClause.getResult() ).render( renderingContext ) );
}
caseExpr.append( " else " )
- .append( ( (ExpressionImplementor) getOtherwiseResult() ).render( renderingContext ) )
+ .append( ( (Renderable) getOtherwiseResult() ).render( renderingContext ) )
.append( " end" );
return caseExpr.toString();
}
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/SubqueryComparisonModifierExpression.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/SubqueryComparisonModifierExpression.java 2009-12-16 23:15:01 UTC (rev 18252)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/SubqueryComparisonModifierExpression.java 2009-12-17 00:21:49 UTC (rev 18253)
@@ -27,6 +27,7 @@
import org.hibernate.ejb.criteria.ParameterRegistry;
import org.hibernate.ejb.criteria.CriteriaBuilderImpl;
import org.hibernate.ejb.criteria.CriteriaQueryCompiler;
+import org.hibernate.ejb.criteria.Renderable;
/**
* Represents a {@link Modifier#ALL}, {@link Modifier#ANY}, {@link Modifier#SOME} modifier appplied to a subquery as
@@ -80,7 +81,7 @@
}
public String render(CriteriaQueryCompiler.RenderingContext renderingContext) {
- return getModifier().rendered() + ( ( ExpressionImplementor ) getSubquery() ).render( renderingContext );
+ return getModifier().rendered() + ( (Renderable) getSubquery() ).render( renderingContext );
}
public String renderProjection(CriteriaQueryCompiler.RenderingContext renderingContext) {
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/UnaryArithmeticOperation.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/UnaryArithmeticOperation.java 2009-12-16 23:15:01 UTC (rev 18252)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/UnaryArithmeticOperation.java 2009-12-17 00:21:49 UTC (rev 18253)
@@ -27,6 +27,7 @@
import org.hibernate.ejb.criteria.ParameterRegistry;
import org.hibernate.ejb.criteria.CriteriaBuilderImpl;
import org.hibernate.ejb.criteria.CriteriaQueryCompiler;
+import org.hibernate.ejb.criteria.Renderable;
/**
* Models unary arithmetic operation (unary plus and unary minus).
@@ -74,7 +75,7 @@
public String render(CriteriaQueryCompiler.RenderingContext renderingContext) {
return ( getOperation() == Operation.UNARY_MINUS ? '-' : '+' )
- + ( (ExpressionImplementor) getOperand() ).render( renderingContext );
+ + ( (Renderable) getOperand() ).render( renderingContext );
}
public String renderProjection(CriteriaQueryCompiler.RenderingContext renderingContext) {
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/LocateFunction.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/LocateFunction.java 2009-12-16 23:15:01 UTC (rev 18252)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/LocateFunction.java 2009-12-17 00:21:49 UTC (rev 18253)
@@ -28,8 +28,8 @@
import org.hibernate.ejb.criteria.ParameterRegistry;
import org.hibernate.ejb.criteria.CriteriaBuilderImpl;
import org.hibernate.ejb.criteria.CriteriaQueryCompiler;
+import org.hibernate.ejb.criteria.Renderable;
import org.hibernate.ejb.criteria.expression.LiteralExpression;
-import org.hibernate.ejb.criteria.expression.ExpressionImplementor;
/**
* Models the ANSI SQL <tt>LOCATE</tt> function.
@@ -102,12 +102,12 @@
public String render(CriteriaQueryCompiler.RenderingContext renderingContext) {
StringBuilder buffer = new StringBuilder();
buffer.append( "locate(" )
- .append( ( (ExpressionImplementor) getPattern() ).render( renderingContext ) )
+ .append( ( (Renderable) getPattern() ).render( renderingContext ) )
.append( ',' )
- .append( ( (ExpressionImplementor) getString() ).render( renderingContext ) );
+ .append( ( (Renderable) getString() ).render( renderingContext ) );
if ( getStart() != null ) {
buffer.append( ',' )
- .append( ( (ExpressionImplementor) getStart() ).render( renderingContext ) );
+ .append( ( (Renderable) getStart() ).render( renderingContext ) );
}
buffer.append( ')' );
return buffer.toString();
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/ParameterizedFunctionExpression.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/ParameterizedFunctionExpression.java 2009-12-16 23:15:01 UTC (rev 18252)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/ParameterizedFunctionExpression.java 2009-12-17 00:21:49 UTC (rev 18253)
@@ -31,8 +31,8 @@
import org.hibernate.ejb.criteria.ParameterRegistry;
import org.hibernate.ejb.criteria.CriteriaBuilderImpl;
import org.hibernate.ejb.criteria.CriteriaQueryCompiler;
+import org.hibernate.ejb.criteria.Renderable;
import org.hibernate.ejb.criteria.expression.LiteralExpression;
-import org.hibernate.ejb.criteria.expression.ExpressionImplementor;
/**
* Support for functions with parameters.
@@ -94,7 +94,7 @@
buffer.append( getFunctionName() )
.append( '(' );
for ( Expression argument : argumentExpressions ) {
- buffer.append( ( (ExpressionImplementor) argument ).render( renderingContext ) );
+ buffer.append( ( (Renderable) argument ).render( renderingContext ) );
}
buffer.append( ')' );
return buffer.toString();
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/SubstringFunction.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/SubstringFunction.java 2009-12-16 23:15:01 UTC (rev 18252)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/SubstringFunction.java 2009-12-17 00:21:49 UTC (rev 18253)
@@ -28,8 +28,8 @@
import org.hibernate.ejb.criteria.ParameterRegistry;
import org.hibernate.ejb.criteria.CriteriaBuilderImpl;
import org.hibernate.ejb.criteria.CriteriaQueryCompiler;
+import org.hibernate.ejb.criteria.Renderable;
import org.hibernate.ejb.criteria.expression.LiteralExpression;
-import org.hibernate.ejb.criteria.expression.ExpressionImplementor;
/**
* Models the ANSI SQL <tt>SUBSTRING</tt> function.
@@ -107,12 +107,12 @@
public String render(CriteriaQueryCompiler.RenderingContext renderingContext) {
StringBuilder buffer = new StringBuilder();
buffer.append( "substring(" )
- .append( ( (ExpressionImplementor) getValue() ).render( renderingContext ) )
+ .append( ( (Renderable) getValue() ).render( renderingContext ) )
.append( ',' )
- .append( ( (ExpressionImplementor) getStart() ).render( renderingContext ) );
+ .append( ( (Renderable) getStart() ).render( renderingContext ) );
if ( getLength() != null ) {
buffer.append( ',' )
- .append( ( (ExpressionImplementor) getLength() ).render( renderingContext ) );
+ .append( ( (Renderable) getLength() ).render( renderingContext ) );
}
buffer.append( ')' );
return buffer.toString();
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/TrimFunction.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/TrimFunction.java 2009-12-16 23:15:01 UTC (rev 18252)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/expression/function/TrimFunction.java 2009-12-17 00:21:49 UTC (rev 18253)
@@ -28,8 +28,8 @@
import org.hibernate.ejb.criteria.ParameterRegistry;
import org.hibernate.ejb.criteria.CriteriaBuilderImpl;
import org.hibernate.ejb.criteria.CriteriaQueryCompiler;
+import org.hibernate.ejb.criteria.Renderable;
import org.hibernate.ejb.criteria.expression.LiteralExpression;
-import org.hibernate.ejb.criteria.expression.ExpressionImplementor;
/**
* Models the ANSI SQL <tt>TRIM</tt> function.
@@ -118,9 +118,9 @@
.append( "trim(" )
.append( trimspec.name() )
.append( ' ' )
- .append( ( (ExpressionImplementor) trimCharacter ).render( renderingContext ) )
+ .append( ( (Renderable) trimCharacter ).render( renderingContext ) )
.append( " from " )
- .append( ( (ExpressionImplementor) trimSource ).render( renderingContext ) )
+ .append( ( (Renderable) trimSource ).render( renderingContext ) )
.append( ')' )
.toString();
}
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/BetweenPredicate.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/BetweenPredicate.java 2009-12-16 23:15:01 UTC (rev 18252)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/BetweenPredicate.java 2009-12-17 00:21:49 UTC (rev 18253)
@@ -28,7 +28,7 @@
import org.hibernate.ejb.criteria.ParameterRegistry;
import org.hibernate.ejb.criteria.CriteriaBuilderImpl;
import org.hibernate.ejb.criteria.CriteriaQueryCompiler;
-import org.hibernate.ejb.criteria.expression.ExpressionImplementor;
+import org.hibernate.ejb.criteria.Renderable;
/**
* Models a <tt>BETWEEN</tt> {@link javax.persistence.criteria.Predicate}.
@@ -83,11 +83,11 @@
}
public String render(CriteriaQueryCompiler.RenderingContext renderingContext) {
- return ( (ExpressionImplementor) getExpression() ).render( renderingContext )
+ return ( (Renderable) getExpression() ).render( renderingContext )
+ " between "
- + ( (ExpressionImplementor) getLowerBound() ).render( renderingContext )
+ + ( (Renderable) getLowerBound() ).render( renderingContext )
+ " and "
- + ( (ExpressionImplementor) getUpperBound() ).render( renderingContext );
+ + ( (Renderable) getUpperBound() ).render( renderingContext );
}
public String renderProjection(CriteriaQueryCompiler.RenderingContext renderingContext) {
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/BooleanExpressionPredicate.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/BooleanExpressionPredicate.java 2009-12-16 23:15:01 UTC (rev 18252)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/BooleanExpressionPredicate.java 2009-12-17 00:21:49 UTC (rev 18253)
@@ -29,7 +29,7 @@
import org.hibernate.ejb.criteria.ParameterRegistry;
import org.hibernate.ejb.criteria.CriteriaBuilderImpl;
import org.hibernate.ejb.criteria.CriteriaQueryCompiler;
-import org.hibernate.ejb.criteria.expression.ExpressionImplementor;
+import org.hibernate.ejb.criteria.Renderable;
/**
* Defines a {@link Predicate} used to wrap an {@link Expression Expression<Boolean>}.
@@ -58,7 +58,7 @@
}
public String render(CriteriaQueryCompiler.RenderingContext renderingContext) {
- return ( ( ExpressionImplementor) getExpression() ).render( renderingContext );
+ return ( (Renderable) getExpression() ).render( renderingContext );
}
public String renderProjection(CriteriaQueryCompiler.RenderingContext renderingContext) {
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/ComparisonPredicate.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/ComparisonPredicate.java 2009-12-16 23:15:01 UTC (rev 18252)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/ComparisonPredicate.java 2009-12-17 00:21:49 UTC (rev 18253)
@@ -28,9 +28,9 @@
import org.hibernate.ejb.criteria.ParameterRegistry;
import org.hibernate.ejb.criteria.CriteriaBuilderImpl;
import org.hibernate.ejb.criteria.CriteriaQueryCompiler;
+import org.hibernate.ejb.criteria.Renderable;
import org.hibernate.ejb.criteria.expression.BinaryOperatorExpression;
import org.hibernate.ejb.criteria.expression.LiteralExpression;
-import org.hibernate.ejb.criteria.expression.ExpressionImplementor;
/**
* Models a basic relational comparison predicate.
@@ -66,7 +66,9 @@
}
public ComparisonOperator getComparisonOperator() {
- return comparisonOperator;
+ return isNegated()
+ ? comparisonOperator.negated()
+ : comparisonOperator;
}
public Expression getLeftHandOperand() {
@@ -142,9 +144,9 @@
}
public String render(CriteriaQueryCompiler.RenderingContext renderingContext) {
- return ( ( ExpressionImplementor) getLeftHandOperand() ).render( renderingContext )
+ return ( (Renderable) getLeftHandOperand() ).render( renderingContext )
+ getComparisonOperator().rendered()
- + ( ( ExpressionImplementor) getRightHandOperand() ).render( renderingContext );
+ + ( (Renderable) getRightHandOperand() ).render( renderingContext );
}
public String renderProjection(CriteriaQueryCompiler.RenderingContext renderingContext) {
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/CompoundPredicate.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/CompoundPredicate.java 2009-12-16 23:15:01 UTC (rev 18252)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/CompoundPredicate.java 2009-12-17 00:21:49 UTC (rev 18253)
@@ -32,7 +32,7 @@
import org.hibernate.ejb.criteria.ParameterRegistry;
import org.hibernate.ejb.criteria.CriteriaBuilderImpl;
import org.hibernate.ejb.criteria.CriteriaQueryCompiler;
-import org.hibernate.ejb.criteria.expression.ExpressionImplementor;
+import org.hibernate.ejb.criteria.Renderable;
/**
* A compound {@link Predicate predicate} is a grouping of other {@link Predicate predicates} in order to apply
@@ -113,14 +113,14 @@
public String render(CriteriaQueryCompiler.RenderingContext renderingContext) {
if ( getExpressions().size() == 1 ) {
- return ( (ExpressionImplementor) getExpressions().get(0) ).render( renderingContext );
+ return ( (Renderable) getExpressions().get(0) ).render( renderingContext );
}
final StringBuilder buffer = new StringBuilder();
String sep = "";
for ( Expression expression : getExpressions() ) {
buffer.append( sep )
.append( "( " )
- .append( ( (ExpressionImplementor) expression ).render( renderingContext ) )
+ .append( ( (Renderable) expression ).render( renderingContext ) )
.append( " )" );
sep = operatorTextWithSeparator();
}
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/ExistsPredicate.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/ExistsPredicate.java 2009-12-16 23:15:01 UTC (rev 18252)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/ExistsPredicate.java 2009-12-17 00:21:49 UTC (rev 18253)
@@ -27,7 +27,7 @@
import org.hibernate.ejb.criteria.ParameterRegistry;
import org.hibernate.ejb.criteria.CriteriaBuilderImpl;
import org.hibernate.ejb.criteria.CriteriaQueryCompiler;
-import org.hibernate.ejb.criteria.expression.ExpressionImplementor;
+import org.hibernate.ejb.criteria.Renderable;
/**
* Models an <tt>EXISTS(<subquery>)</tt> predicate
@@ -52,7 +52,7 @@
public String render(CriteriaQueryCompiler.RenderingContext renderingContext) {
return ( isNegated() ? "not " : "" ) + "exists "
- + ( ( ExpressionImplementor ) getSubquery() ).render( renderingContext );
+ + ( (Renderable) getSubquery() ).render( renderingContext );
}
public String renderProjection(CriteriaQueryCompiler.RenderingContext renderingContext) {
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/ExplicitTruthValueCheck.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/ExplicitTruthValueCheck.java 2009-12-16 23:15:01 UTC (rev 18252)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/ExplicitTruthValueCheck.java 2009-12-17 00:21:49 UTC (rev 18253)
@@ -28,7 +28,7 @@
import org.hibernate.ejb.criteria.ParameterRegistry;
import org.hibernate.ejb.criteria.CriteriaBuilderImpl;
import org.hibernate.ejb.criteria.CriteriaQueryCompiler;
-import org.hibernate.ejb.criteria.expression.ExpressionImplementor;
+import org.hibernate.ejb.criteria.Renderable;
/**
* ANSI-SQL defines <tt>TRUE</tt>, <tt>FALSE</tt> and <tt>UNKNOWN</tt> as <i>truth values</i>. These
@@ -64,7 +64,7 @@
}
public String render(CriteriaQueryCompiler.RenderingContext renderingContext) {
- return ( (ExpressionImplementor) getBooleanExpression() ).render( renderingContext )
+ return ( (Renderable) getBooleanExpression() ).render( renderingContext )
+ " = "
+ ( getTruthValue() == TruthValue.TRUE ? "true" : "false" );
}
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/InPredicate.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/InPredicate.java 2009-12-16 23:15:01 UTC (rev 18252)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/InPredicate.java 2009-12-17 00:21:49 UTC (rev 18253)
@@ -33,8 +33,8 @@
import org.hibernate.ejb.criteria.ParameterRegistry;
import org.hibernate.ejb.criteria.CriteriaBuilderImpl;
import org.hibernate.ejb.criteria.CriteriaQueryCompiler;
+import org.hibernate.ejb.criteria.Renderable;
import org.hibernate.ejb.criteria.expression.LiteralExpression;
-import org.hibernate.ejb.criteria.expression.ExpressionImplementor;
/**
* TODO : javadoc
@@ -158,14 +158,14 @@
boolean isInSubqueryPredicate = getValues().size() == 1
&& Subquery.class.isInstance( getValues().get( 0 ) );
if ( isInSubqueryPredicate ) {
- buffer.append( ( (ExpressionImplementor) getValues().get(0) ).render( renderingContext ) );
+ buffer.append( ( (Renderable) getValues().get(0) ).render( renderingContext ) );
}
else {
buffer.append( '(' );
String sep = "";
for ( Expression value : getValues() ) {
buffer.append( sep )
- .append( ( (ExpressionImplementor) value ).render( renderingContext ) );
+ .append( ( (Renderable) value ).render( renderingContext ) );
sep = ", ";
}
buffer.append( ')' );
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/LikePredicate.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/LikePredicate.java 2009-12-16 23:15:01 UTC (rev 18252)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/LikePredicate.java 2009-12-17 00:21:49 UTC (rev 18253)
@@ -27,8 +27,8 @@
import org.hibernate.ejb.criteria.ParameterRegistry;
import org.hibernate.ejb.criteria.CriteriaBuilderImpl;
import org.hibernate.ejb.criteria.CriteriaQueryCompiler;
+import org.hibernate.ejb.criteria.Renderable;
import org.hibernate.ejb.criteria.expression.LiteralExpression;
-import org.hibernate.ejb.criteria.expression.ExpressionImplementor;
/**
* Models a SQL <tt>LIKE</tt> expression.
@@ -124,12 +124,12 @@
public String render(CriteriaQueryCompiler.RenderingContext renderingContext) {
StringBuilder likeExpr = new StringBuilder();
- likeExpr.append( ( (ExpressionImplementor) getMatchExpression() ).render( renderingContext ) )
+ likeExpr.append( ( (Renderable) getMatchExpression() ).render( renderingContext ) )
.append( " like " )
- .append( ( (ExpressionImplementor) getPattern() ).render( renderingContext ) );
+ .append( ( (Renderable) getPattern() ).render( renderingContext ) );
if ( escapeCharacter != null ) {
likeExpr.append( " escape " )
- .append( ( (ExpressionImplementor) getEscapeCharacter() ).render( renderingContext ) );
+ .append( ( (Renderable) getEscapeCharacter() ).render( renderingContext ) );
}
return likeExpr.toString();
}
Modified: core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/NullnessPredicate.java
===================================================================
--- core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/NullnessPredicate.java 2009-12-16 23:15:01 UTC (rev 18252)
+++ core/trunk/entitymanager/src/main/java/org/hibernate/ejb/criteria/predicate/NullnessPredicate.java 2009-12-17 00:21:49 UTC (rev 18253)
@@ -28,8 +28,8 @@
import org.hibernate.ejb.criteria.ParameterRegistry;
import org.hibernate.ejb.criteria.CriteriaBuilderImpl;
import org.hibernate.ejb.criteria.CriteriaQueryCompiler;
+import org.hibernate.ejb.criteria.Renderable;
import org.hibernate.ejb.criteria.expression.UnaryOperatorExpression;
-import org.hibernate.ejb.criteria.expression.ExpressionImplementor;
/**
* Defines a {@link javax.persistence.criteria.Predicate} for checking the
@@ -65,7 +65,7 @@
}
public String render(CriteriaQueryCompiler.RenderingContext renderingContext) {
- return ( (ExpressionImplementor) operand ).render( renderingContext ) + check();
+ return ( (Renderable) operand ).render( renderingContext ) + check();
}
private String check() {
14 years, 12 months
Hibernate SVN: r18252 - in core/trunk/core/src/main/java/org/hibernate/dialect: function and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2009-12-16 18:15:01 -0500 (Wed, 16 Dec 2009)
New Revision: 18252
Added:
core/trunk/core/src/main/java/org/hibernate/dialect/function/AnsiTrimFunction.java
core/trunk/core/src/main/java/org/hibernate/dialect/function/TrimFunctionTemplate.java
Modified:
core/trunk/core/src/main/java/org/hibernate/dialect/DerbyDialect.java
Log:
HHH-4705 - Derby does now in fact support the full ANSI SQL TRIM function
Modified: core/trunk/core/src/main/java/org/hibernate/dialect/DerbyDialect.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/dialect/DerbyDialect.java 2009-12-16 22:18:03 UTC (rev 18251)
+++ core/trunk/core/src/main/java/org/hibernate/dialect/DerbyDialect.java 2009-12-16 23:15:01 UTC (rev 18252)
@@ -24,27 +24,18 @@
*/
package org.hibernate.dialect;
-import org.hibernate.Hibernate;
-import org.hibernate.QueryException;
-import org.hibernate.HibernateException;
-import org.hibernate.util.ReflectHelper;
-import org.hibernate.engine.Mapping;
-import org.hibernate.engine.SessionFactoryImplementor;
-import org.hibernate.type.Type;
-import org.hibernate.dialect.function.SQLFunction;
-import org.hibernate.dialect.function.SQLFunctionTemplate;
-import org.hibernate.dialect.function.DerbyConcatFunction;
-import org.hibernate.id.TableHiLoGenerator;
-import org.hibernate.sql.CaseFragment;
-import org.hibernate.sql.DerbyCaseFragment;
-
-import java.util.List;
-import java.util.ArrayList;
import java.lang.reflect.Method;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import org.hibernate.dialect.function.AnsiTrimFunction;
+import org.hibernate.dialect.function.DerbyConcatFunction;
+import org.hibernate.id.TableHiLoGenerator;
+import org.hibernate.sql.CaseFragment;
+import org.hibernate.sql.DerbyCaseFragment;
+import org.hibernate.util.ReflectHelper;
+
/**
* Hibernate Dialect for Cloudscape 10 - aka Derby. This implements both an
* override for the identity column generator as well as for the case statement
@@ -62,7 +53,7 @@
public DerbyDialect() {
super();
registerFunction( "concat", new DerbyConcatFunction() );
- registerFunction( "trim", new SQLFunctionTemplate( Hibernate.STRING, "trim(?1 ?2 ?3 ?4)" ) );
+ registerFunction( "trim", new AnsiTrimFunction() );
determineDriverVersion();
}
@@ -210,125 +201,7 @@
return null ;
}
- /**
- * A specialized function template to emulate the ANSI trim function on Derby DB
- * since it does not support the full trim specification. However, we cannot even
- * fully emulate it because there is not standard 'replace' function either. :(
- */
- public static class DerbyTrimFunctionEmulation implements SQLFunction {
- private static final SQLFunction LEADING_SPACE_TRIM = new SQLFunctionTemplate( Hibernate.STRING, "ltrim( ?1 )");
- private static final SQLFunction TRAILING_SPACE_TRIM = new SQLFunctionTemplate( Hibernate.STRING, "rtrim( ?1 )");
- private static final SQLFunction BOTH_SPACE_TRIM = new SQLFunctionTemplate( Hibernate.STRING, "ltrim( rtrim( ?1 ) )");
- private static final SQLFunction BOTH_SPACE_TRIM_FROM = new SQLFunctionTemplate( Hibernate.STRING, "ltrim( rtrim( ?2 ) )");
- public Type getReturnType(Type columnType, Mapping mapping) throws QueryException {
- return Hibernate.STRING;
- }
-
- public boolean hasArguments() {
- return true;
- }
-
- public boolean hasParenthesesIfNoArguments() {
- return false;
- }
-
- public String render(List args, SessionFactoryImplementor factory) throws QueryException {
- // according to both the ANSI-SQL and EJB3 specs, trim can either take
- // exactly one parameter or a variable number of parameters between 1 and 4.
- // from the SQL spec:
- //
- // <trim function> ::=
- // TRIM <left paren> <trim operands> <right paren>
- //
- // <trim operands> ::=
- // [ [ <trim specification> ] [ <trim character> ] FROM ] <trim source>
- //
- // <trim specification> ::=
- // LEADING
- // | TRAILING
- // | BOTH
- //
- // If only <trim specification> is omitted, BOTH is assumed;
- // if <trim character> is omitted, space is assumed
- if ( args.size() == 1 ) {
- // we have the form: trim(trimSource)
- // so we trim leading and trailing spaces
- return BOTH_SPACE_TRIM.render( args, factory );
- }
- else if ( "from".equalsIgnoreCase( ( String ) args.get( 0 ) ) ) {
- // we have the form: trim(from trimSource).
- // This is functionally equivalent to trim(trimSource)
- return BOTH_SPACE_TRIM_FROM.render( args, factory );
- }
- else {
- // otherwise, a trim-specification and/or a trim-character
- // have been specified; we need to decide which options
- // are present and "do the right thing"
- boolean leading = true; // should leading trim-characters be trimmed?
- boolean trailing = true; // should trailing trim-characters be trimmed?
- String trimCharacter; // the trim-character
- String trimSource; // the trim-source
-
- // potentialTrimCharacterArgIndex = 1 assumes that a
- // trim-specification has been specified. we handle the
- // exception to that explicitly
- int potentialTrimCharacterArgIndex = 1;
- String firstArg = ( String ) args.get( 0 );
- if ( "leading".equalsIgnoreCase( firstArg ) ) {
- trailing = false;
- }
- else if ( "trailing".equalsIgnoreCase( firstArg ) ) {
- leading = false;
- }
- else if ( "both".equalsIgnoreCase( firstArg ) ) {
- }
- else {
- potentialTrimCharacterArgIndex = 0;
- }
-
- String potentialTrimCharacter = ( String ) args.get( potentialTrimCharacterArgIndex );
- if ( "from".equalsIgnoreCase( potentialTrimCharacter ) ) {
- trimCharacter = "' '";
- trimSource = ( String ) args.get( potentialTrimCharacterArgIndex + 1 );
- }
- else if ( potentialTrimCharacterArgIndex + 1 >= args.size() ) {
- trimCharacter = "' '";
- trimSource = potentialTrimCharacter;
- }
- else {
- trimCharacter = potentialTrimCharacter;
- if ( "from".equalsIgnoreCase( ( String ) args.get( potentialTrimCharacterArgIndex + 1 ) ) ) {
- trimSource = ( String ) args.get( potentialTrimCharacterArgIndex + 2 );
- }
- else {
- trimSource = ( String ) args.get( potentialTrimCharacterArgIndex + 1 );
- }
- }
-
- List argsToUse = new ArrayList();
- argsToUse.add( trimSource );
- argsToUse.add( trimCharacter );
-
- if ( trimCharacter.equals( "' '" ) ) {
- if ( leading && trailing ) {
- return BOTH_SPACE_TRIM.render( argsToUse, factory );
- }
- else if ( leading ) {
- return LEADING_SPACE_TRIM.render( argsToUse, factory );
- }
- else {
- return TRAILING_SPACE_TRIM.render( argsToUse, factory );
- }
- }
- else {
- throw new HibernateException( "cannot specify trim character when using Derby as Derby does not support the ANSI trim function, not does it support a replace function to properly emmulate it" );
- }
- }
- }
- }
-
-
// Overridden informational metadata ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
public boolean supportsLobValueChangePropogation() {
Added: core/trunk/core/src/main/java/org/hibernate/dialect/function/AnsiTrimFunction.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/dialect/function/AnsiTrimFunction.java (rev 0)
+++ core/trunk/core/src/main/java/org/hibernate/dialect/function/AnsiTrimFunction.java 2009-12-16 23:15:01 UTC (rev 18252)
@@ -0,0 +1,45 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2009, 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.dialect.function;
+
+import org.hibernate.engine.SessionFactoryImplementor;
+
+/**
+ * Defines support for rendering according to ANSI SQL <tt>TRIM<//tt> function specification.
+ *
+ * @author Steve Ebersole
+ */
+public class AnsiTrimFunction extends TrimFunctionTemplate {
+ protected String render(Options options, String trimSource, SessionFactoryImplementor factory) {
+ return new StringBuffer()
+ .append( "trim(" )
+ .append( options.getTrimSpecification().getName() )
+ .append( ' ' )
+ .append( options.getTrimCharacter() )
+ .append( " from " )
+ .append( trimSource )
+ .append( ')' )
+ .toString();
+ }
+}
Added: core/trunk/core/src/main/java/org/hibernate/dialect/function/TrimFunctionTemplate.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/dialect/function/TrimFunctionTemplate.java (rev 0)
+++ core/trunk/core/src/main/java/org/hibernate/dialect/function/TrimFunctionTemplate.java 2009-12-16 23:15:01 UTC (rev 18252)
@@ -0,0 +1,148 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2009, 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.dialect.function;
+
+import java.util.List;
+
+import org.hibernate.Hibernate;
+import org.hibernate.QueryException;
+import org.hibernate.engine.Mapping;
+import org.hibernate.engine.SessionFactoryImplementor;
+import org.hibernate.type.Type;
+
+/**
+ * Defines the basic template support for <tt>TRIM</tt> functions
+ *
+ * @author Steve Ebersole
+ */
+public abstract class TrimFunctionTemplate implements SQLFunction {
+ public Type getReturnType(Type columnType, Mapping mapping) throws QueryException {
+ return Hibernate.STRING;
+ }
+
+ public boolean hasArguments() {
+ return true;
+ }
+
+ public boolean hasParenthesesIfNoArguments() {
+ return false;
+ }
+
+ public String render(List args, SessionFactoryImplementor factory) throws QueryException {
+ final Options options = new Options();
+ final String trimSource;
+
+ if ( args.size() == 1 ) {
+ // we have the form: trim(trimSource)
+ trimSource = ( String ) args.get( 0 );
+ }
+ else if ( "from".equalsIgnoreCase( ( String ) args.get( 0 ) ) ) {
+ // we have the form: trim(from trimSource).
+ // This is functionally equivalent to trim(trimSource)
+ trimSource = ( String ) args.get( 1 );
+ }
+ else {
+ // otherwise, a trim-specification and/or a trim-character
+ // have been specified; we need to decide which options
+ // are present and "do the right thing"
+ //
+ // potentialTrimCharacterArgIndex = 1 assumes that a
+ // trim-specification has been specified. we handle the
+ // exception to that explicitly
+ int potentialTrimCharacterArgIndex = 1;
+ String firstArg = ( String ) args.get( 0 );
+ if ( "leading".equalsIgnoreCase( firstArg ) ) {
+ options.setTrimSpecification( Specification.LEADING );
+ }
+ else if ( "trailing".equalsIgnoreCase( firstArg ) ) {
+ options.setTrimSpecification( Specification.TRAILING );
+ }
+ else if ( "both".equalsIgnoreCase( firstArg ) ) {
+ // already the default in Options
+ }
+ else {
+ potentialTrimCharacterArgIndex = 0;
+ }
+
+ String potentialTrimCharacter = ( String ) args.get( potentialTrimCharacterArgIndex );
+ if ( "from".equalsIgnoreCase( potentialTrimCharacter ) ) {
+ trimSource = ( String ) args.get( potentialTrimCharacterArgIndex + 1 );
+ }
+ else if ( potentialTrimCharacterArgIndex + 1 >= args.size() ) {
+ trimSource = potentialTrimCharacter;
+ }
+ else {
+ options.setTrimCharacter( potentialTrimCharacter );
+ if ( "from".equalsIgnoreCase( ( String ) args.get( potentialTrimCharacterArgIndex + 1 ) ) ) {
+ trimSource = ( String ) args.get( potentialTrimCharacterArgIndex + 2 );
+ }
+ else {
+ trimSource = ( String ) args.get( potentialTrimCharacterArgIndex + 1 );
+ }
+ }
+ }
+ return render( options, trimSource, factory );
+ }
+
+ protected abstract String render(Options options, String trimSource, SessionFactoryImplementor factory);
+
+ public static class Options {
+ public static final String DEFAULT_TRIM_CHARACTER = "' '";
+
+ private String trimCharacter = DEFAULT_TRIM_CHARACTER;
+ private Specification trimSpecification = Specification.BOTH;
+
+ public String getTrimCharacter() {
+ return trimCharacter;
+ }
+
+ public void setTrimCharacter(String trimCharacter) {
+ this.trimCharacter = trimCharacter;
+ }
+
+ public Specification getTrimSpecification() {
+ return trimSpecification;
+ }
+
+ public void setTrimSpecification(Specification trimSpecification) {
+ this.trimSpecification = trimSpecification;
+ }
+ }
+
+ public static class Specification {
+ public static final Specification LEADING = new Specification( "leading" );
+ public static final Specification TRAILING = new Specification( "trailing" );
+ public static final Specification BOTH = new Specification( "both" );
+
+ private final String name;
+
+ private Specification(String name) {
+ this.name = name;
+ }
+
+ public String getName() {
+ return name;
+ }
+ }
+}
14 years, 12 months
Hibernate SVN: r18251 - core/trunk/core/src/main/java/org/hibernate/dialect.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2009-12-16 17:18:03 -0500 (Wed, 16 Dec 2009)
New Revision: 18251
Modified:
core/trunk/core/src/main/java/org/hibernate/dialect/DerbyDialect.java
Log:
HHH-4705 - Derby does now in fact support the full ANSI SQL TRIM function
Modified: core/trunk/core/src/main/java/org/hibernate/dialect/DerbyDialect.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/dialect/DerbyDialect.java 2009-12-16 22:12:45 UTC (rev 18250)
+++ core/trunk/core/src/main/java/org/hibernate/dialect/DerbyDialect.java 2009-12-16 22:18:03 UTC (rev 18251)
@@ -62,7 +62,7 @@
public DerbyDialect() {
super();
registerFunction( "concat", new DerbyConcatFunction() );
- registerFunction( "trim", new DerbyTrimFunctionEmulation() );
+ registerFunction( "trim", new SQLFunctionTemplate( Hibernate.STRING, "trim(?1 ?2 ?3 ?4)" ) );
determineDriverVersion();
}
14 years, 12 months
Hibernate SVN: r18250 - in core/trunk/entitymanager/src/test/java/org/hibernate/ejb: metamodel and 1 other directory.
by hibernate-commits@lists.jboss.org
Author: steve.ebersole(a)jboss.com
Date: 2009-12-16 17:12:45 -0500 (Wed, 16 Dec 2009)
New Revision: 18250
Added:
core/trunk/entitymanager/src/test/java/org/hibernate/ejb/metamodel/
core/trunk/entitymanager/src/test/java/org/hibernate/ejb/metamodel/EmbeddedTypeTest.java
core/trunk/entitymanager/src/test/java/org/hibernate/ejb/metamodel/Product.java
core/trunk/entitymanager/src/test/java/org/hibernate/ejb/metamodel/ShelfLife.java
Log:
Added: core/trunk/entitymanager/src/test/java/org/hibernate/ejb/metamodel/EmbeddedTypeTest.java
===================================================================
--- core/trunk/entitymanager/src/test/java/org/hibernate/ejb/metamodel/EmbeddedTypeTest.java (rev 0)
+++ core/trunk/entitymanager/src/test/java/org/hibernate/ejb/metamodel/EmbeddedTypeTest.java 2009-12-16 22:12:45 UTC (rev 18250)
@@ -0,0 +1,58 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2009, 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.ejb.metamodel;
+
+import javax.persistence.EntityManager;
+import javax.persistence.metamodel.SingularAttribute;
+
+import org.hibernate.ejb.test.TestCase;
+
+/**
+ * TODO : javadoc
+ *
+ * @author Steve Ebersole
+ */
+public class EmbeddedTypeTest extends TestCase {
+ @Override
+ public Class[] getAnnotatedClasses() {
+ return new Class[] {
+ Product.class, ShelfLife.class
+ };
+ }
+
+ public void testSingularAttributeAccessByNameFailureExpected() {
+ // HHH-4702
+ EntityManager em = getOrCreateEntityManager();
+ em.getTransaction().begin();
+
+ SingularAttribute soldDate_ = em.getMetamodel().embeddable( ShelfLife.class )
+ .getSingularAttribute( "soldDate" );
+ assertEquals( java.sql.Date.class, soldDate_.getBindableJavaType());
+ assertEquals( java.sql.Date.class, soldDate_.getType().getJavaType() );
+ assertEquals( java.sql.Date.class, soldDate_.getJavaType() );
+
+ em.getTransaction().commit();
+ em.close();
+ }
+}
Added: core/trunk/entitymanager/src/test/java/org/hibernate/ejb/metamodel/Product.java
===================================================================
--- core/trunk/entitymanager/src/test/java/org/hibernate/ejb/metamodel/Product.java (rev 0)
+++ core/trunk/entitymanager/src/test/java/org/hibernate/ejb/metamodel/Product.java 2009-12-16 22:12:45 UTC (rev 18250)
@@ -0,0 +1,141 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2009, 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.ejb.metamodel;
+
+import javax.persistence.AttributeOverride;
+import javax.persistence.AttributeOverrides;
+import javax.persistence.Column;
+import javax.persistence.DiscriminatorColumn;
+import javax.persistence.DiscriminatorType;
+import javax.persistence.DiscriminatorValue;
+import javax.persistence.Embedded;
+import javax.persistence.Entity;
+import javax.persistence.Id;
+import javax.persistence.Inheritance;
+import javax.persistence.InheritanceType;
+import javax.persistence.PrimaryKeyJoinColumn;
+import javax.persistence.SecondaryTable;
+import javax.persistence.Table;
+
+/**
+ * TODO : javadoc
+ *
+ * @author Steve Ebersole
+ */
+@Entity
+@Table(name = "PRODUCT_TABLE")
+@SecondaryTable(name = "PRODUCT_DETAILS", pkJoinColumns = @PrimaryKeyJoinColumn(name = "ID"))
+@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
+@DiscriminatorColumn(name = "PRODUCT_TYPE", discriminatorType = DiscriminatorType.STRING)
+@DiscriminatorValue("Product")
+public class Product implements java.io.Serializable {
+ private String id;
+ private String name;
+ private double price;
+ private int quantity;
+ private long partNumber;
+ private String wareHouse;
+ private ShelfLife shelfLife;
+
+ public Product() {
+ }
+
+ public Product(String id, String name, double price, int quantity, long partNumber) {
+ this.id = id;
+ this.name = name;
+ this.price = price;
+ this.quantity = quantity;
+ this.partNumber = partNumber;
+ }
+
+ @Id
+ @Column(name = "ID")
+ public String getId() {
+ return id;
+ }
+
+ public void setId(String id) {
+ this.id = id;
+ }
+
+ @Column(name = "NAME")
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ @Column(name = "PRICE")
+ public double getPrice() {
+ return price;
+ }
+
+ public void setPrice(double price) {
+ this.price = price;
+ }
+
+ @Column(name = "QUANTITY")
+ public int getQuantity() {
+ return quantity;
+ }
+
+ public void setQuantity(int v) {
+ this.quantity = v;
+ }
+
+ @Column(name = "PNUM")
+ public long getPartNumber() {
+ return partNumber;
+ }
+
+ public void setPartNumber(long v) {
+ this.partNumber = v;
+ }
+
+ @Column(name = "WHOUSE", nullable = true, table = "PRODUCT_DETAILS")
+ public String getWareHouse() {
+ return wareHouse;
+ }
+
+ public void setWareHouse(String v) {
+ this.wareHouse = v;
+ }
+
+ @Embedded
+ @AttributeOverrides({
+ @AttributeOverride(name = "inceptionDate",
+ column = @Column(name = "INCEPTION", nullable = true)),
+ @AttributeOverride(name = "soldDate",
+ column = @Column(name = "SOLD", nullable = true))
+ })
+ public ShelfLife getShelfLife() {
+ return shelfLife;
+ }
+
+ public void setShelfLife(ShelfLife v) {
+ this.shelfLife = v;
+ }
+}
Added: core/trunk/entitymanager/src/test/java/org/hibernate/ejb/metamodel/ShelfLife.java
===================================================================
--- core/trunk/entitymanager/src/test/java/org/hibernate/ejb/metamodel/ShelfLife.java (rev 0)
+++ core/trunk/entitymanager/src/test/java/org/hibernate/ejb/metamodel/ShelfLife.java 2009-12-16 22:12:45 UTC (rev 18250)
@@ -0,0 +1,60 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2009, 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.ejb.metamodel;
+
+import java.sql.Date;
+import javax.persistence.Basic;
+import javax.persistence.Embeddable;
+
+@Embeddable
+public class ShelfLife implements java.io.Serializable {
+ private Date inceptionDate;
+ private Date soldDate;
+
+ public ShelfLife() {
+ }
+
+ public ShelfLife(Date inceptionDate, Date soldDate) {
+ this.inceptionDate = inceptionDate;
+ this.soldDate = soldDate;
+ }
+
+ @Basic
+ public Date getInceptionDate() {
+ return inceptionDate;
+ }
+
+ public void setInceptionDate(Date inceptionDate) {
+ this.inceptionDate = inceptionDate;
+ }
+
+ @Basic
+ public Date getSoldDate() {
+ return soldDate;
+ }
+
+ public void setSoldDate(Date soldDate) {
+ this.soldDate = soldDate;
+ }
+}
14 years, 12 months
Hibernate SVN: r18249 - core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/bytecode/javassist.
by hibernate-commits@lists.jboss.org
Author: stliu
Date: 2009-12-16 14:03:39 -0500 (Wed, 16 Dec 2009)
New Revision: 18249
Modified:
core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/bytecode/javassist/FieldTransformer.java
Log:
JBPAPP-3173 HHH-4614 (javassist)Instrumented model with abstract MappedSuperclass and field access doesn't work
Modified: core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/bytecode/javassist/FieldTransformer.java
===================================================================
--- core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/bytecode/javassist/FieldTransformer.java 2009-12-16 19:02:16 UTC (rev 18248)
+++ core/branches/Branch_3_3_2_GA_CP/core/src/main/java/org/hibernate/bytecode/javassist/FieldTransformer.java 2009-12-16 19:03:39 UTC (rev 18249)
@@ -338,7 +338,7 @@
}
CodeAttribute codeAttr = minfo.getCodeAttribute();
if (codeAttr == null) {
- return;
+ continue;
}
CodeIterator iter = codeAttr.iterator();
while (iter.hasNext()) {
14 years, 12 months
Hibernate SVN: r18248 - core/branches/Branch_3_2_4_SP1_CP/src/org/hibernate/bytecode/javassist.
by hibernate-commits@lists.jboss.org
Author: stliu
Date: 2009-12-16 14:02:16 -0500 (Wed, 16 Dec 2009)
New Revision: 18248
Modified:
core/branches/Branch_3_2_4_SP1_CP/src/org/hibernate/bytecode/javassist/FieldTransformer.java
Log:
JBPAPP-3173 HHH-4614 (javassist)Instrumented model with abstract MappedSuperclass and field access doesn't work
Modified: core/branches/Branch_3_2_4_SP1_CP/src/org/hibernate/bytecode/javassist/FieldTransformer.java
===================================================================
--- core/branches/Branch_3_2_4_SP1_CP/src/org/hibernate/bytecode/javassist/FieldTransformer.java 2009-12-16 18:53:12 UTC (rev 18247)
+++ core/branches/Branch_3_2_4_SP1_CP/src/org/hibernate/bytecode/javassist/FieldTransformer.java 2009-12-16 19:02:16 UTC (rev 18248)
@@ -327,7 +327,7 @@
}
CodeAttribute codeAttr = minfo.getCodeAttribute();
if (codeAttr == null) {
- return;
+ continue;
}
CodeIterator iter = codeAttr.iterator();
while (iter.hasNext()) {
14 years, 12 months