- add api to support the use of database specific paging feature to return a subset of the query result.
This commit is contained in:
Heng Sin Low 2009-12-14 04:34:16 +00:00
parent 904289b63b
commit d57c61959c
4 changed files with 46 additions and 22 deletions

View File

@ -301,6 +301,21 @@ public interface AdempiereDatabase
* Default sql use to test whether a connection is still valid
*/
public final static String DEFAULT_CONN_TEST_SQL = "SELECT Version FROM AD_System";
/**
* Is the database have sql extension that return a subset of the query result
* @return boolean
*/
public boolean isPagingSupported();
/**
* modify sql to return a subset of the query result
* @param sql
* @param start
* @param end
* @return
*/
public String addPagingSQL(String sql, int start, int end);
} // AdempiereDatabase

View File

@ -1108,6 +1108,14 @@ public class DB_Oracle implements AdempiereDatabase
public boolean isQueryTimeoutSupported() {
return true;
}
public String addPagingSQL(String sql, int start, int end) {
String newSql = "SELECT * FROM (" + sql + ") WHERE ROWNUM BETWEEN " + start + " AND " + end;
return newSql;
}
public boolean isPagingSupported() {
return true;
}
} // DB_Oracle

View File

@ -84,16 +84,17 @@ public class DB_PostgreSQL implements AdempiereDatabase
/** Cached Database Name */
private String m_dbName = null;
private String m_userName = null;
/** Connection String */
private String m_userName = null;
/** Connection String */
private String m_connectionURL;
private boolean m_supportAlias = false;
/** Logger */
private static CLogger log = CLogger.getCLogger (DB_PostgreSQL.class);
private static int m_maxbusyconnections = 0;
private static int m_maxbusyconnections = 0;
public static final String NATIVE_MARKER = "NATIVE_"+Database.DB_POSTGRESQL+"_KEYWORK";
/**
* Get Database Name
@ -791,21 +792,19 @@ public class DB_PostgreSQL implements AdempiereDatabase
return false;
}
/**
* Implemented using the limit and offset feature. use 1 base index for start and end parameter
* @param sql
* @param start
* @param end
*/
public String addPagingSQL(String sql, int start, int end) {
String newSql = sql + " " + NATIVE_MARKER + "LIMIT " + ( end - start + 1 )
+ " " + NATIVE_MARKER + "OFFSET " + (start - 1);
return newSql;
}
/*
public boolean getSupportAlias()
{
if (s_driver == null)
{
s_driver = new org.postgresql.Driver();
if(s_driver.getVersion().indexOf("PostgreSQL 8.2") != -1)
return true;
}
return false;
}*/
public boolean isPagingSupported() {
return true;
}
} // DB_PostgreSQL

View File

@ -22,6 +22,7 @@ import java.util.Vector;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.compiere.db.DB_PostgreSQL;
import org.compiere.model.MSysConfig;
import org.compiere.util.CLogger;
import org.compiere.util.DB;
@ -107,6 +108,7 @@ public class Convert_PostgreSQL extends Convert_SQL92 {
String statement = replaceQuotedStrings(sqlStatement, retVars);
statement = convertWithConvertMap(statement);
statement = statement.replace(DB_PostgreSQL.NATIVE_MARKER, "");
String cmpString = statement.toUpperCase();
boolean isCreate = cmpString.startsWith("CREATE ");