| 
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.j_spaces.core.client.SQLQuery<T>
public class SQLQuery<T>
The SQLQuery class is used to query the space using the SQL syntax.
 The query statement should only include the WHERE clause.
 Supported JavaSpace operations
 read/take/readMultiple/takeMultiple (with JavaSpace.NO_WAIT timeout)
 UnSupported JavaSpace operations
 Notify/readIfExists/takeIfExists  and  read/take/readMultiple/takeMultiple (with longer timeouts than JSpace.NO_WAIT)
 
 Date and Time Formats
 The following Date/TimeStamp Format is supported: 'yyyy-mm-dd hh:mm:ss' - i.e. '2004-12-20 20:40:10'
 The following Time Format is supported: 'hh:mm:ss' - i.e. '20:40:10'
thrown when space operations with SQLQuery fails., 
Serialized Form| Field Summary | |
|---|---|
static String | 
CALL
 | 
static String | 
COUNT_PREFIX
 | 
static String | 
DELETE_PREFIX
 | 
static String | 
GROUP
 | 
static String | 
ORDER
 | 
static String | 
SELECT_PREFIX
 | 
| Constructor Summary | |
|---|---|
SQLQuery()
Empty constructor.  | 
|
SQLQuery(Class<T> clazz,
         String sqlQuery)
Constructor for setting the className of the entry to query with the sql query expression.  | 
|
SQLQuery(Class<T> clazz,
         String sqlQuery,
         Object... parameters)
Constructor for setting the class of the entry to query with the sql query expression.  | 
|
SQLQuery(Entry entry,
         String sqlQuery)
Constructor for setting the entry as a template to query with the sql query expression.  | 
|
SQLQuery(String className,
         String sqlQuery)
Constructor for setting the class of the entry to query with the sql query expression.  | 
|
SQLQuery(String className,
         String sqlQuery,
         Object... parameters)
Constructor for setting the class of the entry to query with the sql query expression.  | 
|
SQLQuery(T object,
         String sqlQuery)
Constructor for setting the object as a template to query with the sql query expression.  | 
|
SQLQuery(T object,
         String sqlQuery,
         Object... parameters)
Constructor for setting the object as a template to query with the sql query expression.  | 
|
| Method Summary | |
|---|---|
 String | 
getClassName()
Extract the Entry class name for the current query.  | 
 Entry | 
getEntry()
Deprecated. use getObject() instead. | 
 String | 
getFromQuery()
Returns a string representation of this SQLQuery, in the form of: FROM table name WHERE query expression  | 
 T | 
getObject()
Extract the POJO for the current query.  | 
 Object[] | 
getParameters()
 | 
 String | 
getQuery()
Returns the 'WHERE' part of this SQL Query.  | 
 String | 
getSelectAllQuery()
Returns a string representation of this SQLQuery, in the form of: SELECT * FROM table name WHERE query expression  | 
 String | 
getSelectCountQuery()
Returns a string representation of this SQLQuery, in the form of: SELECT count(*) FROM table name WHERE query expression  | 
 boolean | 
hasParameters()
 | 
 boolean | 
hasWhereClause()
Returns true if the query has a where clause.  | 
 boolean | 
isNullExpression()
This method should be used for check expression string.  | 
 boolean | 
isStoredProcedure()
Returns true if this query is a stored procedure  | 
 void | 
setClassName(String className)
This method should be used for new Entry classes introduced to the space.  | 
 void | 
setParameter(int index,
             Object value)
Set the query parameter value.  | 
 void | 
setParameters(Object... parameters)
 | 
 void | 
setQuery(String wherePart)
Sets the query statement.  | 
 void | 
setTemplate(Entry entry)
Sets a new entry template.  | 
 void | 
setTemplate(T object)
Sets a new entry template.  | 
 String | 
toString()
Returns a string representation of this SQLQuery, in the form of: SELECT * FROM table name WHERE query expression  | 
| Methods inherited from class java.lang.Object | 
|---|
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait | 
| Field Detail | 
|---|
public static final String SELECT_PREFIX
public static final String DELETE_PREFIX
public static final String COUNT_PREFIX
public static final String CALL
public static final String GROUP
public static final String ORDER
| Constructor Detail | 
|---|
public SQLQuery()
public SQLQuery(String className,
                String sqlQuery)
className - Entry class to be queried.sqlQuery - The SQL Query expression (contents of the WHERE part).
public SQLQuery(String className,
                String sqlQuery,
                Object... parameters)
className - Entry class to be queried.sqlQuery - The SQL Query expression (contents of the WHERE part).parameters - Parameters for the sql query
public SQLQuery(Class<T> clazz,
                String sqlQuery,
                Object... parameters)
clazz - Entry class to be queried.sqlQuery - The SQL Query expression (contents of the WHERE part).parameters - Parameters for the sql query
public SQLQuery(Class<T> clazz,
                String sqlQuery)
