/** * '$Author: leinfelder $' * '$Date: 2012-10-16 20:50:03 +0000 (Tue, 16 Oct 2012) $' * '$Revision: 7403 $' * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ package edu.ucsb.nceas.metacat; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.util.Vector; import org.apache.log4j.Logger; import edu.ucsb.nceas.metacat.database.DBConnection; import edu.ucsb.nceas.metacat.database.DBConnectionPool; import edu.ucsb.nceas.metacat.properties.PropertyService; import edu.ucsb.nceas.metacat.util.DocumentUtil; import edu.ucsb.nceas.metacat.util.MetacatUtil; import edu.ucsb.nceas.utilities.PropertyNotFoundException; import edu.ucsb.nceas.utilities.triple.Triple; import edu.ucsb.nceas.utilities.triple.TripleCollection; public class RelationHandler //implements Runnable { private DBConnection connection = null; private String docid = null; private String docType = null; private static Logger logMetacat = Logger.getLogger(RelationHandler.class); TripleCollection tripleForPackage = null; /** * Constructor for this class. finds all of the relations to a single xml * document and writes them to the database. This includes transitive * relations. * @param docid the ID of the XML document to index. * @param doctype the doctype of this document * @param conn the db connection * @param list the triple list */ public RelationHandler(String docid, String doctype, DBConnection conn, TripleCollection list) throws McdbException, SQLException, AccessionNumberException { this.connection = conn; this.docid = docid; this.docType = doctype; tripleForPackage = list; createRelations(); } /** * insert the relations specified in the triples into xml_relation table */ private void createRelations() throws McdbException, SQLException, AccessionNumberException { String packagetype = docType; String subject = null; String subjectParentId = null; String subDoctype = null; String relationship = null; String relationshipParentId = null; String object = null; String objDoctype = null; PreparedStatement tstmt = null; // to insert each relation into xml_relation logMetacat.info("Running relation handler!"); // first delete the relations for this package document if any deleteRelations(docid); //get the vetor of triples Vector tripleList= new Vector(); //get vector form tripleCollection if (tripleForPackage != null) { tripleList =tripleForPackage.getCollection(); } if (tripleList != null && tripleList.size()>0) { tstmt = connection.prepareStatement("INSERT INTO xml_relation (" + "docid,packagetype,subject,subdoctype," + "relationship, object, objdoctype) " + "VALUES (?, ?, ?, ?, ?, ?, ?)"); // go through tripe list for (int i= 0; i