You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jetspeed-dev@portals.apache.org by Barnhill William <ba...@bah.com> on 2003/12/04 15:27:06 UTC

Re: [J2] BasePersistentObjectFactory createInstance behavior

I'm trying to both wrap my head around Cornerstone and fill a need by 
creating an Open Source voting application and a portlet to go with it. 
I've set up my database and a simple test app based on 
DemoPersistence.java.  The db has no users and I tried to 
createInstance(new Integer(101)), thinking it would create a new record 
in the db.  Apparently retrieveAndPopulate, which createInstance calls, 
just returns null if the query returns and empty recordset.  After doing 
walkabout in the code I discovered the following inheritance tree:
BasePersistentObjectFactory
    which extends BasePersistenceFactory  (implements IPersistenceFactory),
        which extends InversionOfControlFactory,
             which extends BaseFactory

Seeing that store(Object) in BasePersistentObjectFactory first calls 
createInstance(), I tracked createInstance() to the IoC factory.
To make a long story short, and sum up the behavior:
a. createInstance(param) - retreives the instance data from the database
b. createInstance() - creates a fresh new instance
c.  inst = createInstance(), set properties, store(inst) create a fresh 
new instance and stores it in the db

This may be old hat for many folks, but for anyone trying to get a 
handle on creating their own persistent object this may be useful.

Bill Barnhill



---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jetspeed-dev-help@jakarta.apache.org


Re: [J2] BasePersistentObjectFactory createInstance behavior

Posted by Barnhill William <ba...@bah.com>.
Jun Yang wrote:

> You need to use java.sql.Timestamp as the type for the property of the 
> bean.  Database to Java type mapping is done by the JDBC driver.  
> Cornerstone is not involved in that.  There are some differences 
> between JDBC drivers.  For example, Oracle maps INT to BigDecimal 
> while Hsqldb maps it to Integer.

Thanks, I suspect that will fix the problem as I found something similar 
in a web search,

