use of org.whole.lang.sql.iterators.ResultSetIterator in project whole by wholeplatform.
the class SQLInterpreterVisitor method visit.
@Override
public void visit(SQLStatement entity) {
try {
IVisitor ov = getOperation().setVisitor(entity, 0, getOperation().getVisitor(entity, 1));
getOperation().stagedVisit(entity);
getOperation().setVisitor(entity, 0, ov);
entity = (SQLStatement) getResult();
String sql = toPrettyPrintString(entity);
if (batchMode)
statement.addBatch(sql);
else {
String[] names;
if (entity.wGetEntityDescriptor().equals(SQLEntityDescriptorEnum.Select)) {
IEntity columnExprs = entity.wGet(SQLFeatureDescriptorEnum.columnExprs);
int size = columnExprs.wSize();
names = new String[size];
for (int i = 0; i < size; i++) {
IEntity columnExpr = columnExprs.wGet(i);
if (Matcher.matchImpl(SQLEntityDescriptorEnum.ColumnExpression, columnExpr)) {
IEntity alias = columnExpr.wGet(SQLFeatureDescriptorEnum.alias);
if (DataTypeUtils.getDataKind(alias).isString())
names[i] = alias.wStringValue();
else {
IEntity expr = columnExpr.wGet(SQLFeatureDescriptorEnum.expression);
if (Matcher.matchImpl(SQLEntityDescriptorEnum.ColumnName, expr))
names[i] = expr.wStringValue();
}
}
}
} else
names = new String[0];
if (statement.execute(sql))
setResultIterator(new ResultSetIterator(statement.getResultSet(), names));
else {
setResult(null);
statement.close();
}
}
} catch (Exception e) {
try {
statement.close();
} catch (Exception e1) {
}
throw new VisitException(SQL_INTERPRETER_ERROR_MESSAGE, e);
} finally {
if (!batchMode)
statement = null;
}
}
Aggregations