clazz - Entry class  to be queried.sqlQuery - The SQL Query expression (contents of the WHERE part).
 
 SQLQuery query = new SQLQuery(MyEntry.class, "m_integer > 50");
 Entry result[] = space.readMultiple(query, null, Integer.MAX_VALUE);
 System.out.println("Found " + result.length + " Entries");
 for (int i = 0; i < result.length; i++) {
     System.out.println(i + " " + (MyEntry) result[i]);
 }
 
public SQLQuery(T object,
                String sqlQuery,
                Object... parameters)
object - The POJO to query bysqlQuery - The SQL Query expression (contents of the WHERE part).parameters - Parameters for the sql query
 
  // The following query returns all the objects that have m_integer between 50 and 100
 SQLQuery query = new SQLQuery(MyPojo(), "m_integer > ? and m_integer < ?",50,100);
 MyPojo result = (MyPojo)space.read(query, null, JavaSpace.NO_WAIT);
 if (result!=null)
     // if there are more then one, it will return the first entry found
     System.out.println("Found object: " + result.toString());
 else
     System.out.println("None of the objects  match the specified query: "+query);
 SQLQuery(String className, String sqlQuery)
public SQLQuery(T object,
                String sqlQuery)
object - The POJO to query bysqlQuery - The SQL Query expression (contents of the WHERE part).
 
 SQLQuery query = new SQLQuery(MyPojo(), "m_integer > 50");
 MyPojo result = (MyPojo)space.read(query, null, JavaSpace.NO_WAIT);
 if (result!=null)
     // if there are more then one, it will return the first entry found
     System.out.println("Found object: " + result.toString());
 else
     System.out.println("None of the objects  match the specified query: "+query);
 SQLQuery(String className, String sqlQuery)
public SQLQuery(Entry entry,
                String sqlQuery)
entry - The entry to query bysqlQuery - The SQL Query expression (contents of the WHERE part).
 
 //let MyEntry extend ExternalEntry
 SQLQuery query = new SQLQuery(MyEntry(), "m_integer > 50");
 MyEntry result = (MyEntry)space.read(query, null, JavaSpace.NO_WAIT);
 if (result!=null)
     // if there are more then one, it will return the first entry found
     System.out.println("Found entry: " + result.toString());
 else
     System.out.println("None of the entries match the specified query: "+query);
 SQLQuery(String className, String sqlQuery)| Method Detail | 
|---|
public boolean isNullExpression()
true if expression is null or emptypublic T getObject()
@Deprecated public Entry getEntry()
getObject() instead.
public String getClassName()
public void setClassName(String className)
setClassName in interface Query<T>className - The Entry class name to be set.public void setQuery(String wherePart)
setQuery in interface Query<T>wherePart - The where contents of the query
 
 // let EmployeeEntry and AccountEntry be instances of ExternalEntry
 SQLQuery query = new SQLQuery(EmployeeEntry.class.getName(), "m_employeeId"+employeeId);
 EmployeeEntry employee = (EmployeeEntry)space.read(query,null,JavaSpace.NO_WAIT);
 if (employee==null) throw new EmployeeNotFoundException("Employee "+employeeId+" not found");
 query.setClassName(AccountingEntry.class.getName());
 query.setQuery("m_accountNo ="+ employee.accNo);
 AccountEntry account = (AccountEntry)space.take(query,null,JavaSpace.NO_WAIT);
 public void setTemplate(Entry entry)
entry - The Entry or an ExternalEntry
 
 SQLQuery query = new SQLQuery(new Entry(),null);
 query.setTemplate(new MyDateEntry());
 query.setQuery("m_date <"+ new Date(System.currentTimeMillis()));
 Entry[] results = space.takeMultiple(query, null, Integer.MAX_VALUE);
 System.out.println("Found " + result.length + " Entries");
 for (int i = 0; i < result.length; i++) {
    System.out.println(i + " " + (MyEntry) result[i]);
 }
 public void setTemplate(T object)
object - The POJO
 
 SQLQuery query = new SQLQuery(new POJO(),null);
 query.setTemplate(new POJO());
 query.setQuery("m_date <"+ new Date(System.currentTimeMillis()));
 Object[] results = space.takeMultiple(query, null, Integer.MAX_VALUE);
 System.out.println("Found " + result.length + " Entries");
 for (int i = 0; i < result.length; i++) {
    System.out.println(i + " " + (MyEntry) result[i]);
 }
 public String getQuery()
public String getFromQuery()
FROM table name WHERE query expression
public String getSelectAllQuery()
SELECT * FROM table name WHERE query expression
public String getSelectCountQuery()
SELECT count(*) FROM table name WHERE query expression
public String toString()
SELECT * FROM table name WHERE query expression
toString in class Objectpublic boolean isStoredProcedure()
true if represents a stored procedurepublic boolean hasWhereClause()
true has a "where" partpublic Object[] getParameters()
public boolean hasParameters()
public void setParameters(Object... parameters)
parameters - the parameters to set
public void setParameter(int index,
                         Object value)
index - parameter index - start with 1value - parameter value
  | 
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||