> Wonderful!  Thanks again!  Refer to 
> cornerstone-demo/hsqldb/data/*.{sql,bat} for how we set up Hsqldb and 
> query it.
>
Yes, that is what I referred to in creating the database. I created my 
own create.sql to create the db



---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jetspeed-dev-help@jakarta.apache.org


Re: [J2] BasePersistentObjectFactory createInstance behavior

Posted by Jun Yang <ju...@cisco.com>.
Barnhill William wrote:

> You welcome by all means.
> I've gotten to the point of
>    Caused by: java.sql.SQLException:
>        Wrong data type in statement
>             [insert into users (user_name, user_description, 
> registration_date) VALUES ('dummy','A dummy user','000000f94218f84e78')]

You need to use java.sql.Timestamp as the type for the property of the 
bean.  Database to Java type mapping is done by the JDBC driver.  
Cornerstone is not involved in that.  There are some differences between 
JDBC drivers.  For example, Oracle maps INT to BigDecimal while Hsqldb 
maps it to Integer.

> Looks like it's because I'm trying to store a java.util.Date into an 
> SQL Date and it can't handle it. Is this correct?
>
> I could get around it by storing datestamp as string or ticks as long 
> int, but I'd rather store it as a SQL Date. Have you or anyone else 
> done this?
>
> Btw, I will write a tutorial titled "Prevailing with Cornerstone 
> persistence" that walks someone through
>    1. Setup of  HSQL db
>    2. Setup of .reg files
>    3. Creating project dir structure
>    4. Where to put your interface files and naming conventions
>    5. Creating your classes
>    6. Creating a demo app that if supplied arguments created a new 
> object with those props, otherwise dumps objects
> once I am done

Wonderful!  Thanks again!  Refer to 
cornerstone-demo/hsqldb/data/*.{sql,bat} for how we set up Hsqldb and 
query it.

> Bill

Jun

>
> Jun Yang wrote:
>
>> Yes, Bill, your discovery is all correct.  I am very sorry that you 
>> have to a detective to use it right now :).  We just haven't had the 
>> time to document it much yet.  I hope you (or anybody interested) can 
>> help with that too :).  Thanks for your effort!
>>
>> Jun
>>
>> Barnhill William wrote:
>>
>>> More on this..
>>> Your class that you are trying to persist must follow std JavaBeans 
>>> practice of a null-arg constructor and a query.insert config 
>>> property must be present.
>>>
>>>
>>> Barnhill William wrote:
>>>
>>>>
>>>> I'm trying to both wrap my head around Cornerstone and fill a need 
>>>> by creating an Open Source voting application and a portlet to go 
>>>> with it. I've set up my database and a simple test app based on 
>>>> DemoPersistence.java.  The db has no users and I tried to 
>>>> createInstance(new Integer(101)), thinking it would create a new 
>>>> record in the db.  Apparently retrieveAndPopulate, which 
>>>> createInstance calls, just returns null if the query returns and 
>>>> empty recordset.  After doing walkabout in the code I discovered 
>>>> the following inheritance tree:
>>>> BasePersistentObjectFactory
>>>>    which extends BasePersistenceFactory  (implements 
>>>> IPersistenceFactory),
>>>>        which extends InversionOfControlFactory,
>>>>             which extends BaseFactory
>>>>
>>>> Seeing that store(Object) in BasePersistentObjectFactory first 
>>>> calls createInstance(), I tracked createInstance() to the IoC factory.
>>>> To make a long story short, and sum up the behavior:
>>>> a. createInstance(param) - retreives the instance data from the 
>>>> database
>>>> b. createInstance() - creates a fresh new instance
>>>> c.  inst = createInstance(), set properties, store(inst) create a 
>>>> fresh new instance and stores it in the db
>>>>
>>>> This may be old hat for many folks, but for anyone trying to get a 
>>>> handle on creating their own persistent object this may be useful.
>>>>
>>>> Bill Barnhill
>>>


---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jetspeed-dev-help@jakarta.apache.org


Re: [J2] BasePersistentObjectFactory createInstance behavior

Posted by Barnhill William <ba...@bah.com>.
You welcome by all means.
I've gotten to the point of
    Caused by: java.sql.SQLException:
        Wrong data type in statement
             [insert into users (user_name, user_description, 
registration_date) VALUES ('dummy','A dummy user','000000f94218f84e78')]

Looks like it's because I'm trying to store a java.util.Date into an SQL 
Date and it can't handle it. Is this correct?

I could get around it by storing datestamp as string or ticks as long 
int, but I'd rather store it as a SQL Date. 
Have you or anyone else done this?

Btw, I will write a tutorial titled "Prevailing with Cornerstone 
persistence" that walks someone through
    1. Setup of  HSQL db
    2. Setup of .reg files
    3. Creating project dir structure
    4. Where to put your interface files and naming conventions
    5. Creating your classes
    6. Creating a demo app that if supplied arguments created a new 
object with those props, otherwise dumps objects
once I am done

Bill


Jun Yang wrote:

> Yes, Bill, your discovery is all correct.  I am very sorry that you 
> have to a detective to use it right now :).  We just haven't had the 
> time to document it much yet.  I hope you (or anybody interested) can 
> help with that too :).  Thanks for your effort!
>
> Jun
>
> Barnhill William wrote:
>
>> More on this..
>> Your class that you are trying to persist must follow std JavaBeans 
>> practice of a null-arg constructor and a query.insert config property 
>> must be present.
>>
>>
>> Barnhill William wrote:
>>
>>>
>>> I'm trying to both wrap my head around Cornerstone and fill a need 
>>> by creating an Open Source voting application and a portlet to go 
>>> with it. I've set up my database and a simple test app based on 
>>> DemoPersistence.java.  The db has no users and I tried to 
>>> createInstance(new Integer(101)), thinking it would create a new 
>>> record in the db.  Apparently retrieveAndPopulate, which 
>>> createInstance calls, just returns null if the query returns and 
>>> empty recordset.  After doing walkabout in the code I discovered the 
>>> following inheritance tree:
>>> BasePersistentObjectFactory
>>>    which extends BasePersistenceFactory  (implements 
>>> IPersistenceFactory),
>>>        which extends InversionOfControlFactory,
>>>             which extends BaseFactory
>>>
>>> Seeing that store(Object) in BasePersistentObjectFactory first calls 
>>> createInstance(), I tracked createInstance() to the IoC factory.
>>> To make a long story short, and sum up the behavior:
>>> a. createInstance(param) - retreives the instance data from the 
>>> database
>>> b. createInstance() - creates a fresh new instance
>>> c.  inst = createInstance(), set properties, store(inst) create a 
>>> fresh new instance and stores it in the db
>>>
>>> This may be old hat for many folks, but for anyone trying to get a 
>>> handle on creating their own persistent object this may be useful.
>>>
>>> Bill Barnhill 
>>
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: jetspeed-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: jetspeed-dev-help@jakarta.apache.org
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jetspeed-dev-help@jakarta.apache.org


Re: [J2] BasePersistentObjectFactory createInstance behavior

Posted by Jun Yang <ju...@cisco.com>.
Yes, Bill, your discovery is all correct.  I am very sorry that you have 
to a detective to use it right now :).  We just haven't had the time to 
document it much yet.  I hope you (or anybody interested) can help with 
that too :).  Thanks for your effort!

Jun

Barnhill William wrote:

> More on this..
> Your class that you are trying to persist must follow std JavaBeans 
> practice of a null-arg constructor and a query.insert config property 
> must be present.
>
>
> Barnhill William wrote:
>
>>
>> I'm trying to both wrap my head around Cornerstone and fill a need by 
>> creating an Open Source voting application and a portlet to go with 
>> it. I've set up my database and a simple test app based on 
>> DemoPersistence.java.  The db has no users and I tried to 
>> createInstance(new Integer(101)), thinking it would create a new 
>> record in the db.  Apparently retrieveAndPopulate, which 
>> createInstance calls, just returns null if the query returns and 
>> empty recordset.  After doing walkabout in the code I discovered the 
>> following inheritance tree:
>> BasePersistentObjectFactory
>>    which extends BasePersistenceFactory  (implements 
>> IPersistenceFactory),
>>        which extends InversionOfControlFactory,
>>             which extends BaseFactory
>>
>> Seeing that store(Object) in BasePersistentObjectFactory first calls 
>> createInstance(), I tracked createInstance() to the IoC factory.
>> To make a long story short, and sum up the behavior:
>> a. createInstance(param) - retreives the instance data from the database
>> b. createInstance() - creates a fresh new instance
>> c.  inst = createInstance(), set properties, store(inst) create a 
>> fresh new instance and stores it in the db
>>
>> This may be old hat for many folks, but for anyone trying to get a 
>> handle on creating their own persistent object this may be useful.
>>
>> Bill Barnhill 
>


---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jetspeed-dev-help@jakarta.apache.org


Re: [J2] BasePersistentObjectFactory createInstance behavior

Posted by Barnhill William <ba...@bah.com>.
More on this..
Your class that you are trying to persist must follow std JavaBeans 
practice of a null-arg constructor and a query.insert config property 
must be present.


Barnhill William wrote:

>
> I'm trying to both wrap my head around Cornerstone and fill a need by 
> creating an Open Source voting application and a portlet to go with 
> it. I've set up my database and a simple test app based on 
> DemoPersistence.java.  The db has no users and I tried to 
> createInstance(new Integer(101)), thinking it would create a new 
> record in the db.  Apparently retrieveAndPopulate, which 
> createInstance calls, just returns null if the query returns and empty 
> recordset.  After doing walkabout in the code I discovered the 
> following inheritance tree:
> BasePersistentObjectFactory
>    which extends BasePersistenceFactory  (implements 
> IPersistenceFactory),
>        which extends InversionOfControlFactory,
>             which extends BaseFactory
>
> Seeing that store(Object) in BasePersistentObjectFactory first calls 
> createInstance(), I tracked createInstance() to the IoC factory.
> To make a long story short, and sum up the behavior:
> a. createInstance(param) - retreives the instance data from the database
> b. createInstance() - creates a fresh new instance
> c.  inst = createInstance(), set properties, store(inst) create a 
> fresh new instance and stores it in the db
>
> This may be old hat for many folks, but for anyone trying to get a 
> handle on creating their own persistent object this may be useful.
>
> Bill Barnhill
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: jetspeed-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: jetspeed-dev-help@jakarta.apache.org
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jetspeed-dev-help@jakarta.apache.org


Re: [J2] BasePersistentObjectFactory createInstance behavior

Posted by Jun Yang <ju...@cisco.com>.
Yes, Bill, this is exactly the behavior of BasePersistentObjectFactory:

- createInstance(id) retrieves an object from database
- createInstance() creates a fresh instance (with null id property)
- store(object) stores it (does insert if id is null or update otherwise)

Jun

Barnhill William wrote:

>
> I'm trying to both wrap my head around Cornerstone and fill a need by 
> creating an Open Source voting application and a portlet to go with 
> it. I've set up my database and a simple test app based on 
> DemoPersistence.java.  The db has no users and I tried to 
> createInstance(new Integer(101)), thinking it would create a new 
> record in the db.  Apparently retrieveAndPopulate, which 
> createInstance calls, just returns null if the query returns and empty 
> recordset.  After doing walkabout in the code I discovered the 
> following inheritance tree:
> BasePersistentObjectFactory
>    which extends BasePersistenceFactory  (implements 
> IPersistenceFactory),
>        which extends InversionOfControlFactory,
>             which extends BaseFactory
>
> Seeing that store(Object) in BasePersistentObjectFactory first calls 
> createInstance(), I tracked createInstance() to the IoC factory.
> To make a long story short, and sum up the behavior:
> a. createInstance(param) - retreives the instance data from the database
> b. createInstance() - creates a fresh new instance
> c.  inst = createInstance(), set properties, store(inst) create a 
> fresh new instance and stores it in the db
>
> This may be old hat for many folks, but for anyone trying to get a 
> handle on creating their own persistent object this may be useful.
>
> Bill Barnhill 



---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jetspeed-dev-help@jakarta.apache.org