// Path: src/main/java/uk/ac/shef/dcs/oak/jate/model/DocumentImpl.java
// public class DocumentImpl implements Document{
//    private static final Logger _logger = Logger.getLogger(DocumentImpl.class);
// 
// 	protected final URL _url;
// 
//    public DocumentImpl(URL url) {
// 	   _url = url;
//    }
// 
//    public URL getUrl() {
//       return _url;
//    }
// 
//    public String getContent() {
//       String content = null;
//       try {
//          content = UtilFiles.getContent(_url).toString();
//       } catch (IOException e) {
//          _logger.error( "I/O Exception", e );
//       }
//       return content;
//    }
// 
//    public String toString() {
//       return _url.toString();
//    }
// 
//    public boolean equals(Object o) {
//       if (this == o) return true;
//       if (o == null || getClass() != o.getClass()) return false;
//       final DocumentImpl that = (DocumentImpl) o;
// 
// 	   return that.getUrl().equals(getUrl());
// 
//    }
// 
//    public int hashCode() {
//       return _url.hashCode();
//    }
// }


import org.apache.log4j.Logger;
import uk.ac.shef.dcs.oak.jate.model.Document;
import uk.ac.shef.dcs.oak.jate.model.DocumentImpl;
import java.net.MalformedURLException;
import java.net.URL;
import java.sql.*;
import java.util.HashSet;
import java.util.Set;

    public static String getTermString4TermId(int termId, Connection conn) throws SQLException {
        Statement stmt = conn.createStatement();
        ResultSet rs = stmt.executeQuery("SELECT * FROM " + DatabaseTables.TABLE_TERM_2_ID.getTableName()+ " WHERE "
                +DatabaseTables.TABLE_TERM_2_ID.getValueField()+"='" + termId + "'");
        if (rs.next()) {
            return rs.getString(1);
        }
        return null;
    }


    public static int getDocId4Doc(Document doc, Connection conn) throws SQLException {
        Statement stmt = conn.createStatement();
        ResultSet rs = stmt.executeQuery("SELECT "+DatabaseTables.TABLE_DOC_2_ID.getValueField()+
                " FROM " + DatabaseTables.TABLE_DOC_2_ID.getTableName() + " WHERE "+
                DatabaseTables.TABLE_DOC_2_ID.getPrimaryKeyField()+"='" +
                doc.getUrl().toString().replaceAll("'","\\\\'")+ "'");
        if (rs.next()) {
            return rs.getInt(1);
        }
        return -1;
    }

    public static Document getDoc4DocId(int docId, Connection conn) throws SQLException {
        Statement stmt = conn.createStatement();
        ResultSet rs = stmt.executeQuery("SELECT * FROM " + DatabaseTables.TABLE_DOC_2_ID.getTableName() + " WHERE "+
                DatabaseTables.TABLE_DOC_2_ID.getValueField()+"='" + docId + "'");
        if (rs.next()) {
            String url = rs.getString(1);
            try {

// Path: src/main/java/uk/ac/shef/dcs/oak/jate/model/DocumentImpl.java
// public class DocumentImpl implements Document{
//    private static final Logger _logger = Logger.getLogger(DocumentImpl.class);
// 
// 	protected final URL _url;
// 
//    public DocumentImpl(URL url) {
// 	   _url = url;
//    }
// 
//    public URL getUrl() {
//       return _url;
//    }
// 
//    public String getContent() {
//       String content = null;
//       try {
//          content = UtilFiles.getContent(_url).toString();
//       } catch (IOException e) {
//          _logger.error( "I/O Exception", e );
//       }
//       return content;
//    }
// 
//    public String toString() {
//       return _url.toString();
//    }
// 
//    public boolean equals(Object o) {
//       if (this == o) return true;
//       if (o == null || getClass() != o.getClass()) return false;
//       final DocumentImpl that = (DocumentImpl) o;
// 
// 	   return that.getUrl().equals(getUrl());
// 
//    }
// 
//    public int hashCode() {
//       return _url.hashCode();
//    }
// }


// Path: src/main/java/uk/ac/shef/dcs/oak/jate/io/HSQLDBUtil.java
import org.apache.log4j.Logger;
import uk.ac.shef.dcs.oak.jate.model.Document;
import uk.ac.shef.dcs.oak.jate.model.DocumentImpl;
import java.net.MalformedURLException;
import java.net.URL;
import java.sql.*;
import java.util.HashSet;
import java.util.Set;

    public static String getTermString4TermId(int termId, Connection conn) throws SQLException {
        Statement stmt = conn.createStatement();
        ResultSet rs = stmt.executeQuery("SELECT * FROM " + DatabaseTables.TABLE_TERM_2_ID.getTableName()+ " WHERE "
                +DatabaseTables.TABLE_TERM_2_ID.getValueField()+"='" + termId + "'");
        if (rs.next()) {
            return rs.getString(1);
        }
        return null;
    }


    public static int getDocId4Doc(Document doc, Connection conn) throws SQLException {
        Statement stmt = conn.createStatement();
        ResultSet rs = stmt.executeQuery("SELECT "+DatabaseTables.TABLE_DOC_2_ID.getValueField()+
                " FROM " + DatabaseTables.TABLE_DOC_2_ID.getTableName() + " WHERE "+
                DatabaseTables.TABLE_DOC_2_ID.getPrimaryKeyField()+"='" +
                doc.getUrl().toString().replaceAll("'","\\\\'")+ "'");
        if (rs.next()) {
            return rs.getInt(1);
        }
        return -1;
    }

    public static Document getDoc4DocId(int docId, Connection conn) throws SQLException {
        Statement stmt = conn.createStatement();
        ResultSet rs = stmt.executeQuery("SELECT * FROM " + DatabaseTables.TABLE_DOC_2_ID.getTableName() + " WHERE "+
                DatabaseTables.TABLE_DOC_2_ID.getValueField()+"='" + docId + "'");
        if (rs.next()) {
            String url = rs.getString(1);
            try {

                return new DocumentImpl(new URL(url));
