Java Doc for SQuery.java in  » Database-ORM » SimpleORM » simpleorm » core » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Database ORM » SimpleORM » simpleorm.core 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   simpleorm.core.SQuery

SQuery
public class SQuery implements SConstants(Code)
Provides the non-SQL query interface. This is still a thin layer on SQL, but provides more run time type checking at the price of slightly longer queries. There is also a very small performance overhead.

For example:-

SResultSet res = Employee.meta.newQuery() .gt(Employee.NAME, "'J'") //.and() // AND is implied. .eq(Employee.DEPARTMENT, myDept) .decending(Employee.NAME) // ie. Order By .execute(); while (res.hasNext()) {... is equivalent to SPreparedStatement stmt = Employee.meta.select( "NAME > 'j' AND DEPT_ID = ?", "NAME DESC"); stmt.setInt(1, myDept.getInt(DEPT_ID)); SResultSet res = stmt.execute(); while (res.hasNext()) {... This API is a little unusual in that there is only one SQuery instance created, and each of the methods update its state and then return this.

The raw* methods can be used to poke any string into the SQL Where or Order By clauses in the order they appear. But more commonly the raw methods are called by higher level methods such as eq and and.

todo Some of this logic should be moved to sdriver, and integrated with its selectSQL etc.



Field Summary
 SDriverdriver
    
 SArrayListjoinTables
    
 booleanneedsConjunction
    
 StringBufferorderBy
    
 booleanorderByJoinedColumn
    
 SArrayListqueryParameters
    
 SRecordMetarecord
    
 booleanreverseJoin
    
 SFieldMeta[]selectList
    
 longsqy_bitSet
    
 StringBufferwhere
    

Constructor Summary
protected  SQuery(SRecordMeta record, long sqy_bitSet, SFieldMeta[] selectList)
     SQueries are created by SRecordMeta.newQuery().

Method Summary
public  SQueryand()
     Adds rawClause("AND");

This method is optional.

public  SQueryascending(SFieldMeta field)
    
public  SQuerycombineBegin()
    
public  SQuerycombineEnd()
     Inserts ")" into the query.
public  SQuerydescending(SFieldMeta field)
    
public  SQueryeq(SFieldMeta field, Object value)
     Normally just adds fieldRelopParameter(field, "=", value).

If field is a reference it recursively expands the foreign keys, and value must be an instance of the same record type.

value must not be null, you need the special case IS NULL test.

public  SQueryeq(SFieldMeta field, int value)
    
public  SQueryeq(SFieldMeta field, long value)
    
public  SQueryeq(SFieldMeta field, double value)
    
public  SQueryeq(SFieldMeta field1, SFieldMeta field2)
    
 SQueryeqNeAux(SFieldMeta field, Object value, boolean isEq)
    
public  SQueryequivalent(SFieldBoolean field, boolean value)
     True if boolean field == writeFieldValue(value). Ie.
public  SResultSetexecute()
     Execute the query, set the previously specified query values, and return the result set.
public  SResultSetexecute(SPreparedStatement stmt)
    
public  SQueryfieldQuery(SFieldMeta field, String clause)
     Generates field clause, ie the clause string is poked literally into the query.
public  SQueryfieldRelopParameter(SFieldMeta field, String relop, Object value)
     Generates field relop ? and then subsequently sets the parameter value.
public  SQueryfieldRelopParameter(SFieldMeta field1, String relop, SFieldMeta field2)
     Generates field1 relop field2 E.g.
public  SQueryge(SFieldMeta field, Object value)
    
public  SQueryge(SFieldMeta field, int value)
    
public  SQueryge(SFieldMeta field, long value)
    
public  SQueryge(SFieldMeta field, double value)
    
public  SQueryge(SFieldMeta field1, SFieldMeta field2)
    
public  SRecordMetagetSRecordMeta()
    
public  SQuerygt(SFieldMeta field, Object value)
    
public  SQuerygt(SFieldMeta field, int value)
    
public  SQuerygt(SFieldMeta field, long value)
    
public  SQuerygt(SFieldMeta field, double value)
    
public  SQuerygt(SFieldMeta field1, SFieldMeta field2)
    
