com.j256.ormlite.stmt
Class SelectArg

java.lang.Object
  extended by com.j256.ormlite.stmt.SelectArg

public class SelectArg
extends Object

An argument to a select SQL statement. After the query is constructed, the caller can set the value on this argument and run the query. Then the argument can be set again and the query re-executed. This is equivalent in JDBC to a ? type argument.

NOTE: If the argument has not been set by the time the query is executed, an exception will be thrown.

NOTE: For protections sake, the object cannot be reused with different column names.

 // build a query using the Account DAO
 QueryBuilder<Account, String> qb = accountDao.queryBuilder();
 
 // create an argument which will be set later
 SelectArg passwordSelectArg = new SelectArg();
 qb.where().eq(Account.PASSWORD_FIELD_NAME, passwordSelectArg);
 // prepare the query
 PreparedQuery<Account> preparedQuery = qb.prepareQuery();
 // ...
 
 // some time later we set the value and run the query 
 passwordSelectArg.setValue("_secret");
 List<Account> results = accountDao.query(preparedQuery);
 // we can then re-set the value and re-run the query 
 passwordSelectArg.setValue("qwerty");
 List<Account> results = accountDao.query(preparedQuery);
 

Author:
graywatson

Constructor Summary
SelectArg()
           
 
Method Summary
 String getColumnName()
          Return the column-name associated with this argument.
 Object getValue()
          Return the value associated with this argument.
 void setColumnName(String columnName)
          Used internally by the package to set the column-name associated with this argument.
 void setValue(Object value)
          Set the value associated with this argument.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

SelectArg

public SelectArg()
Method Detail

getColumnName

public String getColumnName()
Return the column-name associated with this argument. The name is set by the package internally.


setColumnName

public void setColumnName(String columnName)
Used internally by the package to set the column-name associated with this argument.


getValue

public Object getValue()
                throws SQLException
Return the value associated with this argument. The value should be set by the user before it is consumed.

Throws:
SQLException

setValue

public void setValue(Object value)
Set the value associated with this argument. The value should be set by the user after the query has been built but before it has been executed.


toString

public String toString()
Overrides:
toString in class Object


Copyright © 2010. All Rights Reserved.