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

📄 tablerow.java

📁 dspace 用j2ee架构的一个数字图书馆.开源程序
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * TableRow.java * * Version: $Revision: 1.10 $ * * Date: $Date: 2005/04/20 14:22:42 $ * * Copyright (c) 2002-2005, Hewlett-Packard Company and Massachusetts * Institute of Technology.  All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are * met: * * - Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * - 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. * * - Neither the name of the Hewlett-Packard Company nor the name of the * Massachusetts Institute of Technology nor the names of their * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * ``AS IS'' AND ANY EXPRESS 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 COPYRIGHT * HOLDERS OR 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. */package org.dspace.storage.rdbms;import java.util.HashMap;import java.util.Iterator;import java.util.List;import java.util.Map;import org.dspace.core.ConfigurationManager;/** * Represents a database row. *  * @author Peter Breton * @version $Revision: 1.10 $ */public class TableRow{    /** Marker object to indicate NULLs. */    private static final Object NULL_OBJECT = new Object();    /** The name of the database table containing this row */    private String table;    /**     * A map of column names to column values. The key of the map is a String,     * the column name; the value is an Object, either an Integer, Boolean,     * Date, or String. If the value is NULL_OBJECT, then the column was NULL.     */    private Map data = new HashMap();    /**     * Constructor     *      * @param table     *            The name of the database table containing this row.     * @param columns     *            A list of column names. Each member of the List is a String.     *            After construction, the list of columns is fixed; attempting     *            to access a column not in the list will cause an     *            IllegalArgumentException to be thrown.     */    public TableRow(String table, List columns)    {        this.table = table;        nullColumns(columns);    }    /**     * Return the name of the table containing this row, or null if this row is     * not associated with a database table.     *      * @return The name of the table containing this row     */    public String getTable()    {        return table;    }    /**     * Return true if this row contains a column with this name.     *      * @param column     *            The column name (case-insensitive)     * @return True if this row contains a column with this name.     */    public boolean hasColumn(String column)    {        return data.get(canonicalize(column)) != null;    }    /**     * Return true if the column is an SQL NULL.     *      * @param column     *            The column name (case-insensitive)     * @return True if the column is an SQL NULL     */    public boolean isColumnNull(String column)    {        if (!hasColumn(column))        {            throw new IllegalArgumentException("No such column " + column);        }        return data.get(canonicalize(column)) == NULL_OBJECT;    }    /**     * Return the integer value of column.     *      * If the column's type is not an integer, or the column does not exist, an     * IllegalArgumentException is thrown.     *      * @param column     *            The column name (case-insensitive)     * @return The integer value of the column, or -1 if the column is an SQL     *         null.     */    public int getIntColumn(String column)    {        if (!hasColumn(column))        {            throw new IllegalArgumentException("No such column " + column);        }        String name = canonicalize(column);        if (isColumnNull(name))        {            return -1;        }        Object value = data.get(name);        if (value == null)        {            throw new IllegalArgumentException("Column " + column                    + " not present");        }        if (!(value instanceof Integer))        {            throw new IllegalArgumentException("Value for " + column                    + " is not an integer");        }        return ((Integer) value).intValue();    }    /**     * Return the long value of column.     *      * If the column's type is not an long, or the column does not exist, an     * IllegalArgumentException is thrown.     *      * @param column     *            The column name (case-insensitive)     * @return The long value of the column, or -1 if the column is an SQL null.     */    public long getLongColumn(String column)    {        if (!hasColumn(column))        {            throw new IllegalArgumentException("No such column " + column);        }        String name = canonicalize(column);        if (isColumnNull(name))        {            return -1;        }        Object value = data.get(name);        if (value == null)        {            throw new IllegalArgumentException("Column " + column                    + " not present");        }        if (!(value instanceof Long))        {            throw new IllegalArgumentException("Value is not an long");        }        return ((Long) value).longValue();    }    /**     * Return the String value of column.     *      * If the column's type is not a String, or the column does not exist, an     * IllegalArgumentException is thrown.     *      * @param column     *            The column name (case-insensitive)     * @return The String value of the column, or null if the column is an SQL     *         null.     */    public String getStringColumn(String column)    {        if (!hasColumn(column))        {            throw new IllegalArgumentException("No such column " + column);        }        String name = canonicalize(column);        if (isColumnNull(name))        {            return null;        }        Object value = data.get(name);        if (value == null)        {            throw new IllegalArgumentException("Column " + column                    + " not present");        }        if (!(value instanceof String))        {            throw new IllegalArgumentException("Value is not an string");        }        return (String) value;    }    /**     * Return the boolean value of column.     *      * If the column's type is not a boolean, or the column does not exist, an     * IllegalArgumentException is thrown.     *      * @param column     *            The column name (case-insensitive)     * @return The boolean value of the column, or false if the column is an SQL     *         null.     */    public boolean getBooleanColumn(String column)    {        if (!hasColumn(column))        {            throw new IllegalArgumentException("No such column " + column);        }        String name = canonicalize(column);        if (isColumnNull(name))        {            return false;        }        Object value = data.get(name);        // make sure that we tolerate integers or booleans        if (value == null)        {            throw new IllegalArgumentException("Column " + column                    + " not present");        }        if ((value instanceof Boolean))        {            return ((Boolean) value).booleanValue();        }        else if ((value instanceof Integer))        {

⌨️ 快捷键说明

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