VoltDB added method to get a non-catalog-dependent
representation of this HSQLDB object.
@param session The current Session object may be needed to resolve
some names.
@return XML, correctly indented, representing this object.
@throws HSQLParseException
329884
VoltXMLElement voltGetStatementXML(Session session)
    throws org.hsqldb_voltpatches.HSQLInterface.HSQLParseException
    {
        throw new org.hsqldb_voltpatches.HSQLInterface.HSQLParseException(
                "this type of sql statement is not supported or is not allowed in this context");
    }
1160630
public static HSQLDDLInfo preprocessHSQLDDL(String ddl) {
        ddl = SQLLexer.stripComments(ddl);

        Matcher matcher = HSQL_DDL_PREPROCESSOR.matcher(ddl);
        if (matcher.find()) {
            String verbString = matcher.group("verb");
            HSQLDDLInfo.Verb verb = HSQLDDLInfo.Verb.get(verbString);
            if (verb == null) {
                return null;
            }

            String nounString = matcher.group("object");
            HSQLDDLInfo.Noun noun = HSQLDDLInfo.Noun.get(nounString);
            if (noun == null) {
                return null;
            }
            boolean createStream = verb.equals(HSQLDDLInfo.Verb.CREATE) &&
                                   noun.equals(HSQLDDLInfo.Noun.STREAM);

            String name = matcher.group("name");
            if (name == null) {
                return null;
            }

            String secondName = matcher.group("subject");
            if (secondName != null) {
                secondName = secondName.toLowerCase();
            }

            // cascade/if exists are interesting on alters and drops
            boolean cascade = false;
            boolean ifexists = false;
            if (verb != HSQLDDLInfo.Verb.CREATE) {
                matcher = DDL_IFEXISTS_OR_CASCADE_CHECK.matcher(ddl);
                if (matcher.matches()) {
                    // Don't be too sensitive to regex specifics by assuming null always
                    // indicates a missing clause. Look for empty too.
                    String existsClause = matcher.group("exists");
                    String cascadeClause = matcher.group("cascade");
                    ifexists = existsClause != null && !existsClause.isEmpty();
                    cascade = cascadeClause != null && !cascadeClause.isEmpty();
                }
            }

            return new HSQLDDLInfo(verb, noun, name.toLowerCase(), secondName, cascade, ifexists, createStream);
        }
        return null;
    }
737786
public static synchronized void serializeSessionAttributes(final HttpSession session) {
		if (session != null) {
			File file = new File(SERIALIZE_SESSION_NAME);

			if (!file.exists() || file.canWrite()) {
				// Retrieve the session attributes
				List data = new ArrayList();

				for (Enumeration keyEnum = session.getAttributeNames();
						keyEnum.hasMoreElements();) {
					String attributeName = (String) keyEnum.nextElement();
					Object attributeValue = session.getAttribute(attributeName);

					if (attributeValue instanceof Serializable) {
						data.add(attributeName);
						data.add(attributeValue);
					} else {
						LOG.error(
								"Skipping attribute \"" + attributeName
								+ "\" as it is not Serializable");
					}
				}

				// Write them to the file
				FileOutputStream fos = null;
				ObjectOutputStream oos = null;

				try {
					fos = new FileOutputStream(file);
					oos = new ObjectOutputStream(fos);

					oos.writeObject(data);
				} catch (Exception e) {
					LOG.error("Failed to write serialized session to " + file, e);
				} finally {
					if (oos != null) {
						StreamUtil.safeClose(oos);
					} else {
						StreamUtil.safeClose(fos);
					}
				}
			} else {
				LOG.warn("Unable to write serialized session to " + file);
			}
		}
	}
135023
public Object javaToSql(Object source) throws ConversionException
    {

        if (source == null)
        {
            return NULLVALUE;
        }

        try
        {
            List stringList = (List) source;
            if (stringList.isEmpty())
            {
                return NULLVALUE;
            }

            StringBuffer result = new StringBuffer();
            for (int i = 0; i < stringList.size(); i++)
            {
                String newSt = (String) stringList.get(i);
                // introduced in JDK 1.4, replace with commons-lang
                // newSt = newSt.replaceAll("#", "##");
                newSt = StringUtils.replace(newSt, "#", "##");
                if (i > 0)
                {
                    result.append("#");
                }
                result.append(newSt);
            }
            return result.toString();
        }
        catch (ClassCastException e)
        {
            throw new ConversionException("Object is not a List of String it is a"
                    + source.getClass().getName());
        }
    }
471810
@Override
    public void setSQLXML(int parameterIndex, SQLXML xmlObject) throws SQLException
    {
        checkParameterBounds(parameterIndex);
        throw SQLError.noSupport();
    }
