public void run() { try { for (int i = sessionList.size() - 1; i >= 0; i--) { Session session = (Session) sessionList.get(i); if (session.isClosed()) { synchronized (this) { sessionList.remove(i); } continue; } boolean result = session.timeoutManager.checkTimeout(); /* if (result) { synchronized (this) { sessionList.remove(i); } } */ } } catch (Throwable e) { // ignore exceptions // may be InterruptedException or IOException } }
public OrderedHashSet getSubqueries() { OrderedHashSet set = null; if (joinCondition != null) { set = joinCondition.collectAllSubqueries(set); } if (rangeTable instanceof TableDerived) { QueryExpression queryExpression = ((TableDerived) rangeTable).getQueryExpression(); if (queryExpression == null) { Expression dataExpression = ((TableDerived) rangeTable).getDataExpression(); if (dataExpression != null) { if (set == null) { set = new OrderedHashSet(); } OrderedHashSet.addAll(set, dataExpression.getSubqueries()); } } else { OrderedHashSet temp = queryExpression.getSubqueries(); set = OrderedHashSet.addAll(set, temp); set = OrderedHashSet.add(set, rangeTable); } } return set; }
private Result getExplainResult(Session session) { Result result = Result.newSingleColumnStringResult("OPERATION", describe(session)); OrderedHashSet set = getReferences(); result.navigator.add(new Object[] {"Object References"}); for (int i = 0; i < set.size(); i++) { HsqlName name = (HsqlName) set.get(i); result.navigator.add(new Object[] {name.getSchemaQualifiedStatementName()}); } result.navigator.add(new Object[] {"Read Locks"}); for (int i = 0; i < readTableNames.length; i++) { HsqlName name = readTableNames[i]; result.navigator.add(new Object[] {name.getSchemaQualifiedStatementName()}); } result.navigator.add(new Object[] {"WriteLocks"}); for (int i = 0; i < writeTableNames.length; i++) { HsqlName name = writeTableNames[i]; result.navigator.add(new Object[] {name.getSchemaQualifiedStatementName()}); } return result; }
OrderedHashSet getSubqueries() { OrderedHashSet set = null; if (joinCondition != null) { set = joinCondition.collectAllSubqueries(set); } if (rangeTable instanceof TableDerived) { QueryExpression baseQueryExpression = ((TableDerived) rangeTable).getQueryExpression(); if (((TableDerived) rangeTable).view != null) { if (set == null) { set = new OrderedHashSet(); } set.addAll(((TableDerived) rangeTable).view.getSubqueries()); } else if (baseQueryExpression == null) { set = OrderedHashSet.add(set, rangeTable.getSubQuery()); } else { OrderedHashSet temp = baseQueryExpression.getSubqueries(); set = OrderedHashSet.addAll(set, temp); set = OrderedHashSet.add(set, rangeTable.getSubQuery()); } } return set; }
public OrderedHashSet getComponents() { OrderedHashSet set = new OrderedHashSet(); set.addAll(routines); return set; }
public OrderedHashSet getReferences() { OrderedHashSet set = new OrderedHashSet(); for (int i = 0; i < routines.length; i++) { set.addAll(routines[i].getReferences()); } return set; }
/** Add all columns to a list of expressions */ public void addTableColumns(HsqlArrayList exprList) { if (namedJoinColumns != null) { int count = exprList.size(); int position = 0; for (int i = 0; i < count; i++) { Expression e = (Expression) exprList.get(i); String columnName = e.getColumnName(); if (namedJoinColumns.contains(columnName)) { if (position != i) { exprList.remove(i); exprList.add(position, e); } e = getColumnExpression(columnName); exprList.set(position, e); position++; } } } addTableColumns(exprList, exprList.size(), namedJoinColumns); }
public OrderedHashSet getReferences() { switch (constType) { case Constraint.CHECK: return schemaObjectNames; case Constraint.FOREIGN_KEY: OrderedHashSet set = new OrderedHashSet(); set.add(core.uniqueName); return set; } return null; }
protected void addTableColumns(Expression expression, int start, int count, HashSet exclude) { Table table = getTable(); HsqlArrayList list = new HsqlArrayList(); for (int i = start; i < start + count; i++) { ColumnSchema column = table.getColumn(i); String columnName = columnAliases == null ? column.getName().name : (String) columnAliases.get(i); if (exclude != null && exclude.contains(columnName)) { continue; } Expression e = new ExpressionColumn(this, i); list.add(e); } Expression[] nodes = new Expression[list.size()]; list.toArray(nodes); expression.nodes = nodes; }
public void addSession(Session session) { synchronized (this) { if (timerTask == null) { start(); } sessionList.add(session); } }
/** * Retruns index for column * * @param columnName name of column * @return int index or -1 if not found */ private int findColumn(String columnName) { if (variables != null) { return variables.getIndex(columnName); } else if (columnAliases != null) { return columnAliases.getIndex(columnName); } else { return rangeTable.findColumn(columnName); } }
public OrderedHashSet getUniqueColumnNameSet() { OrderedHashSet set = new OrderedHashSet(); if (columnAliases != null) { set.addAll(columnAliases); return set; } for (int i = 0; i < rangeTable.columnList.size(); i++) { String name = rangeTable.getColumn(i).getName().name; boolean added = set.add(name); if (!added) { throw Error.error(ErrorCode.X_42578, name); } } return set; }
/** * Retruns index for column * * @param columnName name of column * @return int index or -1 if not found */ public int findColumn(String columnName) { if (namedJoinColumnExpressions != null && namedJoinColumnExpressions.containsKey(columnName)) { return -1; } if (variables != null) { return variables.getIndex(columnName); } else if (columnAliases != null) { return columnAliases.getIndex(columnName); } else { return rangeTable.findColumn(columnName); } }
public void stop() { synchronized (this) { if (timerTask == null) { return; } HsqlTimer.cancel(timerTask); sessionList.clear(); timerTask = null; sessionList = null; } }
void setDatabseObjects(Session session, CompileContext compileContext) { parameters = compileContext.getParameters(); setParameters(); setParameterMetaData(); subqueries = getSubqueries(session); rangeIteratorCount = compileContext.getRangeVarCount(); rangeVariables = compileContext.getRangeVariables(); sequences = compileContext.getSequences(); routines = compileContext.getRoutines(); OrderedHashSet set = new OrderedHashSet(); collectTableNamesForWrite(set); if (set.size() > 0) { writeTableNames = new HsqlName[set.size()]; set.toArray(writeTableNames); set.clear(); } collectTableNamesForRead(set); set.removeAll(writeTableNames); if (set.size() > 0) { readTableNames = new HsqlName[set.size()]; set.toArray(readTableNames); } references = compileContext.getSchemaObjectNames(); if (targetTable != null) { references.add(targetTable.getName()); } }
public Object getSequenceValue(NumberSequence sequence) throws HsqlException { if (sequenceMap == null) { sequenceMap = new HashMap(); sequenceUpdateSet = new OrderedHashSet(); } HsqlName key = sequence.getName(); Object value = sequenceMap.get(key); if (value == null) { value = sequence.getValueObject(); sequenceMap.put(key, value); sequenceUpdateSet.add(sequence); } return value; }
public OrderedHashSet getUnkeyedColumns(OrderedHashSet unresolvedSet) { for (int i = 0; i < nodes.length; i++) { if (nodes[i] == null) { continue; } unresolvedSet = nodes[i].getUnkeyedColumns(unresolvedSet); } if (opType == OpTypes.COLUMN && !rangeVariable.hasKeyedColumnInGroupBy) { if (unresolvedSet == null) { unresolvedSet = new OrderedHashSet(); } unresolvedSet.add(this); } return unresolvedSet; }
/** Add all columns to a list of expressions */ public int addTableColumns(HsqlArrayList exprList, int position, HashSet exclude) { Table table = getTable(); int count = table.getColumnCount(); for (int i = 0; i < count; i++) { ColumnSchema column = table.getColumn(i); String columnName = columnAliases == null ? column.getName().name : (String) columnAliases.get(i); if (exclude != null && exclude.contains(columnName)) { continue; } Expression e = new ExpressionColumn(this, i); exprList.add(position++, e); } return position; }
SubQuery[] getSubqueries(Session session) { OrderedHashSet subQueries = null; for (int i = 0; i < targetRangeVariables.length; i++) { if (targetRangeVariables[i] == null) { continue; } OrderedHashSet set = targetRangeVariables[i].getSubqueries(); subQueries = OrderedHashSet.addAll(subQueries, set); } for (int i = 0; i < updateExpressions.length; i++) { subQueries = updateExpressions[i].collectAllSubqueries(subQueries); } if (insertExpression != null) { subQueries = insertExpression.collectAllSubqueries(subQueries); } if (condition != null) { subQueries = condition.collectAllSubqueries(subQueries); } if (queryExpression != null) { OrderedHashSet set = queryExpression.getSubqueries(); subQueries = OrderedHashSet.addAll(subQueries, set); } if (subQueries == null || subQueries.size() == 0) { return SubQuery.emptySubqueryArray; } SubQuery[] subQueryArray = new SubQuery[subQueries.size()]; subQueries.toArray(subQueryArray); ArraySort.sort(subQueryArray, 0, subQueryArray.length, subQueryArray[0]); for (int i = 0; i < subQueryArray.length; i++) { subQueryArray[i].prepareTable(session); } return subQueryArray; }
// this fk references -> other : other read lock void collectTableNamesForRead(OrderedHashSet set) { for (int i = 0; i < rangeVariables.length; i++) { Table rangeTable = rangeVariables[i].rangeTable; HsqlName name = rangeTable.getName(); if (rangeTable.isReadOnly() || rangeTable.isTemp()) { continue; } if (name.schema == SqlInvariants.SYSTEM_SCHEMA_HSQLNAME) { continue; } set.add(name); } for (int i = 0; i < subqueries.length; i++) { if (subqueries[i].queryExpression != null) { subqueries[i].queryExpression.getBaseTableNames(set); } } }
public OrderedHashSet getReferences() { switch (this.constType) { case 3: OrderedHashSet localOrderedHashSet1 = new OrderedHashSet(); this.check.collectObjectNames(localOrderedHashSet1); for (int i = localOrderedHashSet1.size() - 1; i >= 0; i--) { HsqlNameManager.HsqlName localHsqlName = (HsqlNameManager.HsqlName) localOrderedHashSet1.get(i); if ((localHsqlName.type == 9) || (localHsqlName.type == 3)) localOrderedHashSet1.remove(i); } return localOrderedHashSet1; case 0: OrderedHashSet localOrderedHashSet2 = new OrderedHashSet(); localOrderedHashSet2.add(this.core.uniqueName); return localOrderedHashSet2; } return new OrderedHashSet(); }
void moveConditionsToInner(Session session, RangeVariable[] ranges) { Expression[] colExpr; int exclude; HsqlArrayList conditionsList; Expression condition = null; if (whereConditions.length > 1) { return; } if (joinConditions.length > 1) { return; } for (int i = 0; i < ranges.length; i++) { if (ranges[i].isLeftJoin || ranges[i].isRightJoin) { return; } } exclude = ArrayUtil.find(ranges, this); conditionsList = new HsqlArrayList(); addConditionsToList(conditionsList, joinConditions[0].indexCond); if (joinConditions[0].indexCond != null && joinConditions[0].indexCond[0] != joinConditions[0].indexEndCond[0]) { addConditionsToList(conditionsList, joinConditions[0].indexEndCond); } addConditionsToList(conditionsList, whereConditions[0].indexCond); addConditionsToList(conditionsList, whereConditions[0].indexEndCond); RangeVariableResolver.decomposeAndConditions( session, joinConditions[0].nonIndexCondition, conditionsList); RangeVariableResolver.decomposeAndConditions( session, whereConditions[0].nonIndexCondition, conditionsList); for (int i = conditionsList.size() - 1; i >= 0; i--) { Expression e = (Expression) conditionsList.get(i); if (e == null || e.isTrue() || e.hasReference(ranges, exclude)) { conditionsList.remove(i); continue; } } if (conditionsList.size() == 0) { if (rangeTable.isView()) { ((TableDerived) rangeTable).resetToView(); } return; } QueryExpression queryExpression = rangeTable.getQueryExpression(); colExpr = ((QuerySpecification) queryExpression).exprColumns; for (int i = 0; i < conditionsList.size(); i++) { Expression e = (Expression) conditionsList.get(i); OrderedHashSet set = e.collectRangeVariables(null); e = e.duplicate(); e = e.replaceColumnReferences(this, colExpr); if (e.collectAllSubqueries(null) != null) { return; } if (set != null) { for (int j = 0; j < set.size(); j++) { RangeVariable range = (RangeVariable) set.get(j); if (this != range && range.rangeType == RangeVariable.TABLE_RANGE) { queryExpression.setCorrelated(); } } } condition = ExpressionLogical.andExpressions(condition, e); } queryExpression.addExtraConditions(condition); }