From 08bdf2097ad554daf813a1e9da1ac263b2d12ca3 Mon Sep 17 00:00:00 2001 From: Luca Garulli Date: Tue, 10 Jul 2012 19:07:54 +0200 Subject: [PATCH] implemented SELECT 1 so common in reporting tools like pentaho --- .../jdbc/OrientJdbcPreparedStatement.java | 318 +++++++++--------- 1 file changed, 154 insertions(+), 164 deletions(-) diff --git a/src/main/java/com/orientechnologies/orient/jdbc/OrientJdbcPreparedStatement.java b/src/main/java/com/orientechnologies/orient/jdbc/OrientJdbcPreparedStatement.java index d8e40498ca8..d2808bbd5c0 100644 --- a/src/main/java/com/orientechnologies/orient/jdbc/OrientJdbcPreparedStatement.java +++ b/src/main/java/com/orientechnologies/orient/jdbc/OrientJdbcPreparedStatement.java @@ -54,273 +54,263 @@ */ public class OrientJdbcPreparedStatement extends OrientJdbcStatement implements PreparedStatement { - private final String sql; - private final Map params; + private final String sql; + private final Map params; - public OrientJdbcPreparedStatement(OrientJdbcConnection iConnection, String sql) { - super(iConnection); - this.sql = sql; - params = new HashMap(); - } + public OrientJdbcPreparedStatement(OrientJdbcConnection iConnection, String sql) { + super(iConnection); + this.sql = sql; + params = new HashMap(); + } - public ResultSet executeQuery() throws SQLException { + public ResultSet executeQuery() throws SQLException { + if (sql.equalsIgnoreCase("select 1")) { + documents = new ArrayList(); + documents.add(new ODocument().field("1", 1)); + } else { + query = new OCommandSQL(sql); + try { + documents = database.query(new OSQLSynchQuery(sql), params.values().toArray(new Object[] {})); + } catch (OQueryParsingException e) { + throw new SQLSyntaxErrorException("Error on parsing the query", e); + } + } - query = new OCommandSQL(sql); - try { + resultSet = new OrientJdbcResultSet(this, documents, resultSetType, resultSetConcurrency, resultSetHoldability); + return resultSet; + } - /* - * rawResult = - * database.command(query).execute(params.values().toArray(new - * String[] {})); - * - * if (rawResult instanceof List) documents = (List) - * rawResult; else throw new - * SQLException("unable to create a valid resultSet: is query a SELECT?" - * ); - */ + public int executeUpdate() throws SQLException { + return 0; + } - documents = database.query(new OSQLSynchQuery(sql), params.values().toArray(new Object[] {})); + public void setNull(int parameterIndex, int sqlType) throws SQLException { - resultSet = new OrientJdbcResultSet(this, documents, resultSetType, resultSetConcurrency, resultSetHoldability); - return resultSet; + } - } catch (OQueryParsingException e) { - throw new SQLSyntaxErrorException("Error on parsing the query", e); - } - } + public void setBoolean(int parameterIndex, boolean x) throws SQLException { + params.put(parameterIndex, Boolean.toString(x)); - public int executeUpdate() throws SQLException { - return 0; - } + } - public void setNull(int parameterIndex, int sqlType) throws SQLException { + public void setByte(int parameterIndex, byte x) throws SQLException { + params.put(parameterIndex, Byte.toString(x)); - } + } - public void setBoolean(int parameterIndex, boolean x) throws SQLException { - params.put(parameterIndex, Boolean.toString(x)); + public void setShort(int parameterIndex, short x) throws SQLException { + params.put(parameterIndex, Short.toString(x)); + } - } + public void setInt(int parameterIndex, int x) throws SQLException { + params.put(parameterIndex, Integer.toString(x)); + } - public void setByte(int parameterIndex, byte x) throws SQLException { - params.put(parameterIndex, Byte.toString(x)); + public void setLong(int parameterIndex, long x) throws SQLException { + params.put(parameterIndex, Long.toString(x)); + } - } + public void setFloat(int parameterIndex, float x) throws SQLException { + params.put(parameterIndex, Float.toString(x)); + } - public void setShort(int parameterIndex, short x) throws SQLException { - params.put(parameterIndex, Short.toString(x)); - } + public void setDouble(int parameterIndex, double x) throws SQLException { + params.put(parameterIndex, Double.toString(x)); + } - public void setInt(int parameterIndex, int x) throws SQLException { - params.put(parameterIndex, Integer.toString(x)); - } + public void setBigDecimal(int parameterIndex, BigDecimal x) throws SQLException { + params.put(parameterIndex, x.toPlainString()); + } - public void setLong(int parameterIndex, long x) throws SQLException { - params.put(parameterIndex, Long.toString(x)); - } + public void setString(int parameterIndex, String x) throws SQLException { + params.put(parameterIndex, x); + } - public void setFloat(int parameterIndex, float x) throws SQLException { - params.put(parameterIndex, Float.toString(x)); - } + public void setBytes(int parameterIndex, byte[] x) throws SQLException { - public void setDouble(int parameterIndex, double x) throws SQLException { - params.put(parameterIndex, Double.toString(x)); - } + } - public void setBigDecimal(int parameterIndex, BigDecimal x) throws SQLException { - params.put(parameterIndex, x.toPlainString()); - } + public void setDate(int parameterIndex, Date x) throws SQLException { - public void setString(int parameterIndex, String x) throws SQLException { - params.put(parameterIndex, x); - } + } - public void setBytes(int parameterIndex, byte[] x) throws SQLException { + public void setTime(int parameterIndex, Time x) throws SQLException { - } + } - public void setDate(int parameterIndex, Date x) throws SQLException { + public void setTimestamp(int parameterIndex, Timestamp x) throws SQLException { - } + } - public void setTime(int parameterIndex, Time x) throws SQLException { + public void setAsciiStream(int parameterIndex, InputStream x, int length) throws SQLException { - } + } - public void setTimestamp(int parameterIndex, Timestamp x) throws SQLException { + public void setUnicodeStream(int parameterIndex, InputStream x, int length) throws SQLException { - } + } - public void setAsciiStream(int parameterIndex, InputStream x, int length) throws SQLException { + public void setBinaryStream(int parameterIndex, InputStream x, int length) throws SQLException { - } + } - public void setUnicodeStream(int parameterIndex, InputStream x, int length) throws SQLException { + public void clearParameters() throws SQLException { + params.clear(); + } - } + public void setObject(int parameterIndex, Object x, int targetSqlType) throws SQLException { - public void setBinaryStream(int parameterIndex, InputStream x, int length) throws SQLException { + } - } + public void setObject(int parameterIndex, Object x) throws SQLException { - public void clearParameters() throws SQLException { - params.clear(); - } + } - public void setObject(int parameterIndex, Object x, int targetSqlType) throws SQLException { + public boolean execute() throws SQLException { - } + return false; + } - public void setObject(int parameterIndex, Object x) throws SQLException { + public void addBatch() throws SQLException { - } + } - public boolean execute() throws SQLException { + public void setCharacterStream(int parameterIndex, Reader reader, int length) throws SQLException { - return false; - } + } - public void addBatch() throws SQLException { + public void setRef(int parameterIndex, Ref x) throws SQLException { - } + } - public void setCharacterStream(int parameterIndex, Reader reader, int length) throws SQLException { + public void setBlob(int parameterIndex, Blob x) throws SQLException { - } + } - public void setRef(int parameterIndex, Ref x) throws SQLException { + public void setClob(int parameterIndex, Clob x) throws SQLException { - } + } - public void setBlob(int parameterIndex, Blob x) throws SQLException { + public void setArray(int parameterIndex, Array x) throws SQLException { - } + } - public void setClob(int parameterIndex, Clob x) throws SQLException { + public ResultSetMetaData getMetaData() throws SQLException { - } + return null; + } - public void setArray(int parameterIndex, Array x) throws SQLException { + public void setDate(int parameterIndex, Date x, Calendar cal) throws SQLException { - } + } - public ResultSetMetaData getMetaData() throws SQLException { + public void setTime(int parameterIndex, Time x, Calendar cal) throws SQLException { - return null; - } + } - public void setDate(int parameterIndex, Date x, Calendar cal) throws SQLException { + public void setTimestamp(int parameterIndex, Timestamp x, Calendar cal) throws SQLException { - } + } - public void setTime(int parameterIndex, Time x, Calendar cal) throws SQLException { + public void setNull(int parameterIndex, int sqlType, String typeName) throws SQLException { - } + } - public void setTimestamp(int parameterIndex, Timestamp x, Calendar cal) throws SQLException { + public void setURL(int parameterIndex, URL x) throws SQLException { - } + } - public void setNull(int parameterIndex, int sqlType, String typeName) throws SQLException { + public ParameterMetaData getParameterMetaData() throws SQLException { - } + final List definitions = new ArrayList(); - public void setURL(int parameterIndex, URL x) throws SQLException { + int start = 0; + int index = sql.indexOf('?', start); + while (index > 0) { + final OrientJdbcParameterMetadata.ParameterDefinition def = new OrientJdbcParameterMetadata.ParameterDefinition(); + // TODO find a way to know a bit more on each parameter + definitions.add(def); + start = index + 1; + index = sql.indexOf('?', start); + } - } + return new OrientJdbcParameterMetadata(definitions); + } - public ParameterMetaData getParameterMetaData() throws SQLException { + public void setRowId(int parameterIndex, RowId x) throws SQLException { - final List definitions = - new ArrayList(); + } - int start = 0; - int index = sql.indexOf('?', start); - while (index > 0) { - final OrientJdbcParameterMetadata.ParameterDefinition def = new OrientJdbcParameterMetadata.ParameterDefinition(); - // TODO find a way to know a bit more on each parameter - definitions.add(def); - start = index + 1; - index = sql.indexOf('?', start); - } + public void setNString(int parameterIndex, String value) throws SQLException { - return new OrientJdbcParameterMetadata(definitions); - } + } - public void setRowId(int parameterIndex, RowId x) throws SQLException { + public void setNCharacterStream(int parameterIndex, Reader value, long length) throws SQLException { - } + } - public void setNString(int parameterIndex, String value) throws SQLException { + public void setNClob(int parameterIndex, NClob value) throws SQLException { - } + } - public void setNCharacterStream(int parameterIndex, Reader value, long length) throws SQLException { + public void setClob(int parameterIndex, Reader reader, long length) throws SQLException { - } + } - public void setNClob(int parameterIndex, NClob value) throws SQLException { + public void setBlob(int parameterIndex, InputStream inputStream, long length) throws SQLException { - } + } - public void setClob(int parameterIndex, Reader reader, long length) throws SQLException { + public void setNClob(int parameterIndex, Reader reader, long length) throws SQLException { - } + } - public void setBlob(int parameterIndex, InputStream inputStream, long length) throws SQLException { + public void setSQLXML(int parameterIndex, SQLXML xmlObject) throws SQLException { - } + } - public void setNClob(int parameterIndex, Reader reader, long length) throws SQLException { + public void setObject(int parameterIndex, Object x, int targetSqlType, int scaleOrLength) throws SQLException { - } + } - public void setSQLXML(int parameterIndex, SQLXML xmlObject) throws SQLException { + public void setAsciiStream(int parameterIndex, InputStream x, long length) throws SQLException { - } + } - public void setObject(int parameterIndex, Object x, int targetSqlType, int scaleOrLength) throws SQLException { + public void setBinaryStream(int parameterIndex, InputStream x, long length) throws SQLException { - } + } - public void setAsciiStream(int parameterIndex, InputStream x, long length) throws SQLException { + public void setCharacterStream(int parameterIndex, Reader reader, long length) throws SQLException { - } + } - public void setBinaryStream(int parameterIndex, InputStream x, long length) throws SQLException { + public void setAsciiStream(int parameterIndex, InputStream x) throws SQLException { - } + } - public void setCharacterStream(int parameterIndex, Reader reader, long length) throws SQLException { + public void setBinaryStream(int parameterIndex, InputStream x) throws SQLException { - } + } - public void setAsciiStream(int parameterIndex, InputStream x) throws SQLException { + public void setCharacterStream(int parameterIndex, Reader reader) throws SQLException { - } + } - public void setBinaryStream(int parameterIndex, InputStream x) throws SQLException { + public void setNCharacterStream(int parameterIndex, Reader value) throws SQLException { - } + } - public void setCharacterStream(int parameterIndex, Reader reader) throws SQLException { + public void setClob(int parameterIndex, Reader reader) throws SQLException { - } + } - public void setNCharacterStream(int parameterIndex, Reader value) throws SQLException { + public void setBlob(int parameterIndex, InputStream inputStream) throws SQLException { - } + } - public void setClob(int parameterIndex, Reader reader) throws SQLException { + public void setNClob(int parameterIndex, Reader reader) throws SQLException { - } - - public void setBlob(int parameterIndex, InputStream inputStream) throws SQLException { - - } - - public void setNClob(int parameterIndex, Reader reader) throws SQLException { - - } + } }