|
From: Elmer G. <ega...@us...> - 2004-07-27 04:10:29
|
Update of /cvsroot/javaowl/JavaOWL/src/org/javaowl/models/prevalence In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2962/src/org/javaowl/models/prevalence Modified Files: StorageUtil.java Log Message: Fixed build. Index: StorageUtil.java =================================================================== RCS file: /cvsroot/javaowl/JavaOWL/src/org/javaowl/models/prevalence/StorageUtil.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** StorageUtil.java 26 Jul 2004 22:55:02 -0000 1.1 --- StorageUtil.java 27 Jul 2004 04:10:18 -0000 1.2 *************** *** 6,21 **** package org.javaowl.models.prevalence; ! import java.util.ArrayList; ! import java.util.Iterator; ! import java.util.List; import java.util.zip.CRC32; import com.hp.hpl.jena.datatypes.RDFDatatype; import com.hp.hpl.jena.datatypes.TypeMapper; - import com.hp.hpl.jena.db.GraphRDB; import com.hp.hpl.jena.db.IDBConnection; import com.hp.hpl.jena.db.RDFRDBException; import com.hp.hpl.jena.db.impl.DBIDInt; ! import com.hp.hpl.jena.graph.Graph; import com.hp.hpl.jena.graph.Node; import com.hp.hpl.jena.graph.Node_Literal; --- 6,24 ---- package org.javaowl.models.prevalence; ! import java.sql.PreparedStatement; ! import java.sql.ResultSet; ! import java.sql.SQLException; import java.util.zip.CRC32; + import org.apache.xerces.util.XMLChar; + import com.hp.hpl.jena.datatypes.RDFDatatype; import com.hp.hpl.jena.datatypes.TypeMapper; import com.hp.hpl.jena.db.IDBConnection; import com.hp.hpl.jena.db.RDFRDBException; import com.hp.hpl.jena.db.impl.DBIDInt; ! import com.hp.hpl.jena.db.impl.LRUCache; ! import com.hp.hpl.jena.db.impl.SQLCache; ! import com.hp.hpl.jena.db.impl.SpecializedGraph; import com.hp.hpl.jena.graph.Node; import com.hp.hpl.jena.graph.Node_Literal; *************** *** 23,33 **** import com.hp.hpl.jena.graph.Node_Variable; import com.hp.hpl.jena.graph.impl.LiteralLabel; - import com.hp.hpl.jena.rdf.model.AnonId; ! import com.hp.hpl.jena.shared.*; ! ! import com.hp.hpl.jena.vocabulary.RDF; ! ! import org.apache.xerces.util.XMLChar; public class StorageUtil { --- 26,31 ---- import com.hp.hpl.jena.graph.Node_Variable; import com.hp.hpl.jena.graph.impl.LiteralLabel; import com.hp.hpl.jena.rdf.model.AnonId; ! import com.hp.hpl.jena.shared.JenaException; public class StorageUtil { *************** *** 256,270 **** */ ! protected static String RDBCodeURI = "U"; ! protected static String RDBCodeBlank = "B"; ! protected static String RDBCodeLiteral = "L"; ! protected static String RDBCodeVariable = "V"; ! protected static String RDBCodeANY = "A"; ! protected static String RDBCodePrefix = "P"; ! protected static String RDBCodeValue = "v"; ! protected static String RDBCodeRef = "r"; ! protected static String RDBCodeDelim = ":"; ! protected static char RDBCodeDelimChar = ':'; ! protected static String RDBCodeInvalid = "X"; /** --- 254,270 ---- */ ! protected static String RDB_CODE_URI = "U"; ! protected static String RDB_CODE_BLANK = "B"; ! protected static String RDB_CODE_LITERAL = "L"; ! protected static String RDB_CODE_VARIABLE = "V"; ! protected static String RDB_CODE_ANY = "A"; ! protected static String RDB_CODE_PREFIX = "P"; ! protected static String RDB_CODE_VALUE = "v"; ! protected static String RDB_CODE_REF = "r"; ! protected static String RDB_CODE_DELIM = ":"; ! protected static char RDB_CODE_DELIM_CHAR = ':'; ! protected static String RDB_CODE_INVALID = "X"; ! ! private static final int INDEX_KEY_LENGTH = 0; /** *************** *** 278,282 **** if ( node.isURI() ) { String uri = new String(((Node_URI) node).getURI()); ! if ( uri.startsWith(RDBCodeURI) ) { throw new RDFRDBException ("URI Node looks like a blank node: " + uri ); } --- 278,282 ---- if ( node.isURI() ) { String uri = new String(((Node_URI) node).getURI()); ! if ( uri.startsWith(RDB_CODE_URI) ) { throw new RDFRDBException ("URI Node looks like a blank node: " + uri ); } *************** *** 296,300 **** noCompress = true; if ( noCompress ) { ! pfx = RDBCodeDelim + RDBCodeDelim; qname = uri; } else { --- 296,300 ---- noCompress = true; if ( noCompress ) { ! pfx = RDB_CODE_DELIM + RDB_CODE_DELIM; qname = uri; } else { *************** *** 302,309 **** DBIDInt pfxid = URItoPrefix(uri, pos, addIfLong); if ( pfxid == null ) return res; ! pfx = RDBCodeDelim + ((DBIDInt) pfxid).getIntID() + RDBCodeDelim; qname = uri.substring(pos); } ! int encodeLen = RDBCodeURI.length() + 1 + pfx.length() + EOS_LEN; boolean URIisLong = objectIsLong(encodeLen,qname); if ( URIisLong ) { --- 302,309 ---- DBIDInt pfxid = URItoPrefix(uri, pos, addIfLong); if ( pfxid == null ) return res; ! pfx = RDB_CODE_DELIM + ((DBIDInt) pfxid).getIntID() + RDB_CODE_DELIM; qname = uri.substring(pos); } ! int encodeLen = RDB_CODE_URI.length() + 1 + pfx.length() + EOS_LEN; boolean URIisLong = objectIsLong(encodeLen,qname); if ( URIisLong ) { *************** *** 313,319 **** if ( URIid == null ) return res; dbid = URIid.getIntID(); ! res = new String(RDBCodeURI + RDBCodeRef + pfx + dbid); } else { ! res = RDBCodeURI + RDBCodeValue + pfx + qname + EOS; } } else if ( node.isLiteral() ){ --- 313,319 ---- if ( URIid == null ) return res; dbid = URIid.getIntID(); ! res = new String(RDB_CODE_URI + RDB_CODE_REF + pfx + dbid); } else { ! res = RDB_CODE_URI + RDB_CODE_VALUE + pfx + qname + EOS; } } else if ( node.isLiteral() ){ *************** *** 325,329 **** String dtype = ll.getDatatypeURI(); String ld = litLangTypeToRDBString(lang,dtype); ! int encodeLen = RDBCodeLiteral.length() + 2 + ld.length() + EOS_LEN; boolean litIsLong = objectIsLong(encodeLen,lval); if ( litIsLong ) { --- 325,329 ---- String dtype = ll.getDatatypeURI(); String ld = litLangTypeToRDBString(lang,dtype); ! int encodeLen = RDB_CODE_LITERAL.length() + 2 + ld.length() + EOS_LEN; boolean litIsLong = objectIsLong(encodeLen,lval); if ( litIsLong ) { *************** *** 333,344 **** if ( lid == null ) return res; dbid = lid.getIntID(); ! res = new String(RDBCodeLiteral + RDBCodeRef + RDBCodeDelim + dbid); } else { ! res = new String(RDBCodeLiteral + RDBCodeValue + RDBCodeDelim + ld + lval + EOS); } } else if ( node.isBlank() ) { String bnid = node.getBlankNodeId().toString(); String delims = "::"; ! int encodeLen = RDBCodeBlank.length() + 1 + delims.length() + EOS_LEN; boolean BisLong = objectIsLong(encodeLen,bnid); if ( BisLong ) { --- 333,344 ---- if ( lid == null ) return res; dbid = lid.getIntID(); ! res = new String(RDB_CODE_LITERAL + RDB_CODE_REF + RDB_CODE_DELIM + dbid); } else { ! res = new String(RDB_CODE_LITERAL + RDB_CODE_VALUE + RDB_CODE_DELIM + ld + lval + EOS); } } else if ( node.isBlank() ) { String bnid = node.getBlankNodeId().toString(); String delims = "::"; ! int encodeLen = RDB_CODE_BLANK.length() + 1 + delims.length() + EOS_LEN; boolean BisLong = objectIsLong(encodeLen,bnid); if ( BisLong ) { *************** *** 348,354 **** if ( URIid == null ) return res; dbid = URIid.getIntID(); ! res = new String(RDBCodeBlank + RDBCodeRef + delims + dbid); } else { ! res = new String(RDBCodeBlank + RDBCodeValue + delims + bnid + EOS); } --- 348,354 ---- if ( URIid == null ) return res; dbid = URIid.getIntID(); ! res = new String(RDB_CODE_BLANK + RDB_CODE_REF + delims + dbid); } else { ! res = new String(RDB_CODE_BLANK + RDB_CODE_VALUE + delims + bnid + EOS); } *************** *** 358,364 **** if ( (len + 3 + EOS_LEN) > LONG_OBJECT_LENGTH ) throw new JenaException ("Variable name too long: " + name ); ! res = RDBCodeVariable + RDBCodeValue + RDBCodeDelim + name + EOS; } else if ( node.equals(Node.ANY) ) { ! res = RDBCodeANY + RDBCodeValue + RDBCodeDelim; } else { throw new RDFRDBException ("Expected Concrete Node, got " + node.toString() ); --- 358,364 ---- if ( (len + 3 + EOS_LEN) > LONG_OBJECT_LENGTH ) throw new JenaException ("Variable name too long: " + name ); ! res = RDB_CODE_VARIABLE + RDB_CODE_VALUE + RDB_CODE_DELIM + name + EOS; } else if ( node.equals(Node.ANY) ) { ! res = RDB_CODE_ANY + RDB_CODE_VALUE + RDB_CODE_DELIM; } else { throw new RDFRDBException ("Expected Concrete Node, got " + node.toString() ); *************** *** 379,384 **** String nodeType = RDBString.substring(0,1); String valType = RDBString.substring(1,2); ! if ( (!(valType.equals(RDBCodeRef) || valType.equals(RDBCodeValue))) || ! (RDBString.charAt(2) != RDBCodeDelimChar) ) throw new RDFRDBException("Bad RDBString Header: " + RDBString); --- 379,384 ---- String nodeType = RDBString.substring(0,1); String valType = RDBString.substring(1,2); ! if ( (!(valType.equals(RDB_CODE_REF) || valType.equals(RDB_CODE_VALUE))) || ! (RDBString.charAt(2) != RDB_CODE_DELIM_CHAR) ) throw new RDFRDBException("Bad RDBString Header: " + RDBString); *************** *** 386,390 **** int npos; ! if ( nodeType.equals(RDBCodeURI) ) { ParseInt pi = new ParseInt(pos); String prefix = ""; --- 386,390 ---- int npos; ! if ( nodeType.equals(RDB_CODE_URI) ) { ParseInt pi = new ParseInt(pos); String prefix = ""; *************** *** 399,403 **** pos = pi.pos + 1; String qname; ! if ( valType.equals(RDBCodeRef) ) { qname = IDtoURI(RDBString.substring(pos)); if ( qname == null ) --- 399,403 ---- pos = pi.pos + 1; String qname; ! if ( valType.equals(RDB_CODE_REF) ) { qname = IDtoURI(RDBString.substring(pos)); if ( qname == null ) *************** *** 408,415 **** res = Node.createURI(prefix + qname); ! } else if ( nodeType.equals(RDBCodeLiteral) ) { ParseInt pi = new ParseInt(pos); String litString = null; ! if ( valType.equals(RDBCodeRef) ) { RDBStringParseInt(RDBString,pi,true); if ( pi.val != null ) --- 408,415 ---- res = Node.createURI(prefix + qname); ! } else if ( nodeType.equals(RDB_CODE_LITERAL) ) { ParseInt pi = new ParseInt(pos); String litString = null; ! if ( valType.equals(RDB_CODE_REF) ) { RDBStringParseInt(RDBString,pi,true); if ( pi.val != null ) *************** *** 451,457 **** res = Node.createLiteral(llabel); ! } else if ( nodeType.equals(RDBCodeBlank) ) { String bstr = null; ! if ( valType.equals(RDBCodeValue) ) { bstr = RDBString.substring(4,len-EOS_LEN); } else { --- 451,457 ---- res = Node.createLiteral(llabel); ! } else if ( nodeType.equals(RDB_CODE_BLANK) ) { String bstr = null; ! if ( valType.equals(RDB_CODE_VALUE) ) { bstr = RDBString.substring(4,len-EOS_LEN); } else { *************** *** 462,470 **** res = Node.createAnon( new AnonId (bstr) ); ! } else if ( nodeType.equals(RDBCodeVariable) ) { String vname = RDBString.substring(3,len-EOS_LEN); res = Node.createVariable(vname); ! } else if ( nodeType.equals(RDBCodeANY) ) { res = Node.ANY; --- 462,470 ---- res = Node.createAnon( new AnonId (bstr) ); ! } else if ( nodeType.equals(RDB_CODE_VARIABLE) ) { String vname = RDBString.substring(3,len-EOS_LEN); res = Node.createVariable(vname); ! } else if ( nodeType.equals(RDB_CODE_ANY) ) { res = Node.ANY; *************** *** 524,528 **** private void RDBStringParseInt ( String RDBString, ParseInt pi, boolean toEnd ) { ! int npos = toEnd ? RDBString.length() : RDBString.indexOf(RDBCodeDelimChar,pi.pos); if ( npos < 0 ) { throw new RDFRDBException("Bad RDB String: " + RDBString); --- 524,528 ---- private void RDBStringParseInt ( String RDBString, ParseInt pi, boolean toEnd ) { ! int npos = toEnd ? RDBString.length() : RDBString.indexOf(RDB_CODE_DELIM_CHAR,pi.pos); if ( npos < 0 ) { throw new RDFRDBException("Bad RDB String: " + RDBString); *************** *** 560,564 **** int avail; ! res.head = RDBCodePrefix + RDBCodeValue + RDBCodeDelim; headLen = res.head.length(); avail = INDEX_KEY_LENGTH - (headLen + EOS_LEN); --- 560,564 ---- int avail; ! res.head = RDB_CODE_PREFIX + RDB_CODE_VALUE + RDB_CODE_DELIM; headLen = res.head.length(); avail = INDEX_KEY_LENGTH - (headLen + EOS_LEN); *************** *** 581,587 **** */ public String litLangTypeToRDBString ( String lang, String dtype ) throws RDFRDBException { ! String res = RDBCodeDelim; ! res = ((lang == null) ? "" : Integer.toString(lang.length())) + RDBCodeDelim; ! res = res + ((dtype == null) ? "" : Integer.toString(dtype.length())) + RDBCodeDelim; res = res + (lang == null ? "" : lang) + (dtype == null ? "" : dtype); return res; --- 581,587 ---- */ public String litLangTypeToRDBString ( String lang, String dtype ) throws RDFRDBException { ! String res = RDB_CODE_DELIM; ! res = ((lang == null) ? "" : Integer.toString(lang.length())) + RDB_CODE_DELIM; ! res = res + ((dtype == null) ? "" : Integer.toString(dtype.length())) + RDB_CODE_DELIM; res = res + (lang == null ? "" : lang) + (dtype == null ? "" : dtype); return res; *************** *** 613,617 **** String langType = litLangTypeToRDBString(lang,dtype); ! res.head = RDBCodeLiteral + RDBCodeValue + RDBCodeDelim + langType; headLen = res.head.length(); avail = INDEX_KEY_LENGTH - (headLen + EOS_LEN); --- 613,617 ---- String langType = litLangTypeToRDBString(lang,dtype); ! res.head = RDB_CODE_LITERAL + RDB_CODE_VALUE + RDB_CODE_DELIM + langType; headLen = res.head.length(); avail = INDEX_KEY_LENGTH - (headLen + EOS_LEN); *************** *** 639,643 **** */ public DBIDInt getBlankID(String bstr, boolean add) throws RDFRDBException { ! RDBLongObject lobj = URIToLongObject (bstr,RDBCodeBlank); return getLongObjectID(lobj, LONG_URI_TABLE, add); } --- 639,643 ---- */ public DBIDInt getBlankID(String bstr, boolean add) throws RDFRDBException { ! RDBLongObject lobj = URIToLongObject (bstr,RDB_CODE_BLANK); return getLongObjectID(lobj, LONG_URI_TABLE, add); } *************** *** 647,651 **** */ public DBIDInt getURIID(String qname, boolean add) throws RDFRDBException { ! RDBLongObject lobj = URIToLongObject (qname,RDBCodeURI); return getLongObjectID(lobj, LONG_URI_TABLE, add); } --- 647,651 ---- */ public DBIDInt getURIID(String qname, boolean add) throws RDFRDBException { ! RDBLongObject lobj = URIToLongObject (qname,RDB_CODE_URI); return getLongObjectID(lobj, LONG_URI_TABLE, add); } *************** *** 656,660 **** int avail; ! res.head = code + RDBCodeValue + RDBCodeDelim; headLen = res.head.length(); avail = INDEX_KEY_LENGTH - (headLen + EOS_LEN); --- 656,660 ---- int avail; ! res.head = code + RDB_CODE_VALUE + RDB_CODE_DELIM; headLen = res.head.length(); avail = INDEX_KEY_LENGTH - (headLen + EOS_LEN); *************** *** 764,767 **** --- 764,776 ---- /** + * @param table + * @return + */ + private int getInsertID(String table) { + // TODO Auto-generated method stub + return 0; + } + + /** * Return the prefix string that has the given prefix id. * @param prefixID - the dbid of the prefix. *************** *** 775,779 **** return (String) res; else ! return IDtoString ( prefixID, PREFIX_TABLE, RDBCodePrefix); } --- 784,788 ---- return (String) res; else ! return IDtoString ( prefixID, PREFIX_TABLE, RDB_CODE_PREFIX); } *************** *** 784,788 **** */ protected String IDtoBlank(String bnID) { ! return IDtoString(bnID, LONG_URI_TABLE, RDBCodeBlank); } /** --- 793,797 ---- */ protected String IDtoBlank(String bnID) { ! return IDtoString(bnID, LONG_URI_TABLE, RDB_CODE_BLANK); } /** *************** *** 792,796 **** */ protected String IDtoURI(String uriID) { ! return IDtoString(uriID, LONG_URI_TABLE, RDBCodeURI); } --- 801,805 ---- */ protected String IDtoURI(String uriID) { ! return IDtoString(uriID, LONG_URI_TABLE, RDB_CODE_URI); } *************** *** 801,805 **** */ protected String IDtoLiteral ( int litID ) { ! return IDtoString ( litID, LONG_LIT_TABLE, RDBCodeLiteral); } --- 810,814 ---- */ protected String IDtoLiteral ( int litID ) { ! return IDtoString ( litID, LONG_LIT_TABLE, RDB_CODE_LITERAL); } *************** *** 823,827 **** throw new RDFRDBException("Invalid Object ID: " + dbID); // debug check ! if ( !lobj.head.substring(0,3).equals(RDBcode + RDBCodeValue + RDBCodeDelim) ) throw new RDFRDBException("Malformed URI in Database: " + lobj.head); res = lobj.head.substring(3,lobj.head.length() - EOS_LEN); --- 832,836 ---- throw new RDFRDBException("Invalid Object ID: " + dbID); // debug check ! if ( !lobj.head.substring(0,3).equals(RDBcode + RDB_CODE_VALUE + RDB_CODE_DELIM) ) throw new RDFRDBException("Malformed URI in Database: " + lobj.head); res = lobj.head.substring(3,lobj.head.length() - EOS_LEN); |