Re: re : problem with a request with m:n relations

2004-07-26 Thread kristen
hi Jakob,

When I execute the following request :
query.create("select books from Books where writtenBy.belong.name 
= 'Category1'");

I obtain an error message which say : "invalid user.table.column, table.column, 
or column specification". 
I use Oracle.

Is there a means to see the detail of the request when this is executed in 
Oracle ?
because I don't know what Ojb do to "translate" the request...

Thank you for your help.

Kristen


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: ResultSet not closed

2004-07-26 Thread Bogdan Daniliuc
  After several more tests with Oracle 9i and Microsoft SQL server we
discovered that this happends with Oracle platform (oci8 or thin). Currently
the code seems to work ok with SQL server. 

  Regards, 

  Bogdan


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Problems with locking

2004-07-26 Thread Fiona Magner
Hi there,

I am having some problems getting a lock on my objects when I place my application 
under a small bit of pressure. I have two tables, a Clients table and a Messages 
table. The Messages table has a clientid field in it but I have not explicitly set any 
relationships with the Clients table in my repository descriptor as there may not 
always be a clientid value in the field (as well as the fact that I do not need any 
relationship expressed). Anyway I have a sample script that is reading from my clients 
table and then doing an insert into my messages table. This works fine except for when 
I request this script many times in which case the insert into the Messages table 
fails due to the following error:

org.odmg.LockNotGrantedException: Can not lock [AdminID] null ClientID] 12345 
[Comments] test [DateCreated] {ts '2004-07-26 17:19:11'} [ID] -2 [LastUpdated] {ts 
'2004-07-26 17:19:11'} [Message] test for WRITE at 
org.apache.ojb.odmg.TransactionImpl.lock(TransactionImpl.java:236) 

When I remove the read from the clients table before the insert into the Messages 
table I cannot seem to reproduce it. So if I am only doing inserts into the Messages 
table it seems to be OK? I have gone through the lock management documentation to see 
if I am missing anything. I have set all my class descriptors to have 
isolation="read-uncomitted". I have also changed the OJBProperties file to have 
ImplicitLocking=false to see if that could help. The lock manager in OJBProperties is 
set to the default of 
LockManagerClass=org.apache.ojb.odmg.locking.LockManagerDefaultImpl. If anyone has any 
advice on something else I could try I would really appreciate it. This application 
really needs to be able to stand up to high performance and its falling over when I 
simply do multiple requests of this script within a few seconds of each other.

Thanks as always for your help!

Fiona

ODMG and primary key assignment

2004-07-26 Thread Saleem Shafi
Hello,

i have a quick question about when a primary key is assigned to an
object using the ODMG interface provided by OJB..  i realize that the
PersistentBroker.store() method will set the primary key property on
the object, but the .lock() method on the ODMG transaction doesn't
seem to do that for me..  i understand that the transactions are
different between OJB and ODMG and that the object will get its ID
after the ODMG transaction commits, but is there any way to get the ID
assigned before that?


Saleem.

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



ResultSet not closed

2004-07-26 Thread Bogdan Daniliuc
  Hi all, 
  
  What does the following message mean:
  
[Finalizer thread] accesslayer.ResultSetAndStatement - ** Associated resources
(Statement/ResultSet) not closed! Try automatic cleanup ** ??

  We are having a class hierarchy with 3 classes. Class A has a 1-n
relationship with itself (parent-child relationship), a m-n relationship with
class B and a 1-n relationship with class C. Class B has a 1-n relationship
with class C. 
  In the descriptor repository, for class A: 
  - the collection-descriptor for A  is marked as auto-update="true"
  - the collection descriptor for B is marked as auto-update="link"
  - the collection descriptor for C is marked as auto-update="none"
  For class B: 
  - the collection descriptor for A is marked as auto-update="link"
  For class C: 
  - the collection descriptor for A is marked as auto-update="link"
  - the collection descriptor for B is marked as auto-update="link"
 
  At one point we have to take the list  of element A from B, remove one
element (A1) and add another(A2), take all children of A1 and move them to A2,
then take all elements C that used A1 and change then to use A2. 
  Please note, that we do all these operations in a single transaction. In
logs the following message appears:  
[Finalizer thread] accesslayer.ResultSetAndStatement - ** Associated resources
(Statement/ResultSet) not closed! Try automatic cleanup **
  
  If we repeat the operation several times, not all objects are stored in the
database. 
  
  We are using OJB 1.0

  Regards, 

  Bogdan

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: how to postinitialize objects after being completely materialized

2004-07-26 Thread Thomas Dudziak
David Zejda wrote:
It seems, that the order of initialization steps is
1) constructor() (suprisingly :)
2) initialization-method
3) rowreader's readObjectFrom
4) constructors of references etc.
5) afterLookup
The initialization-method is called from the 
RowReaderDefaultImpl#readObjectFrom method as the last step, right after 
the field values have been set. The references and collections are read 
later, so if you require them, you'll have to either supply a Listener 
for PB events to the PersistenceBroker, or implement the 
PersistenceBrokerAware interface.

Tom
-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


Re: how to postinitialize objects after being completely materialized

