Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport insertStringLiteralAsSimple option from rdf4j driver #763

Open
wants to merge 1 commit into
base: develop/7
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion binsrc/sesame2/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ SAMPLES_SOURCE= \
virtuoso_driver/VirtuosoTest.java


SESAME_CLASSPATH= lib/commons-io-2.4.jar:lib/slf4j-api-1.7.13.jar:lib/slf4j-simple-1.7.13.jar:lib/openrdf-sesame-2.8.6-onejar.jar:$(top_srcdir)/libsrc/JDBCDriverType4/virtjdbc4.jar
SESAME_CLASSPATH= lib/commons-io-2.4.jar:lib/slf4j-api-1.7.13.jar:lib/slf4j-simple-1.7.13.jar:lib/openrdf-sesame-2.8.9-onejar.jar:$(top_srcdir)/libsrc/JDBCDriverType4/virtjdbc4.jar

all-am: $(TARGETS)

Expand Down
Binary file modified binsrc/sesame2/virt_sesame2.jar
Binary file not shown.
4 changes: 2 additions & 2 deletions binsrc/sesame2/virtuoso_driver/Version.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@

public class Version {

protected static final String DRV_VER = "2.8.6";
protected static final String DRV_VER = "2.8.9";

// The major and minor version number
protected static final String build_id = "1.31";
protected static final String build_id = "1.32";

public static void main(String args[])
{
Expand Down
121 changes: 72 additions & 49 deletions binsrc/sesame2/virtuoso_driver/VirtuosoRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@
* and that it should be shut down before it is discarded/garbage collected.
* Forgetting the latter can result in loss of data (depending on the Repository
* implementation)!
*
*
*/
public class VirtuosoRepository implements Repository {

ValueFactory valueFactory = new ValueFactoryImpl();
File dataDir;

private VirtuosoConnectionPoolDataSource pds = new VirtuosoConnectionPoolDataSource();
private String url_hostlist;
private String user;
Expand All @@ -67,16 +67,17 @@ public class VirtuosoRepository implements Repository {
private DataSource _ds;
private ConnectionPoolDataSource _pds;
private XADataSource _xads;

boolean useLazyAdd = true;
boolean insertBNodeAsVirtuosoIRI = false;
boolean insertStringLiteralAsSimple = false;
String defGraph;
int prefetchSize = 100;
int batchSize = 5000;
int queryTimeout = 0;
String ruleSet;
boolean useDefGraphForQueries = false;

public VirtuosoRepository(ConnectionPoolDataSource ds, String defGraph, boolean useLazyAdd) {
super();
this.defGraph = defGraph;
Expand All @@ -100,12 +101,12 @@ public VirtuosoRepository(XADataSource ds, String defGraph) {

/**
* Construct a VirtuosoRepository with a specified parameters
*
*
* @param url_hostlist
* the Virtuoso JDBC URL connection string or hostlist for poolled connection.
* Virtuoso database hostlist
* Virtuoso database hostlist
* <pre>
* "hostone:1112,hosttwo:1113"
* "hostone:1112,hosttwo:1113"
* or "hostone,hosttwo" if default port=1111 is used on hosts
* </pre>
* @param user
Expand All @@ -114,15 +115,15 @@ public VirtuosoRepository(XADataSource ds, String defGraph) {
* the user's password
* @param defGraph
* a default Graph name, used for Sesame calls, when contexts list
* is empty, exclude <tt>exportStatements, hasStatement, getStatements</tt> methods
* is empty, exclude <tt>exportStatements, hasStatement, getStatements</tt> methods
* @param useLazyAdd
* set <tt>true</tt> to enable using batch optimization for sequence of
* set <tt>true</tt> to enable using batch optimization for sequence of
* <pre>
* add(Resource subject, URI predicate, Value object, Resource... contexts);
* add(Statement statement, Resource... contexts);
* </pre>
* methods, when autoCommit mode is off. The triples will be sent to DBMS on commit call
* or when batch size become more than predefined batch max_size.
* or when batch size become more than predefined batch max_size.
* LazyAdd will be set false for XADataSource connection
*
*/
Expand All @@ -138,26 +139,26 @@ public VirtuosoRepository(String url_hostlist, String user, String password, Str
/**
* Construct a VirtuosoRepository with a specified parameters
* <tt>defGraph</tt> will be set to <tt>"sesame:nil"</tt>.
*
*
* @param url_hostlist
* the Virtuoso JDBC URL connection string or hostlist for poolled connection.
* Virtuoso database hostlist
* Virtuoso database hostlist
* <pre>
* "hostone:1112,hosttwo:1113"
* "hostone:1112,hosttwo:1113"
* or "hostone,hosttwo" if default port=1111 is used on hosts
* </pre>
* @param user
* the database user on whose behalf the connection is being made
* @param password
* the user's password
* @param useLazyAdd
* set <tt>true</tt> to enable using batch optimization for sequence of
* set <tt>true</tt> to enable using batch optimization for sequence of
* <pre>
* add(Resource subject, URI predicate, Value object, Resource... contexts);
* add(Statement statement, Resource... contexts);
* </pre>
* methods, when autoCommit mode is off. The triples will be sent to DBMS on commit call
* or when batch size become more than predefined batch max_size.
* or when batch size become more than predefined batch max_size.
* LazyAdd will be set false for XADataSource connection
*
*/
Expand All @@ -168,12 +169,12 @@ public VirtuosoRepository(String url_hostlist, String user, String password, boo
/**
* Construct a VirtuosoRepository with a specified parameters.
* useLazyAdd will be set to <tt>false</tt>.
*
*
* @param url_hostlist
* the Virtuoso JDBC URL connection string or hostlist for poolled connection.
* Virtuoso database hostlist
* Virtuoso database hostlist
* <pre>
* "hostone:1112,hosttwo:1113"
* "hostone:1112,hosttwo:1113"
* or "hostone,hosttwo" if the default port=1111 is used for hosts
* </pre>
* @param user
Expand All @@ -182,7 +183,7 @@ public VirtuosoRepository(String url_hostlist, String user, String password, boo
* the user's password
* @param defGraph
* a default Graph name, used for Sesame calls, when contexts list
* is empty, exclude <tt>exportStatements, hasStatement, getStatements</tt> methods
* is empty, exclude <tt>exportStatements, hasStatement, getStatements</tt> methods
*
*/
public VirtuosoRepository(String url_hostlist, String user, String password, String defGraph) {
Expand All @@ -193,12 +194,12 @@ public VirtuosoRepository(String url_hostlist, String user, String password, Str
* Construct a VirtuosoRepository with a specified parameters.
* <tt>useLazyAdd</tt> will be set to <tt>false</tt>.
* <tt>defGraph</tt> will be set to <tt>"sesame:nil"</tt>.
*
*
* @param url_hostlist
* the Virtuoso JDBC URL connection string or hostlist for poolled connection.
* Virtuoso database hostlist
* Virtuoso database hostlist
* <pre>
* "hostone:1112,hosttwo:1113"
* "hostone:1112,hosttwo:1113"
* or "hostone,hosttwo" if the default port=1111 is used for hosts
* </pre>
* @param user
Expand All @@ -215,7 +216,7 @@ public VirtuosoRepository(String url_hostlist, String user, String password) {
* updating the contents of the repository. Created connections need to be
* closed to make sure that any resources they keep hold of are released. The
* best way to do this is to use a try-finally-block as follows:
*
*
* <pre>
* Connection con = repository.getConnection();
* try {
Expand All @@ -225,7 +226,7 @@ public VirtuosoRepository(String url_hostlist, String user, String password) {
* con.close();
* }
* </pre>
*
*
* @return A connection that allows operations on this repository.
* @throws RepositoryException
* If something went wrong during the creation of the Connection.
Expand Down Expand Up @@ -281,14 +282,14 @@ else if (url_hostlist.startsWith("jdbc:virtuoso://")) {
else
url = url + "roundrobin=1";
}

if (url.toLowerCase().indexOf("log_enable=") == -1) {
if (url.charAt(url.length()-1) != '/')
url = url + "/log_enable=2";
else
url = url + "log_enable=2";
}

java.sql.Connection connection = DriverManager.getConnection(url, user, password);
return new VirtuosoRepositoryConnection(this, connection);
}
Expand All @@ -312,12 +313,12 @@ else if (url_hostlist.startsWith("jdbc:virtuoso://")) {
System.out.println("Connection to " + url_hostlist + " has FAILED.");
throw new RepositoryException(e);
}
}
}
}

/**
* Set the buffer fetch size(default 100)
*
* Set the buffer fetch size(default 100)
*
* @param sz
* buffer fetch size.
*/
Expand All @@ -333,8 +334,8 @@ public int getFetchSize() {
}

/**
* Set the batch size for Inserts data(default 5000)
*
* Set the batch size for Inserts data(default 5000)
*
* @param sz
* batch size.
*/
Expand All @@ -350,8 +351,8 @@ public int getBatchSize() {
}

/**
* Set the query timeout(default 0)
*
* Set the query timeout(default 0)
*
* @param seconds
* queryTimeout seconds, 0 - unlimited.
*/
Expand All @@ -367,7 +368,7 @@ public int getQueryTimeout() {
}

/**
* Set the UseLazyAdd state for connection(default true)
* Set the UseLazyAdd state for connection(default true)
* for XADataSource connection set false and can't be changed
* @param v
* true - useLazyAdd
Expand All @@ -385,8 +386,8 @@ public boolean getUseLazyAdd() {


/**
* Set the RoundRobin state for connection(default false)
*
* Set the RoundRobin state for connection(default false)
*
* @param v
* true - use roundrobin
*/
Expand All @@ -403,8 +404,8 @@ public boolean getRoundrobin() {


/**
* Set the insertBNodeAsURI state for connection(default false)
*
* Set the insertBNodeAsURI state for connection(default false)
*
* @param v
* true - insert BNode as Virtuoso IRI
* false - insert BNode as Virtuoso Native BNode
Expand All @@ -421,10 +422,32 @@ public boolean getInsertBNodeAsVirtuosoIRI() {
}




/**
* Get the insertStringLiteralAsSimple state for connection
*
* @return insertStringLiteralAsSimple state
*/
public boolean getInsertStringLiteralAsSimple() {
return this.insertStringLiteralAsSimple;
}

/**
* Set the insertStringLiteralAsSimple state for connection(default false)
*
* @param v
* true - insert String Literals as Simple Literals
* false - insert String Literals as is
*/
public void setInsertStringLiteralAsSimple(boolean v) {
this.insertStringLiteralAsSimple = v;
}



/**
* Set inference RuleSet name
*
*
* @param name
* RuleSet name.
*/
Expand All @@ -441,9 +464,9 @@ public String getRuleSet() {
return this.ruleSet;
}


/**
* Use defGraph with SPARQL queries, if query default graph wasn't set (default false)
* Use defGraph with SPARQL queries, if query default graph wasn't set (default false)
* @param v
* true - useDefGraphForQueries
*/
Expand All @@ -462,7 +485,7 @@ public boolean getUseDefGraphForQueries() {

/**
* Get the directory where data and logging for this repository is stored.
*
*
* @return the directory where data for this repository is stored.
*/
public File getDataDir() {
Expand All @@ -471,7 +494,7 @@ public File getDataDir() {

/**
* Gets a ValueFactory for this Repository.
*
*
* @return A repository-specific ValueFactory.
*/
public ValueFactory getValueFactory() {
Expand All @@ -481,7 +504,7 @@ public ValueFactory getValueFactory() {
/**
* Initializes this repository. A repository needs to be initialized before
* it can be used.
*
*
* @throws RepositoryException
* If the initialization failed.
*/
Expand All @@ -492,13 +515,13 @@ public void initialize() throws RepositoryException {
/**
* Indicates if the Repository has been initialized. Note that the
* initialization status may change if the Repository is shut down.
*
*
* @return true iff the repository has been initialized.
*/
public boolean isInitialized() {
return initialized;
}


/**
* Checks whether this repository is writable, i.e. if the data contained in
Expand All @@ -516,7 +539,7 @@ public boolean isWritable() throws RepositoryException {

/**
* Set the directory where data and logging for this repository is stored.
*
*
* @param dataDir
* the directory where data for this repository is stored
*/
Expand Down