📄 bundle.java
字号:
/* * Bundle.java * * Version: $Revision: 1.25 $ * * Date: $Date: 2006/05/26 14:16:20 $ * * 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.content;import java.io.IOException;import java.io.InputStream;import java.sql.SQLException;import java.util.ArrayList;import java.util.Iterator;import java.util.List;import java.util.ListIterator;import org.apache.log4j.Logger;import org.dspace.authorize.AuthorizeException;import org.dspace.authorize.AuthorizeManager;import org.dspace.core.Constants;import org.dspace.core.Context;import org.dspace.core.LogManager;import org.dspace.storage.rdbms.DatabaseManager;import org.dspace.storage.rdbms.TableRow;import org.dspace.storage.rdbms.TableRowIterator;/** * Class representing bundles of bitstreams stored in the DSpace system * <P> * The corresponding Bitstream objects are loaded into memory. At present, there * is no metadata associated with bundles - they are simple containers. Thus, * the <code>update</code> method doesn't do much yet. Creating, adding or * removing bitstreams has instant effect in the database. * * @author Robert Tansley * @version $Revision: 1.25 $ */public class Bundle extends DSpaceObject{ /** log4j logger */ private static Logger log = Logger.getLogger(Bundle.class); /** Our context */ private Context ourContext; /** The table row corresponding to this bundle */ private TableRow bundleRow; /** The bitstreams in this bundle */ private List bitstreams; /** * Construct a bundle object with the given table row * * @param context * the context this object exists in * @param row * the corresponding row in the table */ Bundle(Context context, TableRow row) throws SQLException { ourContext = context; bundleRow = row; bitstreams = new ArrayList(); // Get bitstreams TableRowIterator tri = DatabaseManager.queryTable( ourContext, "bitstream", "SELECT bitstream.* FROM bitstream, bundle2bitstream WHERE " + "bundle2bitstream.bitstream_id=bitstream.bitstream_id AND " + "bundle2bitstream.bundle_id= ? ", bundleRow.getIntColumn("bundle_id")); while (tri.hasNext()) { TableRow r = (TableRow) tri.next(); // First check the cache Bitstream fromCache = (Bitstream) context.fromCache( Bitstream.class, r.getIntColumn("bitstream_id")); if (fromCache != null) { bitstreams.add(fromCache); } else { bitstreams.add(new Bitstream(ourContext, r)); } } // close the TableRowIterator to free up resources tri.close(); // Cache ourselves context.cache(this, row.getIntColumn("bundle_id")); } /** * Get a bundle from the database. The bundle and bitstream metadata are all * loaded into memory. * * @param context * DSpace context object * @param id * ID of the bundle * * @return the bundle, or null if the ID is invalid. */ public static Bundle find(Context context, int id) throws SQLException { // First check the cache Bundle fromCache = (Bundle) context.fromCache(Bundle.class, id); if (fromCache != null) { return fromCache; } TableRow row = DatabaseManager.find(context, "bundle", id); if (row == null) { if (log.isDebugEnabled()) { log.debug(LogManager.getHeader(context, "find_bundle", "not_found,bundle_id=" + id)); } return null; } else { if (log.isDebugEnabled()) { log.debug(LogManager.getHeader(context, "find_bundle", "bundle_id=" + id)); } return new Bundle(context, row); } } /** * Create a new bundle, with a new ID. This method is not public, since * bundles need to be created within the context of an item. For this * reason, authorisation is also not checked; that is the responsibility of * the caller. * * @param context * DSpace context object * * @return the newly created bundle */ static Bundle create(Context context) throws SQLException { // Create a table row TableRow row = DatabaseManager.create(context, "bundle"); log.info(LogManager.getHeader(context, "create_bundle", "bundle_id=" + row.getIntColumn("bundle_id"))); return new Bundle(context, row); } /** * Get the internal identifier of this bundle * * @return the internal identifier */ public int getID() { return bundleRow.getIntColumn("bundle_id"); } /** * Get the name of the bundle * * @return name of the bundle (ORIGINAL, TEXT, THUMBNAIL) or NULL if not set */ public String getName() { return bundleRow.getStringColumn("name"); } /** * Set the name of the bundle * * @param name * string name of the bundle (ORIGINAL, TEXT, THUMBNAIL) are the * values currently used */ public void setName(String name) { bundleRow.setColumn("name", name); } /** * Get the primary bitstream ID of the bundle * * @return primary bitstream ID or -1 if not set */ public int getPrimaryBitstreamID() { return bundleRow.getIntColumn("primary_bitstream_id"); } /** * Set the primary bitstream ID of the bundle * * @param bitstreamID * int ID of primary bitstream (e.g. index html file) */ public void setPrimaryBitstreamID(int bitstreamID) { bundleRow.setColumn("primary_bitstream_id", bitstreamID); } public String getHandle() { // No Handles for bundles return null; } /** * @param name * name of the bitstream you're looking for * * @return the bitstream or null if not found */ public Bitstream getBitstreamByName(String name) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -