This Bugzilla instance is deprecated, and most Eclipse projects now use GitHub or Eclipse GitLab. Please see the deprecation plan for details.
Bug 215836 - Correct ReturningPolicy support for the EclipseLink-ORM.XML Schema
Summary: Correct ReturningPolicy support for the EclipseLink-ORM.XML Schema
Status: CLOSED WONTFIX
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Eclipselink (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Nobody - feel free to take it CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 238793 227219
  Show dependency tree
 
Reported: 2008-01-18 12:26 EST by Andrei Ilitchev CLA
Modified: 2022-06-09 10:27 EDT (History)
6 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Andrei Ilitchev CLA 2008-01-18 12:26:02 EST
Not sure about the name, for now will use
Return (return) for now.

Annotations:
          @Target({METHOD, FIELD})
          @Retention(RUNTIME)
          public @interface Return {
            boolean insert() default true;
            boolean update() default false;
            boolean insertReturnOnly() default false;
            String type default "";
          }

xsd element:
    <xsd:complexType name="return-written-field">
      <xsd:attribute name="insert" type="xsd:boolean"/>
      <xsd:attribute name="update" type="xsd:boolean"/>
      <xsd:attribute name="insert-return-only" type="xsd:boolean"/>
      <xsd:attribute name="type" type="xsd:string"/>
    </xsd:complexType>

Applied to:
Each Return annotation is concerned with a single db field, therefore
Return annotation could be applied to:
1) any attribute (or getter/setter) mapped to a single database field;
2) FieldTransformer (in transformation mapping).

Defaults:
@Return means returning of the inserted value (the most widwly-used case);
@Return(update=true) - return both inserted and updated values;
@Return(insertReturnOnly=true) - return the value on insert without inserting the value (for instance to return the value generated by Identity).
Comment 1 Doug Clarke CLA 2008-01-30 16:35:15 EST
The insertReturnOnly value is confusing in name. I like insert and update as
attributes of @Return since they qualify when the value will be returned. It
seems odd that the returning policy would have a flag to indicate that we do
not write it.

I would think that if you wanted a value returned from INSERT without have it
included in the row of the statement you would do something like:

@Column(name="VAL", insertable=false)
@Return
private String value

The insertable=false is an existing way to indicate that the value should not
be included in the INSERT statement.

As far as the XML goes I would like to see something like:

<basic name="value">
    <column name="VAL" insertable="false"/>
    <return>
</basic>
Comment 2 Doug Clarke CLA 2008-01-30 16:40:35 EST
Just to be complete:

@Return means return value from INSERT
@Return(insert=true) means return value from INSERT
@Return(insert=true, update=false) means return value from INSERT
@Return(update=true) means return value from INSERT and UPDATE
@Return(insert=true, update=true) means return value from INSERT and UPDATE
@Return(insert=false, update=true) means return value from UPDATE

@Return(insert=false) is an error or warning since it means do not use returning policy

Comment 3 Andrei Ilitchev CLA 2008-01-30 16:58:13 EST
I find it a bit confusing that Return(update=true) will also return on Insert.

Consider defining a enum for return mode values:
public enum ReturnMode {
    INSERT,
    UPDATE,
    INSERT_AND_UPDATE
}

@Target({METHOD, FIELD})
@Retention(RUNTIME)
public @interface Return {
  ReturnMode mode() default INSERT;
  String type default "";
}
Comment 4 Andrei Ilitchev CLA 2008-01-31 16:02:07 EST
Adding NONE value - to be used as default by other annotations including an optional @Return:

public enum ReturnMode {
    INSERT,
    UPDATE,
    INSERT_AND_UPDATE,
    NONE
}

@SomeOtherAnnotation {
  ...
  return default Return(NONE);
}
Comment 5 Andrei Ilitchev CLA 2008-02-05 12:29:03 EST
Suggestion: 
get rid of @Return annotation (xml element), specify ReturningPolicy with ReturnMode enum value instead; move type from @Return to @WriteTransformer.
Motivation:
1. Currently can't use 
  return default Return(NONE);
have to use:
  return default Return(mode=NONE);
in other annotation (such as @Basic) because @Return has String type;
2. Type is needed only for TransformationMapping - so let's move type from @Return into WriteTranformer:
@WriteTranformer(column=@Column(name="START_TIME"), 
      class=package.MyTimeTransformer.class,
      type="java.sql.Time")
3. Now that only ReturnMode is left in @Return it (@Return) is no longer required: @Basic and @Transformation will have:
  ReturnMode return default NONE;
4. For @Transformation a single ReturnMode (relating to all fields) is superior to supplying an individual @Return in each @WriteTransformer because all these @returns should be the same (it's impossible to have INSERT on one field and UPDATE on another).

With the suggested change annotations using returning will look like:
@Basic(column=@Column(name="F_NAME"), return=INSERT);

@Transformation(
read=@ReadTransformer(method="buildNormalHours"),
write={
     @WriteTranformer(column=@Column(name="START_TIME"),
method="getStartTime", type="java.sql.Time"),
     @WriteTranformer(column=@Column(name="END_TIME"), 
method="getEndTime", type="java.sql.Time")
},
return=INSERT,
)

If returning is not used "return" method is simply dropped from the annotation (indicating that the default value NONE should be used).

Accordingly in xml a single attribute in <basic> and <transformation> will be used:
    <xsd:attribute name="return" type="orm:return-mode default=NONE"/>
where:
    <xsd:simpleType name="return-mode">
      <xsd:restriction base="xsd:token">
        <xsd:enumeration value="INSERT"/>
        <xsd:enumeration value="UPDATE"/>
        <xsd:enumeration value="INSERT_AND_UPDATE"/>
        <xsd:enumeration value="NONE"/>
      </xsd:restriction>
    </xsd:simpleType>

Comment 6 Shaun Smith CLA 2009-09-11 11:05:45 EDT
This bug has not been updated to reflect work done on this feature.  Returning has been implemented in annotations but is missing in eclipselink-orm.xml.  We should have full support in xml for all implemented annotations.
Comment 7 Peter Krogh CLA 2009-11-27 11:15:53 EST
This will be looked at in the metadata restructuring work being slated for 2.1.
Comment 8 Guy Pelletier CLA 2009-12-08 08:57:47 EST
Implementation of ReturnInsert and ReturnUpdate will remain as is and available to Basic mappings only.

Implementation of transformation mappings will also remain as is.

Availability of return-insert and return-update through XML on basic mappings was addressed in bug 296289
Comment 9 Eclipse Webmaster CLA 2022-06-09 10:15:39 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink
Comment 10 Eclipse Webmaster CLA 2022-06-09 10:27:05 EDT
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink