HHH-4510 Rename @ReadWriteExpression to @ColumnTransformer

It relates to the ResultTransformer we have but at the column level

git-svn-id: https://svn.jboss.org/repos/hibernate/core/trunk@20748 1b8cb986-b30d-0410-93ca-fae66ebed9b2
This commit is contained in:
Emmanuel Bernard 2010-09-29 09:44:15 +00:00
parent 6a14aeeba7
commit 4e2887c0c0
6 changed files with 24 additions and 22 deletions

View File

@ -40,9 +40,11 @@ import static java.lang.annotation.RetentionPolicy.RUNTIME;
*/
@java.lang.annotation.Target({FIELD,METHOD})
@Retention(RUNTIME)
public @interface ReadWriteExpression {
public @interface ColumnTransformer {
/**
* (Logical) column name for which the expression is used
*
* This can be left out if the property is bound to a single column
*/
String forColumn() default "";

View File

@ -30,13 +30,13 @@ import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
/**
* Plural annotation for @ReadWriteExpressions.
* Plural annotation for @ColumnTransformer.
* Useful when more than one column is using this behavior.
*
* @author Emmanuel Bernard
*/
@java.lang.annotation.Target({FIELD,METHOD})
@Retention(RUNTIME)
public @interface ReadWriteExpressions {
ReadWriteExpression[] value();
public @interface ColumnTransformers {
ColumnTransformer[] value();
}

View File

@ -27,9 +27,9 @@ import java.util.Map;
import org.hibernate.AnnotationException;
import org.hibernate.AssertionFailure;
import org.hibernate.annotations.ColumnTransformer;
import org.hibernate.annotations.ColumnTransformers;
import org.hibernate.annotations.Index;
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;
@ -483,10 +483,10 @@ public class Ejb3Column {
if ( inferredData != null ) {
XProperty property = inferredData.getProperty();
if ( property != null ) {
processExpression( property.getAnnotation( ReadWriteExpression.class ) );
ReadWriteExpressions annotations = property.getAnnotation( ReadWriteExpressions.class );
processExpression( property.getAnnotation( ColumnTransformer.class ) );
ColumnTransformers annotations = property.getAnnotation( ColumnTransformers.class );
if (annotations != null) {
for ( ReadWriteExpression annotation : annotations.value() ) {
for ( ColumnTransformer annotation : annotations.value() ) {
processExpression( annotation );
}
}
@ -494,7 +494,7 @@ public class Ejb3Column {
}
}
private void processExpression(ReadWriteExpression annotation) {
private void processExpression(ColumnTransformer annotation) {
String nonNullLogicalColumnName = logicalColumnName != null ? logicalColumnName : ""; //use the default for annotations
if ( annotation != null &&
( StringHelper.isEmpty( annotation.forColumn() )

View File

@ -2225,8 +2225,8 @@ public class Flight implements Serializable {
<classname>org.hibernate.annotations.SourceType.VM</classname> and
<classname>org.hibernate.annotations.SourceType.DB</classname>. The
default is <classname>SourceType.DB</classname> which is also used in
case there is no <classname>@Source</classname> annotation at all.
</para>
case there is no <classname>@Source</classname> annotation at
all.</para>
<para>Like in the case of version numbers, the timestamp can also be
generated by the database instead of Hibernate. To do that, use
@ -5782,7 +5782,7 @@ class LineItem {
</section>
<section id="mapping-column-read-and-write" revision="1">
<title>Column read and write expressions</title>
<title>Column transformers: read and write expressions</title>
<para>Hibernate allows you to customize the SQL it uses to read and write
the values of columns mapped to <link
@ -5793,7 +5793,7 @@ class LineItem {
<programlisting role="JAVA">@Entity
class CreditCard {
@Column(name="credit_card_num")
@ReadWriteExpression(
@ColumnTransformer(
read="decrypt(credit_card_num)",
write="encrypt(?)")
public String getCreditCardNumber() { return creditCardNumber; }
@ -5812,8 +5812,8 @@ class CreditCard {
<note>
<para>You can use the plural form
<classname>@ReadWriteExpressions</classname> if more than one columns
need to define either of these rules.</para>
<classname>@ColumnTransformers</classname> if more than one columns need
to define either of these rules.</para>
</note>
<para>If a property uses more that one column, you must use the
@ -5826,7 +5826,7 @@ class User {
@Columns( {
@Column(name="credit_card_num"),
@Column(name="exp_date") } )
@ReadWriteExpression(
@ColumnTransformer(
forColumn="credit_card_num",
read="decrypt(credit_card_num)",
write="encrypt(?)")

View File

@ -31,7 +31,7 @@ import org.hibernate.test.annotations.TestCase;
/**
* @author Emmanuel Bernard
*/
public class ReadWriteExpressionTest extends TestCase {
public class ColumnTransformerTest extends TestCase {
public void testCustomColumnReadAndWrite() throws Exception{
Session s = openSession();

View File

@ -28,7 +28,7 @@ import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import org.hibernate.annotations.ReadWriteExpression;
import org.hibernate.annotations.ColumnTransformer;
/**
* @author Emmanuel Bernard
@ -50,7 +50,7 @@ public class Staff {
private Integer id;
@Column(name="size_in_cm")
@ReadWriteExpression(
@ColumnTransformer(
forColumn = "size_in_cm",
read = "size_in_cm / 2.54",
write = "? * 2.54" )
@ -59,7 +59,7 @@ public class Staff {
private double sizeInInches;
//Weird extra S to avoid potential SQL keywords
@ReadWriteExpression(
@ColumnTransformer(
read = "radiusS / 2.54",
write = "? * 2.54" )
public double getRadiusS() { return radiusS; }
@ -67,7 +67,7 @@ public class Staff {
private double radiusS;
@Column(name="diamet")
@ReadWriteExpression(
@ColumnTransformer(
read = "diamet / 2.54",
write = "? * 2.54" )
public double getDiameter() { return diameter; }