📄 tablemap.java
字号:
package org.apache.torque.map;/* ==================================================================== * 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.Iterator;import java.util.Hashtable;import java.util.StringTokenizer;import org.apache.commons.lang.StringUtils;import org.apache.torque.adapter.IDMethod;import org.apache.torque.oid.IdGenerator;/** * TableMap is used to model a table in a database. * * @author <a href="mailto:jmcnally@collab.net">John D. McNally</a> * @author <a href="mailto:dlr@finemaltcoding.com">Daniel Rall</a> * @version $Id: TableMap.java,v 1.13 2003/08/23 13:18:54 mpoeschl Exp $ */public class TableMap implements IDMethod, java.io.Serializable{ /** The list of valid ID generation methods. */ protected static final String[] VALID_ID_METHODS = { NATIVE, AUTO_INCREMENT, SEQUENCE, ID_BROKER, NO_ID_METHOD }; /** The columns in the table. */ private Hashtable columns; /** The database this table belongs to. */ private DatabaseMap dbMap; /** The name of the table. */ private String tableName; /** The prefix on the table name. */ private String prefix; /** The primary key generation method. */ private String primaryKeyMethod = NO_ID_METHOD; /** * Object to store information that is needed if the * for generating primary keys. */ private Object pkInfo = null; /** * Required by proxy. Not used. */ public TableMap() { } /** * Constructor. * * @param tableName The name of the table. * @param numberOfColumns The number of columns in the table. * @param containingDB A DatabaseMap that this table belongs to. */ public TableMap(String tableName, int numberOfColumns, DatabaseMap containingDB) { this.tableName = tableName; dbMap = containingDB; columns = new Hashtable((int) (1.25 * numberOfColumns) + 1); } /** * Constructor. * * @param tableName The name of the table. * @param containingDB A DatabaseMap that this table belongs to. */ public TableMap(String tableName, DatabaseMap containingDB) { this.tableName = tableName; dbMap = containingDB; columns = new Hashtable(20); } /** * Constructor. * * @param tableName The name of the table. * @param prefix The prefix for the table name (ie: SCARAB for * SCARAB_PROJECT). * @param containingDB A DatabaseMap that this table belongs to. */ public TableMap(String tableName, String prefix, DatabaseMap containingDB) { this.tableName = tableName; this.prefix = prefix; dbMap = containingDB; columns = new Hashtable(20); } /** * Does this table contain the specified column? * * @param column A ColumnMap. * @return True if the table contains the column. */ public boolean containsColumn(ColumnMap column) { return containsColumn(column.getColumnName()); } /** * Does this table contain the specified column? * * @param name A String with the name of the column. * @return True if the table contains the column. */ public boolean containsColumn(String name) { if (name.indexOf('.') > 0) { name = name.substring(name.indexOf('.') + 1); } return columns.containsKey(name); } /** * Get the DatabaseMap containing this TableMap. * * @return A DatabaseMap. */ public DatabaseMap getDatabaseMap() { return dbMap; } /** * Returns true if this tableMap contains a column with object * data. If the type of the column is not a string, a number or a * date, it is assumed that it is object data. * * @return True if map contains a column with object data. */ public boolean containsObjectColumn() { Iterator it = columns.values().iterator(); while (it.hasNext()) { Object theType = ((ColumnMap) it.next()).getType(); if (!(theType instanceof String || theType instanceof Number || theType instanceof java.util.Date)) { return true; } } return false; } /** * Get the name of the Table. * * @return A String with the name of the table. */ public String getName() { return tableName; } /** * Get table prefix name. * * @return A String with the prefix. */ public String getPrefix() { return this.prefix; } /** * Set table prefix name. * * @param prefix The prefix for the table name (ie: SCARAB for * SCARAB_PROJECT). */ public void setPrefix(String prefix) { this.prefix = prefix; } /** * Get the method used to generate primary keys for this table. * * @return A String with the method. */ public String getPrimaryKeyMethod() { return primaryKeyMethod; } /** * Get the value of idGenerator. * @return value of idGenerator. */ public IdGenerator getIdGenerator() { return getDatabaseMap().getIdGenerator(primaryKeyMethod); } /** * Get the information used to generate a primary key * * @return An Object. */ public Object getPrimaryKeyMethodInfo() { return pkInfo; } /** * Get a ColumnMap[] of the columns in this table. * * @return A ColumnMap[]. */ public ColumnMap[] getColumns() { ColumnMap[] tableColumns = new ColumnMap[columns.size()];
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -