001/**
002 *  '$RCSfile$'
003 *  '$Author: crawl $'
004 *  '$Date: 2012-06-13 16:44:25 +0000 (Wed, 13 Jun 2012) $'
005 *  '$Revision: 29932 $'
006 *
007 *  For Details:
008 *  http://www.kepler-project.org
009 *
010 *  Copyright (c) 2010 The Regents of the
011 *  University of California. All rights reserved. Permission is hereby granted,
012 *  without written agreement and without license or royalty fees, to use, copy,
013 *  modify, and distribute this software and its documentation for any purpose,
014 *  provided that the above copyright notice and the following two paragraphs
015 *  appear in all copies of this software. IN NO EVENT SHALL THE UNIVERSITY OF
016 *  CALIFORNIA BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL,
017 *  OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS
018 *  DOCUMENTATION, EVEN IF THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE
019 *  POSSIBILITY OF SUCH DAMAGE. THE UNIVERSITY OF CALIFORNIA SPECIFICALLY
020 *  DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
021 *  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE
022 *  SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF
023 *  CALIFORNIA HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
024 *  ENHANCEMENTS, OR MODIFICATIONS.
025 */
026
027package org.kepler.kar;
028
029import java.io.File;
030import java.sql.ResultSet;
031import java.sql.SQLException;
032import java.sql.Statement;
033import java.util.Vector;
034
035import org.kepler.objectmanager.lsid.KeplerLSID;
036
037/**
038 * This class holds the information for one row of the KARS_CACHED table.
039 * 
040 * @author Aaron Schultz
041 */
042public class KARCacheError {
043
044        private File _file;
045        private KeplerLSID _lsid;
046        private String _version;
047        private String _repoName;
048        private Vector<String> _dependencies;
049
050        public KARCacheError() {
051        }
052
053        /**
054         * Populate this object from the database. setLsid() must be called before
055         * running this method.
056         * 
057         * @param stmt
058         * @throws SQLException
059         */
060        public void populate(File karFile, Statement stmt) throws Exception {
061
062                String query = "SELECT LSID,VERSION,REPONAME,DEPENDENCIES FROM "
063                                + KARCacheManager.KAR_ERRORS_TABLE_NAME + " WHERE FILE = '"
064                                + karFile + "'";
065                ResultSet rs = stmt.executeQuery(query);
066                if (rs == null)
067                        throw new SQLException("Query Failed: " + query);
068                if (rs.next()) {
069                        String lsidStr = rs.getString(1);
070                        KeplerLSID lsid = new KeplerLSID(lsidStr);
071                        String version = rs.getString(2);
072                        String reponame = rs.getString(3);
073                        String depStr = rs.getString(4);
074                        Vector<String> deps = ModuleDependencyUtil.parseDependencyString(depStr);
075
076                        setFile(karFile);
077                        setLsid(lsid);
078                        setVersion(version);
079                        setRepoName(reponame);
080                        setDependencies(deps);
081                } else {
082                        throw new SQLException(getFile().toString() + " was not found in "
083                                        + KARCacheManager.KAR_ERRORS_TABLE_NAME);
084                }
085                rs.close();
086        }
087
088        public File getFile() {
089                return _file;
090        }
091
092        public void setFile(File karFile) {
093                _file = karFile;
094        }
095
096        /**
097         * @return the lsid
098         */
099        public KeplerLSID getLsid() {
100                return _lsid;
101        }
102
103        /**
104         * @param lsid
105         *            the lsid to set
106         */
107        public void setLsid(KeplerLSID lsid) {
108                this._lsid = lsid;
109        }
110
111        /**
112         * @return the name
113         */
114        public String getName() {
115                return getFile().getName();
116        }
117
118        /**
119         * @return the version
120         */
121        public String getVersion() {
122                return _version;
123        }
124
125        /**
126         * @param version
127         *            the version to set
128         */
129        public void setVersion(String version) {
130                this._version = version;
131        }
132
133        /**
134         * @return the repoName
135         */
136        public String getRepoName() {
137                return _repoName;
138        }
139
140        /**
141         * @param repoName
142         *            the repoName to set
143         */
144        public void setRepoName(String repoName) {
145                this._repoName = repoName;
146        }
147
148        /**
149         * @return the path
150         */
151        public File getPath() {
152                return getFile().getParentFile();
153        }
154
155        /**
156         * @return the dependencies
157         */
158        public Vector<String> getDependencies() {
159                return _dependencies;
160        }
161
162        /**
163         * @param dependencies
164         *            the dependencies to set
165         */
166        public void setDependencies(Vector<String> dependencies) {
167                this._dependencies = dependencies;
168        }
169
170        public String debugString() {
171                String s = "KARCacheError:\n";
172                s += "  lsid: " + getLsid() + "\n";
173                s += "  name: " + getName() + "\n";
174                s += "  version: " + getVersion() + "\n";
175                s += "  repoName: " + getRepoName() + "\n";
176                s += "  path: " + getPath() + "\n";
177                s += "  dependencies: " + getDependencies() + "\n";
178                return s;
179        }
180
181}