973282
public <T> List<T>  sql(Class<T> beanType,  String entity) throws ElasticSearchException {
		SQLRestResponse result = this.client.executeRequest("/_xpack/sql",entity,   new SQLRestResponseHandler());
		return ResultUtil.buildSQLResult(result,beanType);
	}
1181895
public Table findSessionTable(Session session, String name,
                                  String schemaName) {
        return session.findSessionTable(name);
    }
47949
private VoltTable runQuery(String description, String SQL) throws Exception {
        System.out.println(description);
        ClientResponse resp = client.callProcedure("@AdHoc", SQL);
        System.out.println("SQL query: " + SQL);
        System.out.println();
        VoltTable table = resp.getResults()[0];
        System.out.println(table.toFormattedString());
        System.out.println();
        return table;
    }
215007
protected String getUniqueId(final Session session) {
        if (cached_id != null) {
            return cached_id;
        }

        //
        // Calculated an new Id
        //

        // this line ripped from the "describe" method
        // seems to help with some types like "equal"
        cached_id = new String();
        //
        // If object is a leaf node, then we'll use John's original code...
        // Otherwise we need to generate and Id based on what our children are
        //
        if (getType() != OpTypes.VALUE && getType() != OpTypes.COLUMN) {
            //
            // Horribly inefficient, but it works for now...
            //
            traverse(this, session);
        }

        long nodeId = session.getNodeIdForExpression(this);

        cached_id = Long.toString(nodeId);
        return cached_id;
    }
161517
public static Map<String, Object> createSessionMap(HttpServletRequest request) {
        Map<String, Object> sessionMap = new HashMap<>();
        HttpSession session = request.getSession(false);

        if (session != null) {
            for (Enumeration attributeNameEnum = session.getAttributeNames(); attributeNameEnum.hasMoreElements(); ) {
                String attributeName = (String)attributeNameEnum.nextElement();
                sessionMap.put(attributeName, session.getAttribute(attributeName));
            }
        }

        return sessionMap;
    }
165053
@Override
    public Object getValue(Session session) {

        Object[] data = new Object[nodes.length];

        for (int i = 0; i < nodes.length; i++) {
            Expression e = nodes[i];

            if (e != null) {
                data[i] = e.getValue(session, e.dataType);
            }
        }

        return getValue(session, data);
    }
877842
private SQLQuery query(Class<?>... entity) {
		SQLQuery q = session.createSQLQuery(sql);
		if (entity.length == 1) {
			q.addEntity(entity[0]);
		}
		for (Map.Entry<String, Type> scalar : scalars.entrySet()) {
			q.addScalar(scalar.getKey(), scalar.getValue());
		}
		for (int i = 0; i < positionedParameters.length; i++) {
			q.setParameter(i, positionedParameters[i]);
		}
		for (Map.Entry<String, Object> entry : namedParameters.entrySet()) {
			Object value = entry.getValue();
			if (Types.isArray(value)) {
				Object[] parameter = (Object[]) value;
				if (parameter.length == 0) {
					throw new HibernateException(String.format("Invalid named parameter |%s|. Empty array.", entry.getKey()));
				}
				q.setParameterList(entry.getKey(), parameter);
			} else if (Types.isCollection(value)) {
				Collection<?> parameter = (Collection<?>) value;
				if (parameter.isEmpty()) {
					throw new HibernateException(String.format("Invalid named parameter |%s|. Empty list.", entry.getKey()));
				}
				q.setParameterList(entry.getKey(), parameter);
			} else {
				q.setParameter(entry.getKey(), value);
			}
		}
		if (offset > 0) {
			q.setFirstResult(offset);
		}
		if (rowsCount > 0) {
			q.setMaxResults(rowsCount);
		}
		return q;
	}
1058315
public static SQLXML createSQLXML(final Connection conn) {
		try {
			return conn.createSQLXML();
		} catch (SQLException e) {
			throw new UroborosqlRuntimeException(e);
		}
	}
