Author: epbernard
Date: 2010-09-27 18:09:02 -0400 (Mon, 27 Sep 2010)
New Revision: 20729
Added:
core/trunk/core/src/main/java/org/hibernate/annotations/ReadWriteExpression.java
core/trunk/core/src/main/java/org/hibernate/annotations/ReadWriteExpressions.java
Removed:
core/trunk/core/src/main/java/org/hibernate/annotations/ReadExpression.java
core/trunk/core/src/main/java/org/hibernate/annotations/ReadExpressions.java
core/trunk/core/src/main/java/org/hibernate/annotations/WriteExpression.java
core/trunk/core/src/main/java/org/hibernate/annotations/WriteExpressions.java
Modified:
core/trunk/core/src/main/java/org/hibernate/cfg/Ejb3Column.java
core/trunk/documentation/manual/src/main/docbook/en-US/content/basic_mapping.xml
core/trunk/testsuite/src/test/java/org/hibernate/test/annotations/various/readwriteexpression/Staff.java
Log:
HHH-4510 Merge @ReadExpression and @WriteExpression in @ReadWriteExpression
Deleted: core/trunk/core/src/main/java/org/hibernate/annotations/ReadExpression.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/annotations/ReadExpression.java 2010-09-27
22:07:44 UTC (rev 20728)
+++ core/trunk/core/src/main/java/org/hibernate/annotations/ReadExpression.java 2010-09-27
22:09:02 UTC (rev 20729)
@@ -1,51 +0,0 @@
-/*
- * Hibernate, Relational Persistence for Idiomatic Java
- *
- * Copyright (c) 2010, Red Hat, Inc. and/or its affiliates 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.annotations;
-
-import java.lang.annotation.Retention;
-
-import static java.lang.annotation.ElementType.FIELD;
-import static java.lang.annotation.ElementType.METHOD;
-import static java.lang.annotation.RetentionPolicy.RUNTIME;
-
-/**
- * Custom SQL expression used to read the value from a column. True for direct object
loading as well as queries.
- *
- * For example: <code>decrypt(credit_card_num)</code>
- *
- * @author Emmanuel Bernard
- */
-(a)java.lang.annotation.Target({FIELD,METHOD})
-@Retention(RUNTIME)
-public @interface ReadExpression {
- /**
- * (Logical) column name for which the expression is used
- */
- String forColumn();
-
- /**
- * Custom SQL expression used to read from the column
- */
- String expression();
-}
Deleted: core/trunk/core/src/main/java/org/hibernate/annotations/ReadExpressions.java
===================================================================
---
core/trunk/core/src/main/java/org/hibernate/annotations/ReadExpressions.java 2010-09-27
22:07:44 UTC (rev 20728)
+++
core/trunk/core/src/main/java/org/hibernate/annotations/ReadExpressions.java 2010-09-27
22:09:02 UTC (rev 20729)
@@ -1,42 +0,0 @@
-/*
- * Hibernate, Relational Persistence for Idiomatic Java
- *
- * Copyright (c) 2010, Red Hat, Inc. and/or its affiliates 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.annotations;
-
-import java.lang.annotation.Retention;
-
-import static java.lang.annotation.ElementType.FIELD;
-import static java.lang.annotation.ElementType.METHOD;
-import static java.lang.annotation.RetentionPolicy.RUNTIME;
-
-/**
- * Plural annotation for @ReadExpression.
- * Useful when more than one column is using this behavior.
- *
- * @author Emmanuel Bernard
- */
-(a)java.lang.annotation.Target({FIELD,METHOD})
-@Retention(RUNTIME)
-public @interface ReadExpressions {
- ReadExpression[] value();
-}
Copied: core/trunk/core/src/main/java/org/hibernate/annotations/ReadWriteExpression.java
(from rev 20728,
core/trunk/core/src/main/java/org/hibernate/annotations/WriteExpression.java)
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/annotations/ReadWriteExpression.java
(rev 0)
+++
core/trunk/core/src/main/java/org/hibernate/annotations/ReadWriteExpression.java 2010-09-27
22:09:02 UTC (rev 20729)
@@ -0,0 +1,59 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2010, Red Hat, Inc. and/or its affiliates 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.annotations;
+
+import java.lang.annotation.Retention;
+
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+/**
+ * Custom SQL expression used to read the value from and write a value to a column.
+ * Use for direct object loading/saving as well as queries.
+ * The write expression must contain exactly one '?' placeholder for the value.
+ *
+ * For example: <code>read="decrypt(credit_card_num)"
write="encrypt(?)"</code>
+ *
+ * @author Emmanuel Bernard
+ */
+(a)java.lang.annotation.Target({FIELD,METHOD})
+@Retention(RUNTIME)
+public @interface ReadWriteExpression {
+ /**
+ * (Logical) column name for which the expression is used
+ */
+ String forColumn();
+
+ /**
+ * Custom SQL expression used to read from the column
+ */
+ String read() default "";
+
+ /**
+ * Custom SQL expression used to write to the column.
+ * The write expression must contain exactly one '?' placeholder for the value.
+ */
+ String write() default "";
+}
Copied: core/trunk/core/src/main/java/org/hibernate/annotations/ReadWriteExpressions.java
(from rev 20728,
core/trunk/core/src/main/java/org/hibernate/annotations/ReadExpressions.java)
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/annotations/ReadWriteExpressions.java
(rev 0)
+++
core/trunk/core/src/main/java/org/hibernate/annotations/ReadWriteExpressions.java 2010-09-27
22:09:02 UTC (rev 20729)
@@ -0,0 +1,42 @@
+/*
+ * Hibernate, Relational Persistence for Idiomatic Java
+ *
+ * Copyright (c) 2010, Red Hat, Inc. and/or its affiliates 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.annotations;
+
+import java.lang.annotation.Retention;
+
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+/**
+ * Plural annotation for @ReadWriteExpressions.
+ * Useful when more than one column is using this behavior.
+ *
+ * @author Emmanuel Bernard
+ */
+(a)java.lang.annotation.Target({FIELD,METHOD})
+@Retention(RUNTIME)
+public @interface ReadWriteExpressions {
+ ReadWriteExpression[] value();
+}
Deleted: core/trunk/core/src/main/java/org/hibernate/annotations/WriteExpression.java
===================================================================
---
core/trunk/core/src/main/java/org/hibernate/annotations/WriteExpression.java 2010-09-27
22:07:44 UTC (rev 20728)
+++
core/trunk/core/src/main/java/org/hibernate/annotations/WriteExpression.java 2010-09-27
22:09:02 UTC (rev 20729)
@@ -1,55 +0,0 @@
-/*
- * Hibernate, Relational Persistence for Idiomatic Java
- *
- * Copyright (c) 2010, Red Hat, Inc. and/or its affiliates 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.annotations;
-
-import java.lang.annotation.Retention;
-
-import static java.lang.annotation.ElementType.FIELD;
-import static java.lang.annotation.ElementType.METHOD;
-import static java.lang.annotation.RetentionPolicy.RUNTIME;
-
-/**
- * Custom SQL expression used to write the value to a column. True for direct object
saving as well as insert queries.
- * The write expression must contain exactly one '?' placeholder for the value.
- *
- * For example: <code>encrypt(?)</code>
- *
- *
- *
- * @author Emmanuel Bernard
- */
-(a)java.lang.annotation.Target({FIELD,METHOD})
-@Retention(RUNTIME)
-public @interface WriteExpression {
- /**
- * (Logical) column name for which the expression is used
- */
- String forColumn();
-
- /**
- * Custom SQL expression used to write to the column.
- * The write expression must contain exactly one '?' placeholder for the value.
- */
- String expression();
-}
Deleted: core/trunk/core/src/main/java/org/hibernate/annotations/WriteExpressions.java
===================================================================
---
core/trunk/core/src/main/java/org/hibernate/annotations/WriteExpressions.java 2010-09-27
22:07:44 UTC (rev 20728)
+++
core/trunk/core/src/main/java/org/hibernate/annotations/WriteExpressions.java 2010-09-27
22:09:02 UTC (rev 20729)
@@ -1,42 +0,0 @@
-/*
- * Hibernate, Relational Persistence for Idiomatic Java
- *
- * Copyright (c) 2010, Red Hat, Inc. and/or its affiliates 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.annotations;
-
-import java.lang.annotation.Retention;
-
-import static java.lang.annotation.ElementType.FIELD;
-import static java.lang.annotation.ElementType.METHOD;
-import static java.lang.annotation.RetentionPolicy.RUNTIME;
-
-/**
- * Plural annotation for @WriteExpression.
- * Useful when more than one column is using this behavior.
- *
- * @author Emmanuel Bernard
- */
-(a)java.lang.annotation.Target({FIELD,METHOD})
-@Retention(RUNTIME)
-public @interface WriteExpressions {
- WriteExpression[] value();
-}
Modified: core/trunk/core/src/main/java/org/hibernate/cfg/Ejb3Column.java
===================================================================
--- core/trunk/core/src/main/java/org/hibernate/cfg/Ejb3Column.java 2010-09-27 22:07:44
UTC (rev 20728)
+++ core/trunk/core/src/main/java/org/hibernate/cfg/Ejb3Column.java 2010-09-27 22:09:02
UTC (rev 20729)
@@ -28,10 +28,8 @@
import org.hibernate.AnnotationException;
import org.hibernate.AssertionFailure;
import org.hibernate.annotations.Index;
-import org.hibernate.annotations.ReadExpression;
-import org.hibernate.annotations.ReadExpressions;
-import org.hibernate.annotations.WriteExpression;
-import org.hibernate.annotations.WriteExpressions;
+import org.hibernate.annotations.ReadWriteExpression;
+import org.hibernate.annotations.ReadWriteExpressions;
import org.hibernate.annotations.common.reflection.XProperty;
import org.hibernate.cfg.annotations.Nullability;
import org.hibernate.mapping.Column;
@@ -485,40 +483,30 @@
if ( inferredData != null ) {
XProperty property = inferredData.getProperty();
if ( property != null ) {
- {
- processReadExpression( property.getAnnotation( ReadExpression.class ) );
- ReadExpressions annotations = property.getAnnotation( ReadExpressions.class );
- if (annotations != null) {
- for ( ReadExpression annotation : annotations.value() ) {
- processReadExpression( annotation );
- }
+ processExpression( property.getAnnotation( ReadWriteExpression.class ) );
+ ReadWriteExpressions annotations = property.getAnnotation( ReadWriteExpressions.class
);
+ if (annotations != null) {
+ for ( ReadWriteExpression annotation : annotations.value() ) {
+ processExpression( annotation );
}
}
- {
- processWriteExpression( property.getAnnotation( WriteExpression.class ) );
- WriteExpressions annotations = property.getAnnotation( WriteExpressions.class );
- if (annotations != null) {
- for ( WriteExpression annotation : annotations.value() ) {
- processWriteExpression( annotation );
- }
- }
- }
}
}
}
- private void processReadExpression(ReadExpression annotation) {
+ private void processExpression(ReadWriteExpression annotation) {
if ( annotation != null && annotation.forColumn().equals( logicalColumnName ) )
{
- readExpression = annotation.expression();
+ readExpression = annotation.read();
+ if ( StringHelper.isEmpty( readExpression ) ) {
+ readExpression = null;
+ }
+ writeExpression = annotation.write();
+ if ( StringHelper.isEmpty( writeExpression ) ) {
+ writeExpression = null;
+ }
}
}
- private void processWriteExpression(WriteExpression annotation) {
- if ( annotation != null && annotation.forColumn().equals( logicalColumnName ) )
{
- writeExpression = annotation.expression();
- }
- }
-
private static Ejb3Column[] buildImplicitColumn(
PropertyData inferredData,
String suffixForDefaultColumnName,
Modified:
core/trunk/documentation/manual/src/main/docbook/en-US/content/basic_mapping.xml
===================================================================
---
core/trunk/documentation/manual/src/main/docbook/en-US/content/basic_mapping.xml 2010-09-27
22:07:44 UTC (rev 20728)
+++
core/trunk/documentation/manual/src/main/docbook/en-US/content/basic_mapping.xml 2010-09-27
22:09:02 UTC (rev 20729)
@@ -5782,12 +5782,10 @@
<programlisting role="JAVA">@Entity
class CreditCard {
@Column(name="credit_card_num")
- @ReadExpression(
+ @ReadWriteExpression(
forColumn="credit_card_num",
- expression="decrypt(credit_card_num)")
- @WriteExpression(
- forColumn="credit_card_num",
- expression="encrypt(?)")
+ read="decrypt(credit_card_num)",
+ write="encrypt(?)")
public String getCreditCardNumber() { return creditCardNumber; }
public void setCreditCardNumber(String number) { this.creditCardNumber = number; }
private String creditCardNumber;
@@ -5803,9 +5801,10 @@
</property></programlisting>
<note>
- <para>When using <classname>@ReadExpression</classname> /
- <classname>@WriteExpression</classname> annotations, you must
explicitly
- declare the <literal>(a)Column.name</literal> property.</para>
+ <para>When using <classname>@ReadWriteExpression</classname>, you
must
+ explicitly declare the <literal>(a)Column.name</literal> property. You
can
+ use the plural form <classname>@ReadWriteExpressions</classname> if
more
+ than one columns need to define either of these rules.</para>
</note>
<para>Hibernate applies the custom expressions automatically whenever the
Modified:
core/trunk/testsuite/src/test/java/org/hibernate/test/annotations/various/readwriteexpression/Staff.java
===================================================================
---
core/trunk/testsuite/src/test/java/org/hibernate/test/annotations/various/readwriteexpression/Staff.java 2010-09-27
22:07:44 UTC (rev 20728)
+++
core/trunk/testsuite/src/test/java/org/hibernate/test/annotations/various/readwriteexpression/Staff.java 2010-09-27
22:09:02 UTC (rev 20729)
@@ -28,8 +28,7 @@
import javax.persistence.Id;
import javax.persistence.Table;
-import org.hibernate.annotations.ReadExpression;
-import org.hibernate.annotations.WriteExpression;
+import org.hibernate.annotations.ReadWriteExpression;
/**
* @author Emmanuel Bernard
@@ -50,15 +49,19 @@
private Integer id;
@Column(name="size_in_cm")
- @ReadExpression( forColumn = "size_in_cm", expression = "size_in_cm /
2.54" )
- @WriteExpression( forColumn = "size_in_cm", expression = "? * 2.54"
)
+ @ReadWriteExpression(
+ forColumn = "size_in_cm",
+ read = "size_in_cm / 2.54",
+ write = "? * 2.54" )
public double getSizeInInches() { return sizeInInches; }
public void setSizeInInches(double sizeInInches) { this.sizeInInches = sizeInInches; }
private double sizeInInches;
@Column(name="radiusS")
- @ReadExpression( forColumn = "radiusS", expression = "radiusS /
2.54" )
- @WriteExpression( forColumn = "radiusS", expression = "? * 2.54" )
+ @ReadWriteExpression(
+ forColumn = "radiusS",
+ read = "radiusS / 2.54",
+ write = "? * 2.54" )
public double getRadiusS() { return radiusS; }
public void setRadiusS(double radiusS) { this.radiusS = radiusS; }
private double radiusS;