public  SQueryin(SFieldMeta field, Object[] values)
    
public  SQueryin(SFieldMeta field, int[] values)
    
public  SQueryin(SFieldMeta field, String value)
     value is tokenized into a list of values.
public  booleanisDistinct()
     Return true if this query will use 'SELECT DISTINCT'.
public  SQueryisFalse(SFieldBoolean field)
    
public  SQueryisNotNull(SFieldMeta field)
    
public  SQueryisNotNull(SFieldMeta field, Object value)
    
public  SQueryisNull(SFieldMeta field)
    
public  SQueryisNull(SFieldMeta field, Object value)
    
public  SQueryisTrue(SFieldBoolean field)
    
public  SQueryjoin(SFieldReference reference)
     Join to another table, based on the specified reference.
public  SQueryle(SFieldMeta field, Object value)
    
public  SQueryle(SFieldMeta field, int value)
    
public  SQueryle(SFieldMeta field, long value)
    
public  SQueryle(SFieldMeta field, double value)
    
public  SQueryle(SFieldMeta field1, SFieldMeta field2)
    
public  SQuerylike(SFieldMeta field, Object value)
    
public  SQuerylt(SFieldMeta field, Object value)
    
public  SQuerylt(SFieldMeta field, int value)
    
public  SQuerylt(SFieldMeta field, long value)
    
public  SQuerylt(SFieldMeta field, double value)
    
public  SQuerylt(SFieldMeta field1, SFieldMeta field2)
    
public  SQueryne(SFieldMeta field, int value)
    
public  SQueryne(SFieldMeta field, Object value)
     Just adds fieldRelopParameter(field, "<>", value).

Note that there are few methods ne(SfieldMeta, int) etc.

public  SQueryne(SFieldMeta field, long value)
    
public  SQueryne(SFieldMeta field, double value)
    
public  SQueryne(SFieldMeta field1, SFieldMeta field2)
    
public  SQuerynot()
    
 SQuerynullAux(SFieldMeta field, boolean isNull)
    
public  SQueryor()
    
public  SQueryrawClause(String term)
     Add term to the where clase, eg.
public  SQueryrawField(SFieldMeta field)
     Adds the field's columnName.
public  SQueryrawOrderBy(String orderBy)
     Add a clause to the OrderBy statement, eg.
public  SQueryrawOrderBy(SFieldMeta field, boolean ascending)
     Add a clause to the OrderBy statement.
public  SQueryrawParameter(Object parameter)
     Add a parameter value to the internal array.
static  Stringsubstitute(String qry, SArrayList parameters)
     Substitute '?' in the sql query with the values in the parameters array.
public  StringtoString()
    

Field Detail
driver
SDriver driver(Code)



joinTables
SArrayList joinTables(Code)



needsConjunction
boolean needsConjunction(Code)



orderBy
StringBuffer orderBy(Code)



orderByJoinedColumn
boolean orderByJoinedColumn(Code)



queryParameters
SArrayList queryParameters(Code)



record
SRecordMeta record(Code)



reverseJoin
boolean reverseJoin(Code)



selectList
SFieldMeta[] selectList(Code)



sqy_bitSet
long sqy_bitSet(Code)



where
StringBuffer where(Code)




Constructor Detail
SQuery
protected SQuery(SRecordMeta record, long sqy_bitSet, SFieldMeta[] selectList)(Code)
SQueries are created by SRecordMeta.newQuery().




Method Detail
and
public SQuery and()(Code)
Adds rawClause("AND");

This method is optional. If you call neither and() nor or() between statements (e.g. eq()), then a call to and() is assumed, and is done for you.




ascending
public SQuery ascending(SFieldMeta field)(Code)
rawOrderBy(field.columnName)



combineBegin
public SQuery combineBegin()(Code)
Inserts "(" into the query
author:
   Pierre Awaragi



combineEnd
public SQuery combineEnd()(Code)
Inserts ")" into the query.
author:
   Pierre Awaragi



descending
public SQuery descending(SFieldMeta field)(Code)
rawOrderBy(field.columnName) DESC



eq
public SQuery eq(SFieldMeta field, Object value)(Code)
Normally just adds fieldRelopParameter(field, "=", value).

