Added:
trunk/Caboto/caboto/src/main/java/org/caboto/domain/AnnotationException.java
- copied unchanged from r535,
/branches/man/caboto/src/main/java/org/caboto/domain/AnnotationException.java
Modified:
trunk/Caboto/ (props changed)
trunk/Caboto/caboto/pom.xml
trunk/Caboto/caboto/src/main/java/org/caboto/CabotoUtility.java
trunk/Caboto/caboto/src/main/java/org/caboto/dao/AnnotationDao.java
trunk/Caboto/caboto/src/main/java/org/caboto/dao/AnnotationDaoImpl.java
trunk/Caboto/caboto/src/main/java/org/caboto/domain/Annotation.java
trunk/Caboto/caboto/src/main/java/org/caboto/domain/AnnotationFactory.java
trunk/Caboto/caboto/src/main/java/org/caboto/filters/ (props changed)
trunk/Caboto/caboto/src/main/java/org/caboto/profile/ProfileRepository.java
trunk/Caboto/caboto/src/main/java/org/caboto/profile/ProfileRepositoryXmlImpl.java
trunk/Caboto/caboto/src/test/java/org/caboto/dao/AnnotationDaoImplTest.java
trunk/Caboto/caboto/src/test/java/org/caboto/filters/ (props changed)
trunk/Caboto/caboto/src/test/java/org/caboto/profile/MockProfileRepositoryImpl.java
trunk/Caboto/caboto/src/test/java/org/caboto/rest/resources/BasicAuthenticationClientFilter.java
(contents, props changed)
trunk/Caboto/caboto/src/test/resources/test-graph3.rdf (props changed)
trunk/Caboto/database/src/main/java/org/caboto/jena/db/AbstractDatabase.java
(contents, props changed)
trunk/Caboto/database/src/main/java/org/caboto/jena/db/Data.java
(props changed)
trunk/Caboto/database/src/main/java/org/caboto/jena/db/DataException.java
(props changed)
trunk/Caboto/database/src/main/java/org/caboto/jena/db/Database.java
(contents, props changed)
trunk/Caboto/database/src/main/java/org/caboto/jena/db/Results.java
(props changed)
trunk/Caboto/database/src/main/java/org/caboto/jena/db/Utils.java
(props changed)
trunk/Caboto/database/src/main/java/org/caboto/jena/db/impl/DatasourceDatabase.java
(props changed)
trunk/Caboto/database/src/main/java/org/caboto/jena/db/impl/FileDatabase.java
(props changed)
trunk/Caboto/database/src/main/java/org/caboto/jena/db/impl/RdfFileFilter.java
(props changed)
trunk/Caboto/database/src/main/java/org/caboto/jena/db/impl/SDBAbstractDatabase.java
(contents, props changed)
trunk/Caboto/database/src/main/java/org/caboto/jena/db/impl/SDBDatabase.java
(contents, props changed)
trunk/Caboto/database/src/main/java/org/caboto/jena/db/impl/Scratch.java
(props changed)
trunk/Caboto/database/src/test/java/org/ (props changed)
trunk/Caboto/database/src/test/java/org/caboto/ (props changed)
trunk/Caboto/database/src/test/java/org/caboto/jena/ (props changed)
trunk/Caboto/database/src/test/java/org/caboto/jena/db/ (props changed)
trunk/Caboto/database/src/test/java/org/caboto/jena/db/impl/ (props
changed)
trunk/Caboto/database/src/test/resources/graphs/ (props changed)
trunk/Caboto/database/src/test/resources/graphs/test/ (props changed)
Log:
Merged with branches/man r437:r535
Modified: trunk/Caboto/caboto/pom.xml
==============================================================================
--- trunk/Caboto/caboto/pom.xml (original)
+++ trunk/Caboto/caboto/pom.xml Wed Mar 25 06:25:30 2009
@@ -247,7 +247,6 @@
<version>1.3</version>
<scope>test</scope>
</dependency>
-
</dependencies>
</project>
Modified: trunk/Caboto/caboto/src/main/java/org/caboto/CabotoUtility.java
==============================================================================
--- trunk/Caboto/caboto/src/main/java/org/caboto/CabotoUtility.java
(original)
+++ trunk/Caboto/caboto/src/main/java/org/caboto/CabotoUtility.java Wed Mar
25 06:25:30 2009
@@ -33,6 +33,7 @@
*/
package org.caboto;
+import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.UUID;
@@ -47,6 +48,8 @@
*/
public final class CabotoUtility {
+ private static String DATE_FORMAT_STRING="yyyy-MM-dd'T'HH:mm:ssZ";
+
/**
* Private constructor.
*/
@@ -69,6 +72,26 @@
return graphId + id;
}
+
+
+ public static String getGraphId(final String id) {
+
+ int index=id.lastIndexOf("/");
+ if (index!=-1) {
+ return id.substring(0,index+1);
+
+ }
+ return null;
+ }
+
+ public static String getId(final String uri) {
+
+ int index=uri.lastIndexOf("/");
+ if (index!=-1) {
+ return uri.substring(index+1);
+ }
+ return null;
+ }
/**
* <p>Parses a date to a format that is a valid XSD:dateTime.</p>
@@ -78,12 +101,21 @@
*/
public static String parseDate(final Date date) {
- String temp = new
SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ").format(date);
+ String temp = new
SimpleDateFormat(DATE_FORMAT_STRING).format(date);
return temp.substring(0, temp.length() - 2) + ":"
+ temp.substring(temp.length() - 2, temp.length());
}
+ public static Date parseDate (final String XsdDate) throws
ParseException{
+ String temp = XsdDate.substring(0, XsdDate.length() - 3)
+ + XsdDate.substring(XsdDate.length() - 2, XsdDate.length());
+
+ Date date = new SimpleDateFormat(DATE_FORMAT_STRING).parse(temp);
+ return date;
+ }
+
+
/**
* @param path the path details of a request.
* @return whether or not its a public resource.
Modified:
trunk/Caboto/caboto/src/main/java/org/caboto/dao/AnnotationDao.java
==============================================================================
--- trunk/Caboto/caboto/src/main/java/org/caboto/dao/AnnotationDao.java
(original)
+++ trunk/Caboto/caboto/src/main/java/org/caboto/dao/AnnotationDao.java Wed
Mar 25 06:25:30 2009
@@ -33,6 +33,8 @@
*/
package org.caboto.dao;
+import java.util.List;
+
import com.hp.hpl.jena.rdf.model.Resource;
import com.hp.hpl.jena.rdf.model.Model;
import org.caboto.domain.Annotation;
@@ -53,8 +55,16 @@
Model findAnnotations(AnnotationFilter[] filters);
Model findAnnotationsByGraph(String graph, AnnotationFilter...
filters);
+
+ Annotation getAnnotation(String id);
Model findAnnotations(String about, AnnotationFilter... filters);
+
+ List<Annotation> getAnnotations(String about);
+
+ Model findAnnotationsByAuthor(String author);
+
+ List<Annotation> getAnnotationsByAuthor(String author);
void deleteAnnotation(Resource resource);
Modified:
trunk/Caboto/caboto/src/main/java/org/caboto/dao/AnnotationDaoImpl.java
==============================================================================
--- trunk/Caboto/caboto/src/main/java/org/caboto/dao/AnnotationDaoImpl.java
(original)
+++ trunk/Caboto/caboto/src/main/java/org/caboto/dao/AnnotationDaoImpl.java
Wed Mar 25 06:25:30 2009
@@ -44,6 +44,8 @@
import com.hp.hpl.jena.vocabulary.RDF;
import org.caboto.CabotoUtility;
import org.caboto.domain.Annotation;
+import org.caboto.domain.AnnotationException;
+import org.caboto.domain.AnnotationFactory;
import org.caboto.jena.db.Database;
import org.caboto.jena.db.Utils;
import org.caboto.profile.Profile;
@@ -53,6 +55,7 @@
import org.caboto.vocabulary.Annotea;
import java.util.Date;
+import java.util.List;
import org.caboto.filters.AnnotationFilter;
import org.caboto.filters.AnnotationFilterFactory;
@@ -70,6 +73,7 @@
this.database = database;
}
+
public void addAnnotation(final Annotation annotation) {
try {
@@ -102,15 +106,15 @@
annotationResource.addProperty(Annotea.author,
model.createResource(annotation.getAuthor()));
- Date created = new Date();
-
// creation date
+ if (annotation.getCreated()==null){
+ annotation.setCreated(new Date());
+ }
annotationResource.addProperty(Annotea.created,
-
model.createTypedLiteral(CabotoUtility.parseDate(created),
+
model.createTypedLiteral(CabotoUtility.parseDate(annotation.getCreated()),
XSDDatatype.XSDdateTime));
annotation.setId(uri);
- annotation.setCreated(created);
// --- CREATE THE BODY OF THE ANNOTATION ---
@@ -122,6 +126,9 @@
for (ProfileEntry entry : profile.getProfileEntries()) {
String val = annotation.getBody().get(entry.getId());
+ if ((val == null) && !entry.isRequired()){
+ continue;
+ }
Property prop =
model.createProperty(entry.getPropertyType());
@@ -203,8 +210,44 @@
AnnotationFilterFactory.applyFilters(query, "body", filters);
return database.executeConstructQuery(query,
initialBindings);
+
+ }
+
+ public Annotation getAnnotation(final String id){
+ Annotation annotation=null;
+ try {
+ annotation=new Annotation(findAnnotation(id), profileRepository);
+ } catch (AnnotationException e) {
+ e.printStackTrace();
+ }
+ return annotation;
+ }
+
+ public List<Annotation> getAnnotations(final String about){
+ Model annModel = findAnnotations(about);
+ return
AnnotationFactory.annotationsFromModel(annModel,profileRepository);
+ }
+
+
+ public Model findAnnotationsByAuthor(final String author) {
+
+ // create bindings
+ QuerySolutionMap initialBindings = new QuerySolutionMap();
+
+ initialBindings.add("author",
ResourceFactory.createResource(author));
+
+ Model m = database.executeConstructQuery(findAnnotationSparql,
+ initialBindings);
+
+ return m;
+
}
+ public List<Annotation> getAnnotationsByAuthor(final String author){
+ Model annModel = findAnnotationsByAuthor(author);
+ return
AnnotationFactory.annotationsFromModel(annModel,profileRepository);
+ }
+
public void deleteAnnotation(final Resource resource) {
String id = resource.getURI();
Modified:
trunk/Caboto/caboto/src/main/java/org/caboto/domain/Annotation.java
==============================================================================
--- trunk/Caboto/caboto/src/main/java/org/caboto/domain/Annotation.java
(original)
+++ trunk/Caboto/caboto/src/main/java/org/caboto/domain/Annotation.java Wed
Mar 25 06:25:30 2009
@@ -33,10 +33,25 @@
*/
package org.caboto.domain;
+import java.text.ParseException;
import java.util.Date;
+import java.util.Iterator;
import java.util.Map;
import java.util.HashMap;
+import org.caboto.CabotoUtility;
+import org.caboto.profile.Profile;
+import org.caboto.profile.ProfileEntry;
+import org.caboto.profile.ProfileRepository;
+import org.caboto.vocabulary.Annotea;
+
+import com.hp.hpl.jena.rdf.model.Model;
+import com.hp.hpl.jena.rdf.model.ModelFactory;
+import com.hp.hpl.jena.rdf.model.Property;
+import com.hp.hpl.jena.rdf.model.Resource;
+import com.hp.hpl.jena.rdf.model.Statement;
+import com.hp.hpl.jena.vocabulary.RDF;
+
/**
* @author Mike Jones (mike.a...@bristol.ac.uk)
* @version $Id: Annotation.java 177 2008-05-30 13:50:59Z mike.a.jones $
@@ -58,6 +73,49 @@
this.body = body;
this.type = type;
}
+
+ public Annotation(Resource resource , ProfileRepository
profileRepository) throws AnnotationException {
+ Statement rtype = resource.getProperty(RDF.type);
+ if (rtype==null){
+ throw new AnnotationException("RDF type not set");
+ }
+ this.type = rtype.getResource().getURI();
+ Profile profile;
+ try {
+ profile = profileRepository.findProfileByUri(type);
+ } catch (Exception e) {
+ throw new AnnotationException(e);
+ }
+ if (profile==null){
+ throw new AnnotationException("RDF type unknown in profile");
+ }
+ this.type=profile.getId();
+ Model model=ModelFactory.createDefaultModel();
+ this.id = resource.getURI().toString();
+ this.graphId =CabotoUtility.getGraphId(id);
+ this.annotates =
resource.getProperty(Annotea.annotates).getResource().getURI();
+ this.author =
resource.getProperty(Annotea.author).getResource().getURI();
+ Resource bodyResource =
resource.getProperty(Annotea.body).getResource();
+ try {
+ this.created =
CabotoUtility.parseDate(resource.getProperty(Annotea.created).getString());
+ } catch (ParseException e) {
+ throw new AnnotationException(e);
+ }
+ ProfileEntry profileEntry=null;
+ Statement bodyValue=null;
+ Iterator<ProfileEntry> profileIter =
profile.getProfileEntries().iterator();
+ while (profileIter.hasNext()){
+ profileEntry=profileIter.next();
+
bodyValue=bodyResource.getProperty(model.createProperty(profileEntry.getPropertyType()));
+ if (bodyValue!=null) {
+ body.put(profileEntry.getId(),bodyValue.getString());
+ } else {
+ if (profileEntry.isRequired()){
+ throw new AnnotationException("Annotation needs:" +
profileEntry.getId());
+ }
+ }
+ }
+ }
public String getId() {
return id;
@@ -96,6 +154,7 @@
}
public void setCreated(final Date created) {
+ System.err.println("Date="+created);
this.created = created;
}
Modified:
trunk/Caboto/caboto/src/main/java/org/caboto/domain/AnnotationFactory.java
==============================================================================
---
trunk/Caboto/caboto/src/main/java/org/caboto/domain/AnnotationFactory.java
(original)
+++
trunk/Caboto/caboto/src/main/java/org/caboto/domain/AnnotationFactory.java
Wed Mar 25 06:25:30 2009
@@ -34,8 +34,20 @@
package org.caboto.domain;
import javax.ws.rs.core.MultivaluedMap;
+
+import org.caboto.CabotoUtility;
+import org.caboto.profile.ProfileRepository;
+
+import com.hp.hpl.jena.rdf.model.Model;
+import com.hp.hpl.jena.rdf.model.ResIterator;
+import com.hp.hpl.jena.rdf.model.Resource;
+
import java.net.URI;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
import java.util.Date;
+import java.util.List;
+import java.util.Vector;
/**
* <p>A simple factory for creating Annotation objects.</p>
@@ -50,6 +62,31 @@
*/
private AnnotationFactory() {
}
+
+
+ /**
+ * <p>Creates a List of annotation objects based on values received
from a rdf Model</p>
+ *
+ * @param model the RDF model containing AnnotoationsURI of the named
graph that will hold the annotation.
+ * @param params the parameters from an HTTP POST.
+ * @return an annotation object based on the HTTP POST values.
+ */
+
+ public static List<Annotation> annotationsFromModel(Model model,
ProfileRepository profileRepository){
+ List<Annotation> annList = new Vector<Annotation>();
+ ResIterator resIt = model.listSubjects();
+ while (resIt.hasNext()){
+ Resource annResource = resIt.nextResource();
+ Annotation annotation;
+ try {
+ annotation = new Annotation(annResource,profileRepository);
+ annList.add(annotation);
+ } catch (AnnotationException e) {
+ // resource is not an annotation
+ }
+ }
+ return annList;
+ }
/**
* <p>Creates an annotation object based on values received from a map
- the map values
@@ -85,6 +122,16 @@
if (params.get("type") != null) {
annotation.setType(params.remove("type").get(0));
}
+
+ Date date=new Date();
+ if (params.get("created") !=null) {
+ try {
+ date = CabotoUtility.parseDate(params.remove("created").get(0));
+ } catch (ParseException e) {
+ // do nothing
+ }
+ }
+ annotation.setCreated(date);
// copy the rest of map
for (String key : params.keySet()) {
Modified:
trunk/Caboto/caboto/src/main/java/org/caboto/profile/ProfileRepository.java
==============================================================================
---
trunk/Caboto/caboto/src/main/java/org/caboto/profile/ProfileRepository.java
(original)
+++
trunk/Caboto/caboto/src/main/java/org/caboto/profile/ProfileRepository.java
Wed Mar 25 06:25:30 2009
@@ -40,5 +40,7 @@
public interface ProfileRepository {
Profile findProfile(String profileId) throws
ProfileRepositoryException;
+
+ Profile findProfileByUri(String profileUri) throws
ProfileRepositoryException;
}
Modified:
trunk/Caboto/caboto/src/main/java/org/caboto/profile/ProfileRepositoryXmlImpl.java
==============================================================================
---
trunk/Caboto/caboto/src/main/java/org/caboto/profile/ProfileRepositoryXmlImpl.java
(original)
+++
trunk/Caboto/caboto/src/main/java/org/caboto/profile/ProfileRepositoryXmlImpl.java
Wed Mar 25 06:25:30 2009
@@ -143,6 +143,68 @@
return profile;
}
+ public Profile findProfileByUri(final String profileUri) throws
ProfileRepositoryException {
+
+ Profile profile = null;
+
+ if (profileUri == null) {
+
+ // ????????????????????????
+ }
+
+ try {
+
+ // find the profile matching the id
+ XPathFactory xpathFactory = XPathFactory.newInstance();
+ XPath xpath = xpathFactory.newXPath();
+ XPathExpression expression =
+ xpath.compile("//profile[@type=\"" + profileUri
+ "\"]");
+ Object result = expression.evaluate(document,
XPathConstants.NODE);
+
+ // get the profile
+ Node node = (Node) result;
+
+ // find the rdf type
+ NamedNodeMap attributes = node.getAttributes();
+ String profileId =
attributes.getNamedItem("id").getTextContent();
+
+ // get the child nodes
+ NodeList list = node.getChildNodes();
+
+ // temp container to hold profile entries
+ List<Node> profileEntryList = new ArrayList<Node>();
+
+ for (int i = 0; i < list.getLength(); i++) {
+
+ Node n = list.item(i);
+
+ if (n.getNodeName().equals("profileEntry")) {
+ profileEntryList.add(n);
+ }
+
+ }
+
+ // create the profile object if we have entries
+ if (profileEntryList.size() > 0) {
+
+ // create the profile object
+ profile = new Profile();
+ profile.setId(profileId);
+ profile.setType(profileUri);
+
+ for (Node n : profileEntryList) {
+ profile.getProfileEntries().add(getProfileEntry(n));
+ }
+ }
+
+
+ } catch (XPathExpressionException e) {
+ throw new ProfileRepositoryException(e.getMessage());
+ }
+
+ return profile;
+ }
+
private ProfileEntry getProfileEntry(final Node node) {
ProfileEntry entry = new ProfileEntry();
Modified:
trunk/Caboto/caboto/src/test/java/org/caboto/dao/AnnotationDaoImplTest.java
==============================================================================
---
trunk/Caboto/caboto/src/test/java/org/caboto/dao/AnnotationDaoImplTest.java
(original)
+++
trunk/Caboto/caboto/src/test/java/org/caboto/dao/AnnotationDaoImplTest.java
Wed Mar 25 06:25:30 2009
@@ -34,9 +34,13 @@
package org.caboto.dao;
import com.hp.hpl.jena.rdf.model.Model;
+import com.hp.hpl.jena.rdf.model.ModelFactory;
import com.hp.hpl.jena.rdf.model.Resource;
import com.hp.hpl.jena.sdb.SDBFactory;
import com.hp.hpl.jena.sdb.Store;
+import com.hp.hpl.jena.sdb.StoreDesc;
+import com.hp.hpl.jena.sdb.sql.JDBC;
+
import junit.framework.TestCase;
import org.caboto.domain.Annotation;
import org.caboto.jena.db.Database;
@@ -46,6 +50,8 @@
import org.junit.Test;
import java.io.InputStream;
+import java.sql.Connection;
+import java.sql.DriverManager;
import java.util.HashMap;
import java.util.Map;
import org.caboto.filters.AnnotationFilter;
@@ -61,15 +67,24 @@
@Override
public void setUp() throws Exception {
- store =
SDBFactory.connectStore(this.getClass().getResource("/sdb.ttl").getPath());
- store.getTableFormatter().format();
Database database = new SDBDatabase("/sdb.ttl");
annotationDao = new AnnotationDaoImpl(new
MockProfileRepositoryImpl(),
database);
- }
+ Model ttl = ModelFactory.createDefaultModel();
+ ttl.read(getClass().getResourceAsStream("/sdb.ttl"), null, "TTL");
+ StoreDesc storeDesc = StoreDesc.read(ttl);
+ String driver = JDBC.getDriver(storeDesc.getDbType());
+ JDBC.loadDriver(driver);
+ Connection sqlConn = DriverManager.getConnection(
+ storeDesc.connDesc.getJdbcURL(),
+ storeDesc.connDesc.getUser(),
+ storeDesc.connDesc.getPassword());
+ store = SDBFactory.connectStore(sqlConn, storeDesc);
+ store.getTableFormatter().format();
+ }
@Test
public void testAddAnnotation() {
Modified:
trunk/Caboto/caboto/src/test/java/org/caboto/profile/MockProfileRepositoryImpl.java
==============================================================================
---
trunk/Caboto/caboto/src/test/java/org/caboto/profile/MockProfileRepositoryImpl.java
(original)
+++
trunk/Caboto/caboto/src/test/java/org/caboto/profile/MockProfileRepositoryImpl.java
Wed Mar 25 06:25:30 2009
@@ -68,4 +68,34 @@
return null;
}
+ public Profile findProfileByUri(String profileUri)
+ throws ProfileRepositoryException {
+
+ if
(profileUri.equals("http://caboto.org/schema/annotations#SimpleComment")) {
+
+ Profile profile = new Profile();
+ profile.setId("SimpleComment");
+
profile.setType("http://caboto.org/schema/annotations#SimpleComment");
+
+ ProfileEntry entry1 = new ProfileEntry();
+ entry1.setId("title");
+
entry1.setPropertyType("http://purl.org/dc/elements/1.1/title");
+ entry1.setObjectDatatype("String");
+ entry1.setRequired(true);
+
+ ProfileEntry entry2 = new ProfileEntry();
+ entry2.setId("description");
+
entry2.setPropertyType("http://purl.org/dc/elements/1.1/description");
+ entry2.setObjectDatatype("String");
+ entry2.setRequired(true);
+
+ profile.getProfileEntries().add(entry1);
+ profile.getProfileEntries().add(entry2);
+
+ return profile;
+ }
+
+ return null;
+ }
+
}
Modified:
trunk/Caboto/caboto/src/test/java/org/caboto/rest/resources/BasicAuthenticationClientFilter.java
==============================================================================
---
trunk/Caboto/caboto/src/test/java/org/caboto/rest/resources/BasicAuthenticationClientFilter.java
(original)
+++
trunk/Caboto/caboto/src/test/java/org/caboto/rest/resources/BasicAuthenticationClientFilter.java
Wed Mar 25 06:25:30 2009
@@ -37,17 +37,19 @@
import com.sun.jersey.api.client.ClientRequest;
import com.sun.jersey.api.client.ClientResponse;
import com.sun.jersey.api.client.filter.ClientFilter;
+
import org.apache.commons.codec.binary.Base64;
import java.util.ArrayList;
import java.util.List;
/**
+ *
* @author Mike Jones (mike.a...@bristol.ac.uk)
* @version $Id$
- */
-public class
- BasicAuthenticationClientFilter extends ClientFilter {
+ *
+ **/
+public class BasicAuthenticationClientFilter extends ClientFilter {
public BasicAuthenticationClientFilter(final String username, final
String password) {
this.username = username;
Modified:
trunk/Caboto/database/src/main/java/org/caboto/jena/db/AbstractDatabase.java
==============================================================================
---
trunk/Caboto/database/src/main/java/org/caboto/jena/db/AbstractDatabase.java
(original)
+++
trunk/Caboto/database/src/main/java/org/caboto/jena/db/AbstractDatabase.java
Wed Mar 25 06:25:30 2009
@@ -31,10 +31,21 @@
* POSSIBILITY OF SUCH DAMAGE.
*
*/
+
package org.caboto.jena.db;
-import com.hp.hpl.jena.query.*;
-import com.hp.hpl.jena.rdf.model.*;
+import com.hp.hpl.jena.query.Dataset;
+import com.hp.hpl.jena.query.Query;
+import com.hp.hpl.jena.query.QueryExecution;
+import com.hp.hpl.jena.query.QueryExecutionFactory;
+import com.hp.hpl.jena.query.QueryFactory;
+import com.hp.hpl.jena.query.QuerySolution;
+import com.hp.hpl.jena.rdf.model.Model;
+import com.hp.hpl.jena.rdf.model.ModelFactory;
+import com.hp.hpl.jena.rdf.model.Property;
+import com.hp.hpl.jena.rdf.model.RDFNode;
+import com.hp.hpl.jena.rdf.model.Resource;
+import com.hp.hpl.jena.rdf.model.ResourceFactory;
import com.hp.hpl.jena.sparql.util.Context;
import com.hp.hpl.jena.sparql.util.Symbol;
Modified:
trunk/Caboto/database/src/main/java/org/caboto/jena/db/Database.java
==============================================================================
--- trunk/Caboto/database/src/main/java/org/caboto/jena/db/Database.java
(original)
+++ trunk/Caboto/database/src/main/java/org/caboto/jena/db/Database.java
Wed Mar 25 06:25:30 2009
@@ -31,6 +31,7 @@
* POSSIBILITY OF SUCH DAMAGE.
*
*/
+
package org.caboto.jena.db;
import com.hp.hpl.jena.query.Query;
Modified:
trunk/Caboto/database/src/main/java/org/caboto/jena/db/impl/SDBAbstractDatabase.java
==============================================================================
---
trunk/Caboto/database/src/main/java/org/caboto/jena/db/impl/SDBAbstractDatabase.java
(original)
+++
trunk/Caboto/database/src/main/java/org/caboto/jena/db/impl/SDBAbstractDatabase.java
Wed Mar 25 06:25:30 2009
@@ -33,12 +33,20 @@
*/
package org.caboto.jena.db.impl;
+import com.hp.hpl.jena.query.Dataset;
+import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.sdb.SDBFactory;
import com.hp.hpl.jena.sdb.Store;
import com.hp.hpl.jena.sdb.StoreDesc;
import com.hp.hpl.jena.sdb.sql.SDBConnection;
import org.caboto.jena.db.AbstractDatabase;
+import org.caboto.jena.db.DataException;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URL;
+import java.net.URLDecoder;
import java.sql.Connection;
import java.sql.SQLException;
@@ -79,5 +87,19 @@
*/
protected Store connectToStore(Connection conn) {
return SDBFactory.connectStore(conn, storeDesc);
+ }
+
+ /**
+ * Imports a graph from file(s) in the classpath
+ * @param files The name(s) of the file to import
+ */
+ public void setLoadedFiles(String... files) {
+ for (String filename : files) {
+ Model model = getUpdateModel();
+ InputStream input = getClass().getResourceAsStream(filename);
+ model.read(input, "RDF/XML");
+ URL url = getClass().getResource(filename);
+ addModel(url.toString(), model);
+ }
}
}
Modified:
trunk/Caboto/database/src/main/java/org/caboto/jena/db/impl/SDBDatabase.java
==============================================================================
---
trunk/Caboto/database/src/main/java/org/caboto/jena/db/impl/SDBDatabase.java
(original)
+++
trunk/Caboto/database/src/main/java/org/caboto/jena/db/impl/SDBDatabase.java
Wed Mar 25 06:25:30 2009
@@ -212,4 +212,11 @@
}
}
+ /**
+ * Removes everything from the database
+ * @throws SQLException
+ */
+ public void clean() throws SQLException {
+ getStore().getTableFormatter().format();
+ }
}