⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 column.java

📁 一个数据访问层Torque3.1的生成器的源代码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
package org.apache.torque.engine.database.model;/* ==================================================================== * The Apache Software License, Version 1.1 * * Copyright (c) 2001-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 java.util.ArrayList;import java.util.Date;import java.util.Hashtable;import java.util.List;import org.apache.commons.lang.StringUtils;import org.apache.commons.logging.Log;import org.apache.commons.logging.LogFactory;import org.apache.torque.engine.EngineException;import org.xml.sax.Attributes;/** * A Class for holding data about a column used in an Application. * * @author <a href="mailto:leon@opticode.co.za">Leon Messerschmidt</a> * @author <a href="mailto:jvanzyl@apache.org">Jason van Zyl</a> * @author <a href="mailto:jon@latchkey.com">Jon S. Stevens</a> * @author <a href="mailto:dlr@finemaltcoding.com">Daniel Rall</a> * @author <a href="mailto:byron_foster@byron_foster@yahoo.com>Byron Foster</a> * @version $Id: Column.java,v 1.5 2003/08/08 09:15:12 mpoeschl Exp $ */public class Column{    /** Logging class from commons.logging */    private static Log log = LogFactory.getLog(Column.class);    private String name;    private String description;    private String javaName = null;    private String javaNamingMethod;    private boolean isNotNull = false;    private String size;    /** type as defined in schema.xml */    private String torqueType;    private String javaType;    private Object columnType;    private Table parentTable;    private int position;    private boolean isPrimaryKey = false;    private boolean isUnique = false;    private boolean isAutoIncrement = false;    private String defaultValue;    private List referrers;    // only one type is supported currently, which assumes the    // column either contains the classnames or a key to    // classnames specified in the schema.  Others may be    // supported later.    private String inheritanceType;    private boolean isInheritance;    private boolean isEnumeratedClasses;    private List inheritanceList;    private boolean needsTransactionInPostgres;    /** class name to do input validation on this column */    private String inputValidator = null;    /**     * Creates a new instance with a <code>null</code> name.     */    public Column()    {        this(null);    }    /**     * Creates a new column and set the name     *     * @param name column name     */    public Column(String name)    {        this.name = name;    }    /**     * Return a comma delimited string listing the specified columns.     *     * @param columns Either a list of <code>Column</code> objects, or     * a list of <code>String</code> objects with column names.     */    public static String makeList(List columns)    {        Object obj = columns.get(0);        boolean isColumnList = (obj instanceof Column);        if (isColumnList)        {            obj = ((Column) obj).getName();        }        StringBuffer buf = new StringBuffer((String) obj);        for (int i = 1; i < columns.size(); i++)        {            obj = columns.get(i);            if (isColumnList)            {                obj = ((Column) obj).getName();            }            buf.append(", ").append(obj);        }        return buf.toString();    }    /**     * Imports a column from an XML specification     */    public void loadFromXML(Attributes attrib)    {        //Name        name = attrib.getValue("name");        javaName = attrib.getValue("javaName");        javaType = attrib.getValue("javaType");        if (javaType != null && javaType.length() == 0)        {            javaType = null;        }        // retrieves the method for converting from specified name to        // a java name.        javaNamingMethod = attrib.getValue("javaNamingMethod");        if (javaNamingMethod == null)        {            javaNamingMethod                    = parentTable.getDatabase().getDefaultJavaNamingMethod();        }        //Primary Key        String primaryKey = attrib.getValue("primaryKey");        //Avoid NullPointerExceptions on string comparisons.        isPrimaryKey = ("true".equals (primaryKey));        // If this column is a primary key then it can't be null.        if ("true".equals (primaryKey))        {            isNotNull = true;        }        // HELP: Should primary key, index, and/or idMethod="native"        // affect isNotNull?  If not, please document why here.        String notNull = attrib.getValue("required");        isNotNull = (notNull != null && "true".equals(notNull));        //AutoIncrement/Sequences        String autoIncrement = attrib.getValue("autoIncrement");        isAutoIncrement = ("true".equals(autoIncrement));        //Default column value.        defaultValue = attrib.getValue("default");        size = attrib.getValue("size");        setType(attrib.getValue("type"));        inheritanceType = attrib.getValue("inheritance");        isInheritance = (inheritanceType != null                && !inheritanceType.equals("false"));        this.inputValidator = attrib.getValue("inputValidator");        description = attrib.getValue("description");    }    /**     * Returns table.column     */    public String getFullyQualifiedName()    {        return (parentTable.getName() + '.' + name);    }    /**     * Get the name of the column     */    public String getName()    {        return name;    }    /**     * Set the name of the column     */    public void setName(String newName)    {        name = newName;    }    /**     * Get the description for the Table     */    public String getDescription()    {        return description;    }    /**     * Set the description for the Table     *     * @param newDescription description for the Table     */    public void setDescription(String newDescription)    {        description = newDescription;    }    /**     * Get name to use in Java sources to build method names.     *      * @return the capitalised javaName     */    public String getJavaName()    {        if (javaName == null)        {            List inputs = new ArrayList(2);            inputs.add(name);            inputs.add(javaNamingMethod);            try            {                javaName = NameFactory.generateName(NameFactory.JAVA_GENERATOR,                                                    inputs);            }            catch (EngineException e)            {                log.error(e, e);            }        }        return StringUtils.capitalise(javaName);    }        /**     * Get variable name to use in Java sources (= uncapitalised java name)     */        public String getUncapitalisedJavaName()    {        return StringUtils.uncapitalise(getJavaName());    }    /**     * Set name to use in Java sources     */    public void setJavaName(String javaName)    {        this.javaName = javaName;    }    /**     * Get type to use in Java sources     */    public String getJavaType()    {        return javaType;    }    /**     * Get the location of this column within the table (one-based).     * @return value of position.     */    public int getPosition()    {        return position;    }    /**     * Get the location of this column within the table (one-based).     * @param v  Value to assign to position.     */    public void setPosition(int  v)    {        this.position = v;    }    /**     * Set the parent Table of the column     */    public void setTable(Table parent)    {        parentTable = parent;    }    /**     * Get the parent Table of the column     */    public Table getTable()    {        return parentTable;    }    /**     * Returns the Name of the table the column is in     */    public String getTableName()    {        return parentTable.getName();    }    /**     * A utility function to create a new column     * from attrib and add it to this table.     */    public Inheritance addInheritance(Attributes attrib)    {        Inheritance inh = new Inheritance();        inh.loadFromXML (attrib);        addInheritance(inh);        return inh;    }    /**     * Adds a new inheritance definition to the inheritance list and set the     * parent column of the inheritance to the current column     */    public void addInheritance(Inheritance inh)    {        inh.setColumn(this);        if (inheritanceList == null)        {            inheritanceList = new ArrayList();            isEnumeratedClasses = true;        }        inheritanceList.add(inh);    }    /**     * Get the inheritance definitions.     */    public List getChildren()    {        return inheritanceList;    }    /**     * Determine if this column is a normal property or specifies a     * the classes that are represented in the table containing this column.     */    public boolean isInheritance()    {        return isInheritance;    }    /**     * Determine if possible classes have been enumerated in the xml file.     */    public boolean isEnumeratedClasses()    {        return isEnumeratedClasses;    }    /**     * Return the isNotNull property of the column     */    public boolean isNotNull()    {        return isNotNull;    }    /**     * Set the isNotNull property of the column     */    public void setNotNull(boolean status)    {        isNotNull = status;    }    /**     * Set if the column is a primary key or not     */    public void setPrimaryKey(boolean pk)    {        isPrimaryKey = pk;    }    /**     * Return true if the column is a primary key     */    public boolean isPrimaryKey()    {        return isPrimaryKey;    }    /**     * Set true if the column is UNIQUE     */    public void setUnique (boolean u)    {        isUnique = u;    }    /**     * Get the UNIQUE property     */    public boolean isUnique()    {        return isUnique;    }    /**     * Return true if the column requires a transaction in Postgres     */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -