diff --git a/src/fr/inrialpes/exmo/align/service/Cache.java b/src/fr/inrialpes/exmo/align/service/Cache.java new file mode 100644 index 0000000000000000000000000000000000000000..7b9fae83a98aa2788e176954169e06ad87c27b20 --- /dev/null +++ b/src/fr/inrialpes/exmo/align/service/Cache.java @@ -0,0 +1,12 @@ +package fr.inrialpes.exmo.align.service; + +import java.net.URI; +import java.util.Enumeration; +import org.semanticweb.owl.align.Alignment; + +public interface Cache { + int put(long id, URI uri1, URI uri2, Alignment alignmnet); + Alignment get(long id); + Enumeration get(URI uri); + Enumeration get(URI uri1, URI uri2); +} diff --git a/src/fr/inrialpes/exmo/align/service/CacheImpl.java b/src/fr/inrialpes/exmo/align/service/CacheImpl.java new file mode 100644 index 0000000000000000000000000000000000000000..35633b9c36c76efa249a48bcf8032110d4fc68d2 --- /dev/null +++ b/src/fr/inrialpes/exmo/align/service/CacheImpl.java @@ -0,0 +1,40 @@ +package fr.inrialpes.exmo.align.service; + +import java.net.URI; +import java.sql.ResultSet; +import java.util.Enumeration; +import java.util.Hashtable; +import java.util.Vector; + +import org.semanticweb.owl.align.Alignment; + +public class CacheImpl implements Cache { + Hashtable alignmentTable = null; + + + public CacheImpl() { + + } + + private Hashtable loadAll(boolean force){ + Hashtable result = null; + return result; + } + + public int put(long id, URI uri1, URI uri2, Alignment alignmnet) { + + return 0; + } + public Alignment get(long id) { + Alignment result = null; + return result; + } + public Enumeration get(URI uri) { + Enumeration result = null; + return result; + } + public Enumeration get(URI uri1, URI uri2) { + Enumeration result = null; + return result; + } +} diff --git a/src/fr/inrialpes/exmo/align/service/DBService.java b/src/fr/inrialpes/exmo/align/service/DBService.java index 45cd92627c52b92deca4ddce139af44cebf4c114..8740c299abda5468b309a8ed57cfc950733e9898 100644 --- a/src/fr/inrialpes/exmo/align/service/DBService.java +++ b/src/fr/inrialpes/exmo/align/service/DBService.java @@ -19,13 +19,18 @@ */ package fr.inrialpes.exmo.align.service; + +import java.net.URI; +import java.util.Enumeration; import org.semanticweb.owl.align.Alignment; + public interface DBService { public long store(Alignment alignment); - public Alignment find(long id); public int connect(String password); // password in database - // JE: to be added - //public int init(String IPAdress, String id, String password); // with userID, password in database + public int connect(String IPAdress, String id, String password); // with userID, password in database + public Alignment find(long id); // find alignment with alignmentID + public Enumeration find(URI uri); // find alignment list with an ontology uri + public Enumeration find(URI uri1, URI uri2); // find alignment list with two ontology uri public int close(); } diff --git a/src/fr/inrialpes/exmo/align/service/DBServiceImpl.java b/src/fr/inrialpes/exmo/align/service/DBServiceImpl.java index 9395961e8e73391089207fd40a74ae39752e19ac..12ec27f97cf5e4b0df35844985b698fa9353dbc1 100644 --- a/src/fr/inrialpes/exmo/align/service/DBServiceImpl.java +++ b/src/fr/inrialpes/exmo/align/service/DBServiceImpl.java @@ -1,11 +1,32 @@ +/* + * $Id$ + * + * Copyright (C) XX, 2006 + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public License + * as published by the Free Software Foundation; either version 2.1 + * 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 Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser 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 fr.inrialpes.exmo.align.service; -import java.util.*; +import java.util.Vector; +import java.util.Enumeration; import java.net.URI; import java.sql.Connection; import java.sql.DriverManager; -import com.mysql.jdbc.ResultSet; -import com.mysql.jdbc.Statement; +import java.sql.ResultSet; +import java.sql.Statement; import org.semanticweb.owl.align.Alignment; import org.semanticweb.owl.align.Cell; @@ -40,8 +61,12 @@ public class DBServiceImpl implements DBService{ String s_uri2 = ""; String s_method = ""; String s_cell = ""; + + final int CONNECTION_ERROR = 1; + final int SUCCESS = 2; + final int INIT_ERROR = 3; - static Hashtable cache = null; + static Cache cache = null; public DBServiceImpl() { try{ @@ -55,12 +80,30 @@ public class DBServiceImpl implements DBService{ try { conn = DriverManager.getConnection(url, "root", password); st = (Statement) conn.createStatement(); - - cache = loadAll(true); - } catch(Exception ex) {return -1;} - return 1; + } catch(Exception ex) {return CONNECTION_ERROR;} + + if(init()) return SUCCESS; + else return INIT_ERROR; + } + public int connect(String IPAddress, String id, String password) { + try { + conn = DriverManager.getConnection("jdbc:mysql://"+IPAddress+":3306/DBService", id, password); + st = (Statement) conn.createStatement(); + } catch(Exception ex) {return CONNECTION_ERROR;} + + if(init()) return SUCCESS; + else return INIT_ERROR; + } + + private boolean init() { + try { + cache = new CacheImpl(); + return true; + } catch (Exception e) {return false;} + } + private Hashtable loadAll(boolean force){ Hashtable result = new Hashtable(); String query = null; @@ -187,6 +230,37 @@ public class DBServiceImpl implements DBService{ return result; } + public Enumeration find(URI uri) { + Enumeration result = null; + Alignment temp = null; + String query = null; + try { + result = (Enumeration) cache.get(uri); + + + if (result == null) { + query = "select id " + "from alignment " + "where id = " + id; + + rs = (ResultSet) st.executeQuery(query); + + if(rs == null) return null; + else { + while (rs.next()) { + temp = retrieve(id); + loadOne(id, temp, true); + } + } + } + + } catch (Exception e) {System.out.println("Alignment Finding Exception");} + return result; + } // find alignment list with an ontology uri + + public Enumeration find(URI uri1, URI uri2) { + Enumeration result = null; + return result; + } // find alignment list with two ontology uri + protected Alignment retrieve(long id){ OWLOntology o1 = null; OWLOntology o2 = null; @@ -278,6 +352,7 @@ public class DBServiceImpl implements DBService{ } public int close(){ + try { conn.close(); st.close(); @@ -287,6 +362,7 @@ public class DBServiceImpl implements DBService{ return -1; } } + public static OWLOntology loadOntology(URI uri) throws Exception { OWLRDFParser parser = new OWLRDFParser(); parser.setConnection(OWLManager.getOWLConnection());