com.avaje.ebean
Interface SqlUpdate


public interface SqlUpdate

A SqlUpdate for executing insert update or delete statements.

Provides a simple way to execute raw SQL insert update or delete statements without having to resort to JDBC.

Supports the use of positioned or named parameters and can automatically notify Ebean of the table modified so that Ebean can maintain its cache.

Note that setAutoTableMod(boolean) and Ebean#externalModification(String, boolean, boolean, boolean)} can be to notify Ebean of external changes and enable Ebean to maintain it's "L2" server cache.

 
 // example that uses 'named' parameters 
 String s = "UPDATE f_topic set post_count = :count where id = :id"
 SqlUpdate update = Ebean.createSqlUpdate(s);
 update.setParameter("id", 1);
 update.setParameter("count", 50);
 
 int modifiedCount = Ebean.execute(update);
 
 String msg = "There where " + modifiedCount + "rows updated" 
 

See Also:
Update, SqlQuery, CallableSql

Method Summary
 int execute()
          Execute the update returning the number of rows modified.
 String getLabel()
          Return the label that can be seen in the transaction logs.
 String getSql()
          Return the sql statement.
 int getTimeout()
          Return the timeout used to execute this statement.
 boolean isAutoTableMod()
          Return true if eBean should automatically deduce the table modification information and process it.
 SqlUpdate setAutoTableMod(boolean isAutoTableMod)
          Set this to false if you don't want eBean to automatically deduce the table modification information and process it.
 SqlUpdate setLabel(String label)
          Set a descriptive text that can be put into the transaction log.
 SqlUpdate setNull(int position, int jdbcType)
          Set a null parameter via its index position.
 SqlUpdate setNull(String name, int jdbcType)
          Set a named parameter that has a null value.
 SqlUpdate setNullParameter(int position, int jdbcType)
          Set a null valued parameter using its index position.
 SqlUpdate setNullParameter(String name, int jdbcType)
          Set a named parameter that has a null value.
 SqlUpdate setParameter(int position, Object value)
          Set a parameter via its index position.
 SqlUpdate setParameter(String name, Object param)
          Set a named parameter value.
 SqlUpdate setTimeout(int secs)
          Set the timeout in seconds.
 

Method Detail

execute

int execute()
Execute the update returning the number of rows modified.

After you have executed the SqlUpdate you can bind new variables using setParameter(String, Object) etc and then execute the SqlUpdate again.

For JDBC batch processing refer to Transaction.setBatchMode(boolean) and Transaction.setBatchSize(int).

See Also:
Ebean.execute(SqlUpdate)

isAutoTableMod

boolean isAutoTableMod()
Return true if eBean should automatically deduce the table modification information and process it.

If this is true then cache invalidation and text index management are aware of the modification.


setAutoTableMod

SqlUpdate setAutoTableMod(boolean isAutoTableMod)
Set this to false if you don't want eBean to automatically deduce the table modification information and process it.

Set this to false if you don't want any cache invalidation or text index management to occur. You may do this when say you update only one column and you know that it is not important for cached objects or text indexes.


getLabel

String getLabel()
Return the label that can be seen in the transaction logs.


setLabel

SqlUpdate setLabel(String label)
Set a descriptive text that can be put into the transaction log.

Useful when identifying the statement in the transaction log.


getSql

String getSql()
Return the sql statement.


getTimeout

int getTimeout()
Return the timeout used to execute this statement.


setTimeout

SqlUpdate setTimeout(int secs)
Set the timeout in seconds. Zero implies no limit.

This will set the query timeout on the underlying PreparedStatement. If the timeout expires a SQLException will be throw and wrapped in a PersistenceException.


setParameter

SqlUpdate setParameter(int position,
                       Object value)
Set a parameter via its index position.


setNull

SqlUpdate setNull(int position,
                  int jdbcType)
Set a null parameter via its index position. Exactly the same as setNull(int, int).


setNullParameter

SqlUpdate setNullParameter(int position,
                           int jdbcType)
Set a null valued parameter using its index position.


setParameter

SqlUpdate setParameter(String name,
                       Object param)
Set a named parameter value.


setNull

SqlUpdate setNull(String name,
                  int jdbcType)
Set a named parameter that has a null value. Exactly the same as setNullParameter(String, int).


setNullParameter

SqlUpdate setNullParameter(String name,
                           int jdbcType)
Set a named parameter that has a null value.



Copyright © 2010. All Rights Reserved.