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

📄 table.java

📁 torque服务器源代码
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
     */    public String getPackage()    {        if (pkg != null)        {            return pkg;        }        else        {            return this.getDatabase().getPackage();        }    }    /**     * Set the value of package.     *     * @param v  Value to assign to package.     */    public void setPackage(String v)    {        this.pkg = v;    }    /**     * Returns an Array containing all the columns in the table     */    public Column[] getColumns()    {        int size = columnList.size();        Column[] tbls = new Column[size];        for (int i = 0; i < size; i++)        {            tbls[i] = (Column) columnList.get(i);        }        return tbls;    }    /**     * Utility method to get the number of columns in this table     */    public int getNumColumns()    {        return columnList.size();    }    /**     * Returns an Array containing all the FKs in the table     */    public ForeignKey[] getForeignKeys()    {        int size = foreignKeys.size();        ForeignKey[] tbls = new ForeignKey[size];        for (int i = 0; i < size; i++)        {            tbls[i] = (ForeignKey) foreignKeys.get(i);        }        return tbls;    }    /**     * Returns a Collection of parameters relevant for the chosen     * id generation method.     */    public List getIdMethodParameters()    {        return idMethodParameters;    }    /**     * A name to use for creating a sequence if one is not specified.     *     * @return name of the sequence     */    public String getSequenceName()    {        String result = null;        if (getIdMethod().equals(NATIVE))        {            List idMethodParams = getIdMethodParameters();            if (idMethodParams == null)            {                result = getName() + "_SEQ";            }            else            {                result = ((IdMethodParameter) idMethodParams.get(0)).getValue();            }        }        return result;    }    /**     * Returns an Array containing all the indices in the table     *     * @return An array containing all the indices     */    public Index[] getIndices()    {        int size = indices.size();        Index[] tbls = new Index[size];        for (int i = 0; i < size; i++)        {            tbls[i] = (Index) indices.get(i);        }        return tbls;    }    /**     * Returns an Array containing all the UKs in the table     *     * @return An array containing all the UKs     */    public Unique[] getUnices()    {        int size = unices.size();        Unique[] tbls = new Unique[size];        for (int i = 0; i < size; i++)        {            tbls[i] = (Unique) unices.get(i);        }        return tbls;    }    /**     * Returns a specified column.     *     * @param name name of the column     * @return Return a Column object or null if it does not exist.     */    public Column getColumn(String name)    {        return (Column) columnsByName.get(name);    }    /**     * Returns a specified column.     *     * @param javaName java name of the column     * @return Return a Column object or null if it does not exist.     */    public Column getColumnByJavaName(String javaName)    {        return (Column) columnsByJavaName.get(javaName);    }    /**     * Return the first foreign key that includes col in it's list     * of local columns.  Eg. Foreign key (a,b,c) refrences tbl(x,y,z)     * will be returned of col is either a,b or c.     *     * @param col column name included in the key     * @return Return a Column object or null if it does not exist.     */    public ForeignKey getForeignKey(String col)    {        ForeignKey firstFK = null;        for (Iterator iter = foreignKeys.iterator(); iter.hasNext();)        {            ForeignKey key = (ForeignKey) iter.next();            if (key.getLocalColumns().contains(col))            {                if (firstFK == null)                {                    firstFK = key;                }                else                {                    //System.out.println(col+" is in multiple FKs.  This is not"                    //                   + " being handled properly.");                    //throw new IllegalStateException("Cannot call method if " +                    //    "column is referenced multiple times");                }            }        }        return firstFK;    }    /**     * Returns true if the table contains a specified column     *     * @param col the column     * @return true if the table contains the column     */    public boolean containsColumn(Column col)    {        return columnList.contains(col);    }    /**     * Returns true if the table contains a specified column     *     * @param name name of the column     * @return true if the table contains the column     */    public boolean containsColumn(String name)    {        return (getColumn(name) != null);    }    /**     * Set the parent of the table     *     * @param parent the parant database     */    public void setDatabase(Database parent)    {        tableParent = parent;    }    /**     * Get the parent of the table     *     * @return the parant database     */    public Database getDatabase()    {        return tableParent;    }    /**     * Flag to determine if code/sql gets created for this table.     * Table will be skipped, if return true.     * @return value of forReferenceOnly.     */    public boolean isForReferenceOnly()    {        return forReferenceOnly;    }    /**     * Flag to determine if code/sql gets created for this table.     * Table will be skipped, if set to true.     * @param v  Value to assign to forReferenceOnly.     */    public void setForReferenceOnly(boolean  v)    {        this.forReferenceOnly = v;    }    /**     * Returns a XML representation of this table.     *     * @return XML representation of this table     */    public String toString()    {        StringBuffer result = new StringBuffer();        result.append ("<table name=\"")              .append(name)              .append('\"');        if (javaName != null)        {            result.append(" javaName=\"")                  .append(javaName)                  .append('\"');        }        if (idMethod != null)        {            result.append(" idMethod=\"")                  .append(idMethod)                  .append('\"');        }        if (skipSql)        {            result.append(" skipSql=\"")                  .append(new Boolean(skipSql))                  .append('\"');        }        if (abstractValue)        {            result.append(" abstract=\"")                  .append(new Boolean(abstractValue))                  .append('\"');        }        if (baseClass != null)        {            result.append(" baseClass=\"")                  .append(baseClass)                  .append('\"');        }        if (basePeer != null)        {            result.append(" basePeer=\"")                  .append(basePeer)                  .append('\"');        }        result.append(">\n");        if (columnList != null)        {            for (Iterator iter = columnList.iterator(); iter.hasNext();)            {                result.append(iter.next());            }        }        if (foreignKeys != null)        {            for (Iterator iter = foreignKeys.iterator(); iter.hasNext();)            {                result.append(iter.next());            }        }        if (idMethodParameters != null)        {            Iterator iter = idMethodParameters.iterator();            while (iter.hasNext())            {                result.append(iter.next());            }        }        result.append ("</table>\n");        return result.toString();    }    /**     * Returns the collection of Columns which make up the single primary     * key for this table.     *     * @return A list of the primary key parts.     */    public List getPrimaryKey()    {        List pk = new ArrayList(columnList.size());        Iterator iter = columnList.iterator();        while (iter.hasNext())        {            Column col = (Column) iter.next();            if (col.isPrimaryKey())            {                pk.add(col);            }        }        return pk;    }    /**     * Determine whether this table has a primary key.     *     * @return Whether this table has any primary key parts.     */    public boolean hasPrimaryKey()    {        return (getPrimaryKey().size() > 0);    }    /**     * Returns all parts of the primary key, separated by commas.     *     * @return A CSV list of primary key parts.     */    public String printPrimaryKey()    {        return printList(columnList);    }    /**     * Returns the elements of the list, separated by commas.     *     * @param list a list of Columns     * @return A CSV list.     */    private String printList(List list)    {        StringBuffer result = new StringBuffer();        boolean comma = false;        for (Iterator iter = list.iterator(); iter.hasNext();)        {            Column col = (Column) iter.next();            if (col.isPrimaryKey())            {                if (comma)                {                    result.append(',');                }                else                {                    comma = true;                }                result.append(col.getName());            }        }        return result.toString();    }}

⌨️ 快捷键说明

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