Skip to content

Commit

Permalink
Oracle Paging added
Browse files Browse the repository at this point in the history
  • Loading branch information
ati-ozgur committed Sep 23, 2013
1 parent 4b41ab1 commit e2769e0
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public List<SqlFragment> getFragments() {
protected void toSQL(StringBuilder buf, ElSqlBundle bundle, SqlParameterSource paramSource) {
for (SqlFragment fragment : _fragments) {
fragment.toSQL(buf, bundle, paramSource);
//buf.append("\n");

This comment has been minimized.

Copy link
@jodastephen

jodastephen Sep 25, 2013

Did you comment this out for a reason?

This comment has been minimized.

Copy link
@ati-ozgur

ati-ozgur Sep 25, 2013

Author Owner

Sorry. That line was my trial to implement issue(OpenGamma#1 - Preserve MultiLine SQL). That line is unnecessary for Oracle Support. It breaks tests therefore I commented it out.

}
}

Expand Down
30 changes: 30 additions & 0 deletions src/main/java/com/opengamma/elsql/ElSqlConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ public class ElSqlConfig {
* of FETCH-OFFSET.
*/
public static final ElSqlConfig MYSQL = new MySqlElSqlConfig();


public static final ElSqlConfig ORACLE = new OracleElSqlConfig();

/**
* A constant for the config needed for SQL Server 2008, which pages in a different way.
*/
Expand Down Expand Up @@ -201,6 +205,32 @@ public String getPaging(int offset, int fetchLimit) {
}
}


private static class OracleElSqlConfig extends ElSqlConfig {
public OracleElSqlConfig() {
super("Oracle");
}
@Override
public String addPaging(String selectToPage, int offset, int fetchLimit) {
if (fetchLimit == 0 && offset == 0) {
return selectToPage;
}
if (offset == 0 && fetchLimit > 0)
{
return "SELECT * FROM ( " + selectToPage + " ) where rownum <= " + fetchLimit;

}
int start = offset;
int end = offset + fetchLimit;

return "SELECT * FROM (SELECT row_.*,rownum rownum_ FROM ( " + selectToPage + " ) row_ where rownum <= "+ end +") WHERE rownum_ > " + start;
}
@Override
public String getPaging(int offset, int fetchLimit) {
throw new UnsupportedOperationException();

This comment has been minimized.

Copy link
@jodastephen

jodastephen Sep 25, 2013

Is it possible to implement this in Oracle, or was it just that you didn't need it?

}
}

//-------------------------------------------------------------------------
/**
* Class for SQL server 2008.
Expand Down

0 comments on commit e2769e0

Please sign in to comment.