2004-07-26 Thread David Zejda
It seems, that the order of initialization steps is
1) constructor() (suprisingly :)
2) initialization-method
3) rowreader's readObjectFrom
4) constructors of references etc.
5) afterLookup
..so the only possibility is the fifth one.
I'm not so happy to implement 7 methods of PersistenceBrokerAware in 
most of my objects only becouse one of them, but this is the only 
operating solution I currently know, so get to it..

Thanks once more
David
Charles Anthony wrote:
Hi David,
Another approach : if you get your persistent objects to implement
org.apache.ojb.broker.PersistenceBrokerAware interface, you could then
implement the afterLookup method e.g.
public void afterLookup(PersistenceBroker broker) {
   _postinit();
};
The afterLookup method is invoked after a persistence broker loads the
object - and, I believe, after any of the references are loaded too.
Some people would not like this approach (due to the persistency layer
"invading" your domain objects) - I am not one of them.
HTH,
Chaeers,

-Original Message-
From: David Zejda [mailto:[EMAIL PROTECTED]
Sent: 26 July 2004 09:59
To: OJB Users List
Subject: how to postinitialize objects after being completely
materialized
I have a custom row reader able to initialize materialized objects by
their _postinit() methods. Essentially it works, but there is 
a problem
- the _postinit() should be called after the object is materialized
completely, i.e. with all fields, but also references and collections
filled. So, I guess I have to override some other method of 
rowreader or
 something completely different - please, give a hint.

public class RowReaderPostinitializingImpl extends 
RowReaderDefaultImpl
{
public RowReaderPostinitializingImpl(ClassDescriptor c)
{
super(c);
}

public Object readObjectFrom(Map row)
{
Object result = super.readObjectFrom(row);
if (result instanceof Postinitializable)
{
Postinitializable art = (Postinitializable) result;
art._postinit();
return art;
}
else
{
return result;
}
}
}

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


Re: re : problem with a request with m:n relations

2004-07-26 Thread Jakob Braeuchi
hi kristen,
query.create("select books from Books where writtenBy.belong.name = 'Category1'");
assuming the relationships are named writtenBy and belong
hth
jakob
kristen schrieb:
Thank you for your answer.
And how can I do if I have several M:N relationships ?
For example, I have these relations :
book <--> writtenBy <--> authors <--> belong <--> category
For example, if I would like to obtain the books which belongs to the 
category "Category1" ?

In fact, I don't have a link between book and category and I need to use 
several classes in the "from condition".

Could you help me ?
Thank you

-
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]


OJB runaway lock objects

2004-07-26 Thread Craig Andrews
Hi,
I am looking for help debugging a nasty problem with a JBoss app I am 
building, using OJB as the persistence mechanism. I have a very simple 
set up, with only a single object, and the following session bean:

public class ProductAdmin extends SessionBean {
private Implementation odmg = null;
private Database db = null;
public void ejbCreate() {
odmg = OJB.getInstance();
db = odmg.newDatabase();
try {
db.open("default", Database.OPEN_READ_WRITE);
} catch (ODMGException e) {
e.printStackTrace();
}
}
public void ejbRemove() throws EJBException, RemoteException {
try {
if (db != null) db.close();
} catch (ODMGException e) {
throw new EJBException(e);
}
odmg = null;
}
public Integer create() throws Exception {
Product p = new Product();
Transaction tx = odmg.newTransaction();
tx.begin();

try {
tx.lock(p, Transaction.WRITE);
tx.commit();
} catch (Exception e) {
tx.abort();
throw (e);
}
return p.getId();
}
}
If I then run the create method a few thousand times, it becomes
apparent that there are thousands of 
org.apache.ojb.odmg.locking.ObjectLocks and
org.apache.ojb.odmg.locking.LockEntry objects that cannot be garbage
collected. The net result is that after ~90,000 objects are written to
the database, there is no memory left for the JVM!

The system is supposed to be supporting a userbase of over 200,000, so
this many writes is quite feasible in a short space of time.
Is there anything I'm doing wrong with the transactions? I have followed 
the tutorials as closely as I can and have reached the stage where I 
wouldn't be able to see the woods if there were one, due to these trees 
everywhere.

Thanks!
--
Craig Andrews <[EMAIL PROTECTED]>
-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


Re: little suggestion about "instanceof"

2004-07-26 Thread David Zejda
Imagine, you use the DummyCalendar in Calendar2DateFieldConversion.
javaToSql will be ok.
 (... if (source instanceof Calendar) ...)
but sqlToJava will materialize not the DummyCalendar (that you need), 
but a GregorianCalendar.
 (... GregorianCalendar cal = new GregorianCalendar()...)

 public class TestThingy2 extends TestCase
 {
   public void testCalendarConv()
   {
 DummyCalendar dc0 = new DummyCalendar();
 Date d = Calendar2DateFieldConversion.javaToSql(dc);
 Calendar dc1 = Calendar2DateFieldConversion.javaToSql(d);
 assertEquals(dc1, dc0); //will fail
 DummyCalendar dc2 = (DummyCalendar)dc1; //will fail
   }
 }
