001: /**
002: * Objective Database Abstraction Layer (ODAL)
003: * Copyright (c) 2004, The ODAL Development Group
004: * All rights reserved.
005: * For definition of the ODAL Development Group please refer to LICENCE.txt file
006: *
007: * Distributable under LGPL license.
008: * See terms of license at gnu.org.
009: */package com.completex.objective.components.persistency;
010:
011: /**
012: * @author Gennady Krizhevsky
013: */
014: public interface BasicQuery {
015:
016: OrderDirection ORDER_ASC = OrderDirection.ASC;
017: OrderDirection ORDER_DESC = OrderDirection.DESC;
018:
019: /**
020: * Query states:
021: */
022: int STATE_NEW = 0;
023: int STATE_ACTIVE = 1;
024: int STATE_CLOSED = 2;
025:
026: //
027: // Update related:
028: //
029: String UPDATE = "UPDATE ";
030:
031: //
032: // Seelect related:
033: //
034: String SELECT = "SELECT ";
035: String DISTINCT = " DISTINCT ";
036: String COUNT = " count ";
037: String COUNT_1 = " count(1) ";
038: String EXISTS = " EXISTS ";
039: String WHERE = " WHERE ";
040: String FROM = " FROM ";
041: String ORDER_BY = " ORDER BY ";
042: String GROUP_BY = " GROUP BY ";
043: String HAVING = " HAVING ";
044: String AND = " AND ";
045: String OR = " OR ";
046: String ASC = " ASC ";
047: String DESC = " DESC ";
048: String STAR = " * ";
049: String DOT_STAR = ".* ";
050: String EQ = " = ";
051: String NE = " <> ";
052: String GT = " > ";
053: String GE = " >= ";
054: String LT = " < ";
055: String LE = " <= ";
056: String PH = "?";
057: String PH1 = "? ";
058: String EPH = "=?s";
059: String EPH1 = "=? ";
060: String MULTI_WILD = "%";
061: String SQ = "'";
062:
063: String LIKE = " LIKE ";
064: String BETWEEN = " BETWEEN ";
065: String LOWER = " LOWER";
066: String UPPER = " UPPER";
067:
068: /**
069: * Returns SQL string that this query represents
070: *
071: * @return SQL string that this query represents
072: */
073: String getSql();
074:
075: /**
076: * Sets SQL string that this query represents
077: * @param sql SQL string that this query represents
078: * @return itself
079: */
080: BasicQuery setSql(String sql);
081:
082: //
083: // Name:
084: //
085:
086: /**
087: * Set query name
088: *
089: * @param name
090: */
091: void setName(String name);
092:
093: /**
094: * @return query name
095: */
096: String getName();
097:
098: BasicQuery setParameters(Parameter[] parameters);
099:
100: AbstractParameters getBaseParameters();
101:
102: //
103: // Pagination:
104: //
105: /**
106: * Sets page size in records
107: *
108: * @param pageSize page size in records
109: * @return itself
110: */
111: BasicQuery setPageSize(long pageSize);
112:
113: /**
114: * Returns page size
115: *
116: * @return page size
117: */
118: long getPageSize();
119:
120: /**
121: * Set 0-based offset from which records to be retrieved
122: *
123: * @param offset
124: */
125: void setOffset(long offset);
126:
127: /**
128: * Returns 0-based offset from which records to be retrieved
129: *
130: * @return 0-based offset from which records to be retrieved
131: */
132: long getOffset();
133:
134: /**
135: * Sets page parameters in terms of <code>BasicQuery.Page<code/>
136: *
137: * @param page
138: * @return itself
139: */
140: BasicQuery setPage(Page page);
141:
142: //
143: // Util classes:
144: //
145:
146: /**
147: * Order direction type - ascending or descending.
148: */
149: static class OrderDirection {
150: protected static final OrderDirection ASC = new OrderDirection(
151: "ACS");
152: protected static final OrderDirection DESC = new OrderDirection(
153: "DESC");
154:
155: private String sqlString;
156:
157: private String name;
158:
159: private OrderDirection(String name) {
160: this .name = name;
161: this .sqlString = " " + name + " ";
162: }
163:
164: public String toString() {
165: return name;
166: }
167:
168: public String getSqlString() {
169: return sqlString;
170: }
171: }
172:
173: }
|