Xiaoyong,
please see below ...
Regards
Werner
On Thu, 20 Nov 2003 19:10:02 +0800, Xiaoyong Liang wrote:
>I had a real good experience using Castor XML before I decided to use Castor JDO as the ORM part of a new
project. Thanks for your great effort.
>
>But now my members came to me with some questions which I don't have a good idea to solve too. It might be
stupid, but since the project is real urgent(sorry for this word :P) and I can't find anything helpful by searching
Internet, please kindly give me your suggestions or advice.
>
>1. Where can I find an example/tutorial of complex query thru JDO?
Get the binaries from the web, and have a look at the samples included. More specifically, have a look at the
src/examples/jdo directory which holds quite a normal (= complex) scenario ... especially the mapping file should be
of interest to you, as it holds 1:1 and 1:m relationships.
>2. I'm using Castor v0.9.5.2 & MySQL v4.0.13. Assume that we have a table like this:
>+----------+--------------+------+-----+---------+----------------+
>| Field | Type | Null | Key | Default | Extra |
>+----------+--------------+------+-----+---------+----------------+
>| id | tinyint(4) | | PRI | NULL | auto_increment |
>| name | varchar(255) | YES | | NULL | |
>| sex | char(1) | YES | | NULL | |
>| birthday | date | YES | | NULL | |
>| address | varchar(255) | YES | | NULL | |
>+----------+--------------+------+-----+---------+----------------+
>
>And we also have a class User to represent its model. The create and update methods work real well. But when we
tried the advanced search, we are in a mess.
>
>In the search page, we have these elements: a textinput for name, a dropdown list for sex, two textinput for
birthday, and a textinput for address. We allow the customers to only fill one of these elements to perform the search.
The current way we are using is real ugly:
>
>================ Code Snippet Begin ===============
> List params = new ArrayList();
> String sql = "select u from " + MODEL_CLASS_NAME + " u where";
> boolean isFirst = true;
> int index = 0;
> if(model.getName() != null) {
> index++;
> sql += " u.name LIKE $" + index;
> params.add("%" + model.getName() + "%");
> isFirst = false;
> }
> if(model.getSex() != null) {
> index++;
> if(!isFirst) {
> sql += " and";
> }
> sql += " u.sex = $" + index;
> params.add(model.getSex());
> isFirst = false;
> }
> if(model.getBirthday() != null && model.getBirthday2() != null) {
> index++;
> if(!isFirst) {
> sql += " and";
> }
> sql += " u.birthday between $" + index + " and $" + (index + 1);
> index++;
> params.add(model.getBirthday());
> params.add(model.getBirthday2());
> isFirst = false;
> }else if(model.getBirthday() != null) {
> index++;
> if(!isFirst) {
> sql += " and";
> }
> sql += " u.birthday >= $" + index;
> params.add(model.getBirthday());
> isFirst = false;
> }else if(model.getBirthday2() != null) {
> index++;
> if(!isFirst) {
> sql += " and";
> }
> sql += " u.birthday <= $" + index;
> params.add(model.getBirthday2());
> isFirst = false;
> }
> if(model.getAddress() != null) {
> index++;
> if(!isFirst) {
> sql += " and";
> }
> sql += " u.address LIKE $" + index;
> params.add("%" + model.getAddress() + "%");
> isFirst = false;
> }
> OQLQuery query = db.getOQLQuery(sql);
>================ Code Snippet End ===============
>
>Yes, it should work. But does anyone have a better idea?
>
>3. Not sure if this is a bug.
>After I create/update an object, it will not take effective immediately in a transaction. For example:
>
>// Create a new user
>User user = new User();
>user.setName(userName);
>...
>db.create(user);
>// Return the customer to user list screen
>OQLQuery query = db.getOQLQuery("select u from " + MODEL_CLASS_NAME + " u");
>...
>// The new user will not be count in the result set :(
>
>Any comment or suggestion is appreciated.
As already mentioned by yourself, you'll need to commit the transaction for the inserted object to become visible
globally. Without a commit, an OQLQuery will not see what you've created.
>
>-Sunlxy
>
>-----------------------------------------------------------
>If you wish to unsubscribe from this mailing, send mail to
>[EMAIL PROTECTED] with a subject of:
> unsubscribe castor-dev
>
