Skip to content

Instantly share code, notes, and snippets.

@abbot
Created December 4, 2013 16:03
Show Gist options
  • Save abbot/7790146 to your computer and use it in GitHub Desktop.
Save abbot/7790146 to your computer and use it in GitHub Desktop.
fake data for sesame bug
package fd;
import java.io.Console;
import java.util.ArrayList;
import java.util.Calendar;
import org.openrdf.model.impl.StatementImpl;
import org.openrdf.model.impl.URIImpl;
import org.openrdf.query.QueryLanguage;
import org.openrdf.repository.RepositoryConnection;
import org.openrdf.repository.http.HTTPRepository;
public class App {
public static class LOG {
static Console console = System.console();
static long old_time = 0;
public static void print(String fmt, Object... args) {
String msg = String.format(fmt, args);
Calendar cal = Calendar.getInstance();
long now = cal.getTimeInMillis();
if (old_time == 0) {
console.printf("[%s] (first call) %s\n", cal.getTime(), msg);
} else {
console.printf("[%s] (%d msec) %s\n", cal.getTime(), now - old_time, msg);
}
old_time = now;
}
}
public static void main(String[] args) throws Exception {
HTTPRepository repo = new HTTPRepository("http://localhost:8080/openrdf-sesame/", "tests");
RepositoryConnection conn = repo.getConnection();
fake3(conn, 1, 1000, false);
fake3(conn, 1, 1000, true);
fake3(conn, 100, 1000, false);
LOG.print("Finished.");
}
private static void fake3(RepositoryConnection conn, int NPRED, int NSTMT, boolean move) throws Exception {
String q;
int stmt = 1;
LOG.print("fake3: %d / %d, using move: %s", NPRED, NSTMT, move);
LOG.print("clear");
conn.clear();
LOG.print("begin");
conn.begin();
ArrayList<StatementImpl> stmts = new ArrayList<StatementImpl>();
URIImpl ctx = new URIImpl("urn:dataset:new");
for (int j = 1; j <= NPRED; j++) {
URIImpl pred = new URIImpl("urn:pred:" + j);
for (int i = 1; i <= NSTMT; i++) {
stmts.add(new StatementImpl(new URIImpl("urn:subj:" + stmt), pred, new URIImpl("urn:obj:" + i)));
stmt += 1;
}
}
LOG.print("add");
conn.add(stmts, ctx);
LOG.print("commit");
conn.commit();
LOG.print("Repo size: %d", conn.size());
if (move) {
LOG.print("begin");
conn.begin();
q = "MOVE <urn:dataset:new> TO <urn:dataset:1>";
LOG.print("exec: %s", q);
conn.prepareUpdate(QueryLanguage.SPARQL, q).execute();
conn.commit();
LOG.print("commit");
} else {
LOG.print("begin");
conn.begin();
q = "COPY <urn:dataset:new> TO <urn:dataset:1>";
LOG.print("exec: %s", q);
conn.prepareUpdate(QueryLanguage.SPARQL, q).execute();
q = "DROP GRAPH <urn:dataset:new>";
LOG.print("exec: %s", q);
conn.prepareUpdate(QueryLanguage.SPARQL, q).execute();
conn.commit();
LOG.print("commit");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment