| Method from org.apache.openjpa.jdbc.sql.SelectImpl Detail: |
public void addJoinClassConditions() {
if (_joins == null || _joins.joins() == null)
return;
// join set iterator allows concurrent modification
Join j;
for (Iterator itr = _joins.joins().iterator(); itr.hasNext();) {
j = (Join) itr.next();
if (j.getRelationTarget() != null) {
j.getRelationTarget().getDiscriminator().addClassConditions
(this, j.getSubclasses() == SUBS_JOINABLE,
j.getRelationJoins());
j.setRelation(null, 0, null);
}
}
}
|
public Joins and(Joins joins1,
Joins joins2) {
return and((PathJoins) joins1, (PathJoins) joins2, true);
}
|
public void append(SQLBuffer buf,
Joins joins) {
if (joins == null || joins.isEmpty())
return;
if (!buf.isEmpty())
buf.append(" AND ");
Join join = null;
for (Iterator itr = ((PathJoins) joins).joins().joinIterator();
itr.hasNext();) {
join = (Join) itr.next();
switch (_joinSyntax) {
case JoinSyntaxes.SYNTAX_TRADITIONAL:
buf.append(_dict.toTraditionalJoin(join));
break;
case JoinSyntaxes.SYNTAX_DATABASE:
buf.append(_dict.toNativeJoin(join));
break;
default:
throw new InternalException();
}
if (itr.hasNext())
buf.append(" AND ");
}
}
|
public void clearOrdering() {
_ordering = null;
_orders = 0;
}
|
public void clearPlaceholderSelects() {
_selects.clearPlaceholders();
}
Clear selected placeholders, and return removed select indexes. |
public void clearSelects() {
_selects.clear();
}
|
public Joins crossJoin(Table localTable,
Table foreignTable) {
return new SelectJoins(this).crossJoin(localTable, foreignTable);
}
|
public SelectExecutor eagerClone(FieldMapping key,
int eagerType,
boolean toMany,
int sels) {
if (eagerType == EAGER_OUTER
&& _joinSyntax == JoinSyntaxes.SYNTAX_TRADITIONAL)
return null;
if (_eagerKeys != null && _eagerKeys.contains(key))
return null;
// global set of eager keys
if (_eagerKeys == null)
_eagerKeys = new HashSet();
_eagerKeys.add(key);
SelectExecutor sel;
if (eagerType != EAGER_PARALLEL) {
if (toMany)
_flags |= EAGER_TO_MANY;
else
_flags |= EAGER_TO_ONE;
sel = this;
} else if (sels < 2)
sel = parallelClone();
else {
Select[] clones = new Select[sels];
for (int i = 0; i < clones.length; i++)
clones[i] = parallelClone();
sel = _conf.getSQLFactoryInstance().newUnion(clones);
}
if (_eager == null)
_eager = new HashMap();
_eager.put(toEagerKey(key, getJoins(null, false)), sel);
return sel;
}
|
public Result execute(JDBCStore store,
JDBCFetchConfiguration fetch) throws SQLException {
if (fetch == null)
fetch = store.getFetchConfiguration();
return execute(store.getContext(), store, fetch,
fetch.getReadLockLevel());
}
|
public Result execute(JDBCStore store,
JDBCFetchConfiguration fetch,
int lockLevel) throws SQLException {
if (fetch == null)
fetch = store.getFetchConfiguration();
return execute(store.getContext(), store, fetch, lockLevel);
}
|
protected Result execute(StoreContext ctx,
JDBCStore store,
JDBCFetchConfiguration fetch,
int lockLevel) throws SQLException {
boolean forUpdate = false;
if (!isAggregate() && _grouping == null) {
JDBCLockManager lm = store.getLockManager();
if (lm != null)
forUpdate = lm.selectForUpdate(this, lockLevel);
}
SQLBuffer sql = toSelect(forUpdate, fetch);
boolean isLRS = isLRS();
int rsType = (isLRS && supportsRandomAccess(forUpdate))
? -1 : ResultSet.TYPE_FORWARD_ONLY;
Connection conn = store.getConnection();
PreparedStatement stmnt = null;
ResultSet rs = null;
try {
if (isLRS)
stmnt = prepareStatement(conn, sql, fetch, rsType, -1, true);
else
stmnt = prepareStatement(conn, sql, null, rsType, -1, false);
setTimeout(stmnt, forUpdate, fetch);
rs = executeQuery(conn, stmnt, sql, isLRS, store);
} catch (SQLException se) {
// clean up statement
if (stmnt != null)
try { stmnt.close(); } catch (SQLException se2) {}
try { conn.close(); } catch (SQLException se2) {}
throw se;
}
return getEagerResult(conn, stmnt, rs, store, fetch, forUpdate,
sql.getSQL());
}
Execute this select in the context of the given store manager. The
context is passed in separately for profiling purposes. |
protected ResultSet executeQuery(Connection conn,
PreparedStatement stmnt,
SQLBuffer sql,
boolean isLRS,
JDBCStore store) throws SQLException {
return stmnt.executeQuery();
}
This method is to provide override for non-JDBC or JDBC-like
implementation of executing query. |
public SelectExecutor fullClone(int sels) {
if (sels < 1)
sels = 1;
Select[] clones = null;
SelectImpl sel;
for (int i = 0; i < sels; i++) {
sel = (SelectImpl) whereClone(1);
sel._flags = _flags;
sel._expectedResultCount = _expectedResultCount;
sel._selects.addAll(_selects);
if (_ordering != null)
sel._ordering = new SQLBuffer(_ordering);
sel._orders = _orders;
if (_grouping != null)
sel._grouping = new SQLBuffer(_grouping);
if (_having != null)
sel._having = new SQLBuffer(_having);
if (_from != null) {
sel._from = (SelectImpl) _from.fullClone(1);
sel._from._outer = sel;
}
if (sels == 1)
return sel;
if (clones == null)
clones = new Select[sels];
clones[i] = sel;
}
return _conf.getSQLFactoryInstance().newUnion(clones);
}
|
public boolean getAutoDistinct() {
return (_flags & NONAUTO_DISTINCT) == 0;
}
|
public String getColumnAlias(Column col) {
return getColumnAlias(col, (Joins) null);
}
|
public String getColumnAlias(Column col,
Joins joins) {
return getColumnAlias(col, getJoins(joins, false));
}
|
public String getColumnAlias(String col,
Table table) {
return getColumnAlias(col, table, (Joins) null);
}
|
public String getColumnAlias(String col,
Table table,
Joins joins) {
return getColumnAlias(col, table, getJoins(joins, false));
}
|
public JDBCConfiguration getConfiguration() {
return _conf;
}
|
public int getCount(JDBCStore store) throws SQLException {
Connection conn = null;
PreparedStatement stmnt = null;
ResultSet rs = null;
try {
SQLBuffer sql = toSelectCount();
conn = store.getConnection();
stmnt = prepareStatement(conn, sql, null,
ResultSet.TYPE_FORWARD_ONLY,
ResultSet.CONCUR_READ_ONLY, false);
rs = executeQuery(conn, stmnt, sql, false, store);
return getCount(rs);
} finally {
if (rs != null)
try { rs.close(); } catch (SQLException se) {}
if (stmnt != null)
try { stmnt.close(); } catch (SQLException se) {}
if (conn != null)
try { conn.close(); } catch (SQLException se) {}
}
}
|
protected int getCount(ResultSet rs) throws SQLException {
rs.next();
return rs.getInt(1);
}
This method is to provide override for non-JDBC or JDBC-like
implementation of getting count from the result set. |
public SelectExecutor getEager(FieldMapping key) {
if (_eager == null || !_eagerKeys.contains(key))
return null;
return (SelectExecutor) _eager.get(toEagerKey(key, getJoins(null,
false)));
}
|
public Map getEagerMap() {
return _eager;
}
Return view of eager selects. May be null. |
protected Result getEagerResult(Connection conn,
PreparedStatement stmnt,
ResultSet rs,
JDBCStore store,
JDBCFetchConfiguration fetch,
boolean forUpdate,
String sqlStr) throws SQLException {
SelectResult res = new SelectResult(conn, stmnt, rs, _dict);
res.setSelect(this);
res.setStore(store);
res.setLocking(forUpdate);
try {
addEagerResults(res, this, store, fetch);
} catch (SQLException se) {
res.close();
throw se;
}
return res;
}
This method is to provide override for non-JDBC or JDBC-like
implementation of executing eager selects. |
public long getEndIndex() {
return _endIdx;
}
|
public int getExpectedResultCount() {
// if the count isn't forced and we have to-many eager joins that could
// throw the count off, don't pay attention to it
if ((_flags & FORCE_COUNT) == 0 && hasEagerJoin(true))
return 0;
return _expectedResultCount;
}
|
public Select getFromSelect() {
return _from;
}
|
public SQLBuffer getGrouping() {
return _grouping;
}
|
public SQLBuffer getHaving() {
return _having;
}
|
public List getIdentifierAliases() {
return _selects.getAliases(true, _outer != null);
}
|
public Iterator getJoinIterator() {
if (_joins == null || _joins.isEmpty())
return EmptyIterator.INSTANCE;
return _joins.joins().joinIterator();
}
|
public int getJoinSyntax() {
return _joinSyntax;
}
|
public Joins getJoins() {
return _joins;
}
|
List getOrderedIndexes() {
if (_ordered == null)
return null;
List idxs = new ArrayList(_ordered.size());
for (int i = 0; i < _ordered.size(); i++)
idxs.add(Numbers.valueOf(_selects.indexOf(_ordered.get(i))));
return idxs;
}
Return the indexes in the select list of all items we're ordering
by, or null if none. For use with unions. |
public SQLBuffer getOrdering() {
return _ordering;
}
|
public Select getParent() {
return _parent;
}
|
public List getSelectAliases() {
return _selects.getAliases(false, _outer != null);
}
|
public List getSelects() {
return Collections.unmodifiableList(_selects);
}
|
public long getStartIndex() {
return _startIdx;
}
|
public String getSubselectPath() {
return _subPath;
}
|
public List getSubselects() {
return (_subsels == null) ? Collections.EMPTY_LIST : _subsels;
}
|
public Collection getTableAliases() {
return (_tables == null) ? Collections.EMPTY_SET : _tables.values();
}
|
public SQLBuffer getWhere() {
return _where;
}
|
public void groupBy(SQLBuffer sql) {
groupBy(sql, (Joins) null);
}
|
public void groupBy(String sql) {
groupBy(sql, (Joins) null);
}
|
public void groupBy(Column col) {
groupBy(col, null);
}
|
public void groupBy(Column[] cols) {
groupBy(cols, null);
}
|
public void groupBy(SQLBuffer sql,
Joins joins) {
getJoins(joins, true);
groupByAppend(sql.getSQL());
}
|
public void groupBy(String sql,
Joins joins) {
getJoins(joins, true);
groupByAppend(sql);
}
|
public void groupBy(Column col,
Joins joins) {
PathJoins pj = getJoins(joins, true);
groupByAppend(getColumnAlias(col, pj));
}
|
public void groupBy(Column[] cols,
Joins joins) {
PathJoins pj = getJoins(joins, true);
for (int i = 0; i < cols.length; i++) {
groupByAppend(getColumnAlias(cols[i], pj));
}
}
|
public void groupBy(ClassMapping mapping,
int subclasses,
JDBCStore store,
JDBCFetchConfiguration fetch) {
groupBy(mapping, subclasses, store, fetch, null);
}
|
public void groupBy(ClassMapping mapping,
int subclasses,
JDBCStore store,
JDBCFetchConfiguration fetch,
Joins joins) {
// we implement this by putting ourselves into grouping mode, where
// all select invocations are re-routed to group-by invocations instead.
// this allows us to utilize the same select APIs of the store manager
// and all the mapping strategies, rather than having to create
// equivalent APIs and duplicate logic for grouping
boolean wasGrouping = isGrouping();
_flags |= GROUPING;
try {
select(mapping, subclasses, store, fetch,
EagerFetchModes.EAGER_NONE, joins);
} finally {
if (!wasGrouping)
_flags &= ~GROUPING;
}
}
|
public boolean hasEagerJoin(boolean toMany) {
if (toMany)
return (_flags & EAGER_TO_MANY) != 0;
return (_flags & EAGER_TO_ONE) != 0;
}
|
public boolean hasJoin(boolean toMany) {
if (toMany)
return (_flags & TO_MANY) != 0;
return _tables != null && _tables.size() > 1;
}
|
public void having(SQLBuffer sql) {
having(sql, (Joins) null);
}
|
public void having(String sql) {
having(sql, (Joins) null);
}
|
public void having(SQLBuffer sql,
Joins joins) {
having(sql, getJoins(joins, true));
}
|
public void having(String sql,
Joins joins) {
having(sql, getJoins(joins, true));
}
|
public int indexOf() {
return 0;
}
|
public void insertPlaceholder(String sql,
int pos) {
Object holder = (_placeholders >= PLACEHOLDERS.length)
? new Placeholder() : PLACEHOLDERS[_placeholders++];
_selects.insertAlias(pos, holder, sql);
}
Insert a placeholder at the given index; use a negative index
to count from the back of the select list. |
public boolean isAggregate() {
return (_flags & AGGREGATE) != 0;
}
|
public boolean isDirty() {
return false;
}
|
public boolean isDistinct() {
return (_flags & NOT_DISTINCT) == 0 && ((_flags & DISTINCT) != 0
|| ((_flags & NONAUTO_DISTINCT) == 0
&& (_flags & IMPLICIT_DISTINCT) != 0));
}
|
public boolean isEmpty() {
return true;
}
|
public boolean isLRS() {
return (_flags & LRS) != 0;
}
|
public boolean isLob() {
return (_flags & LOB) != 0;
}
|
public boolean isOuter() {
return false;
}
|
public boolean isSelected(Table table) {
PathJoins pj = getJoins(null, false);
if (_from != null)
return _from.getTableIndex(table, pj, false) != -1;
return getTableIndex(table, pj, false) != -1;
}
|
public Joins join(ForeignKey fk,
boolean inverse,
boolean toMany) {
return new SelectJoins(this).join(fk, inverse, toMany);
}
|
public int joinCount() {
return 0;
}
|
public Joins joinRelation(String name,
ForeignKey fk,
ClassMapping target,
int subs,
boolean inverse,
boolean toMany) {
return new SelectJoins(this).joinRelation(name, fk, target, subs,
inverse, toMany);
}
|
public JoinSet joins() {
return null;
}
|
public Joins newJoins() {
if (_preJoins != null && !_preJoins.isEmpty()) {
SelectJoins sj = (SelectJoins) _preJoins.peek();
return sj.clone(this);
}
// return this for efficiency in case no joins end up being made
return this;
}
|
public Joins newOuterJoins() {
return ((PathJoins) newJoins()).setOuter(true);
}
|
protected SelectImpl.Selects newSelects() {
return new Selects();
}
|
public void nullJoins() {
}
|
public Joins or(Joins joins1,
Joins joins2) {
PathJoins j1 = (PathJoins) joins1;
PathJoins j2 = (PathJoins) joins2;
// if no common joins, return null; if one side of the or clause has
// different joins than the other, then we need to use distinct
boolean j1Empty = j1 == null || j1.isEmpty();
boolean j2Empty = j2 == null || j2.isEmpty();
if (j1Empty || j2Empty) {
if (j1Empty && !j2Empty) {
collectOuterJoins(j2);
if (!j2.isEmpty())
_flags |= IMPLICIT_DISTINCT;
} else if (j2Empty && !j1Empty) {
collectOuterJoins(j1);
if (!j1.isEmpty())
_flags |= IMPLICIT_DISTINCT;
}
return null;
}
// if all common joins, move all joins to returned instance
SelectJoins sj = new SelectJoins(this);
if (j1.joins().equals(j2.joins())) {
sj.setJoins(j1.joins());
j1.nullJoins();
j2.nullJoins();
} else {
JoinSet commonJoins = new JoinSet(j1.joins());
commonJoins.retainAll(j2.joins());
if (!commonJoins.isEmpty()) {
// put common joins in returned instance; remove them from
// each given instance
sj.setJoins(commonJoins);
j1.joins().removeAll(commonJoins);
j2.joins().removeAll(commonJoins);
}
collectOuterJoins(j1);
collectOuterJoins(j2);
// if one side of the or clause has different joins than the other,
// then we need to use distinct
if (!j1.isEmpty() || !j2.isEmpty())
_flags |= IMPLICIT_DISTINCT;
}
return sj;
}
|
public boolean orderBy(Column col,
boolean asc,
boolean sel) {
return orderBy(col, asc, null, sel);
}
|
public int orderBy(Column[] cols,
boolean asc,
boolean sel) {
return orderBy(cols, asc, null, sel);
}
|
public boolean orderBy(SQLBuffer sql,
boolean asc,
boolean sel) {
return orderBy(sql, asc, (Joins) null, sel);
}
|
public boolean orderBy(String sql,
boolean asc,
boolean sel) {
return orderBy(sql, asc, null, sel);
}
|
public boolean orderBy(Column col,
boolean asc,
Joins joins,
boolean sel) {
return orderBy(col, asc, joins, sel, false);
}
|
public int orderBy(Column[] cols,
boolean asc,
Joins joins,
boolean sel) {
return orderBy(cols, asc, joins, sel, false);
}
|
public boolean orderBy(SQLBuffer sql,
boolean asc,
Joins joins,
boolean sel) {
return orderBy(sql, asc, joins, sel, false);
}
|
public boolean orderBy(String sql,
boolean asc,
Joins joins,
boolean sel) {
return orderBy(sql, asc, joins, sel, false);
}
|
boolean orderBy(Column col,
boolean asc,
Joins joins,
boolean sel,
boolean aliasOrder) {
return columnOperation(col, sel, (asc) ? Boolean.TRUE : Boolean.FALSE,
getJoins(joins, true), aliasOrder);
}
Allow unions to set aliases on order columns. |
int orderBy(Column[] cols,
boolean asc,
Joins joins,
boolean sel,
boolean aliasOrder) {
PathJoins pj = getJoins(joins, true);
int seld = 0;
for (int i = 0; i < cols.length; i++)
if (columnOperation(cols[i], sel,
(asc) ? Boolean.TRUE : Boolean.FALSE, pj, aliasOrder))
seld |= 2 < < i;
return seld;
}
Allow unions to set aliases on order columns. |
boolean orderBy(SQLBuffer sql,
boolean asc,
Joins joins,
boolean sel,
boolean aliasOrder) {
return orderBy((Object) sql, asc, joins, sel, aliasOrder);
}
Allow unions to set aliases on order columns. |
boolean orderBy(String sql,
boolean asc,
Joins joins,
boolean sel,
boolean aliasOrder) {
return orderBy((Object) sql, asc, joins, sel, aliasOrder);
}
Allow unions to set aliases on order columns. |
public int orderByPrimaryKey(ClassMapping mapping,
boolean asc,
boolean sel) {
return orderByPrimaryKey(mapping, asc, null, sel);
}
|
public int orderByPrimaryKey(ClassMapping mapping,
boolean asc,
Joins joins,
boolean sel) {
return orderByPrimaryKey(mapping, asc, joins, sel, false);
}
|
public int orderByPrimaryKey(ClassMapping mapping,
boolean asc,
Joins joins,
boolean sel,
boolean aliasOrder) {
return primaryKeyOperation(mapping, sel,
(asc) ? Boolean.TRUE : Boolean.FALSE, joins, aliasOrder);
}
Allow unions to set aliases on order columns. |
public Joins outer(Joins joins) {
if (_joinSyntax == JoinSyntaxes.SYNTAX_TRADITIONAL || joins == null)
return joins;
// record that this is an outer join set, even if it's empty
PathJoins pj = ((PathJoins) joins).setOuter(true);
if (pj.isEmpty())
return pj;
Join join;
Join rec;
boolean hasJoins = _joins != null && _joins.joins() != null;
for (Iterator itr = pj.joins().iterator(); itr.hasNext();) {
join = (Join) itr.next();
if (join.getType() == Join.TYPE_INNER) {
if (!hasJoins)
join.setType(Join.TYPE_OUTER);
else {
rec = _joins.joins().getRecordedJoin(join);
if (rec == null || rec.getType() == Join.TYPE_OUTER)
join.setType(Join.TYPE_OUTER);
}
}
}
return joins;
}
|
public Joins outerJoin(ForeignKey fk,
boolean inverse,
boolean toMany) {
return new SelectJoins(this).outerJoin(fk, inverse, toMany);
}
|
public Joins outerJoinRelation(String name,
ForeignKey fk,
ClassMapping target,
int subs,
boolean inverse,
boolean toMany) {
return new SelectJoins(this).outerJoinRelation(name, fk, target, subs,
inverse, toMany);
}
|
public StringBuffer path() {
return null;
}
|
protected PreparedStatement prepareStatement(Connection conn,
SQLBuffer sql,
JDBCFetchConfiguration fetch,
int rsType,
int rsConcur,
boolean isLRS) throws SQLException {
if (fetch == null)
return sql.prepareStatement(conn, rsType, rsConcur);
else
return sql.prepareStatement(conn, fetch, rsType, -1);
}
This method is to provide override for non-JDBC or JDBC-like
implementation of preparing statement. |
public boolean select(Column col) {
return select(col, (Joins) null);
}
|
public int select(Column[] cols) {
return select(cols, null);
}
|
public boolean select(SQLBuffer sql,
Object id) {
return select(sql, id, null);
}
|
public boolean select(String sql,
Object id) {
return select(sql, id, null);
}
|
public boolean select(Column col,
Joins joins) {
if (!isGrouping())
return select(col, getJoins(joins, true), false);
groupBy(col, joins);
return false;
}
|
public int select(Column[] cols,
Joins joins) {
if (cols == null || cols.length == 0)
return 0;
if (isGrouping()) {
groupBy(cols, joins);
return 0;
}
PathJoins pj = getJoins(joins, true);
int seld = 0;
for (int i = 0; i < cols.length; i++)
if (select(cols[i], pj, false))
seld |= 2 < < i;
return seld;
}
|
public boolean select(SQLBuffer sql,
Object id,
Joins joins) {
if (!isGrouping())
return select((Object) sql, id, joins);
groupBy(sql, joins);
return false;
}
|
public boolean select(String sql,
Object id,
Joins joins) {
if (!isGrouping())
return select((Object) sql, id, joins);
groupBy(sql, joins);
return true;
}
|
public void select(ClassMapping mapping,
int subclasses,
JDBCStore store,
JDBCFetchConfiguration fetch,
int eager) {
select(mapping, subclasses, store, fetch, eager, null);
}
|
public void select(ClassMapping mapping,
int subclasses,
JDBCStore store,
JDBCFetchConfiguration fetch,
int eager,
Joins joins) {
select(this, mapping, subclasses, store, fetch, eager, joins, false);
}
|
void select(Select wrapper,
ClassMapping mapping,
int subclasses,
JDBCStore store,
JDBCFetchConfiguration fetch,
int eager,
Joins joins,
boolean ident) {
// note that this is one case where we don't want to use the result
// of getJoins(); just use the given joins, which will either be clean
// or the result of previous pre-joins. this way we don't push extra
// stack stuff when no actual new joins have been made, and we don't
// think the user wants outer joins when actually only the previous
// joins were outer. we do invoke getJoins(), though, to add these
// joins (if any) to our top-level joins; otherwise it'd be possible
// for the user to immediately do another join and select something,
// and if we're in outer mode all these joins will get switched to outer
// joins. caching them as their original join type prevents that
getJoins(joins, true);
PathJoins pj = (PathJoins) joins;
boolean hasJoins = pj != null && pj.isDirty();
if (hasJoins) {
if (_preJoins == null)
_preJoins = new Stack();
_preJoins.push(pj);
}
// if they are selecting this mapping with outer joins, then all joins
// from this mapping should also be outer
boolean wasOuter = (_flags & OUTER) != 0;
if (hasJoins && !wasOuter && pj.isOuter())
_flags |= OUTER;
// delegate to store manager to select in same order it loads result
((JDBCStoreManager) store).select(wrapper, mapping, subclasses, null,
null, fetch, eager, ident, (_flags & OUTER) != 0);
// reset
if (hasJoins)
_preJoins.pop();
if (!wasOuter && (_flags & OUTER) != 0)
_flags &= ~OUTER;
}
Select the given mapping. |
public boolean selectIdentifier(Column col) {
return selectIdentifier(col, (Joins) null);
}
|
public int selectIdentifier(Column[] cols) {
return selectIdentifier(cols, null);
}
|
public boolean selectIdentifier(Column col,
Joins joins) {
if (!isGrouping())
return select(col, getJoins(joins, true), true);
groupBy(col, joins);
return false;
}
|
public int selectIdentifier(Column[] cols,
Joins joins) {
if (cols == null || cols.length == 0)
return 0;
if (isGrouping()) {
groupBy(cols, joins);
return 0;
}
PathJoins pj = getJoins(joins, true);
int seld = 0;
for (int i = 0; i < cols.length; i++)
if (select(cols[i], pj, true))
seld |= 2 < < i;
return seld;
}
|
public void selectIdentifier(ClassMapping mapping,
int subclasses,
JDBCStore store,
JDBCFetchConfiguration fetch,
int eager) {
selectIdentifier(mapping, subclasses, store, fetch, eager, null);
}
|
public void selectIdentifier(ClassMapping mapping,
int subclasses,
JDBCStore store,
JDBCFetchConfiguration fetch,
int eager,
Joins joins) {
select(this, mapping, subclasses, store, fetch, eager, joins, true);
}
|
public void selectPlaceholder(String sql) {
Object holder = (_placeholders >= PLACEHOLDERS.length)
? new Placeholder() : PLACEHOLDERS[_placeholders++];
select(sql, holder);
}
|
public int selectPrimaryKey(ClassMapping mapping) {
return selectPrimaryKey(mapping, null);
}
|
public int selectPrimaryKey(ClassMapping mapping,
Joins joins) {
return primaryKeyOperation(mapping, true, null, joins, false);
}
|
public void setAggregate(boolean agg) {
if (agg)
_flags |= AGGREGATE;
else
_flags &= ~AGGREGATE;
}
|
public void setAutoDistinct(boolean val) {
if (val)
_flags &= ~NONAUTO_DISTINCT;
else
_flags |= NONAUTO_DISTINCT;
}
|
public void setDistinct(boolean distinct) {
// need two flags in case set not_distinct, then a to-many join happens
// and distinct flag gets set automatically
if (distinct) {
_flags |= DISTINCT;
_flags &= ~NOT_DISTINCT;
} else {
_flags |= NOT_DISTINCT;
_flags &= ~DISTINCT;
}
}
|
public void setExpectedResultCount(int expectedResultCount,
boolean force) {
_expectedResultCount = expectedResultCount;
if (force)
_flags |= FORCE_COUNT;
else
_flags &= ~FORCE_COUNT;
}
|
public void setFromSelect(Select sel) {
_from = (SelectImpl) sel;
if (_from != null)
_from._outer = this;
}
|
public void setJoinSyntax(int joinSyntax) {
_joinSyntax = joinSyntax;
}
|
public void setLRS(boolean lrs) {
if (lrs)
_flags |= LRS;
else
_flags &= ~LRS;
}
|
public void setLob(boolean lob) {
if (lob)
_flags |= LOB;
else
_flags &= ~LOB;
}
|
public PathJoins setOuter(boolean outer) {
return new SelectJoins(this).setOuter(true);
}
|
public void setParent(Select parent,
String path) {
if (path != null)
_subPath = path + ':";
else
_subPath = null;
if (parent == _parent)
return;
if (_parent != null)
_parent._subsels.remove(this);
//### right now we can't use sql92 joins with subselects, cause
//### I can't figure out what to do when the subselect has a join
//### with an alias also present in the outer select... you don't want
//### the join to appear in the FROM clause of the subselect cause
//### then it re-aliases both tables in the scope of the subselect
//### and the correlation with the outer select is lost
_parent = (SelectImpl) parent;
if (_parent != null) {
if (_parent._subsels == null)
_parent._subsels = new ArrayList(2);
_parent._subsels.add(this);
if (_parent._joinSyntax == JoinSyntaxes.SYNTAX_SQL92)
_joinSyntax = JoinSyntaxes.SYNTAX_TRADITIONAL;
else
_joinSyntax = _parent._joinSyntax;
}
}
|
public void setRange(long start,
long end) {
_startIdx = start;
_endIdx = end;
}
|
void setRecordOrderedIndexes(boolean record) {
if (record)
_flags |= RECORD_ORDERED;
else {
_ordered = null;
_flags &= ~RECORD_ORDERED;
}
}
Allow unions to record the select list indexes of items we order by. |
public Joins setSubselect(String alias) {
if (alias == null)
return this;
return new SelectJoins(this).setSubselect(alias);
}
|
protected void setTimeout(PreparedStatement stmnt,
boolean forUpdate,
JDBCFetchConfiguration fetch) throws SQLException {
// if this is a locking select and the lock timeout is greater than
// the configured query timeout, use the lock timeout
if (forUpdate && _dict.supportsQueryTimeout && fetch != null
&& fetch.getLockTimeout() > stmnt.getQueryTimeout() * 1000) {
int timeout = fetch.getLockTimeout();
if (timeout < 1000) {
timeout = 1000;
Log log = _conf.getLog(JDBCConfiguration.LOG_JDBC);
if (log.isWarnEnabled())
log.warn(_loc.get("millis-query-timeout"));
}
stmnt.setQueryTimeout(timeout / 1000);
}
}
This method is to provide override for non-JDBC or JDBC-like
implementation of setting query timeout. |
public Joins setVariable(String var) {
if (var == null)
return this;
return new SelectJoins(this).setVariable(var);
}
|
public boolean supportsLocking() {
return _dict.supportsLocking(this);
}
|
public boolean supportsRandomAccess(boolean forUpdate) {
return _dict.supportsRandomAccessResultSet(this, forUpdate);
}
|
static String toAlias(int index) {
if (index == -1)
return null;
if (index < TABLE_ALIASES.length)
return TABLE_ALIASES[index];
return "t" + index;
}
Helper method to return the proper table alias for the given alias index. |
public static String toOrderAlias(int index) {
if (index == -1)
return null;
if (index < ORDER_ALIASES.length)
return ORDER_ALIASES[index];
return "o" + index;
}
Helper method to return the proper order alias for the given order
column index. |
public SQLBuffer toSelect(boolean forUpdate,
JDBCFetchConfiguration fetch) {
return _dict.toSelect(this, forUpdate, fetch);
}
|
public SQLBuffer toSelectCount() {
return _dict.toSelectCount(this);
}
|
public String toString() {
return toSelect(false, null).getSQL();
}
|
public void where(Joins joins) {
if (joins != null)
where((String) null, joins);
}
|
public void where(SQLBuffer sql) {
where(sql, (Joins) null);
}
|
public void where(String sql) {
where(sql, (Joins) null);
}
|
public void where(SQLBuffer sql,
Joins joins) {
where(sql, getJoins(joins, true));
}
|
public void where(String sql,
Joins joins) {
where(sql, getJoins(joins, true));
}
|
public SelectExecutor whereClone(int sels) {
if (sels < 1)
sels = 1;
Select[] clones = null;
SelectImpl sel;
for (int i = 0; i < sels; i++) {
sel = (SelectImpl) _conf.getSQLFactoryInstance().newSelect();
sel._flags = _flags;
sel._flags &= ~AGGREGATE;
sel._flags &= ~OUTER;
sel._flags &= ~LRS;
sel._flags &= ~EAGER_TO_ONE;
sel._flags &= ~EAGER_TO_MANY;
sel._flags &= ~FORCE_COUNT;
sel._joinSyntax = _joinSyntax;
if (_aliases != null)
sel._aliases = new HashMap(_aliases);
if (_tables != null)
sel._tables = new TreeMap(_tables);
if (_joins != null)
sel._joins = _joins.clone(sel);
if (_where != null)
sel._where = new SQLBuffer(_where);
if (_from != null) {
sel._from = (SelectImpl) _from.whereClone(1);
sel._from._outer = sel;
}
if (_subsels != null) {
sel._subsels = new ArrayList(_subsels.size());
SelectImpl sub, selSub;
for (int j = 0; j < _subsels.size(); j++) {
sub = (SelectImpl) _subsels.get(j);
selSub = (SelectImpl) sub.fullClone(1);
selSub._parent = sel;
selSub._subPath = sub._subPath;
sel._subsels.add(selSub);
if (sel._where != null)
sel._where.replace(sub, selSub);
}
}
if (sels == 1)
return sel;
if (clones == null)
clones = new Select[sels];
clones[i] = sel;
}
return _conf.getSQLFactoryInstance().newUnion(clones);
}
|
public void whereForeignKey(ForeignKey fk,
Object oid,
ClassMapping mapping,
JDBCStore store) {
whereForeignKey(fk, oid, mapping, null, store);
}
|
public void wherePrimaryKey(Object oid,
ClassMapping mapping,
JDBCStore store) {
wherePrimaryKey(oid, mapping, null, store);
}
|