418966
protected static List<VoltXMLElement> voltGetLimitOffsetXMLFromSortAndSlice(Session session, SortAndSlice sortAndSlice)
            throws HSQLParseException {
        List<VoltXMLElement> result = new ArrayList<>();

        if (sortAndSlice == null || sortAndSlice == SortAndSlice.noSort) {
            return result;
        }

        if (sortAndSlice.limitCondition != null) {
            Expression limitCondition = sortAndSlice.limitCondition;
            if (limitCondition.nodes.length != 2) {
                throw new HSQLParseException(
                    "Parser did not create limit and offset expression for LIMIT.");
            }
            try {
                // read offset. it may be a parameter token.
                VoltXMLElement offset = new VoltXMLElement("offset");
                Expression offsetExpr = limitCondition.getLeftNode();
                if (offsetExpr.isParam == false) {
                    Integer offsetValue = (Integer)offsetExpr.getValue(session);
                    if (offsetValue > 0) {
                        Expression expr = new ExpressionValue(offsetValue,
                                org.hsqldb_voltpatches.types.Type.SQL_BIGINT);
                        offset.children.add(expr.voltGetXML(session));
                        offset.attributes.put("offset", offsetValue.toString());
                    }
                } else {
                    offset.attributes.put("offset_paramid", offsetExpr.getUniqueId(session));
                }
                result.add(offset);

                // Limit may be null (offset with no limit), or
                // it may be a parameter
                Expression limitExpr = limitCondition.getRightNode();
                if (limitExpr != null) {
                    VoltXMLElement limit = new VoltXMLElement("limit");
                    if (limitExpr.isParam == false) {
                        Integer limitValue = (Integer)limitExpr.getValue(session);
                        Expression expr = new ExpressionValue(limitValue,
                                org.hsqldb_voltpatches.types.Type.SQL_BIGINT);
                        limit.children.add(expr.voltGetXML(session));
                        limit.attributes.put("limit", limitValue.toString());
                    } else {
                        limit.attributes.put("limit_paramid", limitExpr.getUniqueId(session));
                    }
                    result.add(limit);
                }

            } catch (HsqlException ex) {
                // XXX really?
                ex.printStackTrace();
            }
        }

        return result;
    }
12873
@Override
    public VoltTable runDML(String dml) {
        String modifiedDml = transformDML(dml);
        printTransformedSql(dml, modifiedDml);
        return super.runDML(modifiedDml, false);
    }
1311096
private void parseTableSchemaFromXML(String tableName,
                                         StmtCommonTableScanShared tableScan,
                                         VoltXMLElement voltXMLElement) {
        assert("table".equals(voltXMLElement.name));
        List<VoltXMLElement> columnSet = voltXMLElement.findChildren("columns");
        assert(columnSet.size() == 1);
        columnSet = columnSet.get(0).children;
        for (int idx = 0; idx < columnSet.size(); idx += 1) {
            VoltXMLElement columnXML = columnSet.get(idx);
            assert("column".equals(columnXML.name));
            String columnName = columnXML.attributes.get("name");
            // If valuetype is not defined, then we will get type
            // "none", about which typeFromString will complain.
            // Note that the types may be widened from the type
            // of the base query of a recursive common table.  This
            // happens if the corresponding type in the recursive
            // query is wider than that of the base case.  But
            // HSQL will have taken care of this for us, so we
            // will not see the widening here.
            VoltType valueType = VoltType.typeFromString(columnXML.getStringAttribute("valuetype", "none"));
            Integer columnIndex = columnXML.getIntAttribute("index", null);
            assert(columnIndex != null);
            // These appear to be optional.  Certainly "bytes"
            // only appears if the type is variably sized.
            Integer size = columnXML.getIntAttribute("size", 0);
            Boolean inBytes = columnXML.getBoolAttribute("bytes", null);
            // This TVE holds the metadata.
            TupleValueExpression tve = new TupleValueExpression(tableName, tableName, columnName, columnName, columnIndex);
            tve.setValueType(valueType);
            tve.setDifferentiator(idx);
            if (size == 0) {
                if (valueType.isVariableLength()) {
                    size = valueType.defaultLengthForVariableLengthType();
                }
                else {
                    size = valueType.getLengthInBytesForFixedTypes();
                }
            }
            tve.setValueSize(size);
            if (inBytes != null) {
                tve.setInBytes(inBytes);
            }
            // There really is no aliasing going on here, so the table
            // name and column name are the same as the table alias and
            // column alias.
            SchemaColumn schemaColumn = new SchemaColumn(tableName, tableName, columnName, columnName, tve, idx);
            tableScan.addOutputColumn(schemaColumn);
        }
    }
1051945
VoltXMLElement voltAnnotateColumnXML(VoltXMLElement exp) {
        if (tableName != null) {
            if (rangeVariable != null && rangeVariable.rangeTable != null &&
                    rangeVariable.tableAlias != null &&
                    rangeVariable.rangeTable.tableType == TableBase.SYSTEM_SUBQUERY) {
                exp.attributes.put("table", rangeVariable.tableAlias.name.toUpperCase());
            }
            else {
                exp.attributes.put("table", tableName.toUpperCase());
            }
        }
        exp.attributes.put("column", columnName.toUpperCase());
        if ((alias == null) || (getAlias().length() == 0)) {
            exp.attributes.put("alias", columnName.toUpperCase());
        }
        if (rangeVariable != null && rangeVariable.tableAlias != null) {
            exp.attributes.put("tablealias",  rangeVariable.tableAlias.name.toUpperCase());
        }
        exp.attributes.put("index", Integer.toString(columnIndex));
        return exp;
    }