If field is a reference it recursively expands the foreign keys, and value must be an instance of the same record type.

value must not be null, you need the special case IS NULL test. (It would be possible to optimize this here, but what about field == field where one of them is null -- that would be inconsistent.)




eq
public SQuery eq(SFieldMeta field, int value)(Code)



eq
public SQuery eq(SFieldMeta field, long value)(Code)



eq
public SQuery eq(SFieldMeta field, double value)(Code)



eq
public SQuery eq(SFieldMeta field1, SFieldMeta field2)(Code)



eqNeAux
SQuery eqNeAux(SFieldMeta field, Object value, boolean isEq)(Code)



equivalent
public SQuery equivalent(SFieldBoolean field, boolean value)(Code)
True if boolean field == writeFieldValue(value). Ie. value is converted from bool to "Y"/"N" etc.



execute
public SResultSet execute()(Code)
Execute the query, set the previously specified query values, and return the result set.



execute
public SResultSet execute(SPreparedStatement stmt)(Code)



fieldQuery
public SQuery fieldQuery(SFieldMeta field, String clause)(Code)
Generates field clause, ie the clause string is poked literally into the query. Eg.

fieldQuery(Employee.Name, "= 'Fred'")

Use fieldRelopParameter instead for parameters determined at run time as blindly concatenating strings is dangerous.




fieldRelopParameter
public SQuery fieldRelopParameter(SFieldMeta field, String relop, Object value)(Code)
Generates field relop ? and then subsequently sets the parameter value. Eg.

fieldRelopParameter(Employee.Name, "=", myName)




fieldRelopParameter
public SQuery fieldRelopParameter(SFieldMeta field1, String relop, SFieldMeta field2)(Code)
Generates field1 relop field2 E.g. fieldRelopParameter(Order.QuantityRequired, "=", Order.QuantityReceived)

Mainly useful for Joins.




ge
public SQuery ge(SFieldMeta field, Object value)(Code)
Just adds fieldRelopParameter(field, ">=", value)



ge
public SQuery ge(SFieldMeta field, int value)(Code)



ge
public SQuery ge(SFieldMeta field, long value)(Code)



ge
public SQuery ge(SFieldMeta field, double value)(Code)



ge
public SQuery ge(SFieldMeta field1, SFieldMeta field2)(Code)



getSRecordMeta
public SRecordMeta getSRecordMeta()(Code)



gt
public SQuery gt(SFieldMeta field, Object value)(Code)
Just adds fieldRelopParameter(field, ">", value)



gt
public SQuery gt(SFieldMeta field, int value)(Code)



gt
public SQuery gt(SFieldMeta field, long value)(Code)



gt
public SQuery gt(SFieldMeta field, double value)(Code)



gt
public SQuery gt(SFieldMeta field1, SFieldMeta field2)(Code)



in
public SQuery in(SFieldMeta field, Object[] values)(Code)
Use or clause to simulate the in clause



in
public SQuery in(SFieldMeta field, int[] values)(Code)
Use or clause to simulate the in clause



in
public SQuery in(SFieldMeta field, String value)(Code)
value is tokenized into a list of values.



isDistinct
public boolean isDistinct()(Code)
Return true if this query will use 'SELECT DISTINCT'. This is automatically added if the following two conditions are true:
  1. This query uses a join on a reference FROM another table. For example, a query on department that has a join to employee (note that without the 'DISTINCT' keyword, multiple rows would typically be returned for each department)
  2. There are no order-by columns on fields other than the query table. SQL syntax forces all order-by columns to also be in the select list, if DISTINCT is used.



isFalse
public SQuery isFalse(SFieldBoolean field)(Code)



isNotNull
public SQuery isNotNull(SFieldMeta field)(Code)
Just adds fieldQuery(field, "IS NULL")



isNotNull
public SQuery isNotNull(SFieldMeta field, Object value)(Code)



isNull
public SQuery isNull(SFieldMeta field)(Code)
Just adds fieldQuery(field, "IS NULL")



isNull
public SQuery isNull(SFieldMeta field, Object value)(Code)