Absolutely - but then you must create your own conversion strategy !
Instanceof has nothing to do with this.
>
The Fieldconversion implementation must know what calendar implementation to
instantiate (although Calendar2DateFieldConversion should, probably, do
Calendar.getInstance and not instantiate GregorianCalendar directly) - and
it can't derive this information for the java.sql.Date
If you want to convert java.sql.Date <--> DummyCalendar then you have to
create a DummyCalendar2DateFileConversion class...
But imagine, someone doesn't care about the exact class of calendar, 
only calls getInstance(). In future JDKs, there may be a couple of 
Calendars, depending on locales... and OJB will silently degrade all of 
them onto GregorianCalendar.

In case of .getClass() match, the silent (and maybe not so easily 
debuggable) replacement of Calendar instances easily can't happen.
Are there any cons of .getClass() in favour of instanceof, that I'm missing?

But as you can notice in the title, i called it "little", so I don't 
think it's a huge issue - and it may be a timewaste to flame on the list 
around a single keyword...

And moreover, you are the developers of OJB and I'm currently only a 
[mostly happy] user, so the decision will be definitely yours...

David
Charles.

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


re : problem with a request with m:n relations

2004-07-26 Thread kristen
Thank you for your answer.

And how can I do if I have several M:N relationships ?

For example, I have these relations :

book <--> writtenBy <--> authors <--> belong <--> category

For example, if I would like to obtain the books which belongs to the 
category "Category1" ?

In fact, I don't have a link between book and category and I need to use 
several classes in the "from condition".

Could you help me ?

Thank you




-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: little suggestion about "instanceof"

2004-07-26 Thread Charles Anthony
> Imagine, you use the DummyCalendar in Calendar2DateFieldConversion.
> 
> javaToSql will be ok.
>   (... if (source instanceof Calendar) ...)
> 
> but sqlToJava will materialize not the DummyCalendar (that you need), 
> but a GregorianCalendar.
>   (... GregorianCalendar cal = new GregorianCalendar()...)
> 
>   public class TestThingy2 extends TestCase
>   {
> public void testCalendarConv()
> {
>   DummyCalendar dc0 = new DummyCalendar();
>   Date d = Calendar2DateFieldConversion.javaToSql(dc);
>   Calendar dc1 = Calendar2DateFieldConversion.javaToSql(d);
> 
>   assertEquals(dc1, dc0); //will fail
> 
>   DummyCalendar dc2 = (DummyCalendar)dc1; //will fail
> }
>   }
> 

Absolutely - but then you must create your own conversion strategy !
Instanceof has nothing to do with this.

The Fieldconversion implementation must know what calendar implementation to
instantiate (although Calendar2DateFieldConversion should, probably, do
Calendar.getInstance and not instantiate GregorianCalendar directly) - and
it can't derive this information for the java.sql.Date

If you want to convert java.sql.Date <--> DummyCalendar then you have to
create a DummyCalendar2DateFileConversion class...

Cheers,

Charles.


___
HPD Software Ltd. - Helping Business Finance Business
Email terms and conditions: www.hpdsoftware.com/disclaimer 



-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Debugging Queries

2004-07-26 Thread Tino Schöllhorn
Hi Thomas,
I am perfectly aware of that - but in my opinion you're already doing 
the right thing: emulate the behaviour of paging when the underlying db 
isn't supporting it. But if the underlying db is supporting this feature 
(many db implement this: mysql, mssql, oracle...) it should be used 
because one can have dramatically network and performance increases.

With regards
Tino
Thomas Dudziak wrote:
Jakob Braeuchi wrote:
hi tino,
i do have an implementation using limit, but i think it's not finished 
yet.

Please be aware that not all databases support limits in sql (e.g. McKoi).
Btw, do we use paging resultsets ? In that case, we might not need 
limits as the driver can optimize via cursors, or not ?

Tom

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


Re: little suggestion about "instanceof"

2004-07-26 Thread David Zejda
Thanks for a suggestion!
There is a nice article, where (in the second part) the result of 
improper instanceof check in inheritance hierarchy is demonstrated.

http://www.javaworld.com/javaworld/jw-01-1999/jw-01-object.html
David
Jakob Braeuchi wrote:
hi david,
the instanceof is some kind of standard implemenation for equals(). see 
Effective Java by Josh Bloch.

