db-torque-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mpoes...@apache.org
Subject cvs commit: db-torque/src/generator/src/java/org/apache/torque/engine/database/model Domain.java Database.java Column.java
Date Wed, 29 Oct 2003 01:19:10 GMT
mpoeschl    2003/10/28 17:19:10

  Modified:    src/generator/src/dtd database.dtd
               src/generator/src/java/org/apache/torque/engine/database/transform
                        XmlToAppData.java
               src/generator/src/java/org/apache/torque/engine/database/model
                        Database.java Column.java
  Added:       src/generator/src/java/org/apache/torque/engine/database/model
                        Domain.java
  Log:
  extend model with domain (domain defines type, size and scale for columns and can be reused
in column definitions)
  database.dtd:
    add domain element and domain attribute for column
  Column.java
    load values from Domain (if defined)
  Database.java
    add Map of Domain objects
  XmlToAppData.java
    add Domain handling
  
  Revision  Changes    Path
  1.2       +23 -3     db-torque/src/generator/src/dtd/database.dtd
  
  Index: database.dtd
  ===================================================================
  RCS file: /home/cvs/db-torque/src/generator/src/dtd/database.dtd,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- database.dtd	10 Feb 2003 13:22:37 -0000	1.1
  +++ database.dtd	29 Oct 2003 01:19:10 -0000	1.2
  @@ -31,7 +31,7 @@
                 to lowercase.
   -->
   
  -<!ELEMENT database (external-schema*, table+)>
  +<!ELEMENT database (external-schema*, domain*, table+)>
   <!ATTLIST database
     name CDATA #IMPLIED
     defaultIdMethod (idbroker|native|autoincrement|sequence|none) "none"
  @@ -48,6 +48,25 @@
     filename CDATA #REQUIRED
   >
   
  +<!ELEMENT domain EMPTY>
  +<!ATTLIST domain
  +  name CDATA #REQUIRED
  +  type
  +    (
  +          BIT  | TINYINT | SMALLINT    | INTEGER    | BIGINT    | FLOAT
  +        | REAL | NUMERIC | DECIMAL     | CHAR       | VARCHAR   | LONGVARCHAR
  +        | DATE | TIME    | TIMESTAMP   | BINARY     | VARBINARY | LONGVARBINARY
  +        | NULL | OTHER   | JAVA_OBJECT | DISTINCT   | STRUCT    | ARRAY
  +        | BLOB | CLOB    | REF         | BOOLEANINT | BOOLEANCHAR
  +        | DOUBLE
  +    ) "VARCHAR"
  +  size CDATA #IMPLIED
  +  scale CDATA #IMPLIED
  +  default CDATA #IMPLIED
  +  description CDATA #IMPLIED
  +>
  +
  +
   <!-- 
        note: the interface="true", requires that useManagers=true in the
        properties file. 
  @@ -80,6 +99,7 @@
     javaName CDATA #IMPLIED
     primaryKey (true|false) "false"
     required (true|false) "false"
  +  domain CDATA #IMPLIED
     type
       (
             BIT  | TINYINT | SMALLINT    | INTEGER    | BIGINT    | FLOAT
  @@ -88,7 +108,7 @@
           | NULL | OTHER   | JAVA_OBJECT | DISTINCT   | STRUCT    | ARRAY
           | BLOB | CLOB    | REF         | BOOLEANINT | BOOLEANCHAR
           | DOUBLE
  -    ) "VARCHAR"
  +    ) #IMPLIED 
     javaType (object|primitive) #IMPLIED
     size CDATA #IMPLIED
     default CDATA #IMPLIED
  
  
  
  1.11      +8 -1      db-torque/src/generator/src/java/org/apache/torque/engine/database/transform/XmlToAppData.java
  
  Index: XmlToAppData.java
  ===================================================================
  RCS file: /home/cvs/db-torque/src/generator/src/java/org/apache/torque/engine/database/transform/XmlToAppData.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- XmlToAppData.java	5 Oct 2003 14:14:03 -0000	1.10
  +++ XmlToAppData.java	29 Oct 2003 01:19:10 -0000	1.11
  @@ -69,6 +69,7 @@
   import org.apache.torque.engine.EngineException;
   import org.apache.torque.engine.database.model.Column;
   import org.apache.torque.engine.database.model.Database;
  +import org.apache.torque.engine.database.model.Domain;
   import org.apache.torque.engine.database.model.ForeignKey;
   import org.apache.torque.engine.database.model.Index;
   import org.apache.torque.engine.database.model.Table;
  @@ -287,6 +288,12 @@
                   parseFile(xmlFile);
                   // get the last state from the stack
                   ParseStackElement.popState(this);
  +            }
  +            else if (rawName.equals("domain"))
  +            {
  +                Domain domain = new Domain();
  +                domain.loadFromXML(attributes);
  +                database.addDomain(domain);
               }
               else if (rawName.equals("table"))
               {
  
  
  
  1.11      +12 -2     db-torque/src/generator/src/java/org/apache/torque/engine/database/model/Database.java
  
  Index: Database.java
  ===================================================================
  RCS file: /home/cvs/db-torque/src/generator/src/java/org/apache/torque/engine/database/model/Database.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- Database.java	23 Oct 2003 11:23:02 -0000	1.10
  +++ Database.java	29 Oct 2003 01:19:10 -0000	1.11
  @@ -55,15 +55,16 @@
    */
   
   import java.util.ArrayList;
  +import java.util.HashMap;
   import java.util.Hashtable;
   import java.util.Iterator;
   import java.util.List;
  +import java.util.Map;
   
   import org.apache.torque.engine.EngineException;
   import org.apache.torque.engine.database.transform.DTDResolver;
   import org.apache.torque.engine.platform.Platform;
   import org.apache.torque.engine.platform.PlatformFactory;
  -
   import org.xml.sax.Attributes;
   
   
  @@ -81,6 +82,7 @@
   {
       private String databaseType = null;
       private List tableList = new ArrayList(100);
  +    private Map domainMap = new HashMap();
       private String name;
       private String pkg;
       private String baseClass;
  @@ -352,6 +354,14 @@
           tbl.setPackage(getPackage());
       }
   
  +    public void addDomain(Domain domain) {
  +        domainMap.put(domain.getName(), domain);
  +    }
  +    
  +    public Domain getDomain(String domainName) {
  +        return (Domain) domainMap.get(domainName);
  +    }
  +    
       protected String getDatabaseType()
       {
           return databaseType;
  
  
  
  1.7       +20 -6     db-torque/src/generator/src/java/org/apache/torque/engine/database/model/Column.java
  
  Index: Column.java
  ===================================================================
  RCS file: /home/cvs/db-torque/src/generator/src/java/org/apache/torque/engine/database/model/Column.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- Column.java	9 Sep 2003 09:36:30 -0000	1.6
  +++ Column.java	29 Oct 2003 01:19:10 -0000	1.7
  @@ -80,6 +80,7 @@
    */
   public class Column
   {
  +    private static final String DEFAULT_TYPE = "VARCHAR";
       /** Logging class from commons.logging */
       private static Log log = LogFactory.getLog(Column.class);
       private String name;
  @@ -162,6 +163,17 @@
        */
       public void loadFromXML(Attributes attrib)
       {
  +        String dom = attrib.getValue("domain");
  +        if (StringUtils.isNotEmpty(dom)) {
  +            Domain domain = getTable().getDatabase().getDomain(dom);
  +            size = domain.getSize();
  +            setType(domain.getType());
  +            defaultValue = domain.getDefaultValue();
  +        } 
  +        else
  +        {
  +            setType(DEFAULT_TYPE);
  +        }
           //Name
           name = attrib.getValue("name");
   
  @@ -202,11 +214,12 @@
           isAutoIncrement = ("true".equals(autoIncrement));
   
           //Default column value.
  -        defaultValue = attrib.getValue("default");
  +        defaultValue = StringUtils.defaultString(
  +                attrib.getValue("default"), defaultValue);
   
  -        size = attrib.getValue("size");
  +        size = StringUtils.defaultString(attrib.getValue("size"), size);
   
  -        setType(attrib.getValue("type"));
  +        setType(StringUtils.defaultString(attrib.getValue("type"), torqueType));
   
           inheritanceType = attrib.getValue("inheritance");
           isInheritance = (inheritanceType != null
  @@ -214,6 +227,7 @@
   
           this.inputValidator = attrib.getValue("inputValidator");
           description = attrib.getValue("description");
  +        
       }
   
       /**
  @@ -280,7 +294,7 @@
                   log.error(e, e);
               }
           }
  -        return StringUtils.capitalise(javaName);
  +        return StringUtils.capitalize(javaName);
       }
       
       /**
  @@ -288,7 +302,7 @@
        */    
       public String getUncapitalisedJavaName()
       {
  -        return StringUtils.uncapitalise(getJavaName());
  +        return StringUtils.uncapitalize(getJavaName());
       }
   
       /**
  
  
  
  1.1                  db-torque/src/generator/src/java/org/apache/torque/engine/database/model/Domain.java
  
  Index: Domain.java
  ===================================================================
  package org.apache.torque.engine.database.model;
  
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation.  All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software itself,
   *    if and wherever such third-party acknowledgments normally appear.
   *
   * 4. The names "Apache" and "Apache Software Foundation" and
   *    "Apache Turbine" must not be used to endorse or promote products
   *    derived from this software without prior written permission. For
   *    written permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    "Apache Turbine", nor may "Apache" appear in their name, without
   *    prior written permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  
  import org.apache.commons.logging.Log;
  import org.apache.commons.logging.LogFactory;
  import org.xml.sax.Attributes;
  
  /**
   * A Class for holding data about a column used in an Application.
   *
   * @author <a href="mailto:mpoeschl@marmot.at>Martin Poeschl</a>
   * @version $Id: Domain.java,v 1.1 2003/10/29 01:19:10 mpoeschl Exp $
   */
  public class Domain
  {
      /** Logging class from commons.logging */
      private static Log log = LogFactory.getLog(Domain.class);
      private String name;
      private String description;
      private String size;
      private String scale;
      /** type as defined in schema.xml */
      private String torqueType;
      private String defaultValue;
  
      
      /**
       * Creates a new instance with a <code>null</code> name.
       */
      public Domain()
      {
          this(null);
      }
  
      /**
       * Creates a new column and set the name
       *
       * @param name column name
       */
      public Domain(String name)
      {
          this.name = name;
      }
  
      /**
       * Imports a column from an XML specification
       */
      public void loadFromXML(Attributes attrib)
      {
          //Name
          name = attrib.getValue("name");
          //Default column value.
          defaultValue = attrib.getValue("default");
          size = attrib.getValue("size");
          scale = attrib.getValue("scale");
  
          setType(attrib.getValue("type"));
  
          description = attrib.getValue("description");
      }
  
      /**
       * @return Returns the description.
       */
      public String getDescription()
      {
          return description;
      }
  
      /**
       * @param description The description to set.
       */
      public void setDescription(String description)
      {
          this.description = description;
      }
  
      /**
       * @return Returns the name.
       */
      public String getName()
      {
          return name;
      }
  
      /**
       * @param name The name to set.
       */
      public void setName(String name)
      {
          this.name = name;
      }
  
      /**
       * @return Returns the scale.
       */
      public String getScale()
      {
          return scale;
      }
  
      /**
       * @param scale The scale to set.
       */
      public void setScale(String scale)
      {
          this.scale = scale;
      }
  
      /**
       * @return Returns the size.
       */
      public String getSize()
      {
          return size;
      }
  
      /**
       * @param size The size to set.
       */
      public void setSize(String size)
      {
          this.size = size;
      }
  
      /**
       * @return Returns the torqueType.
       */
      public String getType()
      {
          return torqueType;
      }
  
      /**
       * @param torqueType The torqueType to set.
       */
      public void setType(String torqueType)
      {
          this.torqueType = torqueType;
      }
  
      /**
       * @return Returns the defaultValue.
       */
      public String getDefaultValue()
      {
          return defaultValue;
      }
  
      /**
       * @param defaultValue The defaultValue to set.
       */
      public void setDefaultValue(String defaultValue)
      {
          this.defaultValue = defaultValue;
      }
  
  }
  
  
  

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


Mime
View raw message