Thank you for your post Jakob. It sounds like a bit of an effort. I was
thinking based on other code perviously posted on the board to get around the
problem that it might be a bit easier. I was about to test code people placed
on the board previously to get around the problem. I am not sure based on your
words if it should work? I will try testing it tonight, but I am a bit
nervous it might run me into problems in the future now. Here is the database
specific code:
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 MySqlStatementGenerator extends SqlGeneratorDefaultImpl
{
public MySqlStatementGenerator(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;
}
}
Thank you for your ideas.
JohnE
> hi john,
>
> to be hones, my version of the sql-limit stuff was rather basic
> and didn't work
> correctly for extents.
> before we can really use the sql-LIMIT we'll have to change ojb to
> use a
> _single_ query for all extents (using the UNION clause). with the
> current
> solution using one select for each extent the LIMIT-clause is not
> useful.
> example:
>
> -ojb current version:
> select * from person where ... limit ...
> select * from musicians where ... limit ...
>
> -future version:
> select * from person where ...
> union
> select * from musicians where ...
> limit ...
>
> jakob
>
> [EMAIL PROTECTED] schrieb:
> > Hey all. Thank you for great project.
> >
> > I am very excited about my site having gone live with OJB, but
> there is one aspect of OJB I am really not liking to have to do
> right now -- make it database specific. It was part of my
> marketing to have the platform I created be non-database specific,
> but that can't be for one reason.
> >
> > I am looking at all the posts on the board about not having
> LIMIT supported. I need to do very large table queries but I
> have to add LIMITs specific to MySQL on the query or there would
> be a drastically bad performance issue.
> >
> > Jakob is your LIMIT code you had working working and do you
> think it might get into 1.0.2 or 1.1? I know you have bigger fish
> to fry.
> >
> > I don't know OJB internals well but I am trying to learn so I
> can help in the future.
> >
> > JohnE
> >
> >
> >
> >
> >
> > -----------------------------------------------------------------
> ----
> > 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]