/** * '$RCSfile: DataManager.java,v $' * * '$Author: leinfelder $' * '$Date: 2008-02-28 23:40:53 $' * '$Revision: 1.34 $' * * For Details: http://kepler.ecoinformatics.org * * Copyright (c) 2003 The Regents of the University of California. * All rights reserved. * * Permission is hereby granted, without written agreement and without * license or royalty fees, to use, copy, modify, and distribute this * software and its documentation for any purpose, provided that the * above copyright notice and the following two paragraphs appear in * all copies of this software. * * IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY * FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN * IF THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY * OF SUCH DAMAGE. * * THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES, * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE * PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY * OF CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, * UPDATES, ENHANCEMENTS, OR MODIFICATIONS. */ package org.ecoinformatics.datamanager; import java.io.InputStream; import java.sql.Connection; import java.sql.ResultSet; import java.sql.SQLException; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.ecoinformatics.datamanager.database.ConnectionNotAvailableException; import org.ecoinformatics.datamanager.database.DatabaseAdapter; import org.ecoinformatics.datamanager.database.DatabaseConnectionPoolInterface; import org.ecoinformatics.datamanager.database.DatabaseHandler; import org.ecoinformatics.datamanager.database.HSQLAdapter; import org.ecoinformatics.datamanager.database.OracleAdapter; import org.ecoinformatics.datamanager.database.PostgresAdapter; import org.ecoinformatics.datamanager.database.Query; import org.ecoinformatics.datamanager.database.TableMonitor; import org.ecoinformatics.datamanager.database.Union; import org.ecoinformatics.datamanager.download.DownloadHandler; import org.ecoinformatics.datamanager.download.DataStorageInterface; import org.ecoinformatics.datamanager.download.EcogridEndPointInterface; import org.ecoinformatics.datamanager.parser.Attribute; import org.ecoinformatics.datamanager.parser.AttributeList; import org.ecoinformatics.datamanager.parser.DataPackage; import org.ecoinformatics.datamanager.parser.Entity; import org.ecoinformatics.datamanager.parser.generic.DataPackageParserInterface; import org.ecoinformatics.datamanager.parser.generic.Eml200DataPackageParser; import org.ecoinformatics.datamanager.quality.QualityCheck; import org.ecoinformatics.datamanager.quality.QualityReport; import org.ecoinformatics.datamanager.quality.QualityCheck.Status; /** * * The DataManager class is the controlling class for the library. It exposes * the high-level API to the calling application. * * There are six use-cases that this library supports: * * 1. Parse the metadata to get at its entities and attributes. * 2. Download a data table from a remote site, using the URL in the metadata. * 3. Load a data table into the database table cache. * 4. Query a data table with a SQL select statement. * 5. Set an upper limit on the size of the database table cache. * 6. Set an expiration policy on a table in the database table cache. * */ public class DataManager { /* * Class fields */ public static Log log = LogFactory.getLog(DataManager.class); /* Holds the singleton object for this class */ private static DataManager dataManager = null; private static String databaseAdapterName = null; private static DatabaseConnectionPoolInterface connectionPool = null; // Constants private static final String BLANKSTR = ""; private static final int MAXIMUM_NUMBER_TO_ACCESS_CONNECTIONPOOL = 10; private static final int SLEEP_TIME = 2000; /* * Constructors */ /* * This is singleton class, so constructor is private */ private DataManager(DatabaseConnectionPoolInterface connectionPool, String databaseAdapterName) { DataManager.connectionPool = connectionPool; DataManager.databaseAdapterName = databaseAdapterName; } /* * Class methods */ /** * Gets the singleton instance of this class. * * @return the single instance of the DataManager class. */ static public DataManager getInstance( DatabaseConnectionPoolInterface connectionPool, String databaseAdapterName) { if (dataManager == null) { dataManager = new DataManager(connectionPool, databaseAdapterName); } else if (DataManager.databaseAdapterName != null && !DataManager.databaseAdapterName.equals(databaseAdapterName) ) { dataManager = new DataManager(connectionPool, databaseAdapterName); } return dataManager; } /* * Gets DBConnection from connection pool. If no connection available, it will * sleep and try again. If ceiling times reachs, null will return. * */ public static Connection getConnection() throws SQLException { Connection connection = null; int index = 0; if (connectionPool == null) { throw new SQLException("The Connection Pool is null"); } while (index