jakob
David Zejda schrieb:
I think, it would be better to use something like
((source != null) && (source.getClass()==Calendar.class))
{
...
in conversion strategies than
if (source instanceof Calendar)
{
...
to avoid reducing e.g. custom Calendar subclass to Calendar during 
conversion.

David
-
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: problem with a request with m:n relations (ojb)

2004-07-26 Thread Jakob Braeuchi
hi kristen,
ojb does the join automatically:
query.create("select authors ...Autor where books.title like ?");
this sample need a relationship-definition named 'books' and an attribute 
'title' in class Books. the relationship 'books' is a bidirectional m:n 
relationship based on the table writtenBy.

jakob
kristen schrieb:
Hello !
First, sorry for my english...
I would like to create a request which are based on a m:n relationships.
For example :
a book can be written by several authors and several authors can write books.
This is the relation :
book <-> writtenBy <-> author
For example, How can I obtain the name of all the author who have written the 
book "my book" ?

I have the following code but I don't know how can I put several classes after 
the "from" :

Transaction tx = odmg.newTransaction();
tx.begin();
OQLQuery query = odmg.newOQLQuery();
String queryStr = "select auhors from " + Author.class.getName()+  ?
query.create(queryStr);
GroupsList = (List) query.execute();
tx.commit();
Thank you for your help
-
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: little suggestion about "instanceof"

2004-07-26 Thread David Zejda
Thanks for your testcase.
Imagine, you use the DummyCalendar in Calendar2DateFieldConversion.
javaToSql will be ok.
 (... if (source instanceof Calendar) ...)
but sqlToJava will materialize not the DummyCalendar (that you need), 
but a GregorianCalendar.
 (... GregorianCalendar cal = new GregorianCalendar()...)

 public class TestThingy2 extends TestCase
 {
   public void testCalendarConv()
   {
 DummyCalendar dc0 = new DummyCalendar();
 Date d = Calendar2DateFieldConversion.javaToSql(dc);
 Calendar dc1 = Calendar2DateFieldConversion.javaToSql(d);
 assertEquals(dc1, dc0); //will fail
 DummyCalendar dc2 = (DummyCalendar)dc1; //will fail
   }
 }
David

Just for curiosity what is the purpose of you own calendar class ?
from Calendar apidoc:
Subclasses of Calendar interpret a Date  according to the rules of a 
specific calendar system. The platform provides one concrete 
subclass of 
Calendar: GregorianCalendar. Future subclasses could represent the 
various types of lunar calendars in use in many parts of the world.

..so there are more calendars planned in JDK and also there is no 
guarantee, that there are no other custom subclasses yet.

I think it's a general rule, to take into accout subclasses, 
everywhere 
applicable (~ not final classes), esp. in tools, libraries, 
frameworks...

Indeed it is - and instanceof covers this. I've just knocked together (and
appended) a test case to illustrate and prove this : both java.util.Calendar
and my DummyCalendar are *both* instances of Calendar. This also holds true
of interfaces : if a class A implements interface B, an instance of of class
A is an instance of class B. Moreover, is class C extends class A, an
instance of class C is also an instance of class B.
Hopefully the test case is clearer and more lucid than this explanation :
Cheers,
Charles.

public class TestThingy extends TestCase {
  public void testInstanceOf() {
assertTrue(new GregorianCalendar() instanceof java.util.Calendar);
assertTrue(new DummyCalendar() instanceof java.util.Calendar);
assertTrue(new AnObject() instanceof AnInterface);
assertTrue(new ASubclass() instanceof AnInterface);
  }
  public class DummyCalendar extends Calendar {
public void add(int field, int amount) {
}
protected void computeFields() {
}
protected void computeTime() {
}
public int getGreatestMinimum(int field) {
  return 0;
}
public int getLeastMaximum(int field) {
  return 0;
}
public int getMaximum(int field) {
  return 0;
}
public int getMinimum(int field) {
  return 0;
}
public void roll(int field, boolean up) {
}
  }
  public interface AnInterface {}
  public class AnObject implements AnInterface {}
  public class ASubclass extends AnObject {}
}
___
HPD Software Ltd. - Helping Business Finance Business
Email terms and conditions: www.hpdsoftware.com/disclaimer 


-
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]


problem with a request with m:n relations (ojb)

2004-07-26 Thread kristen
Hello !

First, sorry for my english...

I would like to create a request which are based on a m:n relationships.

For example :

a book can be written by several authors and several authors can write books.


This is the relation :

book <-> writtenBy <-> author

For example, How can I obtain the name of all the author who have written the 
book "my book" ?

I have the following code but I don't know how can I put several classes after 
the "from" :

Transaction tx = odmg.newTransaction();
tx.begin();
OQLQuery query = odmg.newOQLQuery();
String queryStr = "select auhors from " + Author.class.getName()+  ?

query.create(queryStr);
GroupsList = (List) query.execute();
tx.commit();


Thank you for your help


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: Debugging Queries

2004-07-26 Thread Thomas Dudziak
Jakob Braeuchi wrote:
hi tino,
i do have an implementation using limit, but i think it's not finished 
yet.
Please be aware that not all databases support limits in sql (e.g. McKoi).
Btw, do we use paging resultsets ? In that case, we might not need 
limits as the driver can optimize via cursors, or not ?

Tom
-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


Re: little suggestion about "instanceof"

2004-07-26 Thread Jakob Braeuchi
hi david,
the instanceof is some kind of standard implemenation for equals(). see 
Effective Java by Josh Bloch.

jakob
David Zejda schrieb:
I think, it would be better to use something like
((source != null) && (source.getClass()==Calendar.class))
{
...
in conversion strategies than
if (source instanceof Calendar)
{
...
to avoid reducing e.g. custom Calendar subclass to Calendar during 
conversion.

David
-
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: Debugging Queries

2004-07-26 Thread Jakob Braeuchi
hi tino,
i do have an implementation using limit, but i think it's not finished yet.
jakob
Tino Schöllhorn schrieb:
Hi Jakob,
thanks for your answer. Will that feature be implemented in OJB 1.1? We 
have some queries where that feature is important for us. If this is 
just a matter of the MySQLPlatform-Implementation I could help outor 
is this a general problem?

With regards Tino
Jakob Braeuchi wrote:
hi tino,
ojb does not use the limit-clause yet. the paging is implemented by 
positioning the cursor in the resultset.

jakob
Tino Schöllhorn schrieb:
Hi,
I am using MySQL and OJB and now I want to create a Query over a 
large table. For performance reason I want to use the 
"pageing"-feature - but I have the feeling that currently OJB is 
somehow ommitting this (the result is fine - but the SQL seems not to 
include the LIMIT-clause).

Is there a way to get the native SQL from a query which OJB would 
send to the database (this would help for other, complex queries too).

With regards
Tino
-
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: Debugging Queries

2004-07-26 Thread Tino Schöllhorn
Hi Jakob,
thanks for your answer. Will that feature be implemented in OJB 1.1? We 
have some queries where that feature is important for us. If this is 
just a matter of the MySQLPlatform-Implementation I could help outor 
is this a general problem?

With regards Tino
Jakob Braeuchi wrote:
hi tino,
ojb does not use the limit-clause yet. the paging is implemented by 
positioning the cursor in the resultset.

jakob
Tino Schöllhorn schrieb:
Hi,
I am using MySQL and OJB and now I want to create a Query over a large 
table. For performance reason I want to use the "pageing"-feature - 
but I have the feeling that currently OJB is somehow ommitting this 
(the result is fine - but the SQL seems not to include the LIMIT-clause).

Is there a way to get the native SQL from a query which OJB would send 
to the database (this would help for other, complex queries too).

With regards
Tino
-
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: little suggestion about "instanceof"

2004-07-26 Thread Charles Anthony
> > Just for curiosity what is the purpose of you own calendar class ?
> 
> from Calendar apidoc:
> Subclasses of Calendar interpret a Date  according to the rules of a 
> specific calendar system. The platform provides one concrete 
> subclass of 
> Calendar: GregorianCalendar. Future subclasses could represent the 
> various types of lunar calendars in use in many parts of the world.
> 
> ..so there are more calendars planned in JDK and also there is no 
> guarantee, that there are no other custom subclasses yet.
> 
> I think it's a general rule, to take into accout subclasses, 
> everywhere 
> applicable (~ not final classes), esp. in tools, libraries, 
> frameworks...


Indeed it is - and instanceof covers this. I've just knocked together (and
appended) a test case to illustrate and prove this : both java.util.Calendar
and my DummyCalendar are *both* instances of Calendar. This also holds true
of interfaces : if a class A implements interface B, an instance of of class
A is an instance of class B. Moreover, is class C extends class A, an
instance of class C is also an instance of class B.
Hopefully the test case is clearer and more lucid than this explanation :

Cheers,

Charles.



public class TestThingy extends TestCase {
  public void testInstanceOf() {
assertTrue(new GregorianCalendar() instanceof java.util.Calendar);
assertTrue(new DummyCalendar() instanceof java.util.Calendar);
assertTrue(new AnObject() instanceof AnInterface);
assertTrue(new ASubclass() instanceof AnInterface);
  }

  public class DummyCalendar extends Calendar {
public void add(int field, int amount) {
}

protected void computeFields() {
}

protected void computeTime() {
}

public int getGreatestMinimum(int field) {
  return 0;
}

public int getLeastMaximum(int field) {
  return 0;
}

public int getMaximum(int field) {
  return 0;
}

public int getMinimum(int field) {
  return 0;
}

public void roll(int field, boolean up) {
}
  }

  public interface AnInterface {}
  public class AnObject implements AnInterface {}
  public class ASubclass extends AnObject {}

}


___
HPD Software Ltd. - Helping Business Finance Business
Email terms and conditions: www.hpdsoftware.com/disclaimer 



-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Can't insert into Hsqldb data from Oracle

2004-07-26 Thread Igor A . Chebukin
Hi, All!

I'm trying to insert to Hsqldb data loaded from Oracle.

In this example I read table 'AGREE_GR' into 'result'. Then close Oracle, open Hsqldb 
and store 'result' there.
But 'result' NEVER stored (it's size>0). One object, created manually is stored well.
How can I store result from Oracle in Hsqldb?

repository.xml:
===





  
  
  


test.java:
==
import com.entecheco.chameleon.entity.agreegr.dataobject.AgreeGr;
import org.apache.ojb.broker.PersistenceBroker;
import org.apache.ojb.broker.query.QueryByCriteria;
import org.apache.ojb.odmg.HasBroker;
import org.apache.ojb.odmg.OJB;
import org.odmg.Database;
import org.odmg.Implementation;
import org.odmg.Transaction;

import java.math.BigDecimal;
import java.util.Collection;
import java.util.Iterator;

public class test {
  public static void main(String[] args) {

try {
  Collection result = null;
  // Load data from Oracle or not
  boolean loadData = true;

  // get data from Oracle
  if (loadData) {
Implementation odmg = OJB.getInstance();
Database database = odmg.newDatabase();
database.open("default", Database.OPEN_READ_ONLY);
Transaction tx = odmg.newTransaction();
tx.begin();
PersistenceBroker broker = ((HasBroker) tx).getBroker();
QueryByCriteria query = new QueryByCriteria(AgreeGr.class);
result = broker.getCollectionByQuery(query);
tx.commit();
database.close();
  }

  // Paste data to hsqldb
  {
Implementation odmg = OJB.getInstance();
Database database = odmg.newDatabase();
database.open("localCashe", Database.OPEN_READ_WRITE);
Transaction tx = odmg.newTransaction();
tx.begin();

// Store test object
AgreeGr agreeGr = new AgreeGr();
agreeGr.setId(new BigDecimal(12345));
agreeGr.setIdD(new BigDecimal(12345));
agreeGr.setName("sdfg");
tx.lock(agreeGr, Transaction.WRITE);

if (result != null) {
  Iterator iterator = result.iterator();
  System.out.println("Loaded "+result.size()+" records.");
  while (iterator.hasNext()) {
Object o = iterator.next();
tx.lock(o, Transaction.WRITE);
  }
}

tx.commit();
database.close();
  }

} catch (Exception e) {
  e.printStackTrace();
}
System.exit(0);

  }

}


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: little suggestion about "instanceof"

2004-07-26 Thread David Zejda
Guillaume Nodet wrote:
Maybe for the GregorianCalendar as Calendar is an abstract class...
You really use a custom calendar class ?
No, I don't. I only looked on convstrategies to get a bit of inspiration 
for my own ones and noticed that..

Just for curiosity what is the purpose of you own calendar class ?
from Calendar apidoc:
Subclasses of Calendar interpret a Date  according to the rules of a 
specific calendar system. The platform provides one concrete subclass of 
Calendar: GregorianCalendar. Future subclasses could represent the 
various types of lunar calendars in use in many parts of the world.

..so there are more calendars planned in JDK and also there is no 
guarantee, that there are no other custom subclasses yet.

I think it's a general rule, to take into accout subclasses, everywhere 
applicable (~ not final classes), esp. in tools, libraries, frameworks...

David
Guillaume
-Message d'origine-
De : David Zejda [mailto:[EMAIL PROTECTED]
Envoye : samedi 24 juillet 2004 07:59
A : OJB Users List
Objet : little suggestion about "instanceof"
I think, it would be better to use something like
((source != null) && (source.getClass()==Calendar.class))
{
...
in conversion strategies than
if (source instanceof Calendar)
{
...
to avoid reducing e.g. custom Calendar subclass to Calendar during 
conversion.

David

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


Re: Debugging Queries

2004-07-26 Thread Craig Andrews
Tino Schöllhorn wrote:
I am using MySQL and OJB and now I want to create a Query over a large 
table. For performance reason I want to use the "pageing"-feature - but 
I have the feeling that currently OJB is somehow ommitting this (the 
result is fine - but the SQL seems not to include the LIMIT-clause).

Is there a way to get the native SQL from a query which OJB would send 
to the database (this would help for other, complex queries too).
A database specific way would be to add the line:
log=/path/to/some/file.log
to my.cnf, which would cause MySQL to write each and every query it 
receives out to file.log. You can then just monitor what goes in there. 
Unfortunately, there is a large performance penalty, but it can be handy 
for debugging whole transactions.

--
Craig
-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


Re: how to postinitialize objects after being completely materialized

2004-07-26 Thread David Zejda
Thanks, Thomas & Charles...
I'll try it out.
David
-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


Re: Debugging Queries

2004-07-26 Thread Jakob Braeuchi
hi tino,
ojb does not use the limit-clause yet. the paging is implemented by positioning 
the cursor in the resultset.

jakob
Tino Schöllhorn schrieb:
Hi,
I am using MySQL and OJB and now I want to create a Query over a large 
table. For performance reason I want to use the "pageing"-feature - but 
I have the feeling that currently OJB is somehow ommitting this (the 
result is fine - but the SQL seems not to include the LIMIT-clause).

Is there a way to get the native SQL from a query which OJB would send 
to the database (this would help for other, complex queries too).

With regards
Tino
-
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: Debugging Queries

2004-07-26 Thread Charles Anthony
Hi,

The easiest way to do this is to use p6spy.

Please see the FAQ at http://db.apache.org/ojb/docu/faq.html#traceProfileSQL

Cheers,

Charles.

> -Original Message-
> From: Tino Schöllhorn [mailto:[EMAIL PROTECTED]
> Sent: 26 July 2004 12:18
> To: [EMAIL PROTECTED]
> Subject: Debugging Queries
> 
> 
> Hi,
> 
> I am using MySQL and OJB and now I want to create a Query 
> over a large 
> table. For performance reason I want to use the 
> "pageing"-feature - but 
> I have the feeling that currently OJB is somehow ommitting this (the 
> result is fine - but the SQL seems not to include the LIMIT-clause).
> 
> Is there a way to get the native SQL from a query which OJB 
> would send 
> to the database (this would help for other, complex queries too).
> 
> With regards
> Tino
> 
> 
> -
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 
> 


___
HPD Software Ltd. - Helping Business Finance Business
Email terms and conditions: www.hpdsoftware.com/disclaimer 



-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Debugging Queries

2004-07-26 Thread Tino Schöllhorn
Hi,
I am using MySQL and OJB and now I want to create a Query over a large 
table. For performance reason I want to use the "pageing"-feature - but 
I have the feeling that currently OJB is somehow ommitting this (the 
result is fine - but the SQL seems not to include the LIMIT-clause).

Is there a way to get the native SQL from a query which OJB would send 
to the database (this would help for other, complex queries too).

With regards
Tino
-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


RE: little suggestion about "instanceof"

2004-07-26 Thread Guillaume Nodet
Maybe for the GregorianCalendar as Calendar is an abstract class...
You really use a custom calendar class ?
Just for curiosity what is the purpose of you own calendar class ?

Guillaume

> -Message d'origine-
> De : David Zejda [mailto:[EMAIL PROTECTED]
> Envoye : samedi 24 juillet 2004 07:59
> A : OJB Users List
> Objet : little suggestion about "instanceof"
> 
> 
> I think, it would be better to use something like
> 
> ((source != null) && (source.getClass()==Calendar.class))
> {
>  ...
> 
> in conversion strategies than
> 
> if (source instanceof Calendar)
> {
>  ...
> 
> to avoid reducing e.g. custom Calendar subclass to Calendar during 
> conversion.
> 
> David
> 
> -
> 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: removing a child from 1:n

2004-07-26 Thread Jakob Braeuchi
hi joose,
if the collection is a RemovalAwareCollection then removed childs are also 
deleted on update of the parent.

jakob
Joose Vettenranta schrieb:
24.7.2004 kello 21:09, Jakob Braeuchi kirjoitti:
 hi joose,
i assume you're using pb-api now. please check the following doku:
http://db.apache.org/ojb/docu/guides/basic-technique.html#1%3An+auto- 
xxx+setting

Seems like auto-update does only INSERT or UPDATE. and auto-delete  
removes everything.

So seems like I just have to do PersistenceBroker.delete(...) to every  
deleted child to get them deleted.

Thanks,
Joose
--
"Always remember that you are unique, just like everyone else!"
* http://iki.fi/joose/ * [EMAIL PROTECTED] * +358 44 561 0270 *
-
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: how to postinitialize objects after being completely materialized

2004-07-26 Thread Thomas Dudziak
David Zejda wrote:
I have a custom row reader able to initialize materialized objects by
their _postinit() methods. Essentially it works, but there is a problem
- the _postinit() should be called after the object is materialized
completely, i.e. with all fields, but also references and collections
filled. So, I guess I have to override some other method of rowreader or
 something completely different - please, give a hint.
Have you tried the initialization-method attribute of the class 
descriptor? With it you state a no-arg instance method that gets called 
after the object has been loaded from the database and all fields have 
been filled. I'm not sure about the references and collections, but you 
might give it a try nonetheless.

Tom
-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


Re: removing a child from 1:n [SOLVED] [WORKING]

2004-07-26 Thread Joose Vettenranta
I just wanted to say, that I got it to work.. I did it so, that in the  
Child i made delete -variable which is checked on update-action (not  
very good if there is million child).

So my DAO.update() is like this now:
public void update(Parent bean, JdoPMF pmf) {
PersistenceManager persistenceManager =  
pmf.getPersistenceManager();
PersistenceBroker broker =  
PersistenceBrokerFactory.defaultPersistenceBroker();
Iterator it = bean.getChilds().iterator();

broker.beginTransaction();
while (it.hasNext()) {
Child child = it.next();
if (child.getDelete()) {
broker.delete(child);
it.remove();
}
}
broker.store(bean,  
ObjectModificationDefaultImpl.UPDATE);
broker.commitTransaction();
broker.close();
}

and it works.
Thanks,
Joose
26.7.2004 kello 11:36, Joose Vettenranta kirjoitti:

24.7.2004 kello 21:09, Jakob Braeuchi kirjoitti:
 hi joose,
i assume you're using pb-api now. please check the following doku:
http://db.apache.org/ojb/docu/guides/basic-technique.html#1%3An+auto- 
xxx+setting
Seems like auto-update does only INSERT or UPDATE. and auto-delete  
removes everything.

So seems like I just have to do PersistenceBroker.delete(...) to every  
deleted child to get them deleted.

Thanks,
Joose
--
"Always remember that you are unique, just like everyone else!"
* http://iki.fi/joose/ * [EMAIL PROTECTED] * +358 44 561 0270 *
-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

--
"Always remember that you are unique, just like everyone else!"
* http://iki.fi/joose/ * [EMAIL PROTECTED] * +358 44 561 0270 *
-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]


RE: how to postinitialize objects after being completely material ized

2004-07-26 Thread Charles Anthony
Sheesh - I can't even type my name properly today.

It's got to be Monday.

Cheers,

C.H.A.R.L.E.S.

> -Original Message-
> From: Charles Anthony [mailto:[EMAIL PROTECTED]
> Sent: 26 July 2004 10:05
> To: 'OJB Users List'
> Subject: RE: how to postinitialize objects after being completely
> material ized
> 
> 
> Hi David,
> 
> Another approach : if you get your persistent objects to implement
> org.apache.ojb.broker.PersistenceBrokerAware interface, you could then
> implement the afterLookup method e.g.
> 
> public void afterLookup(PersistenceBroker broker) {
>_postinit();
> };
> 
> The afterLookup method is invoked after a persistence broker loads the
> object - and, I believe, after any of the references are loaded too.
> 
> Some people would not like this approach (due to the persistency layer
> "invading" your domain objects) - I am not one of them.
> 
> HTH,
> 
> Chaeers,
> 
> > -Original Message-
> > From: David Zejda [mailto:[EMAIL PROTECTED]
> > Sent: 26 July 2004 09:59
> > To: OJB Users List
> > Subject: how to postinitialize objects after being completely
> > materialized
> > 
> > 
> > I have a custom row reader able to initialize materialized 
> objects by
> > their _postinit() methods. Essentially it works, but there is 
> > a problem
> > - the _postinit() should be called after the object is materialized
> > completely, i.e. with all fields, but also references and 
> collections
> > filled. So, I guess I have to override some other method of 
> > rowreader or
> >   something completely different - please, give a hint.
> > 
> > public class RowReaderPostinitializingImpl extends 
> > RowReaderDefaultImpl
> > {
> >  public RowReaderPostinitializingImpl(ClassDescriptor c)
> >  {
> >  super(c);
> >  }
> > 
> >  public Object readObjectFrom(Map row)
> >  {
> >  Object result = super.readObjectFrom(row);
> >  if (result instanceof Postinitializable)
> >  {
> >  Postinitializable art = (Postinitializable) result;
> >  art._postinit();
> >  return art;
> >  }
> >  else
> >  {
> >  return result;
> >  }
> >  }
> > }
> > 
> > David
> > 
> > 
> -
> > 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]
> > 
> > 
> 
> 
> ___
> HPD Software Ltd. - Helping Business Finance Business
> Email terms and conditions: www.hpdsoftware.com/disclaimer 
> 
> 
> 
> -
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 
> 


___
HPD Software Ltd. - Helping Business Finance Business
Email terms and conditions: www.hpdsoftware.com/disclaimer 



-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



RE: how to postinitialize objects after being completely material ized

2004-07-26 Thread Charles Anthony
Hi David,

Another approach : if you get your persistent objects to implement
org.apache.ojb.broker.PersistenceBrokerAware interface, you could then
implement the afterLookup method e.g.

public void afterLookup(PersistenceBroker broker) {
   _postinit();
};

The afterLookup method is invoked after a persistence broker loads the
object - and, I believe, after any of the references are loaded too.

Some people would not like this approach (due to the persistency layer
"invading" your domain objects) - I am not one of them.

HTH,

Chaeers,

> -Original Message-
> From: David Zejda [mailto:[EMAIL PROTECTED]
> Sent: 26 July 2004 09:59
> To: OJB Users List
> Subject: how to postinitialize objects after being completely
> materialized
> 
> 
> I have a custom row reader able to initialize materialized objects by
> their _postinit() methods. Essentially it works, but there is 
> a problem
> - the _postinit() should be called after the object is materialized
> completely, i.e. with all fields, but also references and collections
> filled. So, I guess I have to override some other method of 
> rowreader or
>   something completely different - please, give a hint.
> 
> public class RowReaderPostinitializingImpl extends 
> RowReaderDefaultImpl
> {
>  public RowReaderPostinitializingImpl(ClassDescriptor c)
>  {
>  super(c);
>  }
> 
>  public Object readObjectFrom(Map row)
>  {
>  Object result = super.readObjectFrom(row);
>  if (result instanceof Postinitializable)
>  {
>  Postinitializable art = (Postinitializable) result;
>  art._postinit();
>  return art;
>  }
>  else
>  {
>  return result;
>  }
>  }
> }
> 
> David
> 
> -
> 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]
> 
> 


___
HPD Software Ltd. - Helping Business Finance Business
Email terms and conditions: www.hpdsoftware.com/disclaimer 



-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



how to postinitialize objects after being completely materialized

2004-07-26 Thread David Zejda
I have a custom row reader able to initialize materialized objects by
their _postinit() methods. Essentially it works, but there is a problem
- the _postinit() should be called after the object is materialized
completely, i.e. with all fields, but also references and collections
filled. So, I guess I have to override some other method of rowreader or
 something completely different - please, give a hint.
public class RowReaderPostinitializingImpl extends RowReaderDefaultImpl
{
public RowReaderPostinitializingImpl(ClassDescriptor c)
{
super(c);
}
public Object readObjectFrom(Map row)
{
Object result = super.readObjectFrom(row);
if (result instanceof Postinitializable)
{
Postinitializable art = (Postinitializable) result;
art._postinit();
return art;
}
else
{
return result;
}
}
}
David
-
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: removing a child from 1:n

2004-07-26 Thread Joose Vettenranta
24.7.2004 kello 21:09, Jakob Braeuchi kirjoitti:
 hi joose,
i assume you're using pb-api now. please check the following doku:
http://db.apache.org/ojb/docu/guides/basic-technique.html#1%3An+auto- 
xxx+setting
Seems like auto-update does only INSERT or UPDATE. and auto-delete  
removes everything.

So seems like I just have to do PersistenceBroker.delete(...) to every  
deleted child to get them deleted.

Thanks,
Joose
--
"Always remember that you are unique, just like everyone else!"
* http://iki.fi/joose/ * [EMAIL PROTECTED] * +358 44 561 0270 *
-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]