Re: Limiting a number of rows returned
hi max, anyone is invited to contribute... jakob Max Vesely wrote: Thanks, Scott. Would database implementation be the right place for this code? If yes, is anyone working on it? If not, Can someone like me contribute to OJB framework? Thank, you. Max. -Original Message- From: Scott Howlett [mailto:[EMAIL PROTECTED] Sent: Wednesday, February 26, 2003 10:30 PM To: OJB Users List Subject: RE: Limiting a number of rows returned I implemented this functionality for PostgreSQL. I subclassed SqlGeneratorDefaultImpl to provide the functionality and then pointed to my subclass in OJB.properties. My OJB.properties entry is: SqlGeneratorClass=PostgreSqlStatementGenerator My subclass code is: import org.apache.ojb.broker.accesslayer.sql.SqlGeneratorDefaultImpl; import org.apache.ojb.broker.metadata.ClassDescriptor; import org.apache.ojb.broker.platforms.Platform; import org.apache.ojb.broker.query.Query; public class PostgreSqlStatementGenerator extends SqlGeneratorDefaultImpl { public SqlStatementGenerator(Platform pf) { super(pf); } public String getPreparedSelectStatement( Query query, ClassDescriptor cld) { String result = super.getPreparedSelectStatement(query, cld); return addOffsetLimit(query, result); } public String getSelectStatementDep(Query query, ClassDescriptor cld) { String result = super.getSelectStatementDep(query, cld); return addOffsetLimit(query, result); } private String addOffsetLimit(Query q, String stmt) { int startIndex = q.getStartAtIndex(); int endIndex = q.getEndAtIndex(); if (endIndex > 0) { if (startIndex < 0 || startIndex >= endIndex) { startIndex = 0; } stmt += " LIMIT " + (endIndex - startIndex); } if (startIndex > 0) { stmt += " OFFSET " + startIndex; } return stmt; } } Hope that helps, Scott Howlett -Original Message- From: Max Vesely [mailto:[EMAIL PROTECTED] Sent: Wednesday, February 26, 2003 10:27 PM To: [EMAIL PROTECTED] Subject: Limiting a number of rows returned Hi, Does anyone know how to limit a number of rows returned from database using OJB? Most of the database engines implement custom keywords to limit a number of rows for select statement (top, limit, rownum () < .), OJB Query interface has methods in it to set EndAt and StartAt indexes as well as the size of resultset returned but setting them doesn't really help. The database engine I'm using is HSQLDB. Thank, you in advance. Max. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Limiting a number of rows returned
Thanks, Scott. Would database implementation be the right place for this code? If yes, is anyone working on it? If not, Can someone like me contribute to OJB framework? Thank, you. Max. -Original Message- From: Scott Howlett [mailto:[EMAIL PROTECTED] Sent: Wednesday, February 26, 2003 10:30 PM To: OJB Users List Subject: RE: Limiting a number of rows returned I implemented this functionality for PostgreSQL. I subclassed SqlGeneratorDefaultImpl to provide the functionality and then pointed to my subclass in OJB.properties. My OJB.properties entry is: SqlGeneratorClass=PostgreSqlStatementGenerator My subclass code is: import org.apache.ojb.broker.accesslayer.sql.SqlGeneratorDefaultImpl; import org.apache.ojb.broker.metadata.ClassDescriptor; import org.apache.ojb.broker.platforms.Platform; import org.apache.ojb.broker.query.Query; public class PostgreSqlStatementGenerator extends SqlGeneratorDefaultImpl { public SqlStatementGenerator(Platform pf) { super(pf); } public String getPreparedSelectStatement( Query query, ClassDescriptor cld) { String result = super.getPreparedSelectStatement(query, cld); return addOffsetLimit(query, result); } public String getSelectStatementDep(Query query, ClassDescriptor cld) { String result = super.getSelectStatementDep(query, cld); return addOffsetLimit(query, result); } private String addOffsetLimit(Query q, String stmt) { int startIndex = q.getStartAtIndex(); int endIndex = q.getEndAtIndex(); if (endIndex > 0) { if (startIndex < 0 || startIndex >= endIndex) { startIndex = 0; } stmt += " LIMIT " + (endIndex - startIndex); } if (startIndex > 0) { stmt += " OFFSET " + startIndex; } return stmt; } } Hope that helps, Scott Howlett -Original Message- From: Max Vesely [mailto:[EMAIL PROTECTED] Sent: Wednesday, February 26, 2003 10:27 PM To: [EMAIL PROTECTED] Subject: Limiting a number of rows returned Hi, Does anyone know how to limit a number of rows returned from database using OJB? Most of the database engines implement custom keywords to limit a number of rows for select statement (top, limit, rownum () < .), OJB Query interface has methods in it to set EndAt and StartAt indexes as well as the size of resultset returned but setting them doesn't really help. The database engine I'm using is HSQLDB. Thank, you in advance. Max. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
AW: Limiting a number of rows returned
Hi, maybe this can point you to a solution: You can use it in the in repository.xml. I think you'll find more explanations on thin in the docs. Regards, Max > -Ursprüngliche Nachricht- > Von: Max Vesely [mailto:[EMAIL PROTECTED] > Gesendet: Donnerstag, 27. Februar 2003 04:27 > An: [EMAIL PROTECTED] > Betreff: Limiting a number of rows returned > > > Hi, > >Does anyone know how to limit a number of rows returned > from database > using OJB? > > Most of the database engines implement custom keywords to > limit a number of > rows for select statement (top, limit, rownum () < .), OJB Query > interface has methods in it to set EndAt and StartAt indexes > as well as the > size of resultset returned but setting them doesn't really help. The > database engine I'm using is HSQLDB. > > Thank, you in advance. > > Max. > - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Limiting a number of rows returned
I implemented this functionality for PostgreSQL. I subclassed SqlGeneratorDefaultImpl to provide the functionality and then pointed to my subclass in OJB.properties. My OJB.properties entry is: SqlGeneratorClass=PostgreSqlStatementGenerator My subclass code is: import org.apache.ojb.broker.accesslayer.sql.SqlGeneratorDefaultImpl; import org.apache.ojb.broker.metadata.ClassDescriptor; import org.apache.ojb.broker.platforms.Platform; import org.apache.ojb.broker.query.Query; public class PostgreSqlStatementGenerator extends SqlGeneratorDefaultImpl { public SqlStatementGenerator(Platform pf) { super(pf); } public String getPreparedSelectStatement( Query query, ClassDescriptor cld) { String result = super.getPreparedSelectStatement(query, cld); return addOffsetLimit(query, result); } public String getSelectStatementDep(Query query, ClassDescriptor cld) { String result = super.getSelectStatementDep(query, cld); return addOffsetLimit(query, result); } private String addOffsetLimit(Query q, String stmt) { int startIndex = q.getStartAtIndex(); int endIndex = q.getEndAtIndex(); if (endIndex > 0) { if (startIndex < 0 || startIndex >= endIndex) { startIndex = 0; } stmt += " LIMIT " + (endIndex - startIndex); } if (startIndex > 0) { stmt += " OFFSET " + startIndex; } return stmt; } } Hope that helps, Scott Howlett -Original Message- From: Max Vesely [mailto:[EMAIL PROTECTED] Sent: Wednesday, February 26, 2003 10:27 PM To: [EMAIL PROTECTED] Subject: Limiting a number of rows returned Hi, Does anyone know how to limit a number of rows returned from database using OJB? Most of the database engines implement custom keywords to limit a number of rows for select statement (top, limit, rownum () < .), OJB Query interface has methods in it to set EndAt and StartAt indexes as well as the size of resultset returned but setting them doesn't really help. The database engine I'm using is HSQLDB. Thank, you in advance. Max. - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Limiting a number of rows returned
Hi, Does anyone know how to limit a number of rows returned from database using OJB? Most of the database engines implement custom keywords to limit a number of rows for select statement (top, limit, rownum () < .), OJB Query interface has methods in it to set EndAt and StartAt indexes as well as the size of resultset returned but setting them doesn't really help. The database engine I'm using is HSQLDB. Thank, you in advance. Max.