net.sf.eodsql
Annotation Type Update


@Target(value=METHOD)
@Retention(value=RUNTIME)
public @interface Update

@Update is the counter-part to the Select annotation. There are a few differences between the two. While Select could technically be used to perform an update on the database, it is not well suited to do so, as it requires the return of a DataSet. Methods annotated with @Update may return an int and correspond to the Statement.executeUpdate(java.lang.String) method. The annotated method will return the number of rows in the database that were modified by it's execution, the method may also return void in which case any response from the database is discarded.

A method annotated by @Update may return a DataSet; or other well known collection or data-type (see Select for more info); to get back AutoGeneratedKeys from the database. In order for this to be valid, the method's @Update must have it's "keys" attribute set to something other than GeneratedKeys.NO_KEYS_RETURNED.

An update method can take any arguments, and map either them directly into the query, or map fields within the passed objects into the SQL statement. An example of several different query syntaxes:

        public class User {
            public Integer id;
            public String username;
        }
        
        public interface UserQuery extends BaseQuery {
            @Update("UPDATE user SET username = ?1 WHERE id = ?2")
            public int updateUser(String username, int id);
            
            @Update("UPDATE user SET username = ?{1.username} WHERE id = ?{1.id}")
            public int updateUser(User user);
        }
    
This example will also work if the User class was:
        public class User {
            private Integer id;
            priavte String username;
            
            public Integer getId() {
                return id;
            }
            
            public String getUsername() {
                return username;
            }
        }
    
The first example of an @Update syntax in the above example is compatible with the origional Java JDBC EoD syntax. The query parser actually ignores any SQL code, and only parses code after the '?', here are some more examples: Field's are mapped by first looking for a field of the given name, and then for a JavaBeans compatible getter method.

Author:
jason
See Also:
Select, GeneratedKeys

Optional Element Summary
 GeneratedKeys keys
           The specification of how auto-generated keys are to be returned for this @Update query.
 String sql
          The SQL query to execute on the database.
 String value
          The SQL query to execute on the database.
 

value

public abstract String value
The SQL query to execute on the database.

Default:
""

sql

public abstract String sql
The SQL query to execute on the database.

Default:
""

keys

public abstract GeneratedKeys keys

The specification of how auto-generated keys are to be returned for this @Update query.

Note: to use this feature (specify anything other than GeneratedKeys.NO_KEYS_RETURNED) your underlying JDBC driver must have support for the required PreparedStatements.

Default:
net.sf.eodsql.GeneratedKeys.NO_KEYS_RETURNED