isTrue
public SQuery isTrue(SFieldBoolean field)(Code)
shortcut for equivalent(field, true);



join
public SQuery join(SFieldReference reference)(Code)
Join to another table, based on the specified reference.

The INNER join works in both directions. So either reference may be from a table that is already in the query to a new table, or from a new table to a table that is already in the query.

This method updates both the from and where claues. After a call to this method is made, you can simply refer to fields from the joined table in subsequent calls to the relative operators such as eq().

This provides an alternative to just using subselects. The effect is almost the same except for inner join issues.

You can call join() multiple times to join several tables together. This will work as long as each subsequent join() call makes a connection from the existing set of tables to a new table.

A single table may not be joined multiple times, so there can be no ambiguity as to which join path to use to access a field.

There is an example in BasicTests.queryTest().




le
public SQuery le(SFieldMeta field, Object value)(Code)
Just adds fieldRelopParameter(field, "<=", value)



le
public SQuery le(SFieldMeta field, int value)(Code)



le
public SQuery le(SFieldMeta field, long value)(Code)



le
public SQuery le(SFieldMeta field, double value)(Code)



le
public SQuery le(SFieldMeta field1, SFieldMeta field2)(Code)



like
public SQuery like(SFieldMeta field, Object value)(Code)
Just adds fieldRelopParameter(field, "like", value)



lt
public SQuery lt(SFieldMeta field, Object value)(Code)
Just adds fieldRelopParameter(field, "<", value)



lt
public SQuery lt(SFieldMeta field, int value)(Code)



lt
public SQuery lt(SFieldMeta field, long value)(Code)



lt
public SQuery lt(SFieldMeta field, double value)(Code)



lt
public SQuery lt(SFieldMeta field1, SFieldMeta field2)(Code)



ne
public SQuery ne(SFieldMeta field, int value)(Code)



ne
public SQuery ne(SFieldMeta field, Object value)(Code)
Just adds fieldRelopParameter(field, "<>", value).

Note that there are few methods ne(SfieldMeta, int) etc. This is because 5 relops * 5 data types would require 25 methods! Java 1.5 boxing will (finally) make this unnecessary anyway.




ne
public SQuery ne(SFieldMeta field, long value)(Code)



ne
public SQuery ne(SFieldMeta field, double value)(Code)



ne
public SQuery ne(SFieldMeta field1, SFieldMeta field2)(Code)



not
public SQuery not()(Code)
Adds rawClause("NOT");



nullAux
SQuery nullAux(SFieldMeta field, boolean isNull)(Code)



or
public SQuery or()(Code)
Adds rawClause("OR");



rawClause
public SQuery rawClause(String term)(Code)
Add term to the where clase, eg. "BUDGET > ?". Not normally called directly.



rawField
public SQuery rawField(SFieldMeta field)(Code)
Adds the field's columnName.



rawOrderBy
public SQuery rawOrderBy(String orderBy)(Code)
Add a clause to the OrderBy statement, eg. "NAME DESC". Commas are added automatically.



rawOrderBy
public SQuery rawOrderBy(SFieldMeta field, boolean ascending)(Code)
Add a clause to the OrderBy statement. Commas are added automatically.



rawParameter
public SQuery rawParameter(Object parameter)(Code)
Add a parameter value to the internal array. These will be setObject later after the prepared statement is created but before it is executed.



substitute
static String substitute(String qry, SArrayList parameters)(Code)
Substitute '?' in the sql query with the values in the parameters array. Used to create meaningful SQL strings for logging purposes ONLY.



toString
public String toString()(Code)



Methods inherited from java.lang.Object
native protected Object clone() throws CloneNotSupportedException(Code)(Java Doc)
public boolean equals(Object obj)(Code)(Java Doc)
protected void finalize() throws Throwable(Code)(Java Doc)
final native public Class getClass()(Code)(Java Doc)
native public int hashCode()(Code)(Java Doc)
final native public void notify()(Code)(Java Doc)
final native public void notifyAll()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
final native public void wait(long timeout) throws InterruptedException(Code)(Java Doc)
final public void wait(long timeout, int nanos) throws InterruptedException(Code)(Java Doc)
final public void wait() throws InterruptedException(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.