Permalink
Browse files

updated version to support multiple threads accessing the parser

  • Loading branch information...
antoniogarrote committed Mar 1, 2011
1 parent ee97b70 commit 5552eaa103ea3cfe12d70472095f38f1c5a2e13a

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
Binary file not shown.
@@ -5,27 +5,15 @@
System.loadLibrary("SparqlParserWrapper");
}
- private native void init();
private native String parse_query(String query);
- private static SparqlParser parser;
-
- private SparqlParser() {
- init();
- }
-
- public String _parse(String query){
- return parse_query(query);
- }
-
public static String parse(String query) {
- if(parser == null) {
- parser = new SparqlParser();
- }
- return parser._parse(query);
+ return (new SparqlParser()).parse_query(query);
}
public static void main(String[] argv) {
- System.out.println("RESULT: "+SparqlParser.parse("SELECT * { ?s ?p ?o }"));
+ String query = "BASE <a> PREFIX test: <b> INSERT DATA { <a> <b> \"c\" }";
+ System.out.println("QUERY BEFORE:"+query);
+ System.out.println("RESULT: "+SparqlParser.parse(query));
}
}
Binary file not shown.
View
@@ -4,17 +4,18 @@
#include "sparqltest_SparqlParser.h"
-SparqlParser parser;
-
-JNIEXPORT void JNICALL Java_sparqltest_SparqlParser_init (JNIEnv *env , jobject obj) {
- parser = SparqlParser();
-}
-
JNIEXPORT jstring JNICALL Java_sparqltest_SparqlParser_parse_1query (JNIEnv *env, jobject obj, jstring javaQuery) {
+ SparqlParser parser;
+ parser = SparqlParser();
const char *query = env->GetStringUTFChars(javaQuery, 0);
+ //std::cout << "QUERY:";
+ //std::cout << std::string(query);
+
std::string result = parser.parse(std::string(query));
+ env->ReleaseStringUTFChars(javaQuery, query);
+
jstring javaResult = env->NewStringUTF(result.c_str());
return javaResult;
Oops, something went wrong.

0 comments on commit 5552eaa

Please sign in to comment.