You are viewing a plain text version of this content. The canonical link for it is here.
Posted to ojb-dev@db.apache.org by mk...@apache.org on 2006/06/05 19:04:14 UTC
svn commit: r411859 - in /db/ojb/branches/OJB_1_0_RELEASE: ./
src/doc/forrest/src/documentation/content/xdocs/
src/doc/forrest/src/documentation/content/xdocs/docu/
src/doc/forrest/src/documentation/content/xdocs/docu/guides/
src/java/org/apache/ojb/br...
Author: mkalen
Date: Mon Jun 5 10:04:13 2006
New Revision: 411859
URL: http://svn.apache.org/viewvc?rev=411859&view=rev
Log:
[OJB-105] Pluggable "null"-definition for persistent fields.
http://issues.apache.org/jira/browse/OJB-105
Added:
db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/accesslayer/NullCheck.java (with props)
db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/accesslayer/NullCheckDefaultImpl.java (with props)
db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/accesslayer/NullCheckRelaxedImpl.java (with props)
Modified:
db/ojb/branches/OJB_1_0_RELEASE/release-notes.txt
db/ojb/branches/OJB_1_0_RELEASE/src/doc/forrest/src/documentation/content/xdocs/docu/faq.xml
db/ojb/branches/OJB_1_0_RELEASE/src/doc/forrest/src/documentation/content/xdocs/docu/guides/basic-technique.xml
db/ojb/branches/OJB_1_0_RELEASE/src/doc/forrest/src/documentation/content/xdocs/docu/guides/jdbc-types.xml
db/ojb/branches/OJB_1_0_RELEASE/src/doc/forrest/src/documentation/content/xdocs/docu/guides/repository.xml
db/ojb/branches/OJB_1_0_RELEASE/src/doc/forrest/src/documentation/content/xdocs/site.xml
db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/metadata/FieldDescriptor.java
db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/metadata/RepositoryElements.java
db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/metadata/RepositoryTags.java
db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/metadata/RepositoryXmlHandler.java
db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/util/BrokerHelper.java
Modified: db/ojb/branches/OJB_1_0_RELEASE/release-notes.txt
URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/release-notes.txt?rev=411859&r1=411858&r2=411859&view=diff
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/release-notes.txt (original)
+++ db/ojb/branches/OJB_1_0_RELEASE/release-notes.txt Mon Jun 5 10:04:13 2006
@@ -18,6 +18,8 @@
Release 1.0.5
---------------------------------------------------------------------
NEW FEATURES:
+- [OJB-105] - Pluggable "null" definition for persistent fields.
+ Restriction: no consistency checking between PK-field and fields used for referring the PK.
- Better support for attributes containing expressions ie. sum(0.9 * price * stock).
Restriction: All attributes contained in the expressions have to belong to the same table !
- Add new CGLib based PersistentField implementation. It requires JavaBeans compliant
Modified: db/ojb/branches/OJB_1_0_RELEASE/src/doc/forrest/src/documentation/content/xdocs/docu/faq.xml
URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/doc/forrest/src/documentation/content/xdocs/docu/faq.xml?rev=411859&r1=411858&r2=411859&view=diff
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/doc/forrest/src/documentation/content/xdocs/docu/faq.xml (original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/doc/forrest/src/documentation/content/xdocs/docu/faq.xml Mon Jun 5 10:04:13 2006
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
- Copyright 2002-2004 The Apache Software Foundation
+ Copyright 2002-2006 The Apache Software Foundation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
@@ -977,18 +977,24 @@
<faq id="primitiveNull">
<question>
- How does OJB manage 'null' for primitive primary key?
+ How does OJB manage 'null' for primitive key- and sequence fields?
</question>
<answer>
<p>
- Primitive values (int, long, ...) can't be <code>null</code>, so OJB interpret '0'
- as <code>null</code>
- for primitive PK/FK fields in persistent objects. Thus primitive PK fields of
- persistent objects should never be represented by a '0' value in DB and never used as a
- <a href="site:sequence-manager">sequence key</a> value.
- <br/>
- This is only true for primitive PK/FK fields (e.g. <code>Integer(0)</code> is allowed).
- All other fields have 'normal' behavior.
+ As primitive fields (int, long, ...) have no <code>null</code>-value,
+ OJB interprets '0' as <code>null</code> by default in persistent objects.
+ <br/>
+ This implies that primitive fields used as primary key, foreign key,
+ <a href="site:sequence-manager">sequence key</a>
+ or any combination thereof can never have a '0' value in the database.
+ </p>
+ <p>
+ To change the default behaviour and allow '0' as database values,
+ change the 'null-check' attribute of the
+ <a href="site:repository/field-descriptor">field-descriptor</a>
+ in the metadata repository XML-file like so:
+ <br/>
+ <code>null-check="org.apache.ojb.broker.accesslayer.NullCheckRelaxedImpl"</code>
</p>
</answer>
</faq>
Modified: db/ojb/branches/OJB_1_0_RELEASE/src/doc/forrest/src/documentation/content/xdocs/docu/guides/basic-technique.xml
URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/doc/forrest/src/documentation/content/xdocs/docu/guides/basic-technique.xml?rev=411859&r1=411858&r2=411859&view=diff
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/doc/forrest/src/documentation/content/xdocs/docu/guides/basic-technique.xml (original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/doc/forrest/src/documentation/content/xdocs/docu/guides/basic-technique.xml Mon Jun 5 10:04:13 2006
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
- Copyright 2002-2005 The Apache Software Foundation
+ Copyright 2002-2006 The Apache Software Foundation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
@@ -24,6 +24,7 @@
<person name="Thomas Mahler" email="thma@apache.org"/>
<person name="Jakob Braeuchli" email="brj@apache.org"/>
<person name="Armin Waibel" email="arminw@apache.org"/>
+ <person name="Martin Kalén" email="mkalen@apache.org"/>
</authors>
</header>
@@ -1735,9 +1736,29 @@
Say your database column contains INTEGER values but you have to
use boolean attributes in your Domain objects. You need a type and
value mapping described by a
- <a href="site:jdbc-types">FieldConversion!</a>
+ <a href="site:jdbc-types">FieldConversion</a>.
</p>
</section>
+ <section id="null-check">
+ <title>Definition of 'null' values</title>
+ <p>
+ By default OJB considers all primitive numerical fields (int, long, ...)
+ as 'null' when they contain a 0-value in Java.
+ <br/>
+ Fields that reference Java objects are considered 'null' when the object
+ reference is null, as expected.
+ </p>
+ <p>
+ If you are using a primitive field that is part of eithar a primary key,
+ foreign key or <a href="site:sequence-manager">sequence key</a> you
+ might want to change the default 'null'-definition in OJB for that
+ particular field to allow 0-values in the database. You might also define
+ your own complex definition of 'null' for a field that references a Java
+ object in your application. See the documentation of the
+ <a href="site:jdbc-types/null-check">NullCheck</a>
+ interface for details on how to do this.
+ </p>
+ </section>
</body>
</document>
Modified: db/ojb/branches/OJB_1_0_RELEASE/src/doc/forrest/src/documentation/content/xdocs/docu/guides/jdbc-types.xml
URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/doc/forrest/src/documentation/content/xdocs/docu/guides/jdbc-types.xml?rev=411859&r1=411858&r2=411859&view=diff
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/doc/forrest/src/documentation/content/xdocs/docu/guides/jdbc-types.xml (original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/doc/forrest/src/documentation/content/xdocs/docu/guides/jdbc-types.xml Mon Jun 5 10:04:13 2006
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
- Copyright 2002-2004 The Apache Software Foundation
+ Copyright 2002-2006 The Apache Software Foundation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
@@ -23,6 +23,7 @@
<authors>
<person name="Thomas Mahler" email="thma@apache.org"/>
<person name="Armin Waibel" email="arminw@apache.org"/>
+ <person name="Martin Kalén" email="mkalen@apache.org"/>
</authors>
</header>
@@ -167,7 +168,7 @@
<anchor id="field-conversion"/>
<section>
- <title>Type and Value Conversions - The <code>FieldConversion</code> Interface</title>
+ <title>Type and Value Conversions - the <code>FieldConversion</code> Interface</title>
<section>
<title>Introduction</title>
@@ -370,6 +371,160 @@
</class-descriptor>]]></source>
</section>
</section>
+
+ <section id="null-check">
+ <title>Definition of 'null' - the <code>NullCheck</code> Interface</title>
+ <p>
+ By default OJB considers all primitive numerical fields (int, long, ...)
+ as 'null' when they contain a 0-value in Java.
+ <br/>
+ Fields that reference Java objects are considered 'null' when the object
+ reference is null, as expected.
+ </p>
+ <p>
+ If you are using a primitive field that is part of eithar a primary key,
+ foreign key or <a href="site:sequence-manager">sequence key</a> you
+ might want to change the default 'null'-definition in OJB for that
+ particular field to allow 0-values in the database. You might also define
+ your own complex definition of 'null' for a field that references a Java
+ object in your application.
+ </p>
+ <p>
+ OJB allows the use of predefined or self-implemented null-definitions
+ through the <code>org.apache.ojb.broker.accesslayer.NullCheck</code>
+ interface, configured with the 'null-check' attribute of the
+ <a href="site:repository/field-descriptor">field-descriptor</a>
+ in the metadata repository XML-file.
+ </p>
+
+
+ <!--
+ TODO: Remove note and repository.xml warning when adding a future
+ consistency check implementation.
+ -->
+ <note>
+ If you change the default null-check class for a primary key field
+ in the repository file, be sure to also check the definition of fields
+ in classes referencing the current one through foreign keys.
+ See also: null-check
+ <a href="site:repository/null-check-fkcheck-warn">syntax warning</a>.
+ </note>
+
+
+ <p>
+ The <code>NullCheck</code> API defines one public method:
+ </p>
+ <source><![CDATA[
+/**
+ * Returns wether the given object value represents 'null' for the specified field.
+ * @param fld descriptor representation of the persistent field
+ * @param aValue the value to check if it represents 'null'
+ * @return true if and only if aValue represents null
+ */
+boolean representsNull(FieldDescriptor fld, Object aValue);
+ ]]></source>
+ <section id="null-check-ojb">
+ <title>Packaged Implementations</title>
+ <p>
+ There are two implementations provided in the OJB distribution.
+ </p>
+ <table>
+ <tr>
+ <th>Class</th>
+ <th>Comment</th>
+ </tr>
+ <tr>
+ <td>org.apache.ojb.broker.accesslayer.NullCheckDefaultImpl</td>
+ <td>Default implementation if the 'null-check' attribute is missing.
+ Defines 0 as null for primitive numerical fields and "" as null
+ for primary key fields.</td>
+ </tr>
+ <tr>
+ <td>org.apache.ojb.broker.accesslayer.NullCheckRelaxedImpl</td>
+ <td>No special handling of primitive fields or String values for
+ primary keys, only Java 'null' references are considered null.</td>
+ </tr>
+ </table>
+ </section>
+ <section id="null-check-custom">
+ <title>Custom Implementations</title>
+ <p>
+ To define you own definition of null for one or more persistent
+ fields, simply write a Java class that implements the
+ <code>org.apache.ojb.broker.accesslayer.NullCheck</code> interface
+ (or extends any default implementation)
+ and configure the <code>null-check</code> of the
+ <a href="site:repository/field-descriptor">field-descriptor</a>
+ with the fully qualified class name of this class.
+ </p>
+ </section>
+ <section id="null-check-custom-example">
+ <title>Custom Implementation Example</title>
+ <p>
+ In the theoretical example below, ACME corporation has a custom
+ <code>isNull</code> method in their VSJO (Very Special Java Object)
+ Java bean, that they want OJB to use for it's null-definition.
+ (The <code>VSJO.java</code> source code is not provided - exact details
+ are left to the reader's imagination...)
+ </p>
+ <p>
+ Example <code>NullCheck</code>-implementation,
+ <code>NullCheckAcmeImpl.java</code>:
+ </p>
+ <source><![CDATA[
+package com.acme.ojb;
+
+import org.apache.ojb.broker.metadata.FieldDescriptor;
+import com.acme.VSJO;
+
+/**
+ * Custom implementation of the OJB NullCheck-interface for our
+ * VSJO (Very Special Java Object).
+ * @author ACME Corporation
+ */
+public class NullCheckAcmeImpl implements NullCheck {
+
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * Returns wether the given object value represents 'null' for the specified field.
+ * <p>
+ * Null is defined as:
+ * <ul>
+ * <li>for VSJO-objects: the 'isNull'-boolean field
+ * <li>any other object: a 'null' object reference
+ * </ul>
+ * @param fld descriptor representation of the persistent field
+ * @param aValue the value to check if it represents 'null'
+ * @return true if and only if aValue represents null
+ */
+ public boolean representsNull(FieldDescriptor fld, Object aValue)
+ {
+ boolean isNull = false;
+ if (aValue instanceof VSJO)
+ {
+ VSJO vsjo = (VSJO) aValue;
+ isNull = vsjo.isNull();
+ }
+ else
+ {
+ isNull = aValue == null;
+ }
+ return isNull;
+ }
+
+}
+ ]]></source>
+ <p>
+ Example <code>repository.xml</code> configuration snippet:
+ </p>
+ <source><![CDATA[
+ <class-descriptor class="com.acme.VSJO" table="THE_DB_TABLE">
+ <field-descriptor column="ID" name="id" jdbc-type="NUMERIC" primarykey="true" null-check="com.acme.ojb.NullCheckAcmeImpl" />
+ <field-descriptor column="TEXTDATA" name="textData" jdbc-type="VARCHAR" />
+ </class-descriptor>
+ ]]></source>
+ </section>
+ </section>
</body>
</document>
-
Modified: db/ojb/branches/OJB_1_0_RELEASE/src/doc/forrest/src/documentation/content/xdocs/docu/guides/repository.xml
URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/doc/forrest/src/documentation/content/xdocs/docu/guides/repository.xml?rev=411859&r1=411858&r2=411859&view=diff
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/doc/forrest/src/documentation/content/xdocs/docu/guides/repository.xml (original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/doc/forrest/src/documentation/content/xdocs/docu/guides/repository.xml Mon Jun 5 10:04:13 2006
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="ISO-8859-15"?>
<!--
- Copyright 2002-2005 The Apache Software Foundation
+ Copyright 2002-2006 The Apache Software Foundation
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
@@ -1318,6 +1318,37 @@
<a href="site:jdbc-types/field-conversion">field conversion</a>.
</p>
<p>
+ The optional <em>null-check</em> attribute (since OJB 1.0.5) should
+ contain a fully qualified class name.
+ This class must implement the interface
+ <code>org.apache.ojb.broker.accesslayer.NullCheck</code>.
+ A NullCheck can be used to implement special requirements for
+ the definitions of a field's 'null' value as Java representation.
+ The default is <code>org.apache.ojb.broker.accesslayer.NullCheckDefaultImpl</code>
+ and an alternative, <code>org.apache.ojb.broker.accesslayer.NullCheckRelaxedImpl</code>,
+ is provided.
+ See the documentation of the <a href="site:jdbc-types/null-check">NullCheck</a>
+ interface for details on OJB-provided implementations and how to write
+ your own.
+ </p>
+
+
+ <!--
+ TODO: Remove anchor and definition in site.xml, warning and
+ jdbc-types.xml backlink when adding a future consistency check
+ implementation.
+ -->
+ <anchor id="null-check-fkcheck-warn" />
+ <warning>
+ As of OJB 1.0.5 there is no consistency checking between the 'null' check
+ implementation used for a primary key and the implementation used for any
+ foreign key field referencing the PK-field from another class.
+ A future version of OJB might throw a <code>RuntimeException</code>
+ while loading the repository if such conditions are detected.
+ </warning>
+
+
+ <p>
The <em>length</em> attribute can be used to specify a length setting if
required by the jdbc-type of the underlying database column.
</p>
@@ -1358,6 +1389,7 @@
update-lock (true | false) "true"
default-fetch (true | false) "false"
conversion CDATA #IMPLIED
+ null-check CDATA #IMPLIED
length CDATA #IMPLIED
precision CDATA #IMPLIED
scale CDATA #IMPLIED
Modified: db/ojb/branches/OJB_1_0_RELEASE/src/doc/forrest/src/documentation/content/xdocs/site.xml
URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/doc/forrest/src/documentation/content/xdocs/site.xml?rev=411859&r1=411858&r2=411859&view=diff
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/doc/forrest/src/documentation/content/xdocs/site.xml (original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/doc/forrest/src/documentation/content/xdocs/site.xml Mon Jun 5 10:04:13 2006
@@ -131,6 +131,7 @@
<jdbc-types label="JDBC Types" href="jdbc-types.html">
<jdbc-mapping href="#jdbc-mapping"/>
<field-conversion href="#field-conversion"/>
+ <null-check href="#null-check"/>
</jdbc-types>
<repository label="Repository file" href="repository.html">
<introduction href="#introduction"/>
@@ -139,6 +140,7 @@
<connection-pool href="#connection-pool"/>
<class-descriptor href="#class-descriptor"/>
<field-descriptor href="#field-descriptor"/>
+ <null-check-fkcheck-warn href="#null-check-fkcheck-warn" />
<custom-attribute href="#custom-attribute"/>
<collection-descriptor href="#collection-descriptor"/>
<reference-descriptor href="#reference-descriptor"/>
Added: db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/accesslayer/NullCheck.java
URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/accesslayer/NullCheck.java?rev=411859&view=auto
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/accesslayer/NullCheck.java (added)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/accesslayer/NullCheck.java Mon Jun 5 10:04:13 2006
@@ -0,0 +1,46 @@
+package org.apache.ojb.broker.accesslayer;
+
+/* Copyright 2002-2006 The Apache Software Foundation
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+import java.io.Serializable;
+
+import org.apache.ojb.broker.metadata.FieldDescriptor;
+
+/**
+ * Declares the protocol for checking if a persistent field's value
+ * represents a 'null' value.
+ * <p>
+ * Used (among other things) for:
+ * <ul>
+ * <li>determining if auto-numbering should grab a new sequence id
+ * <li>checking if a DELETE operation is allowed (all PK-fields must not be null)
+ * <li>checking if identity handling has enough data (all PK-fields must not be null)
+ * </ul>
+ *
+ * @version $Id$
+ * @since OJB 1.0.5
+ */
+public interface NullCheck extends Serializable {
+
+ /**
+ * Returns wether the given object value represents 'null' for the specified field.
+ * @param fld descriptor representation of the persistent field
+ * @param aValue the value to check if it represents 'null'
+ * @return true if and only if aValue represents null
+ */
+ boolean representsNull(FieldDescriptor fld, Object aValue);
+
+}
Propchange: db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/accesslayer/NullCheck.java
------------------------------------------------------------------------------
svn:keywords = Id
Added: db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/accesslayer/NullCheckDefaultImpl.java
URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/accesslayer/NullCheckDefaultImpl.java?rev=411859&view=auto
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/accesslayer/NullCheckDefaultImpl.java (added)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/accesslayer/NullCheckDefaultImpl.java Mon Jun 5 10:04:13 2006
@@ -0,0 +1,75 @@
+package org.apache.ojb.broker.accesslayer;
+
+import org.apache.ojb.broker.metadata.FieldDescriptor;
+
+/* Copyright 2002-2006 The Apache Software Foundation
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+/**
+ * Default implementation of NullCheck.
+ *
+ * @version $Id$
+ * @since OJB 1.0.5
+ * @see org.apache.ojb.broker.accesslayer.NullCheckRelaxedImpl
+ */
+public class NullCheckDefaultImpl implements NullCheck
+{
+
+ private static final long serialVersionUID = -3434296237352411888L;
+
+ /**
+ * Returns wether the given object value represents 'null' for the specified field.
+ * <p>
+ * Null is defined as:
+ * <ul>
+ * <li>given value is 'null' itself
+ * <li>given value is instance of Number with value 0 and the field-descriptor
+ * represents a primitive field
+ * <li>given value is instance of String with length 0 and the field-descriptor
+ * is a primary key
+ * </ul>
+ * @param fld descriptor representation of the persistent field
+ * @param aValue the value to check if it represents 'null'
+ * @return true if and only if aValue represents null
+ */
+ public boolean representsNull(FieldDescriptor fld, Object aValue)
+ {
+ if (aValue == null) return true;
+
+ boolean result = false;
+ if (((aValue instanceof Number) && (((Number) aValue).longValue() == 0)))
+ {
+ Class type = fld.getPersistentField().getType();
+ /*
+ AnonymousPersistentFields will *always* have a null type according to the
+ javadoc comments in AnonymousPersistentField.getType() and never represents
+ a primitve java field with value 0, thus we return always 'false' in this case.
+ (If the value object is null, the first check above return true)
+ */
+ if(type != null)
+ {
+ result = type.isPrimitive();
+ }
+ }
+ // TODO: Do we need this check?? String could be nullified, why should we assume
+ // it's 'null' on empty string?
+ else if ((aValue instanceof String) && (((String) aValue).length() == 0))
+ {
+ result = fld.isPrimaryKey();
+ }
+ return result;
+ }
+
+}
Propchange: db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/accesslayer/NullCheckDefaultImpl.java
------------------------------------------------------------------------------
svn:keywords = Id
Added: db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/accesslayer/NullCheckRelaxedImpl.java
URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/accesslayer/NullCheckRelaxedImpl.java?rev=411859&view=auto
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/accesslayer/NullCheckRelaxedImpl.java (added)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/accesslayer/NullCheckRelaxedImpl.java Mon Jun 5 10:04:13 2006
@@ -0,0 +1,47 @@
+package org.apache.ojb.broker.accesslayer;
+
+import org.apache.ojb.broker.metadata.FieldDescriptor;
+
+/* Copyright 2002-2006 The Apache Software Foundation
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+/**
+ * Implementation of NullCheck with a more relaxed definition of 'null' than
+ * {@link NullCheckDefaultImpl]}.
+ *
+ * @version $Id$
+ * @since OJB 1.0.5
+ */
+public class NullCheckRelaxedImpl implements NullCheck
+{
+
+ private static final long serialVersionUID = -2006686663775435151L;
+
+ /**
+ * Returns wether the given object value represents 'null' for the specified field.
+ * <p>
+ * Null is defined as:
+ * <ul>
+ * <li>given value is 'null' itself
+ * </ul>
+ * @param fld descriptor representation of the persistent field
+ * @param aValue the value to check if it represents 'null'
+ * @return true if and only if aValue represents null
+ */
+ public boolean representsNull(FieldDescriptor fld, Object aValue) {
+ return aValue == null;
+ }
+
+}
Propchange: db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/accesslayer/NullCheckRelaxedImpl.java
------------------------------------------------------------------------------
svn:keywords = Id
Modified: db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/metadata/FieldDescriptor.java
URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/metadata/FieldDescriptor.java?rev=411859&r1=411858&r2=411859&view=diff
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/metadata/FieldDescriptor.java (original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/metadata/FieldDescriptor.java Mon Jun 5 10:04:13 2006
@@ -1,6 +1,6 @@
package org.apache.ojb.broker.metadata;
-/* Copyright 2002-2005 The Apache Software Foundation
+/* Copyright 2002-2006 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -26,6 +26,8 @@
import org.apache.ojb.broker.OJBRuntimeException;
import org.apache.ojb.broker.accesslayer.conversions.FieldConversion;
import org.apache.ojb.broker.metadata.fieldaccess.AnonymousPersistentField;
+import org.apache.ojb.broker.accesslayer.NullCheck;
+import org.apache.ojb.broker.accesslayer.NullCheckDefaultImpl;
import org.apache.ojb.broker.util.ClassHelper;
/**
@@ -40,9 +42,9 @@
*/
public class FieldDescriptor extends AttributeDescriptorBase implements XmlCapable, Serializable
{
- private static final long serialVersionUID = 7865777758296851949L;
-
- public static final String ACCESS_ANONYMOUS = RepositoryElements.TAG_ACCESS_ANONYMOUS;
+ private static final long serialVersionUID = 8231802073685958561L;
+
+ public static final String ACCESS_ANONYMOUS = RepositoryElements.TAG_ACCESS_ANONYMOUS;
public static final String ACCESS_READONLY = RepositoryElements.TAG_ACCESS_READONLY;
public static final String ACCESS_READWRITE = RepositoryElements.TAG_ACCESS_READWRITE;
@@ -65,6 +67,7 @@
private boolean precisionSpecified = false;
private boolean lengthSpecified = false;
private FieldConversion fieldConversion = null;
+ private NullCheck nullCheck = null;
// true if field is used for optimistic locking BRJ
private boolean m_locking = false;
// if locking is true and updateLock is true then
@@ -305,6 +308,37 @@
}
}
+ /**
+ * Returns the NullCheck instance used for this field.
+ * @return NullCheck instance for this field
+ */
+ public NullCheck getNullCheck()
+ {
+ // if no explicit class is specified use the default implementation
+ if (nullCheck == null)
+ {
+ nullCheck = new NullCheckDefaultImpl();
+ }
+ return nullCheck;
+ }
+
+ /**
+ * Creates the NullCheck implementation to use for this field.
+ * @param nullCheckClassName FQCN of the NullCheck implementation to instantiate
+ */
+ public void setNullCheckClassName(String nullCheckClassName)
+ {
+ try
+ {
+ this.nullCheck = (NullCheck) ClassHelper.newInstance(nullCheckClassName);
+ }
+ catch (Exception e)
+ {
+ throw new MetadataException(
+ "Could not instantiate NullCheck class using default constructor", e);
+ }
+ }
+
public boolean isIndexed()
{
return indexed;
@@ -597,6 +631,14 @@
result.append( " " );
result.append( tags.getAttribute( FIELD_CONVERSION, getFieldConversion().getClass().getName() ) );
result.append( eol );
+ }
+
+ // NullCheck
+ if( this.getNullCheck().getClass() != NullCheckDefaultImpl.class )
+ {
+ result.append( " " );
+ result.append( tags.getAttribute( NULL_CHECK, getNullCheck().getClass().getName() ) );
+ result.append( eol );
}
// length
Modified: db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/metadata/RepositoryElements.java
URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/metadata/RepositoryElements.java?rev=411859&r1=411858&r2=411859&view=diff
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/metadata/RepositoryElements.java (original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/metadata/RepositoryElements.java Mon Jun 5 10:04:13 2006
@@ -1,6 +1,6 @@
package org.apache.ojb.broker.metadata;
-/* Copyright 2002-2005 The Apache Software Foundation
+/* Copyright 2002-2006 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -51,6 +51,7 @@
public static final int TABLE_NAME = 14;
public static final int ORDERBY = 36;
public static final int FIELD_CONVERSION = 30;
+ public static final int NULL_CHECK = 116;
public static final int ROW_READER = 32;
public static final int FIELD_DESCRIPTOR = 15;
public static final int FIELD_NAME = 16;
@@ -144,7 +145,7 @@
public static final int PROXY_PREFETCHING_LIMIT = 114;
// maintain a next id to keep track where we are
- static final int _NEXT = 116;
+ static final int _NEXT = 117;
// String constants
public static final String TAG_ACCESS = "access";
Modified: db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/metadata/RepositoryTags.java
URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/metadata/RepositoryTags.java?rev=411859&r1=411858&r2=411859&view=diff
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/metadata/RepositoryTags.java (original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/metadata/RepositoryTags.java Mon Jun 5 10:04:13 2006
@@ -80,6 +80,7 @@
table.put("table", new Integer(TABLE_NAME));
table.put("orderby", new Integer(ORDERBY));
table.put("conversion", new Integer(FIELD_CONVERSION));
+ table.put("null-check", new Integer(NULL_CHECK));
table.put("row-reader", new Integer(ROW_READER));
table.put("field-descriptor", new Integer(FIELD_DESCRIPTOR));
table.put("name", new Integer(FIELD_NAME));
Modified: db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/metadata/RepositoryXmlHandler.java
URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/metadata/RepositoryXmlHandler.java?rev=411859&r1=411858&r2=411859&view=diff
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/metadata/RepositoryXmlHandler.java (original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/metadata/RepositoryXmlHandler.java Mon Jun 5 10:04:13 2006
@@ -445,6 +445,13 @@
m_CurrentFLD.setFieldConversionClassName(fieldConversion);
}
+ String nullCheck = atts.getValue(tags.getTagById(NULL_CHECK));
+ if (isDebug) logger.debug(" " + tags.getTagById(NULL_CHECK) + ": " + nullCheck);
+ if (nullCheck != null)
+ {
+ m_CurrentFLD.setNullCheckClassName(nullCheck);
+ }
+
// set length attribute
String length = atts.getValue(tags.getTagById(LENGTH));
if (length != null)
Modified: db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/util/BrokerHelper.java
URL: http://svn.apache.org/viewvc/db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/util/BrokerHelper.java?rev=411859&r1=411858&r2=411859&view=diff
==============================================================================
--- db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/util/BrokerHelper.java (original)
+++ db/ojb/branches/OJB_1_0_RELEASE/src/java/org/apache/ojb/broker/util/BrokerHelper.java Mon Jun 5 10:04:13 2006
@@ -1,6 +1,6 @@
package org.apache.ojb.broker.util;
-/* Copyright 2002-2005 The Apache Software Foundation
+/* Copyright 2002-2006 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -292,42 +292,11 @@
}
/**
- * Decide if the given object value represents 'null'.<br/>
- *
- * - If given value is 'null' itself, true will be returned<br/>
- *
- * - If given value is instance of Number with value 0 and the field-descriptor
- * represents a primitive field, true will be returned<br/>
- *
- * - If given value is instance of String with length 0 and the field-descriptor
- * is a primary key, true will be returned<br/>
+ * Decide if the given object value represents 'null'.
*/
public boolean representsNull(FieldDescriptor fld, Object aValue)
{
- if(aValue == null) return true;
-
- boolean result = false;
- if(((aValue instanceof Number) && (((Number) aValue).longValue() == 0)))
- {
- Class type = fld.getPersistentField().getType();
- /*
- AnonymousPersistentFields will *always* have a null type according to the
- javadoc comments in AnonymousPersistentField.getType() and never represents
- a primitve java field with value 0, thus we return always 'false' in this case.
- (If the value object is null, the first check above return true)
- */
- if(type != null)
- {
- result = type.isPrimitive();
- }
- }
- // TODO: Do we need this check?? String could be nullified, why should we assume
- // it's 'null' on empty string?
- else if((aValue instanceof String) && (((String) aValue).length() == 0))
- {
- result = fld.isPrimaryKey();
- }
- return result;
+ return fld.getNullCheck().representsNull(fld, aValue);
}
/**
---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org