StorageManager { public abstract String addLimit(String query, int limit, int offset);  void init(String databaseDriver, String username, String password, String databaseURL, int maxDBConnections); void initDatabaseAccess(Connection con); abstract byte convertLocalTypeToGSN(int jdbcType, int precision); abstract String getStatementDropIndex(); abstract String getStatementDropView(); abstract int getTableNotExistsErrNo(); abstract String addLimit(String query, int limit, int offset); abstract StringBuilder getStatementUselessDataRemoval(String virtualSensorName, long storageSize); byte convertLocalTypeToGSN(int jdbcType); boolean tableExists(CharSequence tableName); boolean tableExists(CharSequence tableName, Connection connection); abstract StringBuilder getStatementRemoveUselessDataCountBased(String virtualSensorName, long storageSize); StringBuilder getStatementRemoveUselessDataTimeBased(String virtualSensorName, long storageSize); DataField[] tableToStructure(CharSequence tableName, Connection connection); DataField[] tableToStructureByString(String tableName, Connection connection); boolean tableExists(CharSequence tableName, DataField[] fields, Connection connection); boolean tableExists(CharSequence tableName, DataField[] fields); boolean isThereAnyResult(StringBuilder sqlQuery); ResultSet getBinaryFieldByQuery(StringBuilder query,
                                           String colName, long pk, Connection connection); void closeStatement(Statement stmt); void close(ResultSet resultSet); void close(PreparedStatement preparedStatement); void close(Connection conn); void shutdown(); void executeRenameTable(String oldName, String newName); void executeRenameTable(String oldName, String newName, Connection connection); void executeDropTable(CharSequence tableName); void executeDropTable(CharSequence tableName, Connection connection); void executeDropView(StringBuilder tableName); void executeDropView(StringBuilder tableName, Connection connection); void executeCreateTable(CharSequence tableName, DataField[] structure, boolean unique); void executeCreateTable(CharSequence tableName, DataField[] structure, boolean unique, Connection connection); ResultSet executeQueryWithResultSet(StringBuilder query,Connection connection); ResultSet executeQueryWithResultSet(AbstractQuery abstractQuery, Connection c); DataEnumerator executeQuery(StringBuilder query, boolean binaryFieldsLinked, Connection connection); DataEnumerator executeQuery(AbstractQuery abstractQuery, boolean binaryFieldsLinked, Connection connection); DataEnumerator streamedExecuteQuery(AbstractQuery abstractQuery, boolean binaryFieldsLinked, Connection connection); DataEnumerator executeQuery(StringBuilder query, boolean binaryFieldsLinked); DataEnumerator streamedExecuteQuery(String query, boolean binaryFieldsLinked, Connection conn); DataEnumerator streamedExecuteQuery(String query, boolean binaryFieldsLinked); void executeCreateView(CharSequence viewName, CharSequence selectQuery); void executeCreateView(CharSequence viewName, CharSequence selectQuery, Connection connection); void executeCommand(String sql, Connection connection); int executeUpdate(String updateStatement, Connection connection); int executeUpdate(StringBuilder updateStatement, Connection connection); int executeUpdate(StringBuilder updateStatement); void executeInsert(CharSequence tableName, DataField[] fields, StreamElement se); void executeInsert(CharSequence tableName, DataField[] fields, StreamElement streamElement, Connection connection); StringBuilder getStatementInsert(CharSequence tableName, DataField fields[]); String getStatementRenameTable(String oldName, String newName); abstract StringBuilder getStatementDropTable(CharSequence tableName, Connection conn); StringBuilder getStatementDropIndex(CharSequence indexName, CharSequence tableName,Connection connection); StringBuilder getStatementDropView(CharSequence viewName,Connection connection); StringBuilder getStatementCreateIndexOnTimed(
            CharSequence tableName, boolean unique); StringBuilder getStatementCreateTable(CharSequence tableName, DataField[] structure, Connection connection); abstract StringBuilder getStatementCreateTable(String tableName, DataField[] structure); StringBuilder getStatementCreateView(CharSequence viewName,CharSequence selectQuery); abstract String getJDBCPrefix(); String getJDBCDriverClass(); abstract String convertGSNTypeToLocalType(DataField gsnType); Connection getConnection(); long getTimeDifferenceInMillis(); abstract String getStatementDifferenceTimeInMillis(); ArrayList<String> getInternalTables(); String randomTableNameGenerator( int length ); int tableNameGenerator( ); StringBuilder tableNameGeneratorInString(CharSequence tableName); StringBuilder tableNameGeneratorInString(int code); String tableNamePostFixAppender(CharSequence table_name,String postFix); boolean isOracle(); boolean isH2(); boolean isSqlServer(); boolean isMysqlDB(); boolean isPostgres();  }
@Test public void testOracleRewrites() { StorageManager db = StorageManagerFactory.getInstance("oracle.jdbc.driver.OracleDriver", "sa", "", "jdbc:oracle:thin:.", 100); final String sampleQuery1 = "SELECT * FROM SYSTEM.HELP"; String oracle = db.addLimit( sampleQuery1, 10, 0); assertEquals("SELECT * FROM SYSTEM.HELP WHERE ROWNUM <= 10", oracle.replace(" ", " ")); final String sampleQuery2 = "SELECT * FROM SYSTEM.HELP ORDER BY TIMED"; oracle = db.addLimit( sampleQuery2, 10, 0); assertEquals("SELECT * FROM SYSTEM.HELP WHERE ROWNUM <= 10 ORDER BY TIMED", oracle.replace(" ", " ")); final String sampleQuery3 = "SELECT * FROM SYSTEM.HELP GROUP BY TIMED"; oracle = db.addLimit( sampleQuery3, 10, 0); assertEquals("SELECT * FROM SYSTEM.HELP WHERE ROWNUM <= 10 GROUP BY TIMED", oracle.replace(" ", " ")); final String sampleQuery4 = "SELECT * FROM SYSTEM.HELP WHERE TIMED <0 GROUP BY TIMED"; oracle = db.addLimit( sampleQuery4, 10, 0); assertEquals("SELECT * FROM SYSTEM.HELP WHERE ROWNUM <= 10 AND (TIMED <0) GROUP BY TIMED", oracle.replace(" ", " ")); final String sampleQuery5 = "SELECT * FROM SYSTEM.HELP WHERE TIMED <0 AND TIMED < 10 OR TIMED >30 GROUP BY TIMED"; oracle = db.addLimit( sampleQuery5, 10, 0); assertEquals("SELECT * FROM SYSTEM.HELP WHERE ROWNUM <= 10 AND (TIMED <0 AND TIMED < 10 OR TIMED >30) GROUP BY TIMED", oracle.replace(" ", " ")); final String sampleQuery6 = "SELECT * FROM SYSTEM.HELP WHERE TIMED <0 AND TIMED < 10 OR TIMED >30"; oracle = db.addLimit( sampleQuery6, 10, 0); assertEquals("SELECT * FROM SYSTEM.HELP WHERE ROWNUM <= 10 AND (TIMED <0 AND TIMED < 10 OR TIMED >30)", oracle.replace(" ", " ")); }