Thought inc.

The Dynamic O/R Mapping Company
     

CocoBase Technical Support Forums
For access to developer site with software download and doc's, please request CocoBase download and password
will be emailed to you. Response to posts will appear when answered by THOUGHT Support team.
NOTE:You must register separately with forum in order to post your questions, please click on register icon below.
Home   Frequently Asked Questions   Search   Edit your profile   Registration is free!  
Email This Page to Someone!
Show a Printable Version
CocoBase Enterprise O/R Forums > CocoBase Questions
How to insert NULL values using thought.CocoBase.CBNull
< Previous Thread     Next Thread >
Author
Thread    Post New Thread     Post A Reply
BHLossini
Member

Registered: Jun 2005
Posts: 7

Our installation is using CocoBase 4.5 tied to an Oracle 9.i database. When "updating" existing database rows for columns that allow nulls, we need to be able to physically update a field by insert a null value. My understanding is that thought.CocoBase.CBNull can be used to tell CocoBase to insert an actual NULL value vs. ignoring the column due to being null. I have a class that implement CBProp. The Java property that I am trying to set to NULL in the database is a BigDecimal. Of course I cannot simply insert a CBNull if the value for the BigDecimal is "null" due to the incompatibilities within the setter (i.e.setData(BigDecimal data) will not allow setData(CBNull)). So that's the question, how do I set a value to CBNull when a Java property is null? Any suggestions would be appreciated.

07-06-2005 11:08 AM
Click Here to See the Profile for BHLossini    Find more posts by BHLossini        Edit/Delete Message    Reply w/Quote    IP: Logged
admin
Administrator

Registered: Apr 2001
Posts: 19

That's a great question. Our Facade and Transaction objects manage this automatically if you're using those, but if you're just using the runtime you'll need to indicate this yourself.

Our EJB State Object code generation templates show a great way of doing this through the idea of using 'null indicators'. When the setPropObjectData is called it sets the original values, and then subsequent calls to setData(null) would engage a null indicator boolean. You could generate/regenerate your java class using that code template, or you could simply generate a reference class and copy/paste/merge the logic...

Does that answer your question?

THOUGHT Support

07-06-2005 11:55 AM
Click Here to See the Profile for admin    Find more posts by admin        Edit/Delete Message    Reply w/Quote    IP: Logged
BHLossini
Member

Registered: Jun 2005
Posts: 7

Yes - thanks. The actual line of code that I used was:

// Force CocoBase to insert a NULL value for this field
Object fieldValue = new CBNull();
CBFieldInfo cfi = new CBFieldInfo ();
cfi.setSearchValue (fieldValue);

//groups CBQueryInfo with the field names.
Properties fieldData = new Properties();
fieldData.put (FIELD_NAME_HERE, cfi);


This intentionally inserts "NULL" to the corresponding data base column.

04-21-2006 10:26 AM
Click Here to See the Profile for BHLossini    Find more posts by BHLossini        Edit/Delete Message    Reply w/Quote    IP: Logged
support
Super Moderator

Registered: Apr 2001
Posts: 1

It should also work when you set the property value to CBNull directly:

//groups CBQueryInfo with the field names.
Properties fieldData = new Properties();
fieldData.put (FIELD_NAME_HERE, new CBNull());

Hope this helps
THOUGHT Support

04-21-2006 01:37 PM
Click Here to See the Profile for support    Find more posts by support        Edit/Delete Message    Reply w/Quote    IP: Logged
All times are PST (US)    Post New Thread     Post A Reply
Forum Jump:
< Previous Thread     Next Thread >

Forum Rules:
Who Can Read The Forum? Any registered user or guest.
Who Can Post New Topics? Any registered user.
Who Can Post Replies? Any registered user.
Changes: Messages can be edited by their author. Messages can be deleted by their author.
Posts: HTML code is OFF. Smilies are OFF. vB code is OFF. [IMG] code is OFF.

Admin Options:
Open / Close Thread
Move Thread
Delete Thread
Edit Thread

< Contact Us - THOUGHT Inc. >

Copyright © Jelsoft Enterprises Limited 2000.
Copyright 2001 All Rights Reserved, THOUGHT Inc.