db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From to...@apache.org
Subject cvs commit: db-ojb/src/java/org/apache/ojb/broker/metadata FieldDescriptor.java
Date Mon, 18 Apr 2005 21:13:07 GMT
tomdz       2005/04/18 14:13:07

  Modified:    src/java/org/apache/ojb/broker/accesslayer/conversions
                        FieldConversion.java
               src/java/org/apache/ojb/broker/metadata FieldDescriptor.java
  Added:       src/java/org/apache/ojb/broker/accesslayer/conversions
                        FieldConversionExt.java
  Log:
  Added extended FieldConversion interface for issue OJB-24, which allows the conversion to
use information about the field itself for performing the conversion
  
  Revision  Changes    Path
  1.7       +14 -7     db-ojb/src/java/org/apache/ojb/broker/accesslayer/conversions/FieldConversion.java
  
  Index: FieldConversion.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/accesslayer/conversions/FieldConversion.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- FieldConversion.java	4 Apr 2004 23:53:32 -0000	1.6
  +++ FieldConversion.java	18 Apr 2005 21:13:07 -0000	1.7
  @@ -17,9 +17,7 @@
   
   import java.io.Serializable;
   
  -
   /**
  - *
    * FieldConversion declares a protocol for type and value 
    * conversions between persistent classes attributes and the columns
    * of the RDBMS. 
  @@ -30,14 +28,23 @@
    *
    * @author Thomas Mahler
    * @version $Id$
  - *
    */
   public interface FieldConversion extends Serializable
   {
  -	static final long serialVersionUID = 2692919097691347845L;    /** convert a Java object
to its SQL pendant, used for insert & update*/
  +	static final long serialVersionUID = 2692919097691347845L;
  +    /**
  +     * Converts a Java object to its SQL pendant, used for insert & update.
  +     * 
  +     * @param source The java object to convert to sql
  +     * @return The converted object which can be handled by the JDBC driver
  +     */
       public abstract Object javaToSql(Object source) throws ConversionException;
   
  -    /** convert a SQL value to a Java Object, used for SELECT*/
  +    /**
  +     * Convert a SQL value to a Java object, used for SELECT.
  +     * 
  +     * @param source The value as returned by the JDBC driver
  +     * @return The converted Java object
  +     */
       public abstract Object sqlToJava(Object source) throws ConversionException;
  -
   }
  
  
  
  1.1                  db-ojb/src/java/org/apache/ojb/broker/accesslayer/conversions/FieldConversionExt.java
  
  Index: FieldConversionExt.java
  ===================================================================
  package org.apache.ojb.broker.accesslayer.conversions;
  
  import org.apache.ojb.broker.metadata.FieldDescriptor;
  
  /* Copyright 2002-2004 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.
   */
  
  /**
   * An extended field conversion interface that allows the conversion to use information
   * about the field itself in order to perform the conversion.
   *  
   * @author Thomas Dudziak
   * @version $Id: FieldConversionExt.java,v 1.1 2005/04/18 21:13:07 tomdz Exp $
   */
  public interface FieldConversionExt extends FieldConversion
  {
      /**
       * Sets the field descriptor that this field conversion instance belongs to.
       * 
       * @param fieldDesc The field descriptor
       */
      public void setFieldDescriptor(FieldDescriptor fieldDesc);
  }
  
  
  
  1.38      +14 -4     db-ojb/src/java/org/apache/ojb/broker/metadata/FieldDescriptor.java
  
  Index: FieldDescriptor.java
  ===================================================================
  RCS file: /home/cvs/db-ojb/src/java/org/apache/ojb/broker/metadata/FieldDescriptor.java,v
  retrieving revision 1.37
  retrieving revision 1.38
  diff -u -r1.37 -r1.38
  --- FieldDescriptor.java	11 Aug 2004 00:41:47 -0000	1.37
  +++ FieldDescriptor.java	18 Apr 2005 21:13:07 -0000	1.38
  @@ -25,6 +25,7 @@
   import org.apache.ojb.broker.OJBRuntimeException;
   import org.apache.ojb.broker.accesslayer.conversions.FieldConversion;
   import org.apache.ojb.broker.accesslayer.conversions.FieldConversionDefaultImpl;
  +import org.apache.ojb.broker.accesslayer.conversions.FieldConversionExt;
   import org.apache.ojb.broker.util.ClassHelper;
   import org.apache.ojb.broker.util.JdbcTypesHelper;
   
  @@ -222,6 +223,11 @@
       public void setFieldConversion(FieldConversion fieldConversion)
       {
           this.fieldConversion = fieldConversion;
  +
  +        if (this.fieldConversion instanceof FieldConversionExt)
  +        {
  +            ((FieldConversionExt)fieldConversion).setFieldDescriptor(this);
  +        }
       }
   
       /**
  @@ -232,12 +238,16 @@
       {
           try
           {
  -            this.fieldConversion = (FieldConversion) ClassHelper.newInstance(fieldConversionClassName);
  +            fieldConversion = (FieldConversion)ClassHelper.newInstance(fieldConversionClassName);
  +
  +            if (fieldConversion instanceof FieldConversionExt)
  +            {
  +                ((FieldConversionExt)fieldConversion).setFieldDescriptor(this);
  +            }
           }
           catch (Exception e)
           {
  -            throw new MetadataException(
  -                    "Could not instantiate FieldConversion class using default constructor",
e);
  +            throw new MetadataException("Could not instantiate FieldConversion class using
default constructor", e);
           }
       }
   
  
  
  

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


Mime
View raw message