Strabon
changeset 1183:a92a8a80aae8 sqlite
started adding sqlite database backend
line diff
1.1 --- a/generaldb/src/main/java/org/openrdf/sail/generaldb/managers/TripleTableManager.java Thu May 23 17:30:52 2013 +0300 1.2 +++ b/generaldb/src/main/java/org/openrdf/sail/generaldb/managers/TripleTableManager.java Tue Jun 04 18:06:42 2013 +0300 1.3 @@ -52,7 +52,7 @@ 1.4 1.5 private boolean closed; 1.6 1.7 - private Connection conn; 1.8 + protected Connection conn; 1.9 1.10 private ValueTableFactory factory; 1.11 1.12 @@ -423,7 +423,7 @@ 1.13 logger.debug("Closing helper thread {}", initThread.getName()); 1.14 } 1.15 1.16 - private Set<String> findPredicateTableNames() 1.17 + protected Set<String> findPredicateTableNames() 1.18 throws SQLException 1.19 { 1.20 Set<String> names = findAllTables();
2.1 --- a/pom.xml Thu May 23 17:30:52 2013 +0300 2.2 +++ b/pom.xml Tue Jun 04 18:06:42 2013 +0300 2.3 @@ -129,6 +129,7 @@ 2.4 <module>evaluation</module> 2.5 <module>runtime</module> 2.6 <module>postgis</module> 2.7 + <module>sqlite</module> 2.8 <module>monetdb</module> 2.9 <module>generaldb</module> 2.10 <module>resultio-spatial</module> 2.11 @@ -261,6 +262,12 @@ 2.12 <artifactId>sesame-sail-postgis</artifactId> 2.13 <version>${eu.earthobservatory.version}</version> 2.14 </dependency> 2.15 + <dependency> 2.16 + <groupId>org.openrdf.sesame</groupId> 2.17 + <artifactId>sesame-sail-sqlite</artifactId> 2.18 + <version>${eu.earthobservatory.version}</version> 2.19 + </dependency> 2.20 + 2.21 2.22 <!-- Sesame dependencies --> 2.23 <dependency>
3.1 --- a/runtime/pom.xml Thu May 23 17:30:52 2013 +0300 3.2 +++ b/runtime/pom.xml Tue Jun 04 18:06:42 2013 +0300 3.3 @@ -58,6 +58,11 @@ 3.4 <groupId>org.openrdf.sesame</groupId> 3.5 <artifactId>sesame-sail-postgis</artifactId> 3.6 </dependency> 3.7 + 3.8 + <dependency> 3.9 + <groupId>org.openrdf.sesame</groupId> 3.10 + <artifactId>sesame-sail-sqlite</artifactId> 3.11 + </dependency> 3.12 3.13 <dependency> 3.14 <groupId>org.openrdf.sesame</groupId>
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 4.2 +++ b/runtime/src/main/java/eu/earthobservatory/runtime/sqlite/BracketTest.java Tue Jun 04 18:06:42 2013 +0300 4.3 @@ -0,0 +1,64 @@ 4.4 +package eu.earthobservatory.runtime.sqlite; 4.5 + 4.6 + 4.7 + 4.8 +import java.sql.Connection; 4.9 +import java.sql.DriverManager; 4.10 +import java.sql.PreparedStatement; 4.11 +import java.sql.ResultSet; 4.12 +import java.sql.Statement; 4.13 + 4.14 +import org.sqlite.SQLiteConfig; 4.15 + 4.16 +public class BracketTest { 4.17 + public static void main(String args[]) throws Exception { 4.18 + Class.forName("org.sqlite.JDBC"); 4.19 + // SQLiteConfig config = new SQLiteConfig(); 4.20 + // config.enableLoadExtension(true); 4.21 + 4.22 + // create a database connection 4.23 + // Connection conn = DriverManager.getConnection("jdbc:sqlite:/tmp/666.db", 4.24 + // config.toProperties()); 4.25 + // Statement stmt1 = conn.createStatement(); 4.26 + // stmt1.setQueryTimeout(30); // set timeout to 30 sec. 4.27 + 4.28 + // loading SpatiaLite 4.29 + // stmt1.execute("SELECT load_extension('/usr/local/lib/libspatialite.so')"); 4.30 + 4.31 + // enabling Spatial Metadata 4.32 + // using v.2.4.0 this automatically initializes SPATIAL_REF_SYS and GEOMETRY_COLUMNS 4.33 + // String sql = "SELECT InitSpatialMetadata()"; 4.34 + // stmt1.execute(sql); 4.35 + 4.36 + Connection conn = DriverManager.getConnection("jdbc:sqlite:/tmp/11117.db"); 4.37 + 4.38 + Statement stat = conn.createStatement(); 4.39 + 4.40 + stat.execute("create table person (p_id primary key, p_name)"); 4.41 + stat.execute("insert into person values (1, 'employee')"); 4.42 + stat.execute("create table contact (p_id primary key, p_name)"); 4.43 + stat.execute("insert into contact values (1, 'contact')"); 4.44 + stat.execute("create table company (p_id primary key, p_name)"); 4.45 + stat.execute("insert into company values (1, 'company')"); 4.46 + // stat.close(); 4.47 + // conn.close(); 4.48 + 4.49 + String sql2="select * from contact as ct inner join ( person as p " + 4.50 + "inner join company as c on p.p_id=c.p_id " + 4.51 + ") " + 4.52 + " on p.p_id=ct.p_id " + 4.53 + "where p.p_id=1;"; 4.54 + System.out.println(sql2); 4.55 + //PreparedStatement stmt = conn.prepareStatement(sql2); 4.56 + 4.57 + //stmt.setInt(1, 1); 4.58 + 4.59 + ResultSet rs = conn.createStatement().executeQuery(sql2); 4.60 + 4.61 + rs.next(); 4.62 + System.out.println( 4.63 + rs.getString(1) + "|" + rs.getString(2) + "|" + 4.64 + rs.getString(3) + "|" + rs.getString(4) + "|" + 4.65 + rs.getString(5) + "|" + rs.getString(6)); 4.66 + } 4.67 +} 4.68 \ No newline at end of file
5.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 5.2 +++ b/runtime/src/main/java/eu/earthobservatory/runtime/sqlite/QueryOp.java Tue Jun 04 18:06:42 2013 +0300 5.3 @@ -0,0 +1,53 @@ 5.4 +package eu.earthobservatory.runtime.sqlite; 5.5 + 5.6 +import eu.earthobservatory.utils.Format; 5.7 + 5.8 +import org.slf4j.Logger; 5.9 +import org.slf4j.LoggerFactory; 5.10 + 5.11 +public class QueryOp { 5.12 + 5.13 + private static Logger logger = LoggerFactory.getLogger(eu.earthobservatory.runtime.sqlite.QueryOp.class); 5.14 + 5.15 + /** 5.16 + * @param args 5.17 + * @throws Exception 5.18 + */ 5.19 + public static void main(String[] args) { 5.20 + 5.21 + if (args.length < 3) { 5.22 + System.err.println("Usage: eu.ist.semsorgrid4env.strabon.Strabon <HOST> <PORT> <DATABASE> <USERNAME> <PASSWORD> <QUERY> "); 5.23 + System.err.println(" <DATABASE> is the spatially enabled sqlite database that Strabon will use as a backend, "); 5.24 + System.err.println(" <QUERY> is the stSPARQL query to evaluate."); 5.25 + System.err.println(" <DELET_LOCK> is true when deletion of \"locked\" table should be enforced (e.g., when Strabon has been ungracefully shutdown)."); 5.26 + System.err.println(" [<FORMAT>] is the format of your results (default: XML)"); 5.27 + System.exit(0); 5.28 + } 5.29 + 5.30 + // String host = args[0]; 5.31 + // Integer port = new Integer(args[1]); 5.32 + String db = args[0]; 5.33 + String libspatial = args[1]; 5.34 + String regex = args[2]; 5.35 + String queryString = args[3]; 5.36 + boolean forceDelete = Boolean.valueOf(args[4]); 5.37 + String resultsFormat = ""; 5.38 + if ( args.length == 6 ) { 5.39 + resultsFormat = args[5]; 5.40 + } 5.41 + 5.42 + Strabon strabon = null; 5.43 + try { 5.44 + strabon = new Strabon(db, libspatial, regex, forceDelete); 5.45 + strabon.query(queryString, Format.fromString(resultsFormat), strabon.getSailRepoConnection(), System.out); 5.46 + 5.47 + } catch (Exception e) { 5.48 + logger.error("[Strabon.QueryOp] Error during execution of SPARQL query.", e); 5.49 + 5.50 + } finally { 5.51 + if (strabon != null) { 5.52 + strabon.close(); 5.53 + } 5.54 + } 5.55 + } 5.56 +}
6.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 6.2 +++ b/runtime/src/main/java/eu/earthobservatory/runtime/sqlite/SpatialiteSample.java Tue Jun 04 18:06:42 2013 +0300 6.3 @@ -0,0 +1,264 @@ 6.4 +package eu.earthobservatory.runtime.sqlite; 6.5 + 6.6 +import java.sql.Connection; 6.7 +import java.sql.DriverManager; 6.8 +import java.sql.ResultSet; 6.9 +import java.sql.SQLException; 6.10 +import java.sql.Statement; 6.11 +import java.sql.PreparedStatement; 6.12 +import org.sqlite.SQLiteConfig; 6.13 + 6.14 +public class SpatialiteSample 6.15 +{ 6.16 + public static void main(String[] args) throws ClassNotFoundException 6.17 + { 6.18 + // load the sqlite-JDBC driver using the current class loader 6.19 + Class.forName("org.sqlite.JDBC"); 6.20 + 6.21 + Connection conn = null; 6.22 + try 6.23 + { 6.24 + // enabling dynamic extension loading 6.25 + // absolutely required by SpatiaLite 6.26 + SQLiteConfig config = new SQLiteConfig(); 6.27 + config.enableLoadExtension(true); 6.28 + 6.29 + // create a database connection 6.30 + conn = DriverManager.getConnection("jdbc:sqlite:/tmp/000.db", 6.31 + config.toProperties()); 6.32 + Statement stmt = conn.createStatement(); 6.33 + stmt.setQueryTimeout(30); // set timeout to 30 sec. 6.34 + 6.35 + // loading SpatiaLite 6.36 + stmt.execute("SELECT load_extension('/usr/local/lib/libspatialite.so')"); 6.37 + stmt.execute("SELECT load_extension('/usr/lib/sqlite3/pcre.so')"); 6.38 + // enabling Spatial Metadata 6.39 + // using v.2.4.0 this automatically initializes SPATIAL_REF_SYS and GEOMETRY_COLUMNS 6.40 + String sql = "SELECT InitSpatialMetadata()"; 6.41 + stmt.execute(sql); 6.42 + 6.43 +// sql="SELECT t0.obj,"+ 6.44 +// "l_title.value,"+ 6.45 +// " NULL ,"+ 6.46 +// " NULL ,"+ 6.47 +// "p1.obj,"+ 6.48 +// "l_price.value,"+ 6.49 +// " NULL ,"+ 6.50 +// "d_price.value"+ 6.51 +//"FROM title_47 t0"+ 6.52 +//" LEFT JOIN (price_50 p1"+ 6.53 +//" LEFT JOIN numeric_values n_price ON (n_price.id = p1.obj)"+ 6.54 +//" LEFT JOIN datatype_values d_price ON (d_price.id = p1.obj)"+ 6.55 +//" LEFT JOIN label_values l_price ON (l_price.id = p1.obj)) ON (p1.subj = t0.subj"+ 6.56 +//" AND n_price.value < ? )"+ 6.57 +//" LEFT JOIN label_values l_title ON (l_title.id = t0.obj)"; 6.58 +// stmt.execute(sql); 6.59 +// // creating a POINT table 6.60 + sql = "CREATE TABLE test_pt ("; 6.61 + sql += "id INTEGER NOT NULL PRIMARY KEY,"; 6.62 + sql += "name TEXT NOT NULL)"; stmt.execute(sql); 6.63 +// // creating a POINT Geometry column 6.64 + sql = "SELECT AddGeometryColumn('test_pt', "; 6.65 + sql += "'geom', 4326, 'POINT', 'XY')"; 6.66 + stmt.execute(sql); 6.67 + 6.68 + // creating a LINESTRING table 6.69 + sql = "CREATE TABLE test_ln ("; 6.70 + sql += "id INTEGER NOT NULL PRIMARY KEY,"; 6.71 + sql += "name TEXT NOT NULL)"; 6.72 + stmt.execute(sql); 6.73 + // creating a LINESTRING Geometry column 6.74 + sql = "SELECT AddGeometryColumn('test_ln', "; 6.75 + sql += "'geom', 4326, 'LINESTRING', 'XY')"; 6.76 + stmt.execute(sql); 6.77 + 6.78 + // creating a POLYGON table 6.79 + sql = "CREATE TABLE test_pg ("; 6.80 + sql += "id INTEGER NOT NULL PRIMARY KEY,"; 6.81 + sql += "name TEXT NOT NULL)"; 6.82 + stmt.execute(sql); 6.83 + // creating a POLYGON Geometry column 6.84 + sql = "SELECT AddGeometryColumn('test_pg', "; 6.85 + sql += "'geom', 4326, 'POLYGON', 'XY')"; 6.86 + stmt.execute(sql); 6.87 + 6.88 + // inserting some POINTs 6.89 + // please note well: SQLite is ACID and Transactional, 6.90 + // so (to get best performance) the whole insert cycle 6.91 + // will be handled as a single TRANSACTION 6.92 + conn.setAutoCommit(false); 6.93 + int i; 6.94 + for (i = 0; i < 100000; i++) 6.95 + { 6.96 + // for POINTs we'll use full text sql statements 6.97 + sql = "INSERT INTO test_pt (id, name, geom) VALUES ("; 6.98 + sql += i + 1; 6.99 + sql += ", 'test POINT #"; 6.100 + sql += i + 1; 6.101 + sql += "', GeomFromText('POINT("; 6.102 + sql += i / 1000.0; 6.103 + sql += " "; 6.104 + sql += i / 1000.0; 6.105 + sql += ")', 4326))"; 6.106 + stmt.executeUpdate(sql); 6.107 + } 6.108 + conn.commit(); 6.109 + 6.110 + // checking POINTs 6.111 + sql = "SELECT DISTINCT Count(*), ST_GeometryType(geom), "; 6.112 + sql += "ST_Srid(geom) FROM test_pt"; 6.113 + ResultSet rs = stmt.executeQuery(sql); 6.114 + while(rs.next()) 6.115 + { 6.116 + // read the result set 6.117 + String msg = "> Inserted "; 6.118 + msg += rs.getInt(1); 6.119 + msg += " entities of type "; 6.120 + msg += rs.getString(2); 6.121 + msg += " SRID="; 6.122 + msg += rs.getInt(3); 6.123 + System.out.println(msg); 6.124 + } 6.125 + 6.126 + // inserting some LINESTRINGs 6.127 + // this time we'll use a Prepared Statement 6.128 + sql = "INSERT INTO test_ln (id, name, geom) "; 6.129 + sql += "VALUES (?, ?, GeomFromText(?, 4326))"; 6.130 + PreparedStatement ins_stmt = conn.prepareStatement(sql); 6.131 + conn.setAutoCommit(false); 6.132 + for (i = 0; i < 100000; i++) 6.133 + { 6.134 + // setting up values / binding 6.135 + String name = "test LINESTRING #"; 6.136 + name += i + 1; 6.137 + String geom = "LINESTRING ("; 6.138 + if ((i%2) == 1) 6.139 + { 6.140 + // odd row: five points 6.141 + geom += "-180.0 -90.0, "; 6.142 + geom += -10.0 - (i / 1000.0); 6.143 + geom += " "; 6.144 + geom += -10.0 - (i / 1000.0); 6.145 + geom += ", "; 6.146 + geom += -10.0 - (i / 1000.0); 6.147 + geom += " "; 6.148 + geom += 10.0 + (i / 1000.0); 6.149 + geom += ", "; 6.150 + geom += 10.0 + (i / 1000.0); 6.151 + geom += " "; 6.152 + geom += 10.0 + (i / 1000.0); 6.153 + geom += ", 180.0 90.0"; 6.154 + } 6.155 + else 6.156 + { 6.157 + // even row: two points 6.158 + geom += -10.0 - (i / 1000.0); 6.159 + geom += " "; 6.160 + geom += -10.0 - (i / 1000.0); 6.161 + geom += ", "; 6.162 + geom += 10.0 + (i / 1000.0); 6.163 + geom += " "; 6.164 + geom += 10.0 + (i / 1000.0); 6.165 + } 6.166 + geom += ")"; 6.167 + ins_stmt.setInt(1, i+1); 6.168 + ins_stmt.setString(2, name); 6.169 + ins_stmt.setString(3, geom); 6.170 + ins_stmt.executeUpdate(); 6.171 + } 6.172 + conn.commit(); 6.173 + 6.174 + // checking LINESTRINGs 6.175 + sql = "SELECT DISTINCT Count(*), ST_GeometryType(geom), "; 6.176 + sql += "ST_Srid(geom) FROM test_ln"; 6.177 + rs = stmt.executeQuery(sql); 6.178 + while(rs.next()) 6.179 + { 6.180 + // read the result set 6.181 + String msg = "> Inserted "; 6.182 + msg += rs.getInt(1); 6.183 + msg += " entities of type "; 6.184 + msg += rs.getString(2); 6.185 + msg += " SRID="; 6.186 + msg += rs.getInt(3); 6.187 + System.out.println(msg); 6.188 + } 6.189 + 6.190 + // inserting some POLYGONs 6.191 + // this time too we'll use a Prepared Statement 6.192 + sql = "INSERT INTO test_pg (id, name, geom) "; 6.193 + sql += "VALUES (?, ?, GeomFromText(?, 4326))"; 6.194 + ins_stmt = conn.prepareStatement(sql); 6.195 + conn.setAutoCommit(false); 6.196 + for (i = 0; i < 100000; i++) 6.197 + { 6.198 + // setting up values / binding 6.199 + String name = "test POLYGON #"; 6.200 + name += i + 1; 6.201 + ins_stmt.setInt(1, i+1); 6.202 + ins_stmt.setString(2, name); 6.203 + String geom = "POLYGON(("; 6.204 + geom += -10.0 - (i / 1000.0); 6.205 + geom += " "; 6.206 + geom += -10.0 - (i / 1000.0); 6.207 + geom += ", "; 6.208 + geom += 10.0 + (i / 1000.0); 6.209 + geom += " "; 6.210 + geom += -10.0 - (i / 1000.0); 6.211 + geom += ", "; 6.212 + geom += 10.0 + (i / 1000.0); 6.213 + geom += " "; 6.214 + geom += 10.0 + (i / 1000.0); 6.215 + geom += ", "; 6.216 + geom += -10.0 - (i / 1000.0); 6.217 + geom += " "; 6.218 + geom += 10.0 + (i / 1000.0); 6.219 + geom += ", "; 6.220 + geom += -10.0 - (i / 1000.0); 6.221 + geom += " "; 6.222 + geom += -10.0 - (i / 1000.0); 6.223 + geom += "))"; 6.224 + ins_stmt.setInt(1, i+1); 6.225 + ins_stmt.setString(2, name); 6.226 + ins_stmt.setString(3, geom); 6.227 + ins_stmt.executeUpdate(); 6.228 + } 6.229 + conn.commit(); 6.230 + 6.231 + // checking POLYGONs 6.232 + sql = "SELECT DISTINCT Count(*), ST_GeometryType(geom), "; 6.233 + sql += "ST_Srid(geom) FROM test_pg"; 6.234 + rs = stmt.executeQuery(sql); 6.235 + while(rs.next()) 6.236 + { 6.237 + // read the result set 6.238 + String msg = "> Inserted "; 6.239 + msg += rs.getInt(1); 6.240 + msg += " entities of type "; 6.241 + msg += rs.getString(2); 6.242 + msg += " SRID="; 6.243 + msg += rs.getInt(3); 6.244 + System.out.println(msg); 6.245 + } 6.246 + } 6.247 + catch(SQLException e) 6.248 + { 6.249 + // if the error message is "out of memory", 6.250 + // it probably means no database file is found 6.251 + System.err.println(e.getMessage()); 6.252 + } 6.253 + finally 6.254 + { 6.255 + try 6.256 + { 6.257 + if(conn != null) 6.258 + conn.close(); 6.259 + } 6.260 + catch(SQLException e1) 6.261 + { 6.262 + // connection close failed. 6.263 + System.err.println(e1); 6.264 + } 6.265 + } 6.266 + } 6.267 +} 6.268 \ No newline at end of file
7.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 7.2 +++ b/runtime/src/main/java/eu/earthobservatory/runtime/sqlite/StoreOp.java Tue Jun 04 18:06:42 2013 +0300 7.3 @@ -0,0 +1,81 @@ 7.4 +package eu.earthobservatory.runtime.sqlite; 7.5 + 7.6 +import org.slf4j.Logger; 7.7 +import org.slf4j.LoggerFactory; 7.8 + 7.9 +public class StoreOp { 7.10 + 7.11 + private static Logger logger = LoggerFactory.getLogger(eu.earthobservatory.runtime.postgis.StoreOp.class); 7.12 + 7.13 + /** 7.14 + * @param args 7.15 + * @throws Exception 7.16 + */ 7.17 + public static void main(String[] args) { 7.18 + 7.19 + if (args.length < 2) { 7.20 + help(); 7.21 + System.exit(1); 7.22 + } 7.23 + 7.24 + String db = args[0]; 7.25 + String libspatial = args[1]; 7.26 + String regex = args[2]; 7.27 + String src = args[3]; 7.28 + String format = "NTRIPLES"; 7.29 + String graph = null; 7.30 + 7.31 + for (int i = 4; i < args.length; i += 2) { 7.32 + if (args[i].equals("-f")) { 7.33 + if (i + 1 >= args.length) { 7.34 + System.err.println("Option \"-f\" requires an argument."); 7.35 + help(); 7.36 + System.exit(1); 7.37 + 7.38 + } else { 7.39 + format = args[i+1]; 7.40 + } 7.41 + } else if (args[i].equals("-g")) { 7.42 + if (i + 1 >= args.length) { 7.43 + System.err.println("Option \"-g\" requires an argument."); 7.44 + help(); 7.45 + System.exit(1); 7.46 + 7.47 + } else { 7.48 + graph = args[i+1]; 7.49 + } 7.50 + 7.51 + } else { 7.52 + System.err.println("Unknown argument \"" + args[i] + "\"."); 7.53 + help(); 7.54 + System.exit(1); 7.55 + } 7.56 + } 7.57 + 7.58 + Strabon strabon = null; 7.59 + try { 7.60 + strabon = new Strabon(db, libspatial, regex, false); 7.61 + if (graph == null) { 7.62 + strabon.storeInRepo(src, format); 7.63 + 7.64 + } else { 7.65 + strabon.storeInRepo(src, null, graph, format); 7.66 + } 7.67 + 7.68 + } catch (Exception e) { 7.69 + logger.error("[Strabon.StoreOp] Error during store.", e); 7.70 + 7.71 + } finally { 7.72 + if (strabon != null) { 7.73 + strabon.close(); 7.74 + } 7.75 + } 7.76 + } 7.77 + 7.78 + private static void help() { 7.79 + System.err.println("Usage: eu.earthobservatory.runtime.postgis.StoreOp <HOST> <PORT> <DATABASE> <USERNAME> <PASSWORD> <FILE> [-f <FORMAT>] [-g <NAMED_GRAPH>]"); 7.80 + System.err.println(" <DATABASE> is the spatially enabled postgis database that Strabon will use as a backend, "); 7.81 + System.err.println(" [-f <FORMAT>] is the format of the file (default: NTRIPLES)"); 7.82 + System.err.println(" [-g <NAMED_GRAPH>] is the URI of the named graph to store the input file (default: default graph)"); 7.83 + } 7.84 +}
8.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 8.2 +++ b/runtime/src/main/java/eu/earthobservatory/runtime/sqlite/Strabon.java Tue Jun 04 18:06:42 2013 +0300 8.3 @@ -0,0 +1,221 @@ 8.4 +package eu.earthobservatory.runtime.sqlite; 8.5 + 8.6 +/** 8.7 + * This Source Code Form is subject to the terms of the Mozilla Public 8.8 + * License, v. 2.0. If a copy of the MPL was not distributed with this 8.9 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. 8.10 + * 8.11 + * Copyright (C) 2010, 2011, 2012, Pyravlos Team 8.12 + * 8.13 + * http://www.strabon.di.uoa.gr/ 8.14 + */ 8.15 + 8.16 + 8.17 +import java.sql.Connection; 8.18 +import java.sql.DatabaseMetaData; 8.19 +import java.sql.DriverManager; 8.20 +import java.sql.ResultSet; 8.21 +import java.sql.SQLException; 8.22 +import java.sql.Statement; 8.23 +import java.util.ArrayList; 8.24 + 8.25 +import org.openrdf.repository.RepositoryException; 8.26 +import org.openrdf.repository.sail.SailRepository; 8.27 +import org.openrdf.repository.sail.SailRepositoryConnection; 8.28 +import org.openrdf.sail.SailConnection; 8.29 +import org.openrdf.sail.sqlite.SpatiaLiteSqlStore; 8.30 +import org.slf4j.Logger; 8.31 +import org.slf4j.LoggerFactory; 8.32 +import org.sqlite.SQLiteConfig; 8.33 + 8.34 +/** 8.35 + * 8.36 + * @author Charalampos Nikolaou <charnik@di.uoa.gr> 8.37 + * @author Manos Karpathiotakis <mk@di.uoa.gr> 8.38 + */ 8.39 +public class Strabon extends eu.earthobservatory.runtime.generaldb.Strabon { 8.40 + 8.41 + private static Logger logger = LoggerFactory.getLogger(eu.earthobservatory.runtime.postgis.Strabon.class); 8.42 + 8.43 + public Strabon(String databaseName, String spatialite, String regex, boolean checkForLockTable) 8.44 + throws Exception { 8.45 + super(databaseName, spatialite, regex, 0, "", checkForLockTable); 8.46 + } 8.47 + 8.48 + public Strabon(String databaseName, String user, String password, int port, String serverName, boolean checkForLockTable) throws Exception { 8.49 + super(databaseName, user, password, 0, "", checkForLockTable); 8.50 + createSpatialAndDeleteTemp(databaseName, user, password); 8.51 + 8.52 + } 8.53 + 8.54 + private void createSpatialAndDeleteTemp(String databaseName, String libspatial, String regex) throws SQLException, ClassNotFoundException { 8.55 + String url = ""; 8.56 + try { 8.57 + logger.info("[Strabon] Cleaning..."); 8.58 + Class.forName("org.sqlite.JDBC"); 8.59 + url = "jdbc:sqlite:" + databaseName ; 8.60 + SQLiteConfig config = new SQLiteConfig(); 8.61 + config.enableLoadExtension(true); 8.62 + Connection c=DriverManager.getConnection(url,config.toProperties()); 8.63 + 8.64 + Statement st=c.createStatement(); 8.65 + //st.execute("SELECT load_extension('/usr/local/lib/libspatialite.so')"); 8.66 + //st.execute("SELECT load_extension('/usr/lib/sqlite3/pcre.so')"); 8.67 + st.execute("SELECT load_extension('"+libspatial+"')"); 8.68 + try{ 8.69 + st.execute("SELECT load_extension('"+regex+"')"); 8.70 + }catch(Exception e){ 8.71 + logger.warn("Error loading regex library. Regular expressions will not be supported."); 8.72 + } 8.73 + DatabaseMetaData dbm = c.getMetaData(); 8.74 + ResultSet rs = dbm.getTables(null, null, "spatial_ref_sys", null); 8.75 + if (!rs.next()) { 8.76 + st.execute("SELECT InitSpatialMetaData()"); 8.77 + 8.78 + } 8.79 + // st.execute("SELECT load_extension('/usr/lib/libspatialite.so')"); 8.80 + 8.81 + // check if "employee" table is there 8.82 + rs = dbm.getTables(null, null, "to_drop", null); 8.83 + if (!rs.next()) { 8.84 + st.executeUpdate("CREATE TABLE to_drop (name VARCHAR(255))"); 8.85 + } 8.86 + else{ 8.87 + rs=st.executeQuery("SELECT * FROM to_drop"); 8.88 + ArrayList<String> names=new ArrayList<String>(); 8.89 + while(rs.next()){ 8.90 + names.add(rs.getString(1)); 8.91 + //st.executeUpdate("DROP TABLE IF EXISTS "+ rs.getString(1)); 8.92 + } 8.93 + rs.close(); 8.94 + st.close(); 8.95 + c.close(); //!!! If I continue with the same connection there is a "database table is locked" error 8.96 + 8.97 + Connection c2=DriverManager.getConnection(url); 8.98 + Statement st2=c2.createStatement(); 8.99 + for(String name:names){ 8.100 + st2.executeUpdate("DROP TABLE IF EXISTS "+ name+";"); 8.101 + } 8.102 + st2.executeUpdate("DELETE FROM to_drop WHERE (1=1)"); 8.103 + st2.close(); 8.104 + c2.close(); 8.105 + } 8.106 + 8.107 + //rs.close(); 8.108 + 8.109 + 8.110 + } catch (SQLException e) { 8.111 + logger.error("[Strabon.checkAndDeleteLock] SQL Exception occured. Connection URL is <"+url+">: " + e.getMessage()); 8.112 + throw e; 8.113 + 8.114 + } catch (ClassNotFoundException e) { 8.115 + logger.error("[Strabon.checkAndDeleteLock] Could not load sqlite jdbc driver: " + e.getMessage()); 8.116 + throw e; 8.117 + } 8.118 + } 8.119 + 8.120 + 8.121 + @Override 8.122 + protected void checkAndDeleteLock(String databaseName, String user, String password, int port, String serverName) 8.123 + throws SQLException, ClassNotFoundException { 8.124 + createSpatialAndDeleteTemp(databaseName, user, password); 8.125 + String url = ""; 8.126 + try { 8.127 + logger.info("[Strabon] Cleaning..."); 8.128 + Class.forName("org.sqlite.JDBC"); 8.129 + url = "jdbc:sqlite:" + databaseName ; 8.130 + Connection conn = DriverManager.getConnection(url); 8.131 + java.sql.Statement st = conn.createStatement(); 8.132 + st.execute("DROP TABLE IF EXISTS locked;"); 8.133 + st.close(); 8.134 + conn.close(); 8.135 + 8.136 + logger.info("[Strabon] Clearing Successful."); 8.137 + 8.138 + } catch (SQLException e) { 8.139 + logger.error("[Strabon.checkAndDeleteLock] SQL Exception occured. Connection URL is <"+url+">: " + e.getMessage()); 8.140 + throw e; 8.141 + 8.142 + } catch (ClassNotFoundException e) { 8.143 + logger.error("[Strabon.checkAndDeleteLock] Could not load sqlite jdbc driver: " + e.getMessage()); 8.144 + throw e; 8.145 + } 8.146 + } 8.147 + 8.148 + @Override 8.149 + public void deregisterDriver() { 8.150 + try { 8.151 + logger.info("[Strabon.deregisterDriver] Deregistering JDBC driver..."); 8.152 + java.sql.Driver driver = DriverManager.getDriver("jdbc:sqlite:"+ databaseName); 8.153 + DriverManager.deregisterDriver(driver); 8.154 + logger.info("[Strabon.deregisterDriver] JDBC driver deregistered successfully."); 8.155 + 8.156 + } catch (SQLException e) { 8.157 + logger.warn("[Strabon.deregisterDriver] Could not deregister JDBC driver: {}", e.getMessage()); 8.158 + } 8.159 + } 8.160 + 8.161 + @Override 8.162 + protected boolean isLocked() throws SQLException, ClassNotFoundException{ 8.163 + createSpatialAndDeleteTemp(databaseName, user, password); 8.164 + Connection conn = null; 8.165 + Statement st = null; 8.166 + String url = ""; 8.167 + 8.168 + try { 8.169 + logger.info("[Strabon] Checking for locks..."); 8.170 + Class.forName("org.sqlite.JDBC"); 8.171 + url = "jdbc:sqlite:" + databaseName ; 8.172 + conn = DriverManager.getConnection(url); 8.173 + st = conn.createStatement(); 8.174 + DatabaseMetaData dbm = conn.getMetaData(); 8.175 + ResultSet rs = dbm.getTables(null, null, "locked", null); 8.176 + //dbilid to check for locks in sqlite???? 8.177 + //ResultSet rs = st.executeQuery("SELECT tablename FROM pg_tables WHERE schemaname='public' AND tablename='locked';"); 8.178 + boolean toReturn=false; 8.179 + if(rs.next()) 8.180 + toReturn=true; 8.181 + //dbm=null; 8.182 + st.close(); 8.183 + st=null; 8.184 + conn.close(); 8.185 + conn=null; 8.186 + return toReturn; 8.187 + //return false; 8.188 + } catch (SQLException e) { 8.189 + logger.error("[Strabon.isLocked] SQL Exception occured. Connection URL is <{}>: {}", url, e.getMessage()); 8.190 + throw e; 8.191 + 8.192 + } catch (ClassNotFoundException e) { 8.193 + logger.error("[Strabon.isLocked] Could not load sqlite jdbc driver: {}", e.getMessage()); 8.194 + throw e; 8.195 + 8.196 + } finally { 8.197 + // close statement and connection 8.198 + if (st != null) { 8.199 + st.close(); 8.200 + } 8.201 + 8.202 + if (conn != null) { 8.203 + conn.close(); 8.204 + } 8.205 + } 8.206 + } 8.207 + 8.208 + @Override 8.209 + protected void initiate(String databaseName, String user, String password, 8.210 + int port, String serverName) { 8.211 + db_store = new SpatiaLiteSqlStore(); 8.212 + 8.213 + SpatiaLiteSqlStore spatialLite_store = (SpatiaLiteSqlStore) db_store; 8.214 + 8.215 + spatialLite_store.setDatabaseName(databaseName); 8.216 + spatialLite_store.setMaxNumberOfTripleTables(2048); 8.217 + init(); 8.218 + logger.info("[Strabon] Initialization completed."); 8.219 + 8.220 + } 8.221 + 8.222 + 8.223 + 8.224 +}
9.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 9.2 +++ b/runtime/src/test/java/eu/earthobservatory/runtime/sqlite/AggregateTests.java Tue Jun 04 18:06:42 2013 +0300 9.3 @@ -0,0 +1,32 @@ 9.4 +/** 9.5 + * This Source Code Form is subject to the terms of the Mozilla Public 9.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 9.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. 9.8 + * 9.9 + * Copyright (C) 2010, 2011, 2012, Pyravlos Team 9.10 + * 9.11 + * http://www.strabon.di.uoa.gr/ 9.12 + */ 9.13 +package eu.earthobservatory.runtime.sqlite; 9.14 + 9.15 +import java.sql.SQLException; 9.16 + 9.17 +import org.junit.AfterClass; 9.18 +import org.junit.BeforeClass; 9.19 + 9.20 + 9.21 +public class AggregateTests extends eu.earthobservatory.runtime.generaldb.AggregateTests { 9.22 + 9.23 + @BeforeClass 9.24 + public static void beforeClass() throws Exception 9.25 + { 9.26 + strabon = TemplateTests.beforeClass("/aggregate-tests-srid.nt"); 9.27 + } 9.28 + 9.29 + @AfterClass 9.30 + public static void afterClass() throws SQLException 9.31 + { 9.32 + TemplateTests.afterClass(strabon); 9.33 + } 9.34 + 9.35 +}
10.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 10.2 +++ b/runtime/src/test/java/eu/earthobservatory/runtime/sqlite/AllTests.java Tue Jun 04 18:06:42 2013 +0300 10.3 @@ -0,0 +1,13 @@ 10.4 +package eu.earthobservatory.runtime.sqlite; 10.5 + 10.6 +import org.junit.runner.RunWith; 10.7 +import org.junit.runners.Suite; 10.8 +import org.junit.runners.Suite.SuiteClasses; 10.9 + 10.10 +@RunWith(Suite.class) 10.11 +@SuiteClasses({ AggregateTests.class, GeneralTests.class, HavingTests.class, 10.12 + JoinTests.class, MeaningfulAggregateTests.class, SimpleTests.class, 10.13 + SPARQL11Tests.class, SpatialTests.class }) 10.14 +public class AllTests { 10.15 + 10.16 +}
11.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 11.2 +++ b/runtime/src/test/java/eu/earthobservatory/runtime/sqlite/GeneralTests.java Tue Jun 04 18:06:42 2013 +0300 11.3 @@ -0,0 +1,88 @@ 11.4 +/** 11.5 + * This Source Code Form is subject to the terms of the Mozilla Public 11.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 11.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. 11.8 + * 11.9 + * Copyright (C) 2010, 2011, 2012, Pyravlos Team 11.10 + * 11.11 + * http://www.strabon.di.uoa.gr/ 11.12 + */ 11.13 +package eu.earthobservatory.runtime.sqlite; 11.14 + 11.15 +import java.io.IOException; 11.16 +import java.sql.SQLException; 11.17 + 11.18 +import org.junit.AfterClass; 11.19 +import org.junit.BeforeClass; 11.20 +import org.junit.Test; 11.21 +import org.openrdf.query.MalformedQueryException; 11.22 +import org.openrdf.query.QueryEvaluationException; 11.23 +import org.openrdf.query.TupleQueryResultHandlerException; 11.24 + 11.25 +/** 11.26 + * A set of simple tests on SPARQL query functionality 11.27 + * 11.28 + * @author George Garbis <ggarbis@di.uoa.gr> 11.29 + */ 11.30 +public class GeneralTests extends eu.earthobservatory.runtime.generaldb.GeneralTests { 11.31 + 11.32 + @BeforeClass 11.33 + public static void beforeClass() throws Exception 11.34 + { 11.35 + strabon = TemplateTests.beforeClass("/more-tests.nt"); 11.36 + } 11.37 + 11.38 + @AfterClass 11.39 + public static void afterClass() throws SQLException 11.40 + { 11.41 + TemplateTests.afterClass(strabon); 11.42 + } 11.43 + 11.44 + @Test 11.45 + public void testQuerySpatialProperties() throws MalformedQueryException, QueryEvaluationException, TupleQueryResultHandlerException, IOException 11.46 + { 11.47 + strabon.query(querySpatialPropertiesPostGIS,strabon.getSailRepoConnection()); 11.48 + 11.49 + } 11.50 + 11.51 + @Test 11.52 + public void testQuerySpatialPropertiesConst() throws MalformedQueryException, QueryEvaluationException, TupleQueryResultHandlerException, IOException 11.53 + { 11.54 + strabon.query(querySpatialPropertiesConstPostGIS,strabon.getSailRepoConnection()); 11.55 + 11.56 + } 11.57 + 11.58 + 11.59 +// /** 11.60 +// * @throws java.lang.Exception 11.61 +// */ 11.62 +// @Before 11.63 +// public void before() 11.64 +// throws Exception 11.65 +// { 11.66 +// 11.67 +// } 11.68 +// 11.69 +// /** 11.70 +// * @throws java.lang.Exception 11.71 +// */ 11.72 +// @After 11.73 +// public void after() 11.74 +// throws Exception 11.75 +// { 11.76 +// // Clean database 11.77 +// Statement stmt = conn.createStatement(); 11.78 +// ResultSet results = stmt.executeQuery("SELECT table_name FROM information_schema.tables WHERE " + 11.79 +// "table_schema='public' and table_name <> 'spatial_ref_sys' " + 11.80 +// "and table_name <> 'geometry_columns' and " + 11.81 +// "table_name <> 'geography_columns' and table_name <> 'locked'"); 11.82 +// while (results.next()) { 11.83 +// String table_name = results.getString("table_name"); 11.84 +// Statement stmt2 = conn.createStatement(); 11.85 +// stmt2.executeUpdate("DROP TABLE \""+table_name+"\""); 11.86 +// stmt2.close(); 11.87 +// } 11.88 +// 11.89 +// stmt.close(); 11.90 +// } 11.91 +}
12.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 12.2 +++ b/runtime/src/test/java/eu/earthobservatory/runtime/sqlite/HavingTests.java Tue Jun 04 18:06:42 2013 +0300 12.3 @@ -0,0 +1,32 @@ 12.4 +/** 12.5 + * This Source Code Form is subject to the terms of the Mozilla Public 12.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 12.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. 12.8 + * 12.9 + * Copyright (C) 2010, 2011, 2012, Pyravlos Team 12.10 + * 12.11 + * http://www.strabon.di.uoa.gr/ 12.12 + */ 12.13 +package eu.earthobservatory.runtime.sqlite; 12.14 + 12.15 +import java.sql.SQLException; 12.16 + 12.17 +import org.junit.AfterClass; 12.18 +import org.junit.BeforeClass; 12.19 + 12.20 + 12.21 +public class HavingTests extends eu.earthobservatory.runtime.generaldb.HavingTests { 12.22 + 12.23 + @BeforeClass 12.24 + public static void beforeClass() throws Exception 12.25 + { 12.26 + strabon = TemplateTests.beforeClass("/having-tests-srid.nt"); 12.27 + } 12.28 + 12.29 + @AfterClass 12.30 + public static void afterClass() throws SQLException 12.31 + { 12.32 + TemplateTests.afterClass(strabon); 12.33 + } 12.34 + 12.35 +}
13.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 13.2 +++ b/runtime/src/test/java/eu/earthobservatory/runtime/sqlite/JoinTests.java Tue Jun 04 18:06:42 2013 +0300 13.3 @@ -0,0 +1,31 @@ 13.4 +/** 13.5 + * This Source Code Form is subject to the terms of the Mozilla Public 13.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 13.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. 13.8 + * 13.9 + * Copyright (C) 2010, 2011, 2012, Pyravlos Team 13.10 + * 13.11 + * http://www.strabon.di.uoa.gr/ 13.12 + */ 13.13 +package eu.earthobservatory.runtime.sqlite; 13.14 + 13.15 +import java.sql.SQLException; 13.16 + 13.17 +import org.junit.AfterClass; 13.18 +import org.junit.BeforeClass; 13.19 + 13.20 +public class JoinTests extends eu.earthobservatory.runtime.generaldb.JoinTests { 13.21 + 13.22 + @BeforeClass 13.23 + public static void beforeClass() throws Exception 13.24 + { 13.25 + strabon = TemplateTests.beforeClass("/join-tests-srid.nt"); 13.26 + } 13.27 + 13.28 + @AfterClass 13.29 + public static void afterClass() throws SQLException 13.30 + { 13.31 + TemplateTests.afterClass(strabon); 13.32 + } 13.33 + 13.34 +}
14.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 14.2 +++ b/runtime/src/test/java/eu/earthobservatory/runtime/sqlite/MeaningfulAggregateTests.java Tue Jun 04 18:06:42 2013 +0300 14.3 @@ -0,0 +1,35 @@ 14.4 +/** 14.5 + * This Source Code Form is subject to the terms of the Mozilla Public 14.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 14.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. 14.8 + * 14.9 + * Copyright (C) 2010, 2011, 2012, Pyravlos Team 14.10 + * 14.11 + * http://www.strabon.di.uoa.gr/ 14.12 + */ 14.13 +package eu.earthobservatory.runtime.sqlite; 14.14 + 14.15 +import java.sql.SQLException; 14.16 + 14.17 +import org.junit.AfterClass; 14.18 +import org.junit.BeforeClass; 14.19 + 14.20 + 14.21 +public class MeaningfulAggregateTests extends eu.earthobservatory.runtime.generaldb.MeaningfulAggregateTests { 14.22 + 14.23 + 14.24 + @BeforeClass 14.25 + public static void beforeClass() throws Exception 14.26 + { 14.27 + strabon = TemplateTests.beforeClass("/group-tests-srid.nt"); 14.28 + } 14.29 + 14.30 + @AfterClass 14.31 + public static void afterClass() throws SQLException 14.32 + { 14.33 + TemplateTests.afterClass(strabon); 14.34 + } 14.35 + 14.36 + 14.37 + 14.38 +} 14.39 \ No newline at end of file
15.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 15.2 +++ b/runtime/src/test/java/eu/earthobservatory/runtime/sqlite/SPARQL11Tests.java Tue Jun 04 18:06:42 2013 +0300 15.3 @@ -0,0 +1,71 @@ 15.4 +/** 15.5 + * This Source Code Form is subject to the terms of the Mozilla Public 15.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 15.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. 15.8 + * 15.9 + * Copyright (C) 2010, 2011, 2012, Pyravlos Team 15.10 + * 15.11 + * http://www.strabon.di.uoa.gr/ 15.12 + */ 15.13 +package eu.earthobservatory.runtime.sqlite; 15.14 + 15.15 +import java.sql.SQLException; 15.16 + 15.17 +import org.junit.AfterClass; 15.18 +import org.junit.BeforeClass; 15.19 + 15.20 +/** 15.21 + * A set of simple tests on SPARQL query functionality 15.22 + * 15.23 + * @author George Garbis <ggarbis@di.uoa.gr> 15.24 + */ 15.25 + 15.26 +public class SPARQL11Tests extends eu.earthobservatory.runtime.generaldb.SPARQL11Tests { 15.27 + 15.28 + @BeforeClass 15.29 + public static void beforeClass() throws Exception 15.30 + { 15.31 + strabon = TemplateTests.beforeClass("/sparql11-tests.nt"); 15.32 + } 15.33 + 15.34 + @AfterClass 15.35 + public static void afterClass() throws SQLException 15.36 + { 15.37 + TemplateTests.afterClass(strabon); 15.38 + } 15.39 + 15.40 + 15.41 + 15.42 +// /** 15.43 +// * @throws java.lang.Exception 15.44 +// */ 15.45 +// @Before 15.46 +// public void before() 15.47 +// throws Exception 15.48 +// { 15.49 +// 15.50 +// } 15.51 +// 15.52 +// /** 15.53 +// * @throws java.lang.Exception 15.54 +// */ 15.55 +// @After 15.56 +// public void after() 15.57 +// throws Exception 15.58 +// { 15.59 +// // Clean database 15.60 +// Statement stmt = conn.createStatement(); 15.61 +// ResultSet results = stmt.executeQuery("SELECT table_name FROM information_schema.tables WHERE " + 15.62 +// "table_schema='public' and table_name <> 'spatial_ref_sys' " + 15.63 +// "and table_name <> 'geometry_columns' and " + 15.64 +// "table_name <> 'geography_columns' and table_name <> 'locked'"); 15.65 +// while (results.next()) { 15.66 +// String table_name = results.getString("table_name"); 15.67 +// Statement stmt2 = conn.createStatement(); 15.68 +// stmt2.executeUpdate("DROP TABLE \""+table_name+"\""); 15.69 +// stmt2.close(); 15.70 +// } 15.71 +// 15.72 +// stmt.close(); 15.73 +// } 15.74 +}
16.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 16.2 +++ b/runtime/src/test/java/eu/earthobservatory/runtime/sqlite/SimpleTests.java Tue Jun 04 18:06:42 2013 +0300 16.3 @@ -0,0 +1,68 @@ 16.4 +/** 16.5 + * This Source Code Form is subject to the terms of the Mozilla Public 16.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 16.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. 16.8 + * 16.9 + * Copyright (C) 2010, 2011, 2012, Pyravlos Team 16.10 + * 16.11 + * http://www.strabon.di.uoa.gr/ 16.12 + */ 16.13 +package eu.earthobservatory.runtime.sqlite; 16.14 + 16.15 +import java.sql.SQLException; 16.16 + 16.17 +import org.junit.AfterClass; 16.18 +import org.junit.BeforeClass; 16.19 + 16.20 +/** 16.21 + * A set of simple tests on SPARQL query functionality 16.22 + * 16.23 + * @author George Garbis <ggarbis@di.uoa.gr 16.24 + */ 16.25 +public class SimpleTests extends eu.earthobservatory.runtime.generaldb.SimpleTests { 16.26 + 16.27 + @BeforeClass 16.28 + public static void beforeClass() throws Exception 16.29 + { 16.30 + strabon = TemplateTests.beforeClass("/simple-tests.nt"); 16.31 + } 16.32 + 16.33 + @AfterClass 16.34 + public static void afterClass() throws SQLException 16.35 + { 16.36 + TemplateTests.afterClass(strabon); 16.37 + } 16.38 + 16.39 +// /** 16.40 +// * @throws java.lang.Exception 16.41 +// */ 16.42 +// @Before 16.43 +// public void before() 16.44 +// throws Exception 16.45 +// { 16.46 +// 16.47 +// } 16.48 +// 16.49 +// /** 16.50 +// * @throws java.lang.Exception 16.51 +// */ 16.52 +// @After 16.53 +// public void after() 16.54 +// throws Exception 16.55 +// { 16.56 +// // Clean database 16.57 +// Statement stmt = conn.createStatement(); 16.58 +// ResultSet results = stmt.executeQuery("SELECT table_name FROM information_schema.tables WHERE " + 16.59 +// "table_schema='public' and table_name <> 'spatial_ref_sys' " + 16.60 +// "and table_name <> 'geometry_columns' and " + 16.61 +// "table_name <> 'geography_columns' and table_name <> 'locked'"); 16.62 +// while (results.next()) { 16.63 +// String table_name = results.getString("table_name"); 16.64 +// Statement stmt2 = conn.createStatement(); 16.65 +// stmt2.executeUpdate("DROP TABLE \""+table_name+"\""); 16.66 +// stmt2.close(); 16.67 +// } 16.68 +// 16.69 +// stmt.close(); 16.70 +// } 16.71 +}
17.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 17.2 +++ b/runtime/src/test/java/eu/earthobservatory/runtime/sqlite/SpatialTests.java Tue Jun 04 18:06:42 2013 +0300 17.3 @@ -0,0 +1,69 @@ 17.4 +/** 17.5 + * This Source Code Form is subject to the terms of the Mozilla Public 17.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 17.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. 17.8 + * 17.9 + * Copyright (C) 2010, 2011, 2012, Pyravlos Team 17.10 + * 17.11 + * http://www.strabon.di.uoa.gr/ 17.12 + */ 17.13 +package eu.earthobservatory.runtime.sqlite; 17.14 + 17.15 +import java.sql.SQLException; 17.16 + 17.17 +import org.junit.AfterClass; 17.18 +import org.junit.BeforeClass; 17.19 + 17.20 +/** 17.21 + * A set of simple tests on SPARQL query functionality 17.22 + * 17.23 + * @author George Garbis <ggarbis@di.uoa.gr> 17.24 + */ 17.25 + 17.26 +public class SpatialTests extends eu.earthobservatory.runtime.generaldb.SpatialTests { 17.27 + 17.28 + @BeforeClass 17.29 + public static void beforeClass() throws Exception 17.30 + { 17.31 + strabon = TemplateTests.beforeClass("/spatial-tests-srid.nt"); 17.32 + } 17.33 + 17.34 + @AfterClass 17.35 + public static void afterClass() throws SQLException 17.36 + { 17.37 + TemplateTests.afterClass(strabon); 17.38 + } 17.39 + 17.40 +// /** 17.41 +// * @throws java.lang.Exception 17.42 +// */ 17.43 +// @Before 17.44 +// public void before() 17.45 +// throws Exception 17.46 +// { 17.47 +// 17.48 +// } 17.49 +// 17.50 +// /** 17.51 +// * @throws java.lang.Exception 17.52 +// */ 17.53 +// @After 17.54 +// public void after() 17.55 +// throws Exception 17.56 +// { 17.57 +// // Clean database 17.58 +// Statement stmt = conn.createStatement(); 17.59 +// ResultSet results = stmt.executeQuery("SELECT table_name FROM information_schema.tables WHERE " + 17.60 +// "table_schema='public' and table_name <> 'spatial_ref_sys' " + 17.61 +// "and table_name <> 'geometry_columns' and " + 17.62 +// "table_name <> 'geography_columns' and table_name <> 'locked'"); 17.63 +// while (results.next()) { 17.64 +// String table_name = results.getString("table_name"); 17.65 +// Statement stmt2 = conn.createStatement(); 17.66 +// stmt2.executeUpdate("DROP TABLE \""+table_name+"\""); 17.67 +// stmt2.close(); 17.68 +// } 17.69 +// 17.70 +// stmt.close(); 17.71 +// } 17.72 +}
18.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 18.2 +++ b/runtime/src/test/java/eu/earthobservatory/runtime/sqlite/TemplateTests.java Tue Jun 04 18:06:42 2013 +0300 18.3 @@ -0,0 +1,167 @@ 18.4 +/** 18.5 + * This Source Code Form is subject to the terms of the Mozilla Public 18.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 18.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. 18.8 + * 18.9 + * Copyright (C) 2010, 2011, 2012, Pyravlos Team 18.10 + * 18.11 + * http://www.strabon.di.uoa.gr/ 18.12 + */ 18.13 +package eu.earthobservatory.runtime.sqlite; 18.14 + 18.15 +import java.io.IOException; 18.16 +import java.io.InputStream; 18.17 +import java.sql.DatabaseMetaData; 18.18 +import java.sql.DriverManager; 18.19 +import java.sql.PreparedStatement; 18.20 +import java.sql.ResultSet; 18.21 +import java.sql.SQLException; 18.22 +import java.sql.Statement; 18.23 +import java.sql.Connection; 18.24 +import java.util.ArrayList; 18.25 +import java.util.Properties; 18.26 + 18.27 +import org.junit.AfterClass; 18.28 +import org.junit.BeforeClass; 18.29 +import org.openrdf.repository.RepositoryException; 18.30 +import org.openrdf.rio.RDFHandlerException; 18.31 +import org.openrdf.rio.RDFParseException; 18.32 +import org.sqlite.SQLiteConfig; 18.33 + 18.34 + 18.35 +import eu.earthobservatory.runtime.generaldb.InvalidDatasetFormatFault; 18.36 +import eu.earthobservatory.runtime.generaldb.SimpleTests; 18.37 +import eu.earthobservatory.runtime.generaldb.Strabon; 18.38 + 18.39 +import static org.junit.Assert.assertNull; 18.40 + 18.41 +/** 18.42 + * A set of simple tests on SPARQL query functionality 18.43 + * 18.44 + * @author George Garbis <ggarbis@di.uoa.gr> 18.45 + * @author Panayiotis Smeros <psmeros@di.uoa.gr> 18.46 + */ 18.47 +public class TemplateTests { 18.48 + 18.49 +// public static String databaseTemplateName = null; 18.50 +// public static String defaultUser = null; 18.51 +// public static String serverName = null; 18.52 +// public static String username = null; 18.53 +// public static String password = null; 18.54 +// public static Integer port = null; 18.55 + 18.56 + public static Connection conn = null; 18.57 +// public static String databaseName = null; 18.58 + 18.59 + @BeforeClass 18.60 + public static Strabon beforeClass(String inputFile) throws Exception 18.61 + { 18.62 + //String url=""; 18.63 + // ArrayList<String> databases=new ArrayList<String>(); 18.64 + // PreparedStatement pst = null; 18.65 + 18.66 + // Read properties 18.67 + // Properties properties = new Properties(); 18.68 + // InputStream propertiesStream = SimpleTests.class.getResourceAsStream("/databases.properties"); 18.69 + // properties.load(propertiesStream); 18.70 + 18.71 + // databaseTemplateName = properties.getProperty("postgis.databaseTemplateName");; 18.72 + /// defaultUser = properties.getProperty("postgis.defaultUser"); 18.73 + // serverName = properties.getProperty("postgis.serverName"); 18.74 + // username = properties.getProperty("postgis.username"); 18.75 + // password = properties.getProperty("postgis.password"); 18.76 + // port = Integer.parseInt(properties.getProperty("postgis.port")); 18.77 + 18.78 + //Connect to server and create the temp database 18.79 + // url = "jdbc:postgresql://"+serverName+":"+port+"/"+defaultUser; 18.80 + // conn = DriverManager.getConnection(url, username, password); 18.81 + String db="/tmp/"+ (int)(Math.random()*10000)+".db" ; 18.82 + // url = "jdbc:sqlite:" + db; 18.83 + // SQLiteConfig config = new SQLiteConfig(); 18.84 + // config.enableLoadExtension(true); 18.85 + // conn=DriverManager.getConnection(url,config.toProperties()); 18.86 + 18.87 + //Statement st=conn.createStatement(); 18.88 +// st.execute("SELECT load_extension('/usr/local/lib/libspatialite.so')"); 18.89 + 18.90 + 18.91 + // st.execute("SELECT InitSpatialMetaData()"); 18.92 + 18.93 + // assertNull(conn.getWarnings()); 18.94 + // st.close(); 18.95 + // conn.close(); 18.96 + 18.97 + Strabon strabon = new eu.earthobservatory.runtime.sqlite.Strabon(db, "/usr/local/lib/libspatialite.so", "/usr/lib/sqlite3/pcre.so", true); 18.98 + 18.99 + loadTestData(inputFile, strabon); 18.100 + 18.101 + return strabon; 18.102 + } 18.103 + 18.104 + 18.105 + @AfterClass 18.106 + public static void afterClass(Strabon strabon) throws SQLException 18.107 + { 18.108 + //strabon.close(); 18.109 + 18.110 + //Drop the temp database 18.111 + //conn.close(); 18.112 + 18.113 + } 18.114 + 18.115 + protected static void loadTestData(String inputfile, Strabon strabon) 18.116 + throws RDFParseException, RepositoryException, IOException, RDFHandlerException, InvalidDatasetFormatFault 18.117 + { 18.118 + strabon.storeInRepo(inputfile, "NTRIPLES"); 18.119 + } 18.120 + 18.121 + 18.122 + // Clean database 18.123 +// Statement stmt = conn.createStatement(); 18.124 +// ResultSet results = stmt.executeQuery("SELECT table_name FROM information_schema.tables WHERE " + 18.125 +// "table_schema='public' AND table_name <> 'spatial_ref_sys' " + 18.126 +// "AND table_name <> 'geometry_columns' AND table_name <> 'geography_columns' " + 18.127 +// "AND table_name <> 'raster_columns' AND table_name <> 'raster_overviews' " + 18.128 +// "AND table_name <> 'locked'" 18.129 +// ); 18.130 +// while (results.next()) { 18.131 +// String table_name = results.getString("table_name"); 18.132 +// Statement stmt2 = conn.createStatement(); 18.133 +// stmt2.executeUpdate("DROP TABLE \""+table_name+"\""); 18.134 +// stmt2.close(); 18.135 +// } 18.136 +// stmt.close(); 18.137 + 18.138 +// /** 18.139 +// * @throws java.lang.Exception 18.140 +// */ 18.141 +// @Before 18.142 +// public void before() 18.143 +// throws Exception 18.144 +// { 18.145 +// 18.146 +// } 18.147 +// 18.148 +// /** 18.149 +// * @throws java.lang.Exception 18.150 +// */ 18.151 +// @After 18.152 +// public void after() 18.153 +// throws Exception 18.154 +// { 18.155 +// // Clean database 18.156 +// Statement stmt = conn.createStatement(); 18.157 +// ResultSet results = stmt.executeQuery("SELECT table_name FROM information_schema.tables WHERE " + 18.158 +// "table_schema='public' and table_name <> 'spatial_ref_sys' " + 18.159 +// "and table_name <> 'geometry_columns' and " + 18.160 +// "table_name <> 'geography_columns' and table_name <> 'locked'"); 18.161 +// while (results.next()) { 18.162 +// String table_name = results.getString("table_name"); 18.163 +// Statement stmt2 = conn.createStatement(); 18.164 +// stmt2.executeUpdate("DROP TABLE \""+table_name+"\""); 18.165 +// stmt2.close(); 18.166 +// } 18.167 +// 18.168 +// stmt.close(); 18.169 +// } 18.170 +}
19.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 19.2 +++ b/runtime/src/test/java/eu/earthobservatory/runtime/sqlite/TransformTests.java Tue Jun 04 18:06:42 2013 +0300 19.3 @@ -0,0 +1,69 @@ 19.4 +/** 19.5 + * This Source Code Form is subject to the terms of the Mozilla Public 19.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 19.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. 19.8 + * 19.9 + * Copyright (C) 2010, 2011, 2012, Pyravlos Team 19.10 + * 19.11 + * http://www.strabon.di.uoa.gr/ 19.12 + */ 19.13 +package eu.earthobservatory.runtime.sqlite; 19.14 + 19.15 +import java.sql.SQLException; 19.16 + 19.17 +import org.junit.AfterClass; 19.18 +import org.junit.BeforeClass; 19.19 + 19.20 +/** 19.21 + * A set of simple tests on SPARQL query functionality 19.22 + * 19.23 + * @author George Garbis <ggarbis@di.uoa.gr> 19.24 + */ 19.25 + 19.26 +public class TransformTests extends eu.earthobservatory.runtime.generaldb.TransformTests { 19.27 + 19.28 + @BeforeClass 19.29 + public static void beforeClass() throws Exception 19.30 + { 19.31 + strabon = TemplateTests.beforeClass("/transform-tests.nt"); 19.32 + } 19.33 + 19.34 + @AfterClass 19.35 + public static void afterClass() throws SQLException 19.36 + { 19.37 + TemplateTests.afterClass(strabon); 19.38 + } 19.39 + 19.40 +// /** 19.41 +// * @throws java.lang.Exception 19.42 +// */ 19.43 +// @Before 19.44 +// public void before() 19.45 +// throws Exception 19.46 +// { 19.47 +// 19.48 +// } 19.49 +// 19.50 +// /** 19.51 +// * @throws java.lang.Exception 19.52 +// */ 19.53 +// @After 19.54 +// public void after() 19.55 +// throws Exception 19.56 +// { 19.57 +// // Clean database 19.58 +// Statement stmt = conn.createStatement(); 19.59 +// ResultSet results = stmt.executeQuery("SELECT table_name FROM information_schema.tables WHERE " + 19.60 +// "table_schema='public' and table_name <> 'spatial_ref_sys' " + 19.61 +// "and table_name <> 'geometry_columns' and " + 19.62 +// "table_name <> 'geography_columns' and table_name <> 'locked'"); 19.63 +// while (results.next()) { 19.64 +// String table_name = results.getString("table_name"); 19.65 +// Statement stmt2 = conn.createStatement(); 19.66 +// stmt2.executeUpdate("DROP TABLE \""+table_name+"\""); 19.67 +// stmt2.close(); 19.68 +// } 19.69 +// 19.70 +// stmt.close(); 19.71 +// } 19.72 +}
20.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 20.2 +++ b/sqlite/pom.xml Tue Jun 04 18:06:42 2013 +0300 20.3 @@ -0,0 +1,94 @@ 20.4 +<?xml version="1.0"?> 20.5 +<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0" 20.6 + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 20.7 + <modelVersion>4.0.0</modelVersion> 20.8 + 20.9 + <parent> 20.10 + <groupId>eu.earthobservatory</groupId> 20.11 + <artifactId>strabon</artifactId> 20.12 + <version>3.2.9-SNAPSHOT</version> 20.13 + </parent> 20.14 + 20.15 + <groupId>org.openrdf.sesame</groupId> 20.16 + <artifactId>sesame-sail-sqlite</artifactId> 20.17 + <name>OpenRDF Sesame: SqliteDBStore </name> 20.18 + <description>SqliteDBStore Store Support</description> 20.19 + <packaging>jar</packaging> 20.20 + 20.21 + <url>http://maven.apache.org</url> 20.22 + <dependencies> 20.23 + <dependency> 20.24 + <groupId>junit</groupId> 20.25 + <artifactId>junit</artifactId> 20.26 + <version>3.8.1</version> 20.27 + <scope>test</scope> 20.28 + </dependency> 20.29 + <dependency> 20.30 + <groupId>org.openrdf.sesame</groupId> 20.31 + <artifactId>sesame-queryalgebra-evaluation-spatial</artifactId> 20.32 + </dependency> 20.33 + 20.34 + <dependency> 20.35 + <groupId>org.openrdf.sesame</groupId> 20.36 + <artifactId>sesame-sail-rdbms</artifactId> 20.37 + </dependency> 20.38 + 20.39 + <dependency> 20.40 + <groupId>org.openrdf.sesame</groupId> 20.41 + <artifactId>sesame-sail-api</artifactId> 20.42 + </dependency> 20.43 + 20.44 + <dependency> 20.45 + <groupId>org.openrdf.sesame</groupId> 20.46 + <artifactId>sesame-queryalgebra-evaluation</artifactId> 20.47 + </dependency> 20.48 + 20.49 + <dependency> 20.50 + <groupId>org.openrdf.sesame</groupId> 20.51 + <artifactId>sesame-queryalgebra-model</artifactId> 20.52 + </dependency> 20.53 + 20.54 + <dependency> 20.55 + <groupId>org.openrdf.sesame</groupId> 20.56 + <artifactId>sesame-query</artifactId> 20.57 + </dependency> 20.58 + 20.59 + <dependency> 20.60 + <groupId>org.openrdf.sesame</groupId> 20.61 + <artifactId>sesame-model</artifactId> 20.62 + </dependency> 20.63 + 20.64 + <dependency> 20.65 + <groupId>info.aduna.commons</groupId> 20.66 + <artifactId>aduna-commons-collections</artifactId> 20.67 + </dependency> 20.68 + 20.69 + <dependency> 20.70 + <groupId>info.aduna.commons</groupId> 20.71 + <artifactId>aduna-commons-iteration</artifactId> 20.72 + </dependency> 20.73 + 20.74 + <dependency> 20.75 + <groupId>info.aduna.commons</groupId> 20.76 + <artifactId>aduna-commons-concurrent</artifactId> 20.77 + </dependency> 20.78 + <dependency> 20.79 + <groupId>org.openrdf.sesame</groupId> 20.80 + <artifactId>sesame-sail-generaldb</artifactId> 20.81 + </dependency> 20.82 + <dependency> 20.83 + <groupId>commons-dbcp</groupId> 20.84 + <artifactId>commons-dbcp</artifactId> 20.85 + </dependency> 20.86 + 20.87 +<dependency> 20.88 + <groupId>org.openrdf.sesame</groupId> 20.89 + <artifactId>sesame-repository-sail</artifactId> 20.90 + </dependency> 20.91 + <dependency> 20.92 + <groupId>postgresql</groupId> 20.93 + <artifactId>postgresql</artifactId> 20.94 + <scope>provided</scope> 20.95 + </dependency> 20.96 + </dependencies> 20.97 +</project>
21.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 21.2 +++ b/sqlite/src/main/java/org/openrdf/sail/sqlite/SpatiaLiteSqlStore.java Tue Jun 04 18:06:42 2013 +0300 21.3 @@ -0,0 +1,64 @@ 21.4 +package org.openrdf.sail.sqlite; 21.5 + 21.6 +import java.sql.Connection; 21.7 +import java.sql.DatabaseMetaData; 21.8 +import java.sql.SQLException; 21.9 +import java.sql.Statement; 21.10 +import java.util.Map; 21.11 + 21.12 +import org.sqlite.SQLiteConfig; 21.13 +import org.apache.commons.dbcp.BasicDataSource; 21.14 +import org.openrdf.sail.SailException; 21.15 +import org.openrdf.sail.generaldb.GeneralDBConnectionFactory; 21.16 +import org.openrdf.sail.sqlite.SqliteConnectionFactory; 21.17 +import org.openrdf.sail.rdbms.exceptions.RdbmsException; 21.18 + 21.19 +public class SpatiaLiteSqlStore extends org.openrdf.sail.generaldb.GeneralDBStore{ 21.20 + 21.21 + protected String databaseName; 21.22 + 21.23 + @Override 21.24 + protected GeneralDBConnectionFactory newFactory(DatabaseMetaData metaData) 21.25 + throws SQLException { 21.26 + // TODO Auto-generated method stub 21.27 + return null; 21.28 + } 21.29 + 21.30 + @Override 21.31 + public void initialize() 21.32 + throws SailException 21.33 + { 21.34 + try { 21.35 + Class.forName("org.sqlite.JDBC"); 21.36 + } 21.37 + catch (ClassNotFoundException e) { 21.38 + throw new RdbmsException(e.toString(), e); 21.39 + } 21.40 + StringBuilder url = new StringBuilder(); 21.41 + url.append("jdbc:sqlite:"); 21.42 + 21.43 + url.append(databaseName); 21.44 + BasicDataSource ds = new BasicDataSource(); 21.45 + ds.setUrl(url.toString()); 21.46 + SQLiteConfig config = new SQLiteConfig(); 21.47 + config.enableLoadExtension(true); 21.48 + for (Map.Entry e : config.toProperties().entrySet()) { 21.49 + ds.addConnectionProperty((String)e.getKey(), (String)e.getValue()); 21.50 + } 21.51 + 21.52 + SqliteConnectionFactory factory = new SqliteConnectionFactory(); 21.53 + factory.setSail(this); 21.54 + factory.setDataSource(ds); 21.55 + setBasicDataSource(ds); 21.56 + setConnectionFactory(factory); 21.57 + 21.58 + 21.59 + super.initialize(); 21.60 + 21.61 + } 21.62 + 21.63 + public void setDatabaseName(String databaseName2) { 21.64 + this.databaseName = databaseName2; 21.65 + } 21.66 + 21.67 +}
22.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 22.2 +++ b/sqlite/src/main/java/org/openrdf/sail/sqlite/SqliteConnectionFactory.java Tue Jun 04 18:06:42 2013 +0300 22.3 @@ -0,0 +1,316 @@ 22.4 +package org.openrdf.sail.sqlite; 22.5 + 22.6 +/* 22.7 + * Copyright Aduna (http://www.aduna-software.com/) (c) 2008. 22.8 + * 22.9 + * Licensed under the Aduna BSD-style license. 22.10 + */ 22.11 +import static java.sql.Connection.TRANSACTION_SERIALIZABLE; 22.12 +import info.aduna.concurrent.locks.Lock; 22.13 + 22.14 +import java.sql.Connection; 22.15 +import java.sql.DatabaseMetaData; 22.16 +import java.sql.ResultSet; 22.17 +import java.sql.SQLException; 22.18 +import java.sql.Statement; 22.19 +import java.util.ArrayList; 22.20 + 22.21 +import org.openrdf.model.impl.ValueFactoryImpl; 22.22 +import org.openrdf.sail.SailConnection; 22.23 +import org.openrdf.sail.SailException; 22.24 +import org.openrdf.sail.generaldb.GeneralDBConnection; 22.25 +import org.openrdf.sail.generaldb.GeneralDBConnectionFactory; 22.26 +import org.openrdf.sail.generaldb.GeneralDBTripleRepository; 22.27 +import org.openrdf.sail.generaldb.GeneralDBValueFactory; 22.28 +import org.openrdf.sail.generaldb.evaluation.GeneralDBEvaluationFactory; 22.29 +import org.openrdf.sail.generaldb.evaluation.GeneralDBQueryBuilderFactory; 22.30 +import org.openrdf.sail.generaldb.optimizers.GeneralDBQueryOptimizer; 22.31 +import org.openrdf.sail.generaldb.optimizers.GeneralDBSelectQueryOptimizerFactory; 22.32 +import org.openrdf.sail.helpers.DefaultSailChangedEvent; 22.33 +import org.openrdf.sail.sqlite.evaluation.SqliteEvaluationFactory; 22.34 +import org.openrdf.sail.sqlite.evaluation.SqliteQueryBuilderFactory; 22.35 +import org.openrdf.sail.rdbms.util.DatabaseLockManager; 22.36 +import org.openrdf.sail.rdbms.exceptions.RdbmsException; 22.37 +import org.openrdf.sail.generaldb.managers.BNodeManager; 22.38 +import org.openrdf.sail.generaldb.managers.HashManager; 22.39 +import org.openrdf.sail.generaldb.managers.LiteralManager; 22.40 +import org.openrdf.sail.generaldb.managers.PredicateManager; 22.41 +import org.openrdf.sail.generaldb.managers.TransTableManager; 22.42 +import org.openrdf.sail.generaldb.managers.TripleManager; 22.43 +import org.openrdf.sail.generaldb.managers.TripleTableManager; 22.44 +import org.openrdf.sail.generaldb.managers.UriManager; 22.45 +import org.openrdf.sail.rdbms.managers.NamespaceManager; 22.46 +import org.openrdf.sail.rdbms.schema.NamespacesTable; 22.47 +import org.openrdf.sail.rdbms.schema.TableFactory; 22.48 +import org.openrdf.sail.generaldb.schema.IntegerIdSequence; 22.49 +import org.openrdf.sail.generaldb.schema.LongIdSequence; 22.50 +import org.openrdf.sail.generaldb.schema.ValueTableFactory; 22.51 + 22.52 +/** 22.53 + * Responsible to initialise and wire all components together that will be 22.54 + * needed to satisfy any sail connection request. 22.55 + * 22.56 + * @author James Leigh 22.57 + */ 22.58 +public class SqliteConnectionFactory extends GeneralDBConnectionFactory { 22.59 + 22.60 + protected Connection singleSQLiteCon; 22.61 +// protected SqliteTripleTableManager sqliteTripleTableManager; 22.62 + 22.63 + @Override 22.64 + protected TableFactory createTableFactory() { 22.65 + return new SqliteSqlTableFactory(); 22.66 + } 22.67 + 22.68 + @Override 22.69 + protected SqliteSqlValueTableFactory createValueTableFactory() { 22.70 + return new SqliteSqlValueTableFactory(); 22.71 + } 22.72 + 22.73 + @Override 22.74 + protected Lock createDatabaseLock() 22.75 + throws SailException 22.76 + { 22.77 + DatabaseLockManager manager; 22.78 + manager = new DatabaseLockManager(ds, user, password); 22.79 + if (manager.isDebugEnabled()) 22.80 + return manager.tryLock(); 22.81 + return manager.lockOrFail(); 22.82 + } 22.83 + 22.84 + @Override 22.85 + protected GeneralDBQueryBuilderFactory createQueryBuilderFactory() { 22.86 + return new SqliteQueryBuilderFactory(); 22.87 + } 22.88 + 22.89 + @Override 22.90 + public SailConnection createConnection() 22.91 + throws SailException 22.92 + { 22.93 + try { 22.94 + Connection db = singleSQLiteCon; 22.95 + db.setAutoCommit(true); 22.96 + if (db.getTransactionIsolation() != TRANSACTION_SERIALIZABLE ) { 22.97 + db.setTransactionIsolation(TRANSACTION_SERIALIZABLE ); 22.98 + } 22.99 + TripleManager tripleManager = new TripleManager(); 22.100 + GeneralDBTripleRepository s = new SqliteTripleRepository(); 22.101 + s.setTripleManager(tripleManager); 22.102 + s.setValueFactory(vf); 22.103 + s.setConnection(db); 22.104 + s.setBNodeTable(bnodeTable); 22.105 + s.setURITable(uriTable); 22.106 + s.setLiteralTable(literalTable); 22.107 + s.setIdSequence(ids); 22.108 + DefaultSailChangedEvent sailChangedEvent = new DefaultSailChangedEvent(sail); 22.109 + s.setSailChangedEvent(sailChangedEvent); 22.110 + TableFactory tables = createTableFactory(); 22.111 + TransTableManager trans = createTransTableManager(); 22.112 + trans.setIdSequence(ids); 22.113 + tripleManager.setTransTableManager(trans); 22.114 + trans.setBatchQueue(tripleManager.getQueue()); 22.115 + trans.setSailChangedEvent(sailChangedEvent); 22.116 + trans.setConnection(db); 22.117 + trans.setTemporaryTableFactory(tables); 22.118 + trans.setStatementsTable(tripleTableManager); 22.119 + trans.setFromDummyTable(getFromDummyTable()); 22.120 + trans.initialize(); 22.121 + s.setTransaction(trans); 22.122 + GeneralDBQueryBuilderFactory bfactory = createQueryBuilderFactory(); 22.123 + bfactory.setValueFactory(vf); 22.124 + bfactory.setUsingHashTable(hashManager != null); 22.125 + s.setQueryBuilderFactory(bfactory); 22.126 + GeneralDBConnection conn = new GeneralDBConnection(sail, s); 22.127 + conn.setNamespaces(namespaces); 22.128 + GeneralDBEvaluationFactory efactory = new SqliteEvaluationFactory(); 22.129 + efactory.setQueryBuilderFactory(bfactory); 22.130 + efactory.setRdbmsTripleRepository(s); 22.131 + efactory.setIdSequence(ids); 22.132 + conn.setRdbmsEvaluationFactory(efactory); 22.133 + GeneralDBQueryOptimizer optimizer = createOptimizer(); 22.134 + GeneralDBSelectQueryOptimizerFactory selectOptimizerFactory = createSelectQueryOptimizerFactory(); 22.135 + selectOptimizerFactory.setTransTableManager(trans); 22.136 + selectOptimizerFactory.setValueFactory(vf); 22.137 + selectOptimizerFactory.setIdSequence(ids); 22.138 + optimizer.setSelectQueryOptimizerFactory(selectOptimizerFactory); 22.139 + optimizer.setValueFactory(vf); 22.140 + optimizer.setBnodeTable(bnodeTable); 22.141 + optimizer.setUriTable(uriTable); 22.142 + optimizer.setLiteralTable(literalTable); 22.143 + optimizer.setHashTable(hashTable); 22.144 + conn.setRdbmsQueryOptimizer(optimizer); 22.145 + conn.setLockManager(lock); 22.146 + return conn; 22.147 + } 22.148 + catch (SQLException e) { 22.149 + throw new RdbmsException(e); 22.150 + } 22.151 + } 22.152 + 22.153 + @Override 22.154 + protected Connection getConnection() 22.155 + throws SQLException 22.156 + { 22.157 + Connection conn; 22.158 + if (user == null) 22.159 + // return ds.getConnection(); 22.160 + conn = ds.getConnection(); 22.161 + else 22.162 + // return ds.getConnection(user, password); 22.163 + conn = ds.getConnection(user, password); 22.164 + 22.165 + Statement stmt = conn.createStatement(); 22.166 + stmt.setQueryTimeout(30); // set timeout to 30 sec. 22.167 + 22.168 + // loading SpatiaLite 22.169 + stmt.execute("SELECT load_extension('/usr/local/lib/libspatialite.so')"); 22.170 + stmt.execute("SELECT load_extension('/usr/lib/sqlite3/pcre.so')"); 22.171 + 22.172 + 22.173 + return conn; 22.174 +// return new net.sf.log4jdbc.ConnectionSpy(conn); 22.175 + } 22.176 + 22.177 + /** 22.178 + * FROM DUAL 22.179 + * 22.180 + * @return from clause or empty string 22.181 + */ 22.182 + @Override 22.183 + protected String getFromDummyTable() { 22.184 + return " "; 22.185 + } 22.186 + 22.187 + @Override 22.188 + public void init() 22.189 + throws Exception 22.190 + { 22.191 + databaseLock = createDatabaseLock(); 22.192 + try { 22.193 + 22.194 + // nsAndTableIndexes = getConnection(); 22.195 + // resourceInserts = getConnection(); 22.196 + // literalInserts = getConnection(); 22.197 + // nsAndTableIndexes.setAutoCommit(true); 22.198 + // resourceInserts.setAutoCommit(true); 22.199 + // literalInserts.setAutoCommit(true); 22.200 + singleSQLiteCon=getConnection(); 22.201 + singleSQLiteCon.setAutoCommit(true); 22.202 + bnodeManager = new BNodeManager(); 22.203 + uriManager = new UriManager(); 22.204 + literalManager = new LiteralManager(); 22.205 + ValueTableFactory tables = createValueTableFactory(); 22.206 + tables.setSequenced(sequenced); 22.207 + if (sequenced) { 22.208 + ids = new IntegerIdSequence(); 22.209 + tables.setIdSequence(ids); 22.210 + //hashLookups = getConnection(); 22.211 + //hashLookups.setAutoCommit(true); 22.212 + hashManager = new HashManager(); 22.213 + hashTable = tables.createHashTable(singleSQLiteCon, hashManager.getQueue()); 22.214 + ids.setHashTable(hashTable); 22.215 + ids.init(); 22.216 + hashManager.setHashTable(hashTable); 22.217 + hashManager.setBNodeManager(bnodeManager); 22.218 + hashManager.setLiteralManager(literalManager); 22.219 + hashManager.setUriManager(uriManager); 22.220 + hashManager.setIdSequence(ids); 22.221 + hashManager.init(); 22.222 + //hashLookups.close(); 22.223 + } else { 22.224 + ids = new LongIdSequence(); 22.225 + ids.init(); 22.226 + tables.setIdSequence(ids); 22.227 + } 22.228 + namespaces = new NamespaceManager(); 22.229 + namespaces.setConnection(singleSQLiteCon); 22.230 + NamespacesTable nsTable = tables.createNamespacesTable(singleSQLiteCon); 22.231 + nsTable.initialize(); 22.232 + namespaces.setNamespacesTable(nsTable); 22.233 + namespaces.initialize(); 22.234 + //nsAndTableIndexes.close(); 22.235 + bnodeManager.setHashManager(hashManager); 22.236 + bnodeManager.setIdSequence(ids); 22.237 + uriManager.setHashManager(hashManager); 22.238 + uriManager.setIdSequence(ids); 22.239 + bnodeTable = tables.createBNodeTable(singleSQLiteCon, bnodeManager.getQueue()); 22.240 + uriTable = tables.createURITable(singleSQLiteCon, uriManager.getQueue()); 22.241 + literalManager.setHashManager(hashManager); 22.242 + literalManager.setIdSequence(ids); 22.243 + //resourceInserts.close(); 22.244 + literalTable = tables.createLiteralTable(singleSQLiteCon, literalManager.getQueue()); 22.245 + literalTable.setIdSequence(ids); 22.246 + vf = new GeneralDBValueFactory(); 22.247 + vf.setDelegate(ValueFactoryImpl.getInstance()); 22.248 + vf.setIdSequence(ids); 22.249 + uriManager.setUriTable(uriTable); 22.250 + uriManager.init(); 22.251 + predicateManager = new PredicateManager(); 22.252 + predicateManager.setUriManager(uriManager); 22.253 + tripleTableManager = (TripleTableManager) new SqliteTripleTableManager(tables); 22.254 + //nsAndTableIndexes = getConnection(); 22.255 + tripleTableManager.setConnection(singleSQLiteCon); 22.256 + tripleTableManager.setIdSequence(ids); 22.257 + tripleTableManager.setBNodeManager(bnodeManager); 22.258 + tripleTableManager.setUriManager(uriManager); 22.259 + tripleTableManager.setLiteralManager(literalManager); 22.260 + tripleTableManager.setHashManager(hashManager); 22.261 + tripleTableManager.setPredicateManager(predicateManager); 22.262 + tripleTableManager.setMaxNumberOfTripleTables(maxTripleTables); 22.263 + tripleTableManager.setIndexingTriples(triplesIndexed); 22.264 + tripleTableManager.initialize(); 22.265 + if (triplesIndexed) { 22.266 + tripleTableManager.createTripleIndexes(); 22.267 + } else { 22.268 + tripleTableManager.dropTripleIndexes(); 22.269 + } 22.270 + //nsAndTableIndexes.close(); 22.271 + bnodeManager.setTable(bnodeTable); 22.272 + bnodeManager.init(); 22.273 + vf.setBNodeManager(bnodeManager); 22.274 + vf.setURIManager(uriManager); 22.275 + literalManager.setTable(literalTable); 22.276 + literalManager.init(); 22.277 + vf.setLiteralManager(literalManager); 22.278 + vf.setPredicateManager(predicateManager); 22.279 + //literalInserts.close(); 22.280 + } catch (SQLException e) { 22.281 + throw new RdbmsException(e); 22.282 + } 22.283 + } 22.284 + 22.285 + @Override 22.286 + public void shutDown() throws SailException { 22.287 + try { 22.288 + if (tripleTableManager != null) { 22.289 + tripleTableManager.close(); 22.290 + } 22.291 + if (uriManager != null) { 22.292 + uriManager.close(); 22.293 + } 22.294 + if (bnodeManager != null) { 22.295 + bnodeManager.close(); 22.296 + } 22.297 + if (literalManager != null) { 22.298 + literalManager.close(); 22.299 + } 22.300 + if (hashManager != null) { 22.301 + hashManager.close(); 22.302 + } 22.303 + if (resourceInserts != null) { 22.304 + resourceInserts.close(); 22.305 + resourceInserts = null; 22.306 + } 22.307 + if (singleSQLiteCon != null) { 22.308 + singleSQLiteCon.close(); 22.309 + singleSQLiteCon = null; 22.310 + } 22.311 + } catch (SQLException e) { 22.312 + throw new RdbmsException(e); 22.313 + } finally { 22.314 + if (databaseLock != null) { 22.315 + databaseLock.release(); 22.316 + } 22.317 + } 22.318 + } 22.319 +}
23.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 23.2 +++ b/sqlite/src/main/java/org/openrdf/sail/sqlite/SqliteSqlTable.java Tue Jun 04 18:06:42 2013 +0300 23.3 @@ -0,0 +1,121 @@ 23.4 +package org.openrdf.sail.sqlite; 23.5 + 23.6 +import java.sql.SQLException; 23.7 + 23.8 +import org.openrdf.query.algebra.evaluation.function.spatial.GeoConstants; 23.9 +import org.openrdf.sail.generaldb.GeneralDBSqlTable; 23.10 +import org.slf4j.Logger; 23.11 +import org.slf4j.LoggerFactory; 23.12 + 23.13 +/** 23.14 + * Converts table names to lower-case and include the analyse optimisation. 23.15 + * 23.16 + * @author James Leigh 23.17 + * 23.18 + */ 23.19 +public class SqliteSqlTable extends GeneralDBSqlTable { 23.20 + 23.21 + protected final Logger logger = LoggerFactory.getLogger(this.getClass()); 23.22 + 23.23 + public SqliteSqlTable(String name) { 23.24 + super(name.toLowerCase()); 23.25 + } 23.26 + 23.27 + @Override 23.28 + protected String buildOptimize() 23.29 + throws SQLException 23.30 + { 23.31 +// return "VACUUM ANALYZE " + getName(); 23.32 + return null; // TODO vacuum analyze in sqliie 23.33 + } 23.34 + 23.35 + @Override 23.36 + protected String buildClear() { 23.37 +// return "TRUNCATE " + getName(); 23.38 + return "DELETE FROM "+ getName(); 23.39 + } 23.40 + 23.41 + @Override 23.42 + public String buildGeometryCollumn() { 23.43 + return "SELECT AddGeometryColumn('geo_values','strdfgeo',4326,'GEOMETRY',2)"; 23.44 + } 23.45 + 23.46 + @Override 23.47 + public String buildIndexOnGeometryCollumn() { 23.48 + return "CREATE INDEX geoindex ON geo_values (strdfgeo)"; 23.49 + } 23.50 + 23.51 + @Override 23.52 + public String buildInsertGeometryValue() { 23.53 + Integer srid= GeoConstants.defaultSRID; 23.54 + return " (id, strdfgeo,srid) VALUES (?,ST_Transform(ST_GeomFromWKB(?,?),"+srid+"),?)"; 23.55 + } 23.56 + 23.57 + @Override 23.58 + public String buildInsertValue(String type) { 23.59 + return " (id, value) VALUES ( ?, ?) "; 23.60 + } 23.61 + 23.62 + @Override 23.63 + protected String buildCreateTemporaryTable(CharSequence columns) { 23.64 + StringBuilder sb = new StringBuilder(); 23.65 + sb.append("CREATE TEMPORARY TABLE ").append(getName()); 23.66 + sb.append(" (\n").append(columns).append(")"); 23.67 + return sb.toString(); 23.68 + } 23.69 + 23.70 + @Override 23.71 + public String buildDummyFromAndWhere(String fromDummy) { 23.72 + StringBuilder sb = new StringBuilder(256); 23.73 + sb.append(fromDummy); 23.74 + sb.append("\nWHERE 1=0"); 23.75 + return sb.toString(); 23.76 + } 23.77 + 23.78 + @Override 23.79 + public String buildDynamicParameterInteger() { 23.80 + return "?"; 23.81 + } 23.82 + 23.83 + @Override 23.84 + public String buildWhere() { 23.85 + return " WHERE (1=1) "; 23.86 + } 23.87 + 23.88 + @Override 23.89 + public void primaryIndex(String... columns) 23.90 + throws SQLException 23.91 + { 23.92 + this.buildIndex(columns); 23.93 + } 23.94 + 23.95 + @Override 23.96 + public void index(String... columns) 23.97 + throws SQLException 23.98 + { 23.99 + try{ 23.100 + if (columns.length == 1 && columns[0].equalsIgnoreCase("value") 23.101 + && getName().toUpperCase().contains("LONG_")) 23.102 + { 23.103 + execute(buildLongIndex(columns)); 23.104 + } 23.105 + else { 23.106 + execute(buildIndex(columns)); 23.107 + }} 23.108 + catch(java.sql.SQLException e){ 23.109 + if(e.getMessage().contains("already exists")){ 23.110 + logger.warn(e.getMessage()); 23.111 + } 23.112 + else{ 23.113 + throw e; 23.114 + } 23.115 + } 23.116 + } 23.117 + 23.118 + @Override 23.119 + public void drop() 23.120 + throws SQLException 23.121 + { 23.122 + executeUpdate("INSERT INTO to_drop VALUES ('" + getName()+"')"); 23.123 + } 23.124 +} 23.125 \ No newline at end of file
24.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 24.2 +++ b/sqlite/src/main/java/org/openrdf/sail/sqlite/SqliteSqlTableFactory.java Tue Jun 04 18:06:42 2013 +0300 24.3 @@ -0,0 +1,12 @@ 24.4 +package org.openrdf.sail.sqlite; 24.5 + 24.6 +import org.openrdf.sail.generaldb.GeneralDBSqlTableFactory; 24.7 +import org.openrdf.sail.rdbms.schema.RdbmsTable; 24.8 + 24.9 +public class SqliteSqlTableFactory extends GeneralDBSqlTableFactory { 24.10 + 24.11 + @Override 24.12 + protected RdbmsTable newTable(String name) { 24.13 + return new SqliteSqlTable(name); 24.14 + } 24.15 +} 24.16 \ No newline at end of file
25.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 25.2 +++ b/sqlite/src/main/java/org/openrdf/sail/sqlite/SqliteSqlValueTableFactory.java Tue Jun 04 18:06:42 2013 +0300 25.3 @@ -0,0 +1,22 @@ 25.4 +package org.openrdf.sail.sqlite; 25.5 + 25.6 +import org.openrdf.sail.generaldb.GeneralDBSqlTableFactory; 25.7 +import org.openrdf.sail.generaldb.GeneralDBSqlValueTableFactory; 25.8 +import org.openrdf.sail.sqlite.SqliteSqlTableFactory; 25.9 +import org.openrdf.sail.sqlite.schema.SqliteValueTable; 25.10 + 25.11 + 25.12 +public class SqliteSqlValueTableFactory extends GeneralDBSqlValueTableFactory { 25.13 + 25.14 + public SqliteSqlValueTableFactory(SqliteSqlTableFactory sqlTableFactory) { 25.15 + super(sqlTableFactory); 25.16 + } 25.17 + 25.18 + public SqliteSqlValueTableFactory(){ 25.19 + super(new SqliteSqlTableFactory()); 25.20 + } 25.21 + 25.22 + public SqliteValueTable newValueTable() { 25.23 + return new SqliteValueTable(); 25.24 + } 25.25 +}
26.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 26.2 +++ b/sqlite/src/main/java/org/openrdf/sail/sqlite/SqliteTripleRepository.java Tue Jun 04 18:06:42 2013 +0300 26.3 @@ -0,0 +1,120 @@ 26.4 +package org.openrdf.sail.sqlite; 26.5 + 26.6 +import info.aduna.concurrent.locks.Lock; 26.7 + 26.8 +import java.sql.SQLException; 26.9 + 26.10 +import org.openrdf.sail.generaldb.GeneralDBTripleRepository; 26.11 +import org.openrdf.sail.rdbms.exceptions.RdbmsException; 26.12 +import org.openrdf.sail.rdbms.model.RdbmsResource; 26.13 +import org.openrdf.sail.rdbms.model.RdbmsURI; 26.14 +import org.openrdf.sail.rdbms.model.RdbmsValue; 26.15 +import org.openrdf.sail.generaldb.schema.BNodeTable; 26.16 +import org.openrdf.sail.generaldb.schema.LiteralTable; 26.17 +import org.openrdf.sail.generaldb.schema.URITable; 26.18 + 26.19 + 26.20 +/** 26.21 + * Facade to {@link GeneralDBTransTableManager}, {@link URITable}, {@link BNodeTable} and 26.22 + * {@link LiteralTable} for adding, removing, and retrieving statements from the 26.23 + * database. 26.24 + * 26.25 + * @author James Leigh 26.26 + */ 26.27 +public class SqliteTripleRepository extends GeneralDBTripleRepository { 26.28 + 26.29 + @Override 26.30 + protected String buildDeleteQuery(String tableName, RdbmsResource subj, RdbmsURI pred, RdbmsValue obj, 26.31 + RdbmsResource... ctxs) 26.32 + throws RdbmsException, SQLException 26.33 + { 26.34 + StringBuilder sb = new StringBuilder(); 26.35 + sb.append("DELETE FROM ").append(tableName); 26.36 + return buildWhere(sb, subj, pred, obj, ctxs); 26.37 + } 26.38 + 26.39 + @Override 26.40 + protected String buildWhere(StringBuilder sb, RdbmsResource subj, RdbmsURI pred, RdbmsValue obj, 26.41 + RdbmsResource... ctxs) 26.42 + { 26.43 + sb.append("\nWHERE (1=1)"); 26.44 + if (ctxs != null && ctxs.length > 0) { 26.45 + sb.append(" AND ("); 26.46 + for (int i = 0; i < ctxs.length; i++) { 26.47 + sb.append("ctx = ?"); 26.48 + if (i < ctxs.length - 1) { 26.49 + sb.append(" OR "); 26.50 + } 26.51 + } 26.52 + sb.append(")"); 26.53 + } 26.54 + if (subj != null) { 26.55 + sb.append(" AND subj = ? "); 26.56 + } 26.57 + if (pred != null) { 26.58 + sb.append(" AND pred = ? "); 26.59 + } 26.60 + if (obj != null) { 26.61 + sb.append(" AND obj = ?"); 26.62 + } 26.63 + return sb.toString(); 26.64 + } 26.65 + 26.66 + @Override 26.67 + public synchronized void commit() 26.68 + throws SQLException, RdbmsException, InterruptedException 26.69 + { 26.70 + synchronized (queue) { 26.71 + while (!queue.isEmpty()) { 26.72 + insert(queue.removeFirst()); 26.73 + } 26.74 + } 26.75 + manager.flush(); 26.76 + conn.commit(); 26.77 + conn.setAutoCommit(true); 26.78 + releaseLock(); 26.79 + Lock writeLock = vf.tryIdWriteLock(); 26.80 + try { 26.81 + vf.flush(); 26.82 + statements.committed(writeLock != null); 26.83 + } 26.84 + finally { 26.85 + if (writeLock != null) { 26.86 + writeLock.release(); 26.87 + } 26.88 + } 26.89 + } 26.90 + 26.91 + @Override 26.92 + protected String buildCountQuery(RdbmsResource... ctxs) 26.93 + throws SQLException 26.94 + { 26.95 + String tableName = statements.getCombinedTableName(); 26.96 + StringBuilder sb = new StringBuilder(); 26.97 + sb.append("SELECT COUNT(*) FROM "); 26.98 + sb.append(tableName).append(" t"); 26.99 + if (ctxs != null && ctxs.length > 0) { 26.100 + sb.append("\nWHERE "); 26.101 + for (int i = 0; i < ctxs.length; i++) { 26.102 + sb.append("t.ctx = ?"); 26.103 + if (i < ctxs.length - 1) { 26.104 + sb.append(" OR "); 26.105 + } 26.106 + } 26.107 + } 26.108 + return sb.toString(); 26.109 + } 26.110 + 26.111 + @Override 26.112 + public synchronized void close() 26.113 + throws SQLException 26.114 + { 26.115 + manager.close(); 26.116 + if (!conn.getAutoCommit()) { 26.117 + conn.rollback(); 26.118 + } 26.119 + conn.setAutoCommit(true); 26.120 + //conn.close(); 26.121 + releaseLock(); 26.122 + } 26.123 +}
27.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 27.2 +++ b/sqlite/src/main/java/org/openrdf/sail/sqlite/SqliteTripleTableManager.java Tue Jun 04 18:06:42 2013 +0300 27.3 @@ -0,0 +1,46 @@ 27.4 +package org.openrdf.sail.sqlite; 27.5 + 27.6 +import java.sql.DatabaseMetaData; 27.7 +import java.sql.ResultSet; 27.8 +import java.sql.SQLException; 27.9 +import java.sql.Statement; 27.10 +import java.util.HashSet; 27.11 +import java.util.Set; 27.12 + 27.13 +import org.openrdf.sail.generaldb.schema.ValueTableFactory; 27.14 + 27.15 +public class SqliteTripleTableManager extends org.openrdf.sail.generaldb.managers.TripleTableManager{ 27.16 + 27.17 + public SqliteTripleTableManager(ValueTableFactory factory) { 27.18 + super(factory); 27.19 + } 27.20 + 27.21 + //must override this method because metadata.getColumns() does not 27.22 + //work properly for sqlite jdbc driver 27.23 + @Override 27.24 + protected Set<String> findPredicateTableNames() 27.25 + throws SQLException 27.26 + { 27.27 + Set<String> names = findAllTables(); 27.28 + Set<String> result=new HashSet<String>(); 27.29 + 27.30 + for(String name:names){ 27.31 + Statement st=conn.createStatement(); 27.32 + ResultSet rs=st.executeQuery("pragma table_info ('" + name + "');"); 27.33 + int matched=0; 27.34 + while(rs.next()){ 27.35 + 27.36 + String colName=rs.getString(2).toLowerCase(); 27.37 + if(colName.equals("ctx")||colName.equals("subj")||colName.equals("obj")){ 27.38 + matched++; 27.39 + if(matched>2){ 27.40 + result.add(name); 27.41 + continue; 27.42 + } 27.43 + } 27.44 + } 27.45 + } 27.46 + return result; 27.47 + } 27.48 + 27.49 +}
28.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 28.2 +++ b/sqlite/src/main/java/org/openrdf/sail/sqlite/evaluation/SqliteEvaluation.java Tue Jun 04 18:06:42 2013 +0300 28.3 @@ -0,0 +1,91 @@ 28.4 +package org.openrdf.sail.sqlite.evaluation; 28.5 + 28.6 +import info.aduna.iteration.CloseableIteration; 28.7 + 28.8 +import java.sql.Connection; 28.9 +import java.sql.PreparedStatement; 28.10 +import java.sql.SQLException; 28.11 +import java.sql.Statement; 28.12 +import java.util.ArrayList; 28.13 +import java.util.Collection; 28.14 +import java.util.List; 28.15 + 28.16 +import org.openrdf.query.BindingSet; 28.17 +import org.openrdf.query.Dataset; 28.18 +import org.openrdf.query.QueryEvaluationException; 28.19 +import org.openrdf.query.algebra.evaluation.QueryBindingSet; 28.20 +import org.openrdf.sail.generaldb.GeneralDBTripleRepository; 28.21 +import org.openrdf.sail.generaldb.algebra.GeneralDBColumnVar; 28.22 +import org.openrdf.sail.generaldb.algebra.GeneralDBSelectQuery; 28.23 +import org.openrdf.sail.generaldb.evaluation.GeneralDBEvaluation; 28.24 +import org.openrdf.sail.generaldb.evaluation.GeneralDBQueryBuilderFactory; 28.25 +import org.openrdf.sail.generaldb.iteration.GeneralDBBindingIteration; 28.26 +import org.openrdf.sail.sqlite.iteration.SqliteBindingIteration; 28.27 +import org.openrdf.sail.rdbms.exceptions.RdbmsException; 28.28 +import org.openrdf.sail.rdbms.exceptions.RdbmsQueryEvaluationException; 28.29 +import org.openrdf.sail.rdbms.exceptions.UnsupportedRdbmsOperatorException; 28.30 +import org.openrdf.sail.generaldb.schema.IdSequence; 28.31 +import org.slf4j.LoggerFactory; 28.32 + 28.33 +/** 28.34 + * Extends the default strategy by accepting {@link GeneralDBSelectQuery} and evaluating 28.35 + * them on a database. 28.36 + * 28.37 + * @author James Leigh 28.38 + * 28.39 + */ 28.40 +public class SqliteEvaluation extends GeneralDBEvaluation { 28.41 + 28.42 + 28.43 + public SqliteEvaluation(GeneralDBQueryBuilderFactory factory, GeneralDBTripleRepository triples, Dataset dataset, 28.44 + IdSequence ids) 28.45 + { 28.46 + super(factory, triples, dataset, ids); 28.47 + logger = LoggerFactory.getLogger(SqliteEvaluation.class); 28.48 + this.factory = factory; 28.49 + } 28.50 + 28.51 + protected CloseableIteration<BindingSet, QueryEvaluationException> evaluate(GeneralDBSelectQuery qb, BindingSet b) 28.52 + throws UnsupportedRdbmsOperatorException, RdbmsQueryEvaluationException 28.53 + { 28.54 + List<Object> parameters = new ArrayList<Object>(); 28.55 + try { 28.56 + QueryBindingSet bindings = new QueryBindingSet(b); 28.57 + String query = toQueryString(qb, bindings, parameters); 28.58 + //String q2=new String(); 28.59 + //q2=query; 28.60 + //q2=q2.replaceAll("\\?", "30.0"); 28.61 + try { 28.62 + Connection conn = triples.getConnection(); 28.63 + // Statement st=conn.createStatement(); 28.64 + // st.executeQuery(q2); 28.65 + PreparedStatement stmt = conn.prepareStatement(query); 28.66 + int p = 0; 28.67 + for (Object o : parameters) { 28.68 + stmt.setObject(++p, o); 28.69 + } 28.70 + Collection<GeneralDBColumnVar> proj = qb.getProjections(); 28.71 +// System.out.println("In PostGIS Evaluation, query is: \n" + stmt); 28.72 + GeneralDBBindingIteration result = new SqliteBindingIteration(stmt); 28.73 + result.setProjections(proj); 28.74 + result.setBindings(bindings); 28.75 + result.setValueFactory(vf); 28.76 + result.setIdSequence(ids); 28.77 + //XXX addition 28.78 + result.setGeoNames(this.geoNames); 28.79 + result.setConstructIndexesAndNames(this.constructIndexesAndNames); 28.80 + 28.81 + if (logger.isDebugEnabled()) { 28.82 + logger.debug("In SQLite Evaluation, query is: \n{}", stmt); 28.83 + } 28.84 + return result; 28.85 + } 28.86 + catch (SQLException e) { 28.87 + throw new RdbmsQueryEvaluationException(e.toString() + "\n" + query, e); 28.88 + } 28.89 + } 28.90 + catch (RdbmsException e) { 28.91 + throw new RdbmsQueryEvaluationException(e); 28.92 + } 28.93 + } 28.94 +}
29.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 29.2 +++ b/sqlite/src/main/java/org/openrdf/sail/sqlite/evaluation/SqliteEvaluationFactory.java Tue Jun 04 18:06:42 2013 +0300 29.3 @@ -0,0 +1,13 @@ 29.4 +package org.openrdf.sail.sqlite.evaluation; 29.5 + 29.6 +import org.openrdf.query.Dataset; 29.7 +import org.openrdf.sail.generaldb.evaluation.GeneralDBEvaluation; 29.8 +import org.openrdf.sail.generaldb.evaluation.GeneralDBEvaluationFactory; 29.9 + 29.10 +public class SqliteEvaluationFactory extends GeneralDBEvaluationFactory{ 29.11 + 29.12 + @Override 29.13 + public GeneralDBEvaluation createRdbmsEvaluation(Dataset dataset) { 29.14 + return new SqliteEvaluation(factory, triples, dataset, ids); 29.15 + } 29.16 +}
30.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 30.2 +++ b/sqlite/src/main/java/org/openrdf/sail/sqlite/evaluation/SqliteQueryBuilder.java Tue Jun 04 18:06:42 2013 +0300 30.3 @@ -0,0 +1,2486 @@ 30.4 +package org.openrdf.sail.sqlite.evaluation; 30.5 + 30.6 +/* 30.7 + * Copyright Aduna (http://www.aduna-software.com/) (c) 2008. 30.8 + * 30.9 + * Licensed under the Aduna BSD-style license. 30.10 + */ 30.11 +import java.util.ArrayList; 30.12 +import java.util.List; 30.13 + 30.14 +import org.openrdf.query.algebra.evaluation.function.spatial.StrabonPolyhedron; 30.15 +import org.openrdf.sail.generaldb.algebra.GeneralDBColumnVar; 30.16 +import org.openrdf.sail.generaldb.algebra.GeneralDBDateTimeColumn; 30.17 +import org.openrdf.sail.generaldb.algebra.GeneralDBDoubleValue; 30.18 +import org.openrdf.sail.generaldb.algebra.GeneralDBLabelColumn; 30.19 +import org.openrdf.sail.generaldb.algebra.GeneralDBNumberValue; 30.20 +import org.openrdf.sail.generaldb.algebra.GeneralDBNumericColumn; 30.21 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlAbove; 30.22 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlAnd; 30.23 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlBelow; 30.24 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlCase; 30.25 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlContains; 30.26 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlMbbContains; 30.27 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlCrosses; 30.28 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlDiffDateTime; 30.29 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlDisjoint; 30.30 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlEqualsSpatial; 30.31 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlGeoArea; 30.32 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlGeoAsGML; 30.33 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlGeoAsText; 30.34 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlGeoBoundary; 30.35 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlGeoBuffer; 30.36 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlGeoConvexHull; 30.37 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlGeoDifference; 30.38 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlGeoDimension; 30.39 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlGeoDistance; 30.40 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlGeoEnvelope; 30.41 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlGeoGeometryType; 30.42 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlGeoIntersection; 30.43 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlGeoIsEmpty; 30.44 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlGeoIsSimple; 30.45 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlGeoSrid; 30.46 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlGeoSymDifference; 30.47 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlGeoTransform; 30.48 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlGeoUnion; 30.49 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlIntersects; 30.50 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlIsNull; 30.51 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlLeft; 30.52 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlMathExpr; 30.53 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlMbbEquals; 30.54 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlMbbWithin; 30.55 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlMbbIntersects; 30.56 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlNot; 30.57 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlNull; 30.58 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlOverlaps; 30.59 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlRelate; 30.60 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlRight; 30.61 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlSpatialConstructBinary; 30.62 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlSpatialConstructUnary; 30.63 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlSpatialMetricBinary; 30.64 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlSpatialMetricUnary; 30.65 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlSpatialProperty; 30.66 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlTouches; 30.67 +import org.openrdf.sail.generaldb.algebra.GeneralDBSqlWithin; 30.68 +import org.openrdf.sail.generaldb.algebra.GeneralDBStringValue; 30.69 +import org.openrdf.sail.generaldb.algebra.GeneralDBURIColumn; 30.70 +import org.openrdf.sail.generaldb.algebra.GeneralDBUnionItem; 30.71 +import org.openrdf.sail.generaldb.algebra.base.BinaryGeneralDBOperator; 30.72 +import org.openrdf.sail.generaldb.algebra.base.GeneralDBFromItem; 30.73 +import org.openrdf.sail.generaldb.algebra.base.GeneralDBSqlExpr; 30.74 +import org.openrdf.sail.generaldb.algebra.base.TripleGeneralDBOperator; 30.75 +import org.openrdf.sail.generaldb.algebra.base.UnaryGeneralDBOperator; 30.76 +import org.openrdf.sail.generaldb.algebra.egenhofer.GeneralDBSqlEgenhofer_Contains; 30.77 +import org.openrdf.sail.generaldb.algebra.egenhofer.GeneralDBSqlEgenhofer_CoveredBy; 30.78 +import org.openrdf.sail.generaldb.algebra.egenhofer.GeneralDBSqlEgenhofer_Covers; 30.79 +import org.openrdf.sail.generaldb.algebra.egenhofer.GeneralDBSqlEgenhofer_Disjoint; 30.80 +import org.openrdf.sail.generaldb.algebra.egenhofer.GeneralDBSqlEgenhofer_Equals; 30.81 +import org.openrdf.sail.generaldb.algebra.egenhofer.GeneralDBSqlEgenhofer_Inside; 30.82 +import org.openrdf.sail.generaldb.algebra.egenhofer.GeneralDBSqlEgenhofer_Meet; 30.83 +import org.openrdf.sail.generaldb.algebra.egenhofer.GeneralDBSqlEgenhofer_Overlap; 30.84 +import org.openrdf.sail.generaldb.algebra.rcc8.GeneralDBSqlRCC8_Dc; 30.85 +import org.openrdf.sail.generaldb.algebra.rcc8.GeneralDBSqlRCC8_Ec; 30.86 +import org.openrdf.sail.generaldb.algebra.rcc8.GeneralDBSqlRCC8_Eq; 30.87 +import org.openrdf.sail.generaldb.algebra.rcc8.GeneralDBSqlRCC8_Ntpp; 30.88 +import org.openrdf.sail.generaldb.algebra.rcc8.GeneralDBSqlRCC8_Ntppi; 30.89 +import org.openrdf.sail.generaldb.algebra.rcc8.GeneralDBSqlRCC8_Po; 30.90 +import org.openrdf.sail.generaldb.algebra.rcc8.GeneralDBSqlRCC8_Tpp; 30.91 +import org.openrdf.sail.generaldb.algebra.rcc8.GeneralDBSqlRCC8_Tppi; 30.92 +import org.openrdf.sail.generaldb.algebra.sf.GeneralDBSqlSF_Contains; 30.93 +import org.openrdf.sail.generaldb.algebra.sf.GeneralDBSqlSF_Crosses; 30.94 +import org.openrdf.sail.generaldb.algebra.sf.GeneralDBSqlSF_Disjoint; 30.95 +import org.openrdf.sail.generaldb.algebra.sf.GeneralDBSqlSF_Equals; 30.96 +import org.openrdf.sail.generaldb.algebra.sf.GeneralDBSqlSF_Intersects; 30.97 +import org.openrdf.sail.generaldb.algebra.sf.GeneralDBSqlSF_Overlaps; 30.98 +import org.openrdf.sail.generaldb.algebra.sf.GeneralDBSqlSF_Touches; 30.99 +import org.openrdf.sail.generaldb.algebra.sf.GeneralDBSqlSF_Within; 30.100 +import org.openrdf.sail.generaldb.evaluation.GeneralDBQueryBuilder; 30.101 +import org.openrdf.sail.generaldb.evaluation.GeneralDBSqlBracketBuilder; 30.102 +import org.openrdf.sail.generaldb.evaluation.GeneralDBSqlExprBuilder; 30.103 +import org.openrdf.sail.generaldb.evaluation.GeneralDBSqlJoinBuilder; 30.104 +import org.openrdf.sail.generaldb.evaluation.GeneralDBSqlQueryBuilder; 30.105 +import org.openrdf.sail.rdbms.exceptions.RdbmsException; 30.106 +import org.openrdf.sail.rdbms.exceptions.UnsupportedRdbmsOperatorException; 30.107 + 30.108 +/** 30.109 + * Constructs an SQL query from {@link GeneralDBSqlExpr}s and {@link GeneralDBFromItem}s. 30.110 + * 30.111 + * @author Manos Karpathiotakis <mk@di.uoa.gr> 30.112 + * 30.113 + */ 30.114 +public class SqliteQueryBuilder extends GeneralDBQueryBuilder { 30.115 + 30.116 + public static final String STRDFGEO_FIELD = "strdfgeo"; 30.117 + public static final String SRID_FIELD = "srid"; 30.118 + public static final String ST_TRANSFORM = "ST_Transform"; 30.119 + public static final String ST_ASBINARY = "ST_AsBinary"; 30.120 + /** 30.121 + * If (spatial) label column met is null, I must not try to retrieve its srid. 30.122 + * Opting to ask for 'null' instead 30.123 + */ 30.124 + boolean nullLabel = false; 30.125 + 30.126 + public enum SpatialOperandsPostGIS { intersects, equals, contains, inside, left, right, above, below; } 30.127 + public enum SpatialFunctionsPostGIS 30.128 + { //stSPARQL++ 30.129 + //Spatial Relationships 30.130 + ST_Equals, 30.131 + ST_Disjoint, 30.132 + ST_Intersects, 30.133 + ST_Touches, 30.134 + ST_Crosses, 30.135 + ST_Within, 30.136 + ST_Contains, 30.137 + ST_Overlaps, 30.138 + ST_Relate, 30.139 + 30.140 + //Spatial Constructs - Binary 30.141 + ST_Union, 30.142 + ST_Intersection, 30.143 + ST_Difference, 30.144 + ST_Buffer, 30.145 + ST_Transform, 30.146 + ST_SymDifference, 30.147 + 30.148 + 30.149 + //Spatial Constructs - Unary 30.150 + ST_Envelope, 30.151 + ST_ConvexHull, 30.152 + ST_Boundary, 30.153 + 30.154 + //Spatial Metrics - Binary 30.155 + ST_Distance, 30.156 + 30.157 + //Spatial Metrics - Unary 30.158 + ST_Area, 30.159 + 30.160 + //Spatial Properties - All Unary 30.161 + ST_Dimension, 30.162 + ST_GeometryType, 30.163 + ST_AsGML, 30.164 + ST_AsText, 30.165 + ST_SRID, 30.166 + ST_IsEmpty, 30.167 + ST_IsSimple, 30.168 + 30.169 + //GeoSPARQL 30.170 + //Simple Features 30.171 + SF_Equals, 30.172 + SF_Disjoint, 30.173 + SF_Intersects, 30.174 + SF_Touches, 30.175 + SF_Within, 30.176 + SF_Contains, 30.177 + SF_Overlaps, 30.178 + SF_Crosses, 30.179 + 30.180 + //RCC8 30.181 + RCC8_Eq, 30.182 + RCC8_Dc, 30.183 + RCC8_Ec, 30.184 + RCC8_Po, 30.185 + RCC8_Tppi, 30.186 + RCC8_Tpp, 30.187 + RCC8_Ntppi, 30.188 + RCC8_Ntpp, 30.189 + 30.190 + //Egenhofer 30.191 + EH_Equals, 30.192 + EH_Disjoint, 30.193 + EH_Meet, 30.194 + EH_Overlap, 30.195 + EH_Covers, 30.196 + EH_CoveredBy, 30.197 + EH_Inside, 30.198 + EH_Contains, 30.199 + ; 30.200 + } 30.201 + 30.202 + /** Addition for datetime metric functions 30.203 + * 30.204 + * @author George Garbis <ggarbis@di.uoa.gr> 30.205 + * 30.206 + */ 30.207 + public enum DateTimeFunctionPostGIS { Difference; } 30.208 + /***/ 30.209 + 30.210 + public SqliteQueryBuilder() { 30.211 + super(); 30.212 + } 30.213 + 30.214 + public SqliteQueryBuilder(GeneralDBSqlQueryBuilder builder) { 30.215 + super(builder); 30.216 + this.query = builder; 30.217 + } 30.218 + 30.219 + @Override 30.220 + protected void append(GeneralDBSqlNull expr, GeneralDBSqlExprBuilder filter) { 30.221 + filter.appendNull(); 30.222 + } 30.223 + 30.224 + @Override 30.225 + protected void append(GeneralDBSqlIsNull expr, GeneralDBSqlExprBuilder filter) 30.226 + throws UnsupportedRdbmsOperatorException 30.227 + { 30.228 + dispatch(expr.getArg(), filter); 30.229 + filter.isNull(); 30.230 + } 30.231 + 30.232 + @Override 30.233 + protected void append(GeneralDBSqlNot expr, GeneralDBSqlExprBuilder filter) 30.234 + throws UnsupportedRdbmsOperatorException 30.235 + { 30.236 + if (expr.getArg() instanceof GeneralDBSqlIsNull) { 30.237 + GeneralDBSqlIsNull arg = (GeneralDBSqlIsNull)expr.getArg(); 30.238 + dispatch(arg.getArg(), filter); 30.239 + filter.isNotNull(); 30.240 + } 30.241 + else { 30.242 + GeneralDBSqlBracketBuilder open = filter.not(); 30.243 + dispatch(expr.getArg(), (GeneralDBSqlExprBuilder) open); 30.244 + open.close(); 30.245 + } 30.246 + } 30.247 + 30.248 + @Override 30.249 + protected void append(GeneralDBDateTimeColumn var, GeneralDBSqlExprBuilder filter) { 30.250 + String alias = getDateTimeAlias(var.getRdbmsVar()); 30.251 + filter.column(alias, "value"); 30.252 + } 30.253 + 30.254 + @Override 30.255 + protected void append(GeneralDBLabelColumn var, GeneralDBSqlExprBuilder filter) { 30.256 + if (var.getRdbmsVar().isResource()) { 30.257 + filter.appendNull(); 30.258 + nullLabel = true; 30.259 + } 30.260 + else { 30.261 + if(var.isSpatial()) 30.262 + { 30.263 + filter.appendFunction(ST_ASBINARY); 30.264 + filter.openBracket(); 30.265 + //XXX SRID 30.266 + filter.appendFunction(ST_TRANSFORM); 30.267 + filter.openBracket(); 30.268 + // 30.269 + String alias = getLabelAlias(var.getRdbmsVar()); 30.270 + 30.271 + filter.column(alias, STRDFGEO_FIELD); 30.272 + //XXX SRID 30.273 + filter.appendComma(); 30.274 + filter.column(alias, SRID_FIELD); 30.275 + filter.closeBracket(); 30.276 + // 30.277 + filter.closeBracket(); 30.278 + 30.279 + //Adding srid field explicitly for my StrabonPolyhedron constructor later on! 30.280 + filter.appendComma(); 30.281 + filter.column(alias, SRID_FIELD); 30.282 + } 30.283 + else 30.284 + { 30.285 + //XXX original/default case 30.286 + String alias = getLabelAlias(var.getRdbmsVar()); 30.287 + filter.column(alias, "value"); 30.288 + } 30.289 + } 30.290 + } 30.291 + 30.292 + @Override 30.293 + protected void append(GeneralDBSqlAnd expr, GeneralDBSqlExprBuilder filter) 30.294 + throws UnsupportedRdbmsOperatorException 30.295 + { 30.296 + dispatch(expr.getLeftArg(), filter); 30.297 + filter.and(); 30.298 + dispatch(expr.getRightArg(), filter); 30.299 + } 30.300 + 30.301 + protected GeneralDBSqlJoinBuilder subJoinAndFilter(GeneralDBSqlJoinBuilder query, GeneralDBFromItem from) 30.302 + throws RdbmsException, UnsupportedRdbmsOperatorException 30.303 + { 30.304 + if (from instanceof GeneralDBUnionItem) { 30.305 + GeneralDBUnionItem union = (GeneralDBUnionItem)from; 30.306 + List<String> names = union.getSelectVarNames(); 30.307 + List<GeneralDBColumnVar> vars = union.appendVars(new ArrayList<GeneralDBColumnVar>()); 30.308 + GeneralDBSqlQueryBuilder subquery = query.subquery(); 30.309 + for (GeneralDBFromItem item : union.getUnion()) { 30.310 + for (int i = 0, n = names.size(); i < n; i++) { 30.311 + GeneralDBColumnVar var = item.getVar(names.get(i)); 30.312 + GeneralDBSqlExprBuilder select = subquery.select(); 30.313 + if (var == null) { 30.314 + select.appendNull(); 30.315 + } 30.316 + else if (var.isImplied()) { 30.317 + select.appendNumeric(vf.getInternalId(var.getValue())); 30.318 + } 30.319 + else { 30.320 + select.column(var.getAlias(), var.getColumn()); 30.321 + } 30.322 + select.as(vars.get(i).getColumn()); 30.323 + } 30.324 + from(subquery, item); 30.325 + subquery = subquery.union(); 30.326 + } 30.327 + } 30.328 + for (GeneralDBFromItem join : from.getJoins()) { 30.329 + join(query, join); 30.330 + } 30.331 + for (GeneralDBSqlExpr expr : from.getFilters()) { 30.332 + dispatch(expr, query.on().and()); 30.333 + } 30.334 + return query; 30.335 + } 30.336 + 30.337 + //FIXME my addition from here on 30.338 + 30.339 + //Issue with this function: crashes when MathExpr is present in Select but does not 30.340 + //involve spatial variables! must escape this somehow 30.341 + @Override 30.342 + public GeneralDBQueryBuilder construct(GeneralDBSqlExpr expr) throws UnsupportedRdbmsOperatorException 30.343 + { 30.344 + if(!(expr instanceof GeneralDBSqlSpatialMetricBinary) 30.345 + &&!(expr instanceof GeneralDBSqlSpatialMetricUnary) 30.346 + &&!(expr instanceof GeneralDBSqlMathExpr) 30.347 + &&!(expr instanceof GeneralDBSqlSpatialProperty)) 30.348 + { 30.349 + query.select().appendFunction(ST_ASBINARY); 30.350 + } 30.351 + else 30.352 + { 30.353 + query.select(); 30.354 + } 30.355 + if(expr instanceof BinaryGeneralDBOperator) 30.356 + { 30.357 + dispatchBinarySqlOperator((BinaryGeneralDBOperator) expr, query.select); 30.358 + } 30.359 + else if(expr instanceof UnaryGeneralDBOperator) 30.360 + { 30.361 + dispatchUnarySqlOperator((UnaryGeneralDBOperator) expr, query.select); 30.362 + } 30.363 + //SRID support must be explicitly added! 30.364 + 30.365 + return this; 30.366 + } 30.367 + 30.368 + //Spatial Relationship Functions 30.369 + @Override 30.370 + protected void append(GeneralDBSqlEqualsSpatial expr, GeneralDBSqlExprBuilder filter) 30.371 + throws UnsupportedRdbmsOperatorException { 30.372 + 30.373 + appendGeneralDBSpatialFunctionBinary(expr, filter, SpatialFunctionsPostGIS.ST_Equals); 30.374 + } 30.375 + 30.376 + @Override 30.377 + protected void append(GeneralDBSqlDisjoint expr, GeneralDBSqlExprBuilder filter) 30.378 + throws UnsupportedRdbmsOperatorException { 30.379 + 30.380 + appendGeneralDBSpatialFunctionBinary(expr, filter, SpatialFunctionsPostGIS.ST_Disjoint); 30.381 + } 30.382 + 30.383 + @Override 30.384 + protected void append(GeneralDBSqlIntersects expr, GeneralDBSqlExprBuilder filter) 30.385 + throws UnsupportedRdbmsOperatorException { 30.386 + appendGeneralDBSpatialFunctionBinary(expr, filter, SpatialFunctionsPostGIS.ST_Intersects); 30.387 + } 30.388 + 30.389 + @Override 30.390 + protected void append(GeneralDBSqlTouches expr, GeneralDBSqlExprBuilder filter) 30.391 + throws UnsupportedRdbmsOperatorException { 30.392 + 30.393 + appendGeneralDBSpatialFunctionBinary(expr, filter, SpatialFunctionsPostGIS.ST_Touches); 30.394 + } 30.395 + 30.396 + @Override 30.397 + protected void append(GeneralDBSqlCrosses expr, GeneralDBSqlExprBuilder filter) 30.398 + throws UnsupportedRdbmsOperatorException { 30.399 + 30.400 + appendGeneralDBSpatialFunctionBinary(expr, filter, SpatialFunctionsPostGIS.ST_Crosses); 30.401 + } 30.402 + 30.403 + @Override 30.404 + protected void append(GeneralDBSqlWithin expr, GeneralDBSqlExprBuilder filter) 30.405 + throws UnsupportedRdbmsOperatorException { 30.406 + 30.407 + appendGeneralDBSpatialFunctionBinary(expr, filter, SpatialFunctionsPostGIS.ST_Within); 30.408 + 30.409 + } 30.410 + 30.411 + @Override 30.412 + protected void append(GeneralDBSqlContains expr, GeneralDBSqlExprBuilder filter) 30.413 + throws UnsupportedRdbmsOperatorException { 30.414 + 30.415 + appendGeneralDBSpatialFunctionBinary(expr, filter, SpatialFunctionsPostGIS.ST_Contains); 30.416 + } 30.417 + 30.418 + @Override 30.419 + protected void append(GeneralDBSqlOverlaps expr, GeneralDBSqlExprBuilder filter) 30.420 + throws UnsupportedRdbmsOperatorException { 30.421 + 30.422 + appendGeneralDBSpatialFunctionBinary(expr, filter, SpatialFunctionsPostGIS.ST_Overlaps); 30.423 + } 30.424 + 30.425 + @Override 30.426 + protected void append(GeneralDBSqlRelate expr, GeneralDBSqlExprBuilder filter) 30.427 + throws UnsupportedRdbmsOperatorException { 30.428 + appendGeneralDBSpatialFunctionTriple(expr, filter, SpatialFunctionsPostGIS.ST_Relate); 30.429 + } 30.430 + 30.431 +// @Override 30.432 +// protected void append(GeneralDBSqlCovers expr, GeneralDBSqlExprBuilder filter) 30.433 +// throws UnsupportedRdbmsOperatorException { 30.434 +// 30.435 +// appendGeneralDBSpatialFunctionBinary(expr, filter, SpatialFunctionsPostGIS.ST_Covers); 30.436 +// } 30.437 +// 30.438 +// @Override 30.439 +// protected void append(GeneralDBSqlCoveredBy expr, GeneralDBSqlExprBuilder filter) 30.440 +// throws UnsupportedRdbmsOperatorException { 30.441 +// 30.442 +// appendGeneralDBSpatialFunctionBinary(expr, filter, SpatialFunctionsPostGIS.ST_CoveredBy); 30.443 +// } 30.444 + 30.445 + 30.446 + 30.447 + 30.448 + 30.449 + 30.450 + @Override 30.451 + protected void append(GeneralDBSqlLeft expr, GeneralDBSqlExprBuilder filter) 30.452 + throws UnsupportedRdbmsOperatorException 30.453 + { 30.454 + appendStSPARQLSpatialOperand(expr, filter, SpatialOperandsPostGIS.left); 30.455 + } 30.456 + 30.457 + @Override 30.458 + protected void append(GeneralDBSqlRight expr, GeneralDBSqlExprBuilder filter) 30.459 + throws UnsupportedRdbmsOperatorException 30.460 + { 30.461 + appendStSPARQLSpatialOperand(expr, filter, SpatialOperandsPostGIS.right); 30.462 + } 30.463 + 30.464 + @Override 30.465 + protected void append(GeneralDBSqlAbove expr, GeneralDBSqlExprBuilder filter) 30.466 + throws UnsupportedRdbmsOperatorException 30.467 + { 30.468 + appendStSPARQLSpatialOperand(expr, filter, SpatialOperandsPostGIS.above); 30.469 + } 30.470 + 30.471 + @Override 30.472 + protected void append(GeneralDBSqlBelow expr, GeneralDBSqlExprBuilder filter) 30.473 + throws UnsupportedRdbmsOperatorException 30.474 + { 30.475 + appendStSPARQLSpatialOperand(expr, filter, SpatialOperandsPostGIS.below); 30.476 + } 30.477 + 30.478 + @Override 30.479 + protected void append(GeneralDBSqlMbbIntersects expr, GeneralDBSqlExprBuilder filter) 30.480 + throws UnsupportedRdbmsOperatorException { 30.481 + appendStSPARQLSpatialOperand(expr, filter, SpatialOperandsPostGIS.intersects); 30.482 + } 30.483 + 30.484 + @Override 30.485 + protected void append(GeneralDBSqlMbbWithin expr, GeneralDBSqlExprBuilder filter) 30.486 + throws UnsupportedRdbmsOperatorException { 30.487 + appendStSPARQLSpatialOperand(expr, filter, SpatialOperandsPostGIS.inside); 30.488 + } 30.489 + 30.490 + 30.491 + @Override 30.492 + protected void append(GeneralDBSqlMbbContains expr, GeneralDBSqlExprBuilder filter) 30.493 + throws UnsupportedRdbmsOperatorException { 30.494 + appendStSPARQLSpatialOperand(expr, filter, SpatialOperandsPostGIS.contains); 30.495 + } 30.496 + 30.497 + 30.498 + @Override 30.499 + protected void append(GeneralDBSqlMbbEquals expr, GeneralDBSqlExprBuilder filter) 30.500 + throws UnsupportedRdbmsOperatorException { 30.501 + appendStSPARQLSpatialOperand(expr, filter, SpatialOperandsPostGIS.equals); 30.502 + } 30.503 + 30.504 + //GeoSPARQL - Spatial Relationship Functions 30.505 + //Simple Features 30.506 + @Override 30.507 + protected void append(GeneralDBSqlSF_Contains expr, GeneralDBSqlExprBuilder filter) 30.508 + throws UnsupportedRdbmsOperatorException 30.509 + { 30.510 + appendgeoSPARQLSpatialRelation(expr, filter,SpatialFunctionsPostGIS.SF_Contains); 30.511 + } 30.512 + 30.513 + @Override 30.514 + protected void append(GeneralDBSqlSF_Crosses expr, GeneralDBSqlExprBuilder filter) 30.515 + throws UnsupportedRdbmsOperatorException 30.516 + { 30.517 + //follow the same approach as stSPARQL, because the implementation used in 30.518 + //appendgeoSPARQLSpatialRelation (which is based on ST_Relate) is not correct for this case 30.519 + appendGeneralDBSpatialFunctionBinary(expr, filter, SpatialFunctionsPostGIS.ST_Crosses); 30.520 + } 30.521 + 30.522 + @Override 30.523 + protected void append(GeneralDBSqlSF_Disjoint expr, GeneralDBSqlExprBuilder filter) 30.524 + throws UnsupportedRdbmsOperatorException 30.525 + { 30.526 + appendgeoSPARQLSpatialRelation(expr, filter,SpatialFunctionsPostGIS.SF_Disjoint); 30.527 + } 30.528 + 30.529 + @Override 30.530 + protected void append(GeneralDBSqlSF_Equals expr, GeneralDBSqlExprBuilder filter) 30.531 + throws UnsupportedRdbmsOperatorException 30.532 + { 30.533 + appendgeoSPARQLSpatialRelation(expr, filter,SpatialFunctionsPostGIS.SF_Equals); 30.534 + } 30.535 + 30.536 + @Override 30.537 + protected void append(GeneralDBSqlSF_Intersects expr, GeneralDBSqlExprBuilder filter) 30.538 + throws UnsupportedRdbmsOperatorException 30.539 + { 30.540 + appendgeoSPARQLSpatialRelation(expr, filter,SpatialFunctionsPostGIS.SF_Intersects); 30.541 + } 30.542 + 30.543 + @Override 30.544 + protected void append(GeneralDBSqlSF_Overlaps expr, GeneralDBSqlExprBuilder filter) 30.545 + throws UnsupportedRdbmsOperatorException 30.546 + { 30.547 + //follow the same approach as stSPARQL, because the implementation used in 30.548 + //appendgeoSPARQLSpatialRelation (which is based on ST_Relate) is not correct for this case 30.549 + appendGeneralDBSpatialFunctionBinary(expr, filter, SpatialFunctionsPostGIS.ST_Overlaps); 30.550 + } 30.551 + 30.552 + @Override 30.553 + protected void append(GeneralDBSqlSF_Touches expr, GeneralDBSqlExprBuilder filter) 30.554 + throws UnsupportedRdbmsOperatorException 30.555 + { 30.556 + appendgeoSPARQLSpatialRelation(expr, filter,SpatialFunctionsPostGIS.SF_Touches); 30.557 + } 30.558 + 30.559 + @Override 30.560 + protected void append(GeneralDBSqlSF_Within expr, GeneralDBSqlExprBuilder filter) 30.561 + throws UnsupportedRdbmsOperatorException 30.562 + { 30.563 + appendgeoSPARQLSpatialRelation(expr, filter,SpatialFunctionsPostGIS.SF_Within); 30.564 + } 30.565 + 30.566 + //Egenhofer 30.567 + @Override 30.568 + protected void append(GeneralDBSqlEgenhofer_CoveredBy expr, GeneralDBSqlExprBuilder filter) 30.569 + throws UnsupportedRdbmsOperatorException 30.570 + { 30.571 + appendgeoSPARQLSpatialRelation(expr, filter,SpatialFunctionsPostGIS.EH_CoveredBy); 30.572 + } 30.573 + 30.574 + @Override 30.575 + protected void append(GeneralDBSqlEgenhofer_Covers expr, GeneralDBSqlExprBuilder filter) 30.576 + throws UnsupportedRdbmsOperatorException 30.577 + { 30.578 + appendgeoSPARQLSpatialRelation(expr, filter,SpatialFunctionsPostGIS.EH_Covers); 30.579 + } 30.580 + 30.581 + @Override 30.582 + protected void append(GeneralDBSqlEgenhofer_Contains expr, GeneralDBSqlExprBuilder filter) 30.583 + throws UnsupportedRdbmsOperatorException 30.584 + { 30.585 + appendgeoSPARQLSpatialRelation(expr, filter,SpatialFunctionsPostGIS.EH_Contains); 30.586 + } 30.587 + 30.588 + @Override 30.589 + protected void append(GeneralDBSqlEgenhofer_Disjoint expr, GeneralDBSqlExprBuilder filter) 30.590 + throws UnsupportedRdbmsOperatorException 30.591 + { 30.592 + appendgeoSPARQLSpatialRelation(expr, filter,SpatialFunctionsPostGIS.EH_Disjoint); 30.593 + } 30.594 + 30.595 + @Override 30.596 + protected void append(GeneralDBSqlEgenhofer_Equals expr, GeneralDBSqlExprBuilder filter) 30.597 + throws UnsupportedRdbmsOperatorException 30.598 + { 30.599 + appendgeoSPARQLSpatialRelation(expr, filter,SpatialFunctionsPostGIS.EH_Equals); 30.600 + } 30.601 + 30.602 + @Override 30.603 + protected void append(GeneralDBSqlEgenhofer_Inside expr, GeneralDBSqlExprBuilder filter) 30.604 + throws UnsupportedRdbmsOperatorException 30.605 + { 30.606 + appendgeoSPARQLSpatialRelation(expr, filter,SpatialFunctionsPostGIS.EH_Inside); 30.607 + } 30.608 + 30.609 + @Override 30.610 + protected void append(GeneralDBSqlEgenhofer_Meet expr, GeneralDBSqlExprBuilder filter) 30.611 + throws UnsupportedRdbmsOperatorException 30.612 + { 30.613 + appendgeoSPARQLSpatialRelation(expr, filter,SpatialFunctionsPostGIS.EH_Meet); 30.614 + } 30.615 + 30.616 + @Override 30.617 + protected void append(GeneralDBSqlEgenhofer_Overlap expr, GeneralDBSqlExprBuilder filter) 30.618 + throws UnsupportedRdbmsOperatorException 30.619 + { 30.620 + //follow the same approach as stSPARQL, because the implementation used in 30.621 + //appendgeoSPARQLSpatialRelation (which is based on ST_Relate) is not correct for this case 30.622 + appendGeneralDBSpatialFunctionBinary(expr, filter, SpatialFunctionsPostGIS.ST_Overlaps); 30.623 + } 30.624 + 30.625 + //RCC8 30.626 + @Override 30.627 + protected void append(GeneralDBSqlRCC8_Dc expr, GeneralDBSqlExprBuilder filter) 30.628 + throws UnsupportedRdbmsOperatorException 30.629 + { 30.630 + appendgeoSPARQLSpatialRelation(expr, filter,SpatialFunctionsPostGIS.RCC8_Dc); 30.631 + } 30.632 + 30.633 + @Override 30.634 + protected void append(GeneralDBSqlRCC8_Eq expr, GeneralDBSqlExprBuilder filter) 30.635 + throws UnsupportedRdbmsOperatorException 30.636 + { 30.637 + appendgeoSPARQLSpatialRelation(expr, filter,SpatialFunctionsPostGIS.RCC8_Eq); 30.638 + } 30.639 + 30.640 + @Override 30.641 + protected void append(GeneralDBSqlRCC8_Ec expr, GeneralDBSqlExprBuilder filter) 30.642 + throws UnsupportedRdbmsOperatorException 30.643 + { 30.644 + appendgeoSPARQLSpatialRelation(expr, filter,SpatialFunctionsPostGIS.RCC8_Ec); 30.645 + } 30.646 + 30.647 + @Override 30.648 + protected void append(GeneralDBSqlRCC8_Po expr, GeneralDBSqlExprBuilder filter) 30.649 + throws UnsupportedRdbmsOperatorException 30.650 + { 30.651 + appendgeoSPARQLSpatialRelation(expr, filter,SpatialFunctionsPostGIS.RCC8_Po); 30.652 + } 30.653 + 30.654 + @Override 30.655 + protected void append(GeneralDBSqlRCC8_Tppi expr, GeneralDBSqlExprBuilder filter) 30.656 + throws UnsupportedRdbmsOperatorException 30.657 + { 30.658 + appendgeoSPARQLSpatialRelation(expr, filter,SpatialFunctionsPostGIS.RCC8_Tppi); 30.659 + } 30.660 + 30.661 + @Override 30.662 + protected void append(GeneralDBSqlRCC8_Tpp expr, GeneralDBSqlExprBuilder filter) 30.663 + throws UnsupportedRdbmsOperatorException 30.664 + { 30.665 + appendgeoSPARQLSpatialRelation(expr, filter,SpatialFunctionsPostGIS.RCC8_Tpp); 30.666 + } 30.667 + 30.668 + @Override 30.669 + protected void append(GeneralDBSqlRCC8_Ntpp expr, GeneralDBSqlExprBuilder filter) 30.670 + throws UnsupportedRdbmsOperatorException 30.671 + { 30.672 + appendgeoSPARQLSpatialRelation(expr, filter,SpatialFunctionsPostGIS.RCC8_Ntpp); 30.673 + } 30.674 + 30.675 + @Override 30.676 + protected void append(GeneralDBSqlRCC8_Ntppi expr, GeneralDBSqlExprBuilder filter) 30.677 + throws UnsupportedRdbmsOperatorException 30.678 + { 30.679 + appendgeoSPARQLSpatialRelation(expr, filter,SpatialFunctionsPostGIS.RCC8_Ntppi); 30.680 + } 30.681 + 30.682 + //Spatial Construct Functions 30.683 + @Override 30.684 + protected void append(GeneralDBSqlGeoUnion expr, GeneralDBSqlExprBuilder filter) 30.685 + throws UnsupportedRdbmsOperatorException 30.686 + { 30.687 + appendGeneralDBSpatialFunctionBinary(expr, filter, SpatialFunctionsPostGIS.ST_Union); 30.688 + } 30.689 + 30.690 + @Override 30.691 + protected void append(GeneralDBSqlGeoBuffer expr, GeneralDBSqlExprBuilder filter) 30.692 + throws UnsupportedRdbmsOperatorException 30.693 + { 30.694 + appendGeneralDBSpatialFunctionBinary(expr, filter, SpatialFunctionsPostGIS.ST_Buffer); 30.695 + } 30.696 + 30.697 + //XXX Different Behavior 30.698 + @Override 30.699 + protected void append(GeneralDBSqlGeoTransform expr, GeneralDBSqlExprBuilder filter) 30.700 + throws UnsupportedRdbmsOperatorException 30.701 + { 30.702 + appendTransformFunc(expr, filter); 30.703 + } 30.704 + 30.705 + @Override 30.706 + protected void append(GeneralDBSqlGeoEnvelope expr, GeneralDBSqlExprBuilder filter) 30.707 + throws UnsupportedRdbmsOperatorException 30.708 + { 30.709 + appendGeneralDBSpatialFunctionUnary(expr, filter, SpatialFunctionsPostGIS.ST_Envelope); 30.710 + } 30.711 + 30.712 + @Override 30.713 + protected void append(GeneralDBSqlGeoConvexHull expr, GeneralDBSqlExprBuilder filter) 30.714 + throws UnsupportedRdbmsOperatorException 30.715 + { 30.716 + appendGeneralDBSpatialFunctionUnary(expr, filter, SpatialFunctionsPostGIS.ST_ConvexHull); 30.717 + } 30.718 + 30.719 + @Override 30.720 + protected void append(GeneralDBSqlGeoBoundary expr, GeneralDBSqlExprBuilder filter) 30.721 + throws UnsupportedRdbmsOperatorException 30.722 + { 30.723 + appendGeneralDBSpatialFunctionUnary(expr, filter, SpatialFunctionsPostGIS.ST_Boundary); 30.724 + } 30.725 + 30.726 + @Override 30.727 + protected void append(GeneralDBSqlGeoIntersection expr, GeneralDBSqlExprBuilder filter) 30.728 + throws UnsupportedRdbmsOperatorException 30.729 + { 30.730 + appendGeneralDBSpatialFunctionBinary(expr, filter, SpatialFunctionsPostGIS.ST_Intersection); 30.731 + } 30.732 + 30.733 + @Override 30.734 + protected void append(GeneralDBSqlGeoDifference expr, GeneralDBSqlExprBuilder filter) 30.735 + throws UnsupportedRdbmsOperatorException 30.736 + { 30.737 + appendGeneralDBSpatialFunctionBinary(expr, filter, SpatialFunctionsPostGIS.ST_Difference); 30.738 + } 30.739 + 30.740 + @Override 30.741 + protected void append(GeneralDBSqlGeoSymDifference expr, GeneralDBSqlExprBuilder filter) 30.742 + throws UnsupportedRdbmsOperatorException 30.743 + { 30.744 + appendGeneralDBSpatialFunctionBinary(expr, filter, SpatialFunctionsPostGIS.ST_SymDifference); 30.745 + } 30.746 + 30.747 + /** Addition for datetime metric functions 30.748 + * 30.749 + * @author George Garbis <ggarbis@di.uoa.gr> 30.750 + * 30.751 + */ 30.752 + @Override 30.753 + protected void append(GeneralDBSqlDiffDateTime expr, GeneralDBSqlExprBuilder filter) 30.754 + throws UnsupportedRdbmsOperatorException 30.755 + { 30.756 + appendGeneralDBDateTimeFunctionBinary(expr, filter, DateTimeFunctionPostGIS.Difference); 30.757 + } 30.758 + /***/ 30.759 + 30.760 + //Spatial Metric Functions 30.761 + @Override 30.762 + protected void append(GeneralDBSqlGeoDistance expr, GeneralDBSqlExprBuilder filter) 30.763 + throws UnsupportedRdbmsOperatorException 30.764 + { 30.765 + appendGeneralDBSpatialFunctionBinary(expr, filter, SpatialFunctionsPostGIS.ST_Distance); 30.766 + } 30.767 + 30.768 + @Override 30.769 + protected void append(GeneralDBSqlGeoArea expr, GeneralDBSqlExprBuilder filter) 30.770 + throws UnsupportedRdbmsOperatorException 30.771 + { 30.772 + appendGeneralDBSpatialFunctionUnary(expr, filter, SpatialFunctionsPostGIS.ST_Area); 30.773 + } 30.774 + 30.775 + //Spatial Property Functions 30.776 + @Override 30.777 + protected void append(GeneralDBSqlGeoDimension expr, GeneralDBSqlExprBuilder filter) 30.778 + throws UnsupportedRdbmsOperatorException 30.779 + { 30.780 + appendGeneralDBSpatialFunctionUnary(expr, filter, SpatialFunctionsPostGIS.ST_Dimension); 30.781 + } 30.782 + 30.783 + @Override 30.784 + protected void append(GeneralDBSqlGeoGeometryType expr, GeneralDBSqlExprBuilder filter) 30.785 + throws UnsupportedRdbmsOperatorException 30.786 + { 30.787 + appendGeneralDBSpatialFunctionUnary(expr, filter, SpatialFunctionsPostGIS.ST_GeometryType); 30.788 + } 30.789 + 30.790 + @Override 30.791 + protected void append(GeneralDBSqlGeoAsText expr, GeneralDBSqlExprBuilder filter) 30.792 + throws UnsupportedRdbmsOperatorException 30.793 + { 30.794 + appendGeneralDBSpatialFunctionUnary(expr, filter, SpatialFunctionsPostGIS.ST_AsText); 30.795 + } 30.796 + 30.797 + @Override 30.798 + protected void append(GeneralDBSqlGeoAsGML expr, GeneralDBSqlExprBuilder filter) 30.799 + throws UnsupportedRdbmsOperatorException 30.800 + { 30.801 + appendGeneralDBSpatialFunctionUnary(expr, filter, SpatialFunctionsPostGIS.ST_AsGML); 30.802 + } 30.803 + 30.804 + // @Override 30.805 + // protected void append(GeneralDBSqlGeoSrid expr, GeneralDBSqlExprBuilder filter) 30.806 + // throws UnsupportedRdbmsOperatorException 30.807 + // { 30.808 + // appendGeneralDBSpatialFunctionUnary(expr, filter, SpatialFunctionsPostGIS.ST_SRID); 30.809 + // } 30.810 + 30.811 + /** 30.812 + * Special Case because I need to retrieve a single different column from geo_values when this function occurs 30.813 + * in the select clause 30.814 + */ 30.815 + @Override 30.816 + protected void append(GeneralDBSqlGeoSrid expr, GeneralDBSqlExprBuilder filter) 30.817 + throws UnsupportedRdbmsOperatorException 30.818 + { 30.819 + boolean sridNeeded = true; 30.820 + filter.openBracket(); 30.821 + 30.822 + boolean check1 = expr.getArg().getClass().getCanonicalName().equals("org.openrdf.sail.generaldb.algebra.GeneralDBSqlNull"); 30.823 + boolean check2 = false; 30.824 + if(expr.getArg() instanceof GeneralDBLabelColumn) 30.825 + { 30.826 + if(((GeneralDBLabelColumn) expr.getArg()).getRdbmsVar().isResource()) 30.827 + { 30.828 + check2 = true; 30.829 + } 30.830 + } 30.831 + if(check1) 30.832 + { 30.833 + this.append((GeneralDBSqlNull)expr.getArg(), filter); 30.834 + 30.835 + } 30.836 + else if (check2) 30.837 + { 30.838 + appendMBB((GeneralDBLabelColumn)(expr.getArg()),filter); 30.839 + } 30.840 + else 30.841 + { 30.842 + //XXX Incorporating SRID 30.843 + GeneralDBSqlExpr tmp = expr; 30.844 + if(tmp.getParentNode() == null) 30.845 + { 30.846 + String sridExpr; 30.847 + while(true) 30.848 + { 30.849 + GeneralDBSqlExpr child = null; 30.850 + 30.851 + if(tmp instanceof BinaryGeneralDBOperator) 30.852 + { 30.853 + child = ((BinaryGeneralDBOperator) tmp).getLeftArg(); 30.854 + } 30.855 + else if(tmp instanceof UnaryGeneralDBOperator) 30.856 + { 30.857 + child = ((UnaryGeneralDBOperator) tmp).getArg(); 30.858 + } 30.859 + else if(tmp instanceof GeneralDBStringValue) 30.860 + { 30.861 + //Constant!! 30.862 + sridNeeded = false; 30.863 + break; 30.864 + } 30.865 + 30.866 + tmp = child; 30.867 + if(tmp instanceof GeneralDBLabelColumn) 30.868 + { 30.869 + //Reached the innermost left var -> need to capture its SRID 30.870 + String alias; 30.871 + if (((GeneralDBLabelColumn) tmp).getRdbmsVar().isResource()) { 30.872 + //Predicates used in triple patterns non-existent in db 30.873 + alias="NULL"; 30.874 + } 30.875 + else 30.876 + { 30.877 + //Reached the innermost left var -> need to capture its SRID 30.878 + alias = getLabelAlias(((GeneralDBLabelColumn) tmp).getRdbmsVar()); 30.879 + alias=alias+".srid"; 30.880 + } 30.881 + sridExpr = alias; 30.882 + filter.append(sridExpr); 30.883 + filter.closeBracket(); 30.884 + return; 30.885 + //break; 30.886 + } 30.887 + else if(tmp instanceof GeneralDBStringValue) 30.888 + { 30.889 + //Constant!! 30.890 + sridNeeded = false; 30.891 + break; 30.892 + } 30.893 + 30.894 + } 30.895 + } 30.896 + 30.897 + if(sridNeeded) 30.898 + { 30.899 + filter.appendFunction("ST_SRID"); 30.900 + filter.openBracket(); 30.901 + if(expr.getArg() instanceof GeneralDBStringValue) 30.902 + { 30.903 + appendWKT(expr.getArg(),filter); 30.904 + } 30.905 + else if(expr.getArg() instanceof GeneralDBSqlSpatialConstructBinary) 30.906 + { 30.907 + appendConstructFunction(expr.getArg(), filter); 30.908 + } 30.909 + else if(expr.getArg() instanceof GeneralDBSqlSpatialConstructUnary) 30.910 + { 30.911 + appendConstructFunction(expr.getArg(), filter); 30.912 + } 30.913 + else if(expr.getArg() instanceof GeneralDBSqlCase) 30.914 + { 30.915 + GeneralDBLabelColumn onlyLabel = (GeneralDBLabelColumn)((GeneralDBSqlCase)expr.getArg()).getEntries().get(0).getResult(); 30.916 + appendMBB(onlyLabel,filter); 30.917 + } 30.918 + else 30.919 + { 30.920 + appendMBB((GeneralDBLabelColumn)(expr.getArg()),filter); 30.921 + } 30.922 + 30.923 + filter.closeBracket(); 30.924 + } 30.925 + else 30.926 + { 30.927 + //4326 by default - Software House additions 30.928 + filter.append("4326"); 30.929 + } 30.930 + } 30.931 + 30.932 + filter.closeBracket(); 30.933 + } 30.934 + 30.935 + @Override 30.936 + protected void append(GeneralDBSqlGeoIsSimple expr, GeneralDBSqlExprBuilder filter) 30.937 + throws UnsupportedRdbmsOperatorException 30.938 + { 30.939 + appendGeneralDBSpatialFunctionUnary(expr, filter, SpatialFunctionsPostGIS.ST_IsSimple); 30.940 + } 30.941 + 30.942 + @Override 30.943 + protected void append(GeneralDBSqlGeoIsEmpty expr, GeneralDBSqlExprBuilder filter) 30.944 + throws UnsupportedRdbmsOperatorException 30.945 + { 30.946 + appendGeneralDBSpatialFunctionUnary(expr, filter, SpatialFunctionsPostGIS.ST_IsEmpty); 30.947 + } 30.948 + 30.949 + 30.950 + /** 30.951 + * 'helper' functions 30.952 + */ 30.953 + 30.954 + @Override 30.955 + protected String appendWKT(GeneralDBSqlExpr expr, GeneralDBSqlExprBuilder filter) 30.956 + { 30.957 + GeneralDBStringValue arg = (GeneralDBStringValue) expr; 30.958 + String raw = arg.getValue(); 30.959 + 30.960 + StrabonPolyhedron poly = null; 30.961 + try{ 30.962 + poly = new StrabonPolyhedron(raw); 30.963 + } catch (Exception e) { 30.964 + e.printStackTrace(); 30.965 + } 30.966 + 30.967 + filter.append(" ST_GeomFromText('"+poly.toWKT() +"',4326)"); 30.968 + 30.969 + return raw; 30.970 + } 30.971 + 30.972 + //Used in all the generaldb boolean spatial functions of the form ?GEO1 ~ ?GEO2 30.973 + // protected void appendStSPARQLSpatialOperand(BinaryGeneralDBOperator expr, GeneralDBSqlExprBuilder filter, SpatialOperandsPostGIS operand) throws UnsupportedRdbmsOperatorException 30.974 + // { 30.975 + // filter.openBracket(); 30.976 + // 30.977 + // boolean check1a = expr.getLeftArg().getClass().getCanonicalName().equals("org.openrdf.sail.generaldb.algebra.GeneralDBSqlNull"); 30.978 + // //boolean check2a = expr.getRightArg().getClass().getCanonicalName().equals("org.openrdf.sail.generaldb.algebra.GeneralDBSqlNull"); 30.979 + // 30.980 + // if(check1a) 30.981 + // { 30.982 + // this.append((GeneralDBSqlNull)expr.getLeftArg(), filter); 30.983 + // 30.984 + // } 30.985 + //// else if(check2a) 30.986 + //// { 30.987 + //// this.append((GeneralDBSqlNull)expr.getRightArg(), filter); 30.988 + //// } 30.989 + // else 30.990 + // { 30.991 + // if(expr.getLeftArg() instanceof GeneralDBSqlCase) 30.992 + // { 30.993 + // this.append((GeneralDBSqlCase)expr.getLeftArg(), filter); 30.994 + // } 30.995 + // else if(expr.getLeftArg() instanceof GeneralDBStringValue) 30.996 + // { 30.997 + // appendWKT(expr.getLeftArg(),filter); 30.998 + // } 30.999 + // else if(expr.getLeftArg() instanceof GeneralDBSqlSpatialConstructBinary) 30.1000 + // { 30.1001 + // appendConstructFunction(expr.getLeftArg(), filter); 30.1002 + // } 30.1003 + // else if(expr.getLeftArg() instanceof GeneralDBSqlSpatialConstructUnary) 30.1004 + // { 30.1005 + // appendConstructFunction(expr.getLeftArg(), filter); 30.1006 + // } 30.1007 + // else 30.1008 + // { 30.1009 + // appendMBB((GeneralDBLabelColumn)(expr.getLeftArg()),filter); 30.1010 + // } 30.1011 + // 30.1012 + // switch(operand) 30.1013 + // { 30.1014 + // case mbbIntersects: filter.mbbIntersects(); break; 30.1015 + // case equals: filter.equals(); break; 30.1016 + // case contains: filter.contains(); break; 30.1017 + // case inside: filter.inside(); break; 30.1018 + // case left: filter.left(); break; 30.1019 + // case right: filter.right(); break; 30.1020 + // case above: filter.above(); break; 30.1021 + // case below: filter.below(); break; 30.1022 + // } 30.1023 + // 30.1024 + // boolean check2a = expr.getRightArg().getClass().getCanonicalName().equals("org.openrdf.sail.generaldb.algebra.GeneralDBSqlNull"); 30.1025 + // 30.1026 + // if(check2a) 30.1027 + // { 30.1028 + // this.append((GeneralDBSqlNull)expr.getRightArg(), filter); 30.1029 + // } 30.1030 + // else 30.1031 + // { 30.1032 + // 30.1033 + // if(expr.getRightArg() instanceof GeneralDBSqlCase) 30.1034 + // { 30.1035 + // this.append((GeneralDBSqlCase)expr.getRightArg(), filter); 30.1036 + // } 30.1037 + // else if(expr.getRightArg() instanceof GeneralDBStringValue) 30.1038 + // { 30.1039 + // appendWKT(expr.getRightArg(),filter); 30.1040 + // } 30.1041 + // else if(expr.getRightArg() instanceof GeneralDBSqlSpatialConstructBinary) 30.1042 + // { 30.1043 + // appendConstructFunction(expr.getRightArg(), filter); 30.1044 + // } 30.1045 + // else if(expr.getRightArg() instanceof GeneralDBSqlSpatialConstructUnary) 30.1046 + // { 30.1047 + // appendConstructFunction(expr.getRightArg(), filter); 30.1048 + // } 30.1049 + // else 30.1050 + // { 30.1051 + // appendMBB((GeneralDBLabelColumn)(expr.getRightArg()),filter); 30.1052 + // } 30.1053 + // 30.1054 + // } 30.1055 + // } 30.1056 + // filter.closeBracket(); 30.1057 + // } 30.1058 + 30.1059 + 30.1060 + protected void appendStSPARQLSpatialOperand(BinaryGeneralDBOperator expr, GeneralDBSqlExprBuilder filter, SpatialOperandsPostGIS operand) throws UnsupportedRdbmsOperatorException 30.1061 + { 30.1062 + switch(operand) 30.1063 + { 30.1064 + case intersects: filter.intersectsMBB(); break; 30.1065 + case equals: filter.equalsMBB(); break; 30.1066 + case contains: filter.containsMBB(); break; 30.1067 + case inside: filter.insideMBB(); break; 30.1068 + case left: throw new UnsupportedRdbmsOperatorException("Operator << is not supported by Spatialite"); 30.1069 + case right: throw new UnsupportedRdbmsOperatorException("Operator >> is not supported by Spatialite"); 30.1070 + case above: throw new UnsupportedRdbmsOperatorException("Operator |>> is not supported by Spatialite"); 30.1071 + case below: throw new UnsupportedRdbmsOperatorException("Operator <<| is not supported by Spatialite"); 30.1072 + } 30.1073 + 30.1074 + filter.openBracket(); 30.1075 + 30.1076 + boolean check1a = expr.getLeftArg().getClass().getCanonicalName().equals("org.openrdf.sail.generaldb.algebra.GeneralDBSqlNull"); 30.1077 + boolean check2a = expr.getRightArg().getClass().getCanonicalName().equals("org.openrdf.sail.generaldb.algebra.GeneralDBSqlNull"); 30.1078 + 30.1079 + if(check1a) 30.1080 + { 30.1081 + this.append((GeneralDBSqlNull)expr.getLeftArg(), filter); 30.1082 + 30.1083 + } 30.1084 + else if(check2a) 30.1085 + { 30.1086 + this.append((GeneralDBSqlNull)expr.getRightArg(), filter); 30.1087 + } 30.1088 + else 30.1089 + { 30.1090 + if(expr.getLeftArg() instanceof GeneralDBSqlCase) 30.1091 + { 30.1092 + this.append((GeneralDBSqlCase)expr.getLeftArg(), filter); 30.1093 + } 30.1094 + else if(expr.getLeftArg() instanceof GeneralDBStringValue) 30.1095 + { 30.1096 + appendWKT(expr.getLeftArg(),filter); 30.1097 + } 30.1098 + else if(expr.getLeftArg() instanceof GeneralDBSqlSpatialConstructBinary) 30.1099 + { 30.1100 + appendConstructFunction(expr.getLeftArg(), filter); 30.1101 + } 30.1102 + else if(expr.getLeftArg() instanceof GeneralDBSqlSpatialConstructUnary) 30.1103 + { 30.1104 + appendConstructFunction(expr.getLeftArg(), filter); 30.1105 + } 30.1106 + else 30.1107 + { 30.1108 + appendMBB((GeneralDBLabelColumn)(expr.getLeftArg()),filter); 30.1109 + } 30.1110 + 30.1111 + filter.appendComma(); 30.1112 + 30.1113 + 30.1114 + // boolean check2a = expr.getRightArg().getClass().getCanonicalName().equals("org.openrdf.sail.generaldb.algebra.GeneralDBSqlNull"); 30.1115 + // 30.1116 + // if(check2a) 30.1117 + // { 30.1118 + // this.append((GeneralDBSqlNull)expr.getRightArg(), filter); 30.1119 + // } 30.1120 + // else 30.1121 + // { 30.1122 + 30.1123 + if(expr.getRightArg() instanceof GeneralDBSqlCase) 30.1124 + { 30.1125 + this.append((GeneralDBSqlCase)expr.getRightArg(), filter); 30.1126 + } 30.1127 + else if(expr.getRightArg() instanceof GeneralDBStringValue) 30.1128 + { 30.1129 + appendWKT(expr.getRightArg(),filter); 30.1130 + } 30.1131 + else if(expr.getRightArg() instanceof GeneralDBSqlSpatialConstructBinary) 30.1132 + { 30.1133 + appendConstructFunction(expr.getRightArg(), filter); 30.1134 + } 30.1135 + else if(expr.getRightArg() instanceof GeneralDBSqlSpatialConstructUnary) 30.1136 + { 30.1137 + appendConstructFunction(expr.getRightArg(), filter); 30.1138 + } 30.1139 + else 30.1140 + { 30.1141 + appendMBB((GeneralDBLabelColumn)(expr.getRightArg()),filter); 30.1142 + } 30.1143 + 30.1144 + //} 30.1145 + } 30.1146 + filter.closeBracket(); 30.1147 + } 30.1148 + 30.1149 + //Used in all the generaldb stsparql boolean spatial functions of the form ST_Function(?GEO1,?GEO2) 30.1150 + protected void appendTransformFunc(GeneralDBSqlGeoTransform expr, GeneralDBSqlExprBuilder filter) 30.1151 + throws UnsupportedRdbmsOperatorException 30.1152 + { 30.1153 + //In the case where no variable is present in the expression! e.g ConvexHull("POLYGON((.....))") 30.1154 + boolean sridNeeded = true; 30.1155 + //XXX Incorporating SRID 30.1156 + String sridExpr = null; 30.1157 + 30.1158 + filter.openBracket(); 30.1159 + filter.appendFunction(ST_TRANSFORM); 30.1160 + filter.openBracket(); 30.1161 + 30.1162 + boolean check1 = expr.getLeftArg().getClass().getCanonicalName().equals("org.openrdf.sail.generaldb.algebra.GeneralDBSqlNull"); 30.1163 + boolean check2 = expr.getRightArg().getClass().getCanonicalName().equals("org.openrdf.sail.generaldb.algebra.GeneralDBSqlNull"); 30.1164 + 30.1165 + if(check1) 30.1166 + { 30.1167 + this.append((GeneralDBSqlNull)expr.getLeftArg(), filter); 30.1168 + 30.1169 + } 30.1170 + else if(check2) 30.1171 + { 30.1172 + this.append((GeneralDBSqlNull)expr.getRightArg(), filter); 30.1173 + } 30.1174 + else 30.1175 + { 30.1176 + GeneralDBSqlExpr tmp = expr; 30.1177 + if(tmp instanceof GeneralDBSqlSpatialConstructBinary && tmp.getParentNode() == null) 30.1178 + { 30.1179 + while(true) 30.1180 + { 30.1181 + GeneralDBSqlExpr child; 30.1182 + 30.1183 + if(tmp instanceof BinaryGeneralDBOperator) 30.1184 + { 30.1185 + child = ((BinaryGeneralDBOperator) tmp).getLeftArg(); 30.1186 + } 30.1187 + else //(tmp instanceof UnaryGeneralDBOperator) 30.1188 + { 30.1189 + child = ((UnaryGeneralDBOperator) tmp).getArg(); 30.1190 + } 30.1191 + 30.1192 + tmp = child; 30.1193 + if(tmp instanceof GeneralDBLabelColumn) 30.1194 + { 30.1195 + String alias; 30.1196 + if (((GeneralDBLabelColumn) tmp).getRdbmsVar().isResource()) { 30.1197 + //Predicates used in triple patterns non-existent in db 30.1198 + alias="NULL"; 30.1199 + } 30.1200 + else 30.1201 + { 30.1202 + //Reached the innermost left var -> need to capture its SRID 30.1203 + alias = getLabelAlias(((GeneralDBLabelColumn) tmp).getRdbmsVar()); 30.1204 + alias=alias+".srid"; 30.1205 + } 30.1206 + sridExpr = alias; 30.1207 + break; 30.1208 + } 30.1209 + else if (tmp instanceof GeneralDBStringValue) //Constant!! 30.1210 + { 30.1211 + sridNeeded = false; 30.1212 + break; 30.1213 + } 30.1214 + 30.1215 + } 30.1216 + if(sridNeeded) 30.1217 + { 30.1218 + filter.appendFunction(ST_TRANSFORM); 30.1219 + filter.openBracket(); 30.1220 + } 30.1221 + } 30.1222 + 30.1223 + if(expr.getLeftArg() instanceof GeneralDBStringValue) 30.1224 + { 30.1225 + appendWKT(expr.getLeftArg(),filter); 30.1226 + } 30.1227 + else if(expr.getLeftArg() instanceof GeneralDBSqlSpatialConstructBinary) 30.1228 + { 30.1229 + appendConstructFunction(expr.getLeftArg(), filter); 30.1230 + } 30.1231 + else if(expr.getLeftArg() instanceof GeneralDBSqlSpatialConstructUnary) 30.1232 + { 30.1233 + appendConstructFunction(expr.getLeftArg(), filter); 30.1234 + } 30.1235 + else if(expr.getLeftArg() instanceof GeneralDBSqlCase) 30.1236 + { 30.1237 + GeneralDBLabelColumn onlyLabel = (GeneralDBLabelColumn)((GeneralDBSqlCase)expr.getLeftArg()).getEntries().get(0).getResult(); 30.1238 + appendMBB(onlyLabel,filter); 30.1239 + } 30.1240 + else 30.1241 + { 30.1242 + appendMBB((GeneralDBLabelColumn)(expr.getLeftArg()),filter); 30.1243 + } 30.1244 + 30.1245 + //SRID Support 30.1246 + if(expr instanceof GeneralDBSqlSpatialConstructBinary && expr.getParentNode() == null) 30.1247 + { 30.1248 + filter.appendComma(); 30.1249 + //filter.append(((GeneralDBSqlSpatialConstructBinary)expr).getSrid()); 30.1250 + filter.append(sridExpr); 30.1251 + filter.closeBracket(); 30.1252 + } 30.1253 + 30.1254 + filter.appendComma(); 30.1255 + 30.1256 + if(expr.getRightArg() instanceof GeneralDBSqlCase) //case met in transform! 30.1257 + { 30.1258 + GeneralDBURIColumn plainURI = (GeneralDBURIColumn)((GeneralDBSqlCase)expr.getRightArg()).getEntries().get(0).getResult(); 30.1259 + 30.1260 + //XXX This case would be met if we recovered the SRID URI from the db!!! 30.1261 + //Need to set sridExpr to the value of this new URI, otherwise the appended uri 30.1262 + //to the spatial object will be the wrong one!!!! (Seee following case) 30.1263 + filter.keepSRID_part1(); 30.1264 + append(plainURI, filter); 30.1265 + filter.keepSRID_part2(); 30.1266 + append(plainURI, filter); 30.1267 + filter.keepSRID_part3(); 30.1268 + } 30.1269 + else if(expr.getRightArg() instanceof GeneralDBStringValue) 30.1270 + { 30.1271 + String unparsedSRID = ((GeneralDBStringValue)expr.getRightArg()).getValue(); 30.1272 + // int srid = Integer.parseInt(unparsedSRID.substring(unparsedSRID.lastIndexOf('/')+1)); 30.1273 + sridExpr = unparsedSRID.substring(unparsedSRID.lastIndexOf('/')+1); 30.1274 + filter.append(sridExpr); 30.1275 + filter.closeBracket(); 30.1276 + } 30.1277 + 30.1278 + 30.1279 + } 30.1280 + filter.closeBracket(); 30.1281 + //In this case, SRID is the one that has been provided by the user!! 30.1282 + //I am including this extra binding to be used in subsequent (Aggregate) steps 30.1283 + if(expr instanceof GeneralDBSqlSpatialConstructBinary && expr.getParentNode() == null) 30.1284 + { 30.1285 + filter.appendComma(); 30.1286 + filter.append(sridExpr); 30.1287 + } 30.1288 + 30.1289 + } 30.1290 + 30.1291 + /** Addition for datetime metric functions 30.1292 + * 30.1293 + * @author George Garbis <ggarbis@di.uoa.gr> 30.1294 + * 30.1295 + */ 30.1296 + protected void appendGeneralDBDateTimeFunctionBinary(BinaryGeneralDBOperator expr, GeneralDBSqlExprBuilder filter, DateTimeFunctionPostGIS func) 30.1297 + throws UnsupportedRdbmsOperatorException 30.1298 + { 30.1299 + filter.openBracket(); 30.1300 + 30.1301 + boolean check1 = expr.getLeftArg().getClass().getCanonicalName().equals("org.openrdf.sail.generaldb.algebra.GeneralDBSqlNull"); 30.1302 + boolean check2 = expr.getRightArg().getClass().getCanonicalName().equals("org.openrdf.sail.generaldb.algebra.GeneralDBSqlNull"); 30.1303 + 30.1304 + if(check1) 30.1305 + { 30.1306 + this.append((GeneralDBSqlNull)expr.getLeftArg(), filter); 30.1307 + 30.1308 + } 30.1309 + else if(check2) 30.1310 + { 30.1311 + this.append((GeneralDBSqlNull)expr.getRightArg(), filter); 30.1312 + } 30.1313 + else 30.1314 + { 30.1315 + 30.1316 + GeneralDBSqlExpr tmp = expr; 30.1317 + if(tmp instanceof GeneralDBSqlSpatialConstructBinary && tmp.getParentNode() == null) 30.1318 + { 30.1319 + while(true) 30.1320 + { 30.1321 + GeneralDBSqlExpr child; 30.1322 + 30.1323 + if(tmp instanceof BinaryGeneralDBOperator) 30.1324 + { 30.1325 + child = ((BinaryGeneralDBOperator) tmp).getLeftArg(); 30.1326 + } 30.1327 + else //(tmp instanceof UnaryGeneralDBOperator) 30.1328 + { 30.1329 + child = ((UnaryGeneralDBOperator) tmp).getArg(); 30.1330 + } 30.1331 + 30.1332 + tmp = child; 30.1333 + if(tmp instanceof GeneralDBLabelColumn) 30.1334 + { 30.1335 + //Reached the innermost left var -> need to capture its SRID 30.1336 + String alias; 30.1337 + if (((GeneralDBLabelColumn) tmp).getRdbmsVar().isResource()) { 30.1338 + //Predicates used in triple patterns non-existent in db 30.1339 + alias="NULL"; 30.1340 + } 30.1341 + else 30.1342 + { 30.1343 + //Reached the innermost left var -> need to capture its SRID 30.1344 + alias = getLabelAlias(((GeneralDBLabelColumn) tmp).getRdbmsVar()); 30.1345 + } 30.1346 + break; 30.1347 + } 30.1348 + } 30.1349 + } 30.1350 + 30.1351 + filter.openBracket(); 30.1352 + 30.1353 + if(expr.getLeftArg() instanceof GeneralDBStringValue) 30.1354 + { 30.1355 + GeneralDBStringValue arg = (GeneralDBStringValue) expr.getLeftArg(); 30.1356 + String raw = arg.getValue(); 30.1357 + filter.append(" "+raw+" "); 30.1358 + } 30.1359 + else if(expr.getLeftArg() instanceof GeneralDBNumberValue) 30.1360 + { 30.1361 + append(((GeneralDBNumberValue)expr.getLeftArg()), filter); 30.1362 + } 30.1363 + else if(expr.getLeftArg() instanceof GeneralDBDateTimeColumn) 30.1364 + { 30.1365 + append(((GeneralDBDateTimeColumn)expr.getLeftArg()),filter); 30.1366 + } 30.1367 + else 30.1368 + { 30.1369 + // Den prepei na ftasei edw 30.1370 + } 30.1371 + 30.1372 + switch(func) 30.1373 + { 30.1374 + case Difference: filter.append(" - "); break; 30.1375 + } 30.1376 + 30.1377 + if(expr.getRightArg() instanceof GeneralDBStringValue) 30.1378 + { 30.1379 + GeneralDBStringValue arg = (GeneralDBStringValue) expr.getRightArg(); 30.1380 + String raw = arg.getValue(); 30.1381 + filter.append(" "+raw+" "); 30.1382 + } 30.1383 + else if(expr.getRightArg() instanceof GeneralDBNumberValue) 30.1384 + { 30.1385 + append(((GeneralDBNumberValue)expr.getRightArg()), filter); 30.1386 + } 30.1387 + else if(expr.getRightArg() instanceof GeneralDBDateTimeColumn) 30.1388 + { 30.1389 + append(((GeneralDBDateTimeColumn)expr.getRightArg()),filter); 30.1390 + } 30.1391 + else 30.1392 + { 30.1393 + // Den prepei na ftasei edw 30.1394 + } 30.1395 + 30.1396 + 30.1397 + filter.closeBracket(); 30.1398 + } 30.1399 + filter.closeBracket(); 30.1400 + } 30.1401 + /***/ 30.1402 + 30.1403 + //Used in all the generaldb stsparql (and geosparql) boolean spatial functions of the form ST_Function(?GEO1,?GEO2) 30.1404 + //EXCEPT ST_Transform!!! 30.1405 + protected void appendGeneralDBSpatialFunctionBinary(BinaryGeneralDBOperator expr, GeneralDBSqlExprBuilder filter, SpatialFunctionsPostGIS func) 30.1406 + throws UnsupportedRdbmsOperatorException 30.1407 + { 30.1408 + //In the case where no variable is present in the expression! e.g ConvexHull("POLYGON((.....))") 30.1409 + boolean sridNeeded = true; 30.1410 + //XXX Incorporating SRID 30.1411 + String sridExpr = null; 30.1412 + 30.1413 + filter.openBracket(); 30.1414 + 30.1415 + boolean check1 = expr.getLeftArg().getClass().getCanonicalName().equals("org.openrdf.sail.generaldb.algebra.GeneralDBSqlNull"); 30.1416 + boolean check2 = expr.getRightArg().getClass().getCanonicalName().equals("org.openrdf.sail.generaldb.algebra.GeneralDBSqlNull"); 30.1417 + 30.1418 + if(check1) 30.1419 + { 30.1420 + this.append((GeneralDBSqlNull)expr.getLeftArg(), filter); 30.1421 + 30.1422 + } 30.1423 + else if(check2) 30.1424 + { 30.1425 + this.append((GeneralDBSqlNull)expr.getRightArg(), filter); 30.1426 + } 30.1427 + else 30.1428 + { 30.1429 + 30.1430 + GeneralDBSqlExpr tmp = expr; 30.1431 + if(tmp instanceof GeneralDBSqlSpatialConstructBinary && tmp.getParentNode() == null) 30.1432 + { 30.1433 + while(true) 30.1434 + { 30.1435 + GeneralDBSqlExpr child; 30.1436 + 30.1437 + if(tmp instanceof BinaryGeneralDBOperator) 30.1438 + { 30.1439 + child = ((BinaryGeneralDBOperator) tmp).getLeftArg(); 30.1440 + } 30.1441 + else //(tmp instanceof UnaryGeneralDBOperator) 30.1442 + { 30.1443 + child = ((UnaryGeneralDBOperator) tmp).getArg(); 30.1444 + } 30.1445 + 30.1446 + tmp = child; 30.1447 + if(tmp instanceof GeneralDBLabelColumn) 30.1448 + { 30.1449 + //Reached the innermost left var -> need to capture its SRID 30.1450 + String alias; 30.1451 + if (((GeneralDBLabelColumn) tmp).getRdbmsVar().isResource()) { 30.1452 + //Predicates used in triple patterns non-existent in db 30.1453 + alias="NULL"; 30.1454 + } 30.1455 + else 30.1456 + { 30.1457 + //Reached the innermost left var -> need to capture its SRID 30.1458 + alias = getLabelAlias(((GeneralDBLabelColumn) tmp).getRdbmsVar()); 30.1459 + alias=alias+".srid"; 30.1460 + } 30.1461 + sridExpr = alias; 30.1462 + break; 30.1463 + } 30.1464 + else if (tmp instanceof GeneralDBStringValue) //Constant!! 30.1465 + { 30.1466 + sridNeeded = false; 30.1467 + break; 30.1468 + } 30.1469 + 30.1470 + } 30.1471 + if(sridNeeded) 30.1472 + { 30.1473 + filter.appendFunction(ST_TRANSFORM); 30.1474 + filter.openBracket(); 30.1475 + } 30.1476 + } 30.1477 + ///// 30.1478 + 30.1479 + 30.1480 + 30.1481 + switch(func) 30.1482 + { 30.1483 + //XXX Careful: ST_Transform support MISSING!!! 30.1484 + case ST_Difference: filter.appendFunction("ST_Difference"); break; 30.1485 + case ST_Intersection: filter.appendFunction("ST_Intersection"); break; 30.1486 + case ST_Union: filter.appendFunction("ST_Union"); break; 30.1487 + case ST_SymDifference: filter.appendFunction("ST_SymDifference"); break; 30.1488 + case ST_Buffer: filter.appendFunction("ST_Buffer"); break; 30.1489 + case ST_Distance: filter.appendFunction("ST_Distance"); break; 30.1490 + 30.1491 + case ST_Equals: filter.appendFunction("ST_Equals"); break; 30.1492 + case ST_Disjoint: filter.appendFunction("ST_Disjoint"); break; 30.1493 + case ST_Intersects: filter.appendFunction("ST_Intersects"); break; 30.1494 + case ST_Touches: filter.appendFunction("ST_Touches"); break; 30.1495 + case ST_Crosses: filter.appendFunction("ST_Crosses"); break; 30.1496 + case ST_Within: filter.appendFunction("ST_Within"); break; 30.1497 + case ST_Contains: filter.appendFunction("ST_Contains"); break; 30.1498 + case ST_Overlaps: filter.appendFunction("ST_Overlaps"); break; 30.1499 + 30.1500 + } 30.1501 + 30.1502 + filter.openBracket(); 30.1503 + if(expr.getLeftArg() instanceof GeneralDBStringValue) 30.1504 + { 30.1505 + appendWKT(expr.getLeftArg(),filter); 30.1506 + } 30.1507 + else if(expr.getLeftArg() instanceof GeneralDBSqlSpatialConstructBinary) 30.1508 + { 30.1509 + appendConstructFunction(expr.getLeftArg(), filter); 30.1510 + } 30.1511 + else if(expr.getLeftArg() instanceof GeneralDBSqlSpatialConstructUnary) 30.1512 + { 30.1513 + appendConstructFunction(expr.getLeftArg(), filter); 30.1514 + } 30.1515 + else if(expr.getLeftArg() instanceof GeneralDBSqlCase) 30.1516 + { 30.1517 + GeneralDBLabelColumn onlyLabel = (GeneralDBLabelColumn)((GeneralDBSqlCase)expr.getLeftArg()).getEntries().get(0).getResult(); 30.1518 + appendMBB(onlyLabel,filter); 30.1519 + } 30.1520 + else 30.1521 + { 30.1522 + appendMBB((GeneralDBLabelColumn)(expr.getLeftArg()),filter); 30.1523 + } 30.1524 + filter.appendComma(); 30.1525 + 30.1526 + 30.1527 + if(expr.getRightArg() instanceof GeneralDBStringValue) 30.1528 + { 30.1529 + appendWKT(expr.getRightArg(),filter); 30.1530 + } 30.1531 + else if(expr.getRightArg() instanceof GeneralDBSqlSpatialConstructUnary) 30.1532 + { 30.1533 + appendConstructFunction(expr.getRightArg(), filter); 30.1534 + } 30.1535 + else if(expr.getRightArg() instanceof GeneralDBSqlSpatialConstructBinary) 30.1536 + { 30.1537 + appendConstructFunction(expr.getRightArg(), filter); 30.1538 + } 30.1539 + else if(expr.getRightArg() instanceof GeneralDBSqlCase) 30.1540 + { 30.1541 + GeneralDBLabelColumn onlyLabel = (GeneralDBLabelColumn)((GeneralDBSqlCase)expr.getRightArg()).getEntries().get(0).getResult(); 30.1542 + appendMBB(onlyLabel,filter); 30.1543 + } 30.1544 + else if(expr.getRightArg() instanceof GeneralDBDoubleValue) //case met in buffer! 30.1545 + { 30.1546 + append(((GeneralDBDoubleValue)expr.getRightArg()), filter); 30.1547 + } 30.1548 + else if(expr.getRightArg() instanceof GeneralDBNumericColumn) //case met in buffer! 30.1549 + { 30.1550 + append(((GeneralDBNumericColumn)expr.getRightArg()), filter); 30.1551 + } 30.1552 + else if(expr.getRightArg() instanceof GeneralDBURIColumn) //case met in transform! 30.1553 + { 30.1554 + filter.keepSRID_part1(); 30.1555 + append(((GeneralDBURIColumn)expr.getRightArg()), filter); 30.1556 + filter.keepSRID_part2(); 30.1557 + append(((GeneralDBURIColumn)expr.getRightArg()), filter); 30.1558 + filter.keepSRID_part3(); 30.1559 + } 30.1560 + //case met in buffer when in select -> buffer(?spatial,?thematic) 30.1561 + else if(expr.getRightArg() instanceof GeneralDBLabelColumn && !((GeneralDBLabelColumn)expr.getRightArg()).isSpatial()) 30.1562 + { 30.1563 + appendCastToDoubleBefore(filter); 30.1564 + append(((GeneralDBLabelColumn)expr.getRightArg()),filter); 30.1565 + appendCastToDoubleAfter(filter); 30.1566 + } 30.1567 + else if(expr.getRightArg() instanceof GeneralDBSqlSpatialMetricBinary) 30.1568 + { 30.1569 + appendMetricFunction(expr.getRightArg(), filter); 30.1570 + } 30.1571 + else if(expr.getRightArg() instanceof GeneralDBSqlSpatialMetricUnary) 30.1572 + { 30.1573 + appendMetricFunction(expr.getRightArg(), filter); 30.1574 + } 30.1575 + else 30.1576 + { 30.1577 + appendMBB((GeneralDBLabelColumn)(expr.getRightArg()),filter); 30.1578 + } 30.1579 + 30.1580 + 30.1581 + filter.closeBracket(); 30.1582 + //SRID Support 30.1583 + if(expr instanceof GeneralDBSqlSpatialConstructBinary && expr.getParentNode() == null) 30.1584 + { 30.1585 + filter.appendComma(); 30.1586 + //filter.append(((GeneralDBSqlSpatialConstructBinary)expr).getSrid()); 30.1587 + filter.append(sridExpr); 30.1588 + filter.closeBracket(); 30.1589 + } 30.1590 + /// 30.1591 + } 30.1592 + filter.closeBracket(); 30.1593 + //Used to explicitly include SRID 30.1594 + if(expr instanceof GeneralDBSqlSpatialConstructBinary && expr.getParentNode() == null) 30.1595 + { 30.1596 + filter.appendComma(); 30.1597 + filter.append(sridExpr); 30.1598 + } 30.1599 + 30.1600 + } 30.1601 + 30.1602 + //Used in all the generaldb boolean spatial functions of the form ST_Function(?GEO1) 30.1603 + protected void appendGeneralDBSpatialFunctionUnary(UnaryGeneralDBOperator expr, GeneralDBSqlExprBuilder filter, SpatialFunctionsPostGIS func) 30.1604 + throws UnsupportedRdbmsOperatorException 30.1605 + { 30.1606 + //In the case where no variable is present in the expression! e.g ConvexHull("POLYGON((.....))") 30.1607 + boolean sridNeeded = true; 30.1608 + String sridExpr = null; 30.1609 + 30.1610 + filter.openBracket(); 30.1611 + 30.1612 + boolean check1 = expr.getArg().getClass().getCanonicalName().equals("org.openrdf.sail.generaldb.algebra.GeneralDBSqlNull"); 30.1613 + boolean check2 = false; 30.1614 + if(expr.getArg() instanceof GeneralDBLabelColumn) 30.1615 + { 30.1616 + if(((GeneralDBLabelColumn) expr.getArg()).getRdbmsVar().isResource()) 30.1617 + { 30.1618 + check2 = true; 30.1619 + } 30.1620 + } 30.1621 + if(check1) 30.1622 + { 30.1623 + this.append((GeneralDBSqlNull)expr.getArg(), filter); 30.1624 + 30.1625 + } 30.1626 + else if (check2) 30.1627 + { 30.1628 + appendMBB((GeneralDBLabelColumn)(expr.getArg()),filter); 30.1629 + } 30.1630 + else 30.1631 + { 30.1632 + 30.1633 + GeneralDBSqlExpr tmp = expr; 30.1634 + 30.1635 + 30.1636 + if(tmp instanceof GeneralDBSqlSpatialConstructUnary && tmp.getParentNode() == null) 30.1637 + { 30.1638 + while(true) 30.1639 + { 30.1640 + GeneralDBSqlExpr child = null; 30.1641 + 30.1642 + if(tmp instanceof BinaryGeneralDBOperator) 30.1643 + { 30.1644 + child = ((BinaryGeneralDBOperator) tmp).getLeftArg(); 30.1645 + } 30.1646 + else if(tmp instanceof UnaryGeneralDBOperator) 30.1647 + { 30.1648 + child = ((UnaryGeneralDBOperator) tmp).getArg(); 30.1649 + } 30.1650 + else if(tmp instanceof GeneralDBStringValue) 30.1651 + { 30.1652 + sridNeeded = false; 30.1653 + break; 30.1654 + } 30.1655 + 30.1656 + tmp = child; 30.1657 + if(tmp instanceof GeneralDBLabelColumn) 30.1658 + { 30.1659 + //Reached the innermost left var -> need to capture its SRID 30.1660 + String alias; 30.1661 + if (((GeneralDBLabelColumn) tmp).getRdbmsVar().isResource()) { 30.1662 + //Predicates used in triple patterns non-existent in db 30.1663 + alias="NULL"; 30.1664 + } 30.1665 + else 30.1666 + { 30.1667 + //Reached the innermost left var -> need to capture its SRID 30.1668 + alias = getLabelAlias(((GeneralDBLabelColumn) tmp).getRdbmsVar()); 30.1669 + alias=alias+".srid"; 30.1670 + } 30.1671 + sridExpr = alias; 30.1672 + break; 30.1673 + } 30.1674 + else if (tmp instanceof GeneralDBStringValue) //Constant!! 30.1675 + { 30.1676 + sridNeeded = false; 30.1677 + break; 30.1678 + } 30.1679 + 30.1680 + } 30.1681 + if(sridNeeded) 30.1682 + { 30.1683 + filter.appendFunction(ST_TRANSFORM); 30.1684 + filter.openBracket(); 30.1685 + } 30.1686 + } 30.1687 + ///// 30.1688 + 30.1689 + switch(func) 30.1690 + { 30.1691 + case ST_Envelope: filter.appendFunction("ST_Envelope"); break; 30.1692 + case ST_ConvexHull: filter.appendFunction("ST_ConvexHull"); break; 30.1693 + case ST_Boundary: filter.appendFunction("ST_Boundary"); break; 30.1694 + case ST_Area: filter.appendFunction("ST_Area"); break; 30.1695 + case ST_Dimension: filter.appendFunction("ST_Dimension"); break; 30.1696 + case ST_GeometryType: filter.appendFunction("ST_GeometryType"); break; 30.1697 + case ST_AsText: filter.appendFunction("ST_AsText"); break; 30.1698 + case ST_AsGML: filter.appendFunction("ST_AsGML"); break; 30.1699 + case ST_SRID: filter.appendFunction("ST_SRID"); break; 30.1700 + case ST_IsEmpty: filter.appendFunction("ST_IsEmpty"); break; 30.1701 + case ST_IsSimple: filter.appendFunction("ST_IsSimple"); break; 30.1702 + } 30.1703 + filter.openBracket(); 30.1704 + if(expr.getArg() instanceof GeneralDBStringValue) 30.1705 + { 30.1706 + appendWKT(expr.getArg(),filter); 30.1707 + } 30.1708 + else if(expr.getArg() instanceof GeneralDBSqlSpatialConstructBinary) 30.1709 + { 30.1710 + appendConstructFunction(expr.getArg(), filter); 30.1711 + } 30.1712 + else if(expr.getArg() instanceof GeneralDBSqlSpatialConstructUnary) 30.1713 + { 30.1714 + appendConstructFunction(expr.getArg(), filter); 30.1715 + } 30.1716 + else if(expr.getArg() instanceof GeneralDBSqlCase) 30.1717 + { 30.1718 + GeneralDBLabelColumn onlyLabel = (GeneralDBLabelColumn)((GeneralDBSqlCase)expr.getArg()).getEntries().get(0).getResult(); 30.1719 + appendMBB(onlyLabel,filter); 30.1720 + } 30.1721 + else 30.1722 + { 30.1723 + appendMBB((GeneralDBLabelColumn)(expr.getArg()),filter); 30.1724 + } 30.1725 + 30.1726 + filter.closeBracket(); 30.1727 + // //SRID Support 30.1728 + if(sridNeeded) 30.1729 + { 30.1730 + if(expr instanceof GeneralDBSqlSpatialConstructUnary && expr.getParentNode() == null) 30.1731 + { 30.1732 + filter.appendComma(); 30.1733 + // filter.append(((GeneralDBSqlSpatialConstructUnary)expr).getSrid()); 30.1734 + filter.append(sridExpr); 30.1735 + filter.closeBracket(); 30.1736 + } 30.1737 + } 30.1738 + /// 30.1739 + } 30.1740 + 30.1741 + filter.closeBracket(); 30.1742 + //Used to explicitly include SRID 30.1743 + if(expr instanceof GeneralDBSqlSpatialConstructUnary && expr.getParentNode() == null) 30.1744 + { 30.1745 + filter.appendComma(); 30.1746 + filter.append(sridExpr); 30.1747 + } 30.1748 + } 30.1749 + 30.1750 + //Used in all the generaldb boolean spatial functions of the form ST_Function(?GEO1,?GEO2) 30.1751 + protected void appendGeneralDBSpatialFunctionTriple(TripleGeneralDBOperator expr, GeneralDBSqlExprBuilder filter, SpatialFunctionsPostGIS func) 30.1752 + throws UnsupportedRdbmsOperatorException 30.1753 + { 30.1754 + filter.openBracket(); 30.1755 + 30.1756 + boolean check1a = expr.getLeftArg().getClass().getCanonicalName().equals("org.openrdf.sail.generaldb.algebra.GeneralDBSqlNull"); 30.1757 + boolean check2a = expr.getRightArg().getClass().getCanonicalName().equals("org.openrdf.sail.generaldb.algebra.GeneralDBSqlNull"); 30.1758 + boolean check3 = expr.getRightArg().getClass().getCanonicalName().equals("org.openrdf.sail.generaldb.algebra.GeneralDBSqlNull"); 30.1759 + 30.1760 + if(check1a) 30.1761 + { 30.1762 + this.append((GeneralDBSqlNull)expr.getLeftArg(), filter); 30.1763 + 30.1764 + } 30.1765 + else if(check2a) 30.1766 + { 30.1767 + this.append((GeneralDBSqlNull)expr.getRightArg(), filter); 30.1768 + } 30.1769 + else if(check3) 30.1770 + { 30.1771 + this.append((GeneralDBSqlNull)expr.getThirdArg(), filter); 30.1772 + } 30.1773 + else 30.1774 + { 30.1775 + switch(func) 30.1776 + { 30.1777 + case ST_Relate: filter.appendFunction("ST_Relate"); break; 30.1778 + } 30.1779 + filter.openBracket(); 30.1780 + if(expr.getLeftArg() instanceof GeneralDBStringValue) 30.1781 + { 30.1782 + appendWKT(expr.getLeftArg(),filter); 30.1783 + } 30.1784 + else if(expr.getLeftArg() instanceof GeneralDBSqlSpatialConstructBinary) 30.1785 + { 30.1786 + appendConstructFunction(expr.getLeftArg(), filter); 30.1787 + } 30.1788 + else if(expr.getLeftArg() instanceof GeneralDBSqlSpatialConstructUnary) 30.1789 + { 30.1790 + appendConstructFunction(expr.getLeftArg(), filter); 30.1791 + } 30.1792 + else if(expr.getLeftArg() instanceof GeneralDBSqlCase) 30.1793 + { 30.1794 + GeneralDBLabelColumn onlyLabel = (GeneralDBLabelColumn)((GeneralDBSqlCase)expr.getLeftArg()).getEntries().get(0).getResult(); 30.1795 + appendMBB(onlyLabel,filter); 30.1796 + } 30.1797 + else 30.1798 + { 30.1799 + appendMBB((GeneralDBLabelColumn)(expr.getLeftArg()),filter); 30.1800 + } 30.1801 + filter.appendComma(); 30.1802 + // boolean check2 = expr.getRightArg().getClass().getCanonicalName().equals("org.openrdf.sail.generaldb.algebra.GeneralDBSqlNull"); 30.1803 + // if(check2) 30.1804 + // { 30.1805 + // this.append((GeneralDBSqlNull)expr.getRightArg(), filter); 30.1806 + // } 30.1807 + // else 30.1808 + // { 30.1809 + if(expr.getRightArg() instanceof GeneralDBStringValue) 30.1810 + { 30.1811 + appendWKT(expr.getRightArg(),filter); 30.1812 + } 30.1813 + else if(expr.getRightArg() instanceof GeneralDBSqlSpatialConstructUnary) 30.1814 + { 30.1815 + appendConstructFunction(expr.getRightArg(), filter); 30.1816 + } 30.1817 + else if(expr.getRightArg() instanceof GeneralDBSqlSpatialConstructBinary) 30.1818 + { 30.1819 + appendConstructFunction(expr.getRightArg(), filter); 30.1820 + } 30.1821 + else if(expr.getRightArg() instanceof GeneralDBSqlCase) 30.1822 + { 30.1823 + GeneralDBLabelColumn onlyLabel = (GeneralDBLabelColumn)((GeneralDBSqlCase)expr.getRightArg()).getEntries().get(0).getResult(); 30.1824 + appendMBB(onlyLabel,filter); 30.1825 + } 30.1826 + else if(expr.getRightArg() instanceof GeneralDBDoubleValue) //case met in buffer! 30.1827 + { 30.1828 + append(((GeneralDBDoubleValue)expr.getRightArg()), filter); 30.1829 + } 30.1830 + else if(expr.getRightArg() instanceof GeneralDBNumericColumn) //case met in buffer! 30.1831 + { 30.1832 + append(((GeneralDBNumericColumn)expr.getRightArg()), filter); 30.1833 + } 30.1834 + //case met in buffer when in select -> buffer(?spatial,?thematic) 30.1835 + else if(expr.getRightArg() instanceof GeneralDBLabelColumn && !((GeneralDBLabelColumn)expr.getRightArg()).isSpatial()) 30.1836 + { 30.1837 + appendCastToDoubleBefore(filter); 30.1838 + append(((GeneralDBLabelColumn)expr.getRightArg()),filter); 30.1839 + appendCastToDoubleAfter(filter); 30.1840 + } 30.1841 + else if(expr.getRightArg() instanceof GeneralDBSqlSpatialMetricBinary) 30.1842 + { 30.1843 + appendMetricFunction(expr.getRightArg(), filter); 30.1844 + } 30.1845 + else if(expr.getRightArg() instanceof GeneralDBSqlSpatialMetricUnary) 30.1846 + { 30.1847 + appendMetricFunction(expr.getRightArg(), filter); 30.1848 + } 30.1849 + else 30.1850 + { 30.1851 + appendMBB((GeneralDBLabelColumn)(expr.getRightArg()),filter); 30.1852 + } 30.1853 + 30.1854 + // } 30.1855 + //3rd arg 30.1856 + filter.appendComma(); 30.1857 + // boolean check3 = expr.getRightArg().getClass().getCanonicalName().equals("org.openrdf.sail.generaldb.algebra.GeneralDBSqlNull"); 30.1858 + // if(check3) 30.1859 + // { 30.1860 + // this.append((GeneralDBSqlNull)expr.getThirdArg(), filter); 30.1861 + // } 30.1862 + // else 30.1863 + // { 30.1864 + 30.1865 + if(expr.getThirdArg() instanceof GeneralDBStringValue) 30.1866 + { 30.1867 + append(((GeneralDBStringValue)expr.getThirdArg()),filter); 30.1868 + } 30.1869 + else if(expr.getThirdArg() instanceof GeneralDBSqlCase) 30.1870 + { 30.1871 + append(((GeneralDBSqlCase)expr.getThirdArg()),filter); 30.1872 + } 30.1873 + //case met in buffer when in select -> buffer(?spatial,?thematic) 30.1874 + else if(expr.getThirdArg() instanceof GeneralDBLabelColumn )//&& !((GeneralDBLabelColumn)expr.getThirdArg()).isSpatial()) 30.1875 + { 30.1876 + 30.1877 + append(((GeneralDBLabelColumn)expr.getThirdArg()),filter); 30.1878 + } 30.1879 + 30.1880 + 30.1881 + // } 30.1882 + filter.closeBracket(); 30.1883 + } 30.1884 + 30.1885 + filter.closeBracket(); 30.1886 + } 30.1887 + 30.1888 + 30.1889 + 30.1890 + private void appendCastToDoubleAfter(GeneralDBSqlExprBuilder filter) { 30.1891 + filter.append(" AS DOUBLE PRECISION)"); 30.1892 + 30.1893 + } 30.1894 + 30.1895 + private void appendCastToDoubleBefore(GeneralDBSqlExprBuilder filter) { 30.1896 + filter.append("CAST("); 30.1897 + 30.1898 + } 30.1899 + 30.1900 + //GeoSPARQL 30.1901 + //XXX 30.1902 + protected void appendRelate(BinaryGeneralDBOperator expr, SqliteSqlExprBuilder filter, char[] intersectionPattern) 30.1903 + throws UnsupportedRdbmsOperatorException 30.1904 + { 30.1905 + filter.openBracket(); 30.1906 + 30.1907 + boolean check1 = expr.getLeftArg().getClass().getCanonicalName().equals("org.openrdf.sail.generaldb.algebra.GeneralDBSqlNull"); 30.1908 + boolean check2 = expr.getRightArg().getClass().getCanonicalName().equals("org.openrdf.sail.generaldb.algebra.GeneralDBSqlNull"); 30.1909 + 30.1910 + if(check1) 30.1911 + { 30.1912 + this.append((GeneralDBSqlNull)expr.getLeftArg(), filter); 30.1913 + 30.1914 + } 30.1915 + else if(check2) 30.1916 + { 30.1917 + this.append((GeneralDBSqlNull)expr.getRightArg(), filter); 30.1918 + } 30.1919 + else 30.1920 + { 30.1921 + filter.appendFunction("ST_Relate"); 30.1922 + 30.1923 + 30.1924 + filter.openBracket(); 30.1925 + if(expr.getLeftArg() instanceof GeneralDBStringValue) 30.1926 + { 30.1927 + appendWKT(expr.getLeftArg(),filter); 30.1928 + } 30.1929 + else if(expr.getLeftArg() instanceof GeneralDBSqlSpatialConstructBinary) 30.1930 + { 30.1931 + appendConstructFunction(expr.getLeftArg(), filter); 30.1932 + } 30.1933 + else if(expr.getLeftArg() instanceof GeneralDBSqlSpatialConstructUnary) 30.1934 + { 30.1935 + appendConstructFunction(expr.getLeftArg(), filter); 30.1936 + } 30.1937 + else if(expr.getLeftArg() instanceof GeneralDBSqlCase) 30.1938 + { 30.1939 + GeneralDBLabelColumn onlyLabel = (GeneralDBLabelColumn)((GeneralDBSqlCase)expr.getLeftArg()).getEntries().get(0).getResult(); 30.1940 + appendMBB(onlyLabel,filter); 30.1941 + } 30.1942 + else 30.1943 + { 30.1944 + appendMBB((GeneralDBLabelColumn)(expr.getLeftArg()),filter); 30.1945 + } 30.1946 + filter.appendComma(); 30.1947 + 30.1948 + if(expr.getRightArg() instanceof GeneralDBStringValue) 30.1949 + { 30.1950 + appendWKT(expr.getRightArg(),filter); 30.1951 + } 30.1952 + else if(expr.getRightArg() instanceof GeneralDBSqlSpatialConstructUnary) 30.1953 + { 30.1954 + appendConstructFunction(expr.getRightArg(), filter); 30.1955 + } 30.1956 + else if(expr.getRightArg() instanceof GeneralDBSqlSpatialConstructBinary) 30.1957 + { 30.1958 + appendConstructFunction(expr.getRightArg(), filter); 30.1959 + } 30.1960 + else if(expr.getRightArg() instanceof GeneralDBSqlCase) 30.1961 + { 30.1962 + GeneralDBLabelColumn onlyLabel = (GeneralDBLabelColumn)((GeneralDBSqlCase)expr.getRightArg()).getEntries().get(0).getResult(); 30.1963 + appendMBB(onlyLabel,filter); 30.1964 + } 30.1965 + else if(expr.getRightArg() instanceof GeneralDBDoubleValue) //case met in buffer! 30.1966 + { 30.1967 + append(((GeneralDBDoubleValue)expr.getRightArg()), filter); 30.1968 + } 30.1969 + else if(expr.getRightArg() instanceof GeneralDBNumericColumn) //case met in buffer! 30.1970 + { 30.1971 + append(((GeneralDBNumericColumn)expr.getRightArg()), filter); 30.1972 + } 30.1973 + //case met in buffer when in select -> buffer(?spatial,?thematic) 30.1974 + else if(expr.getRightArg() instanceof GeneralDBLabelColumn && !((GeneralDBLabelColumn)expr.getRightArg()).isSpatial()) 30.1975 + { 30.1976 + appendCastToDoubleBefore(filter); 30.1977 + append(((GeneralDBLabelColumn)expr.getRightArg()),filter); 30.1978 + appendCastToDoubleAfter(filter); 30.1979 + } 30.1980 + else if(expr.getRightArg() instanceof GeneralDBSqlSpatialMetricBinary) 30.1981 + { 30.1982 + appendMetricFunction(expr.getRightArg(), filter); 30.1983 + } 30.1984 + else if(expr.getRightArg() instanceof GeneralDBSqlSpatialMetricUnary) 30.1985 + { 30.1986 + appendMetricFunction(expr.getRightArg(), filter); 30.1987 + } 30.1988 + else 30.1989 + { 30.1990 + appendMBB((GeneralDBLabelColumn)(expr.getRightArg()),filter); 30.1991 + } 30.1992 + 30.1993 + //3rd arg 30.1994 + filter.appendComma(); 30.1995 + 30.1996 + //must turn the table of characters I have to a valid sql value! 30.1997 + filter.append("'"); 30.1998 + for(int i = 0; i< intersectionPattern.length; i++) 30.1999 + { 30.2000 + filter.append(intersectionPattern[i]+""); 30.2001 + } 30.2002 + filter.append("'"); 30.2003 + 30.2004 + filter.closeBracket(); 30.2005 + 30.2006 + } 30.2007 + 30.2008 + filter.closeBracket(); 30.2009 + } 30.2010 + 30.2011 + 30.2012 + protected void appendgeoSPARQLSpatialRelation(BinaryGeneralDBOperator expr, GeneralDBSqlExprBuilder filter, SpatialFunctionsPostGIS func) 30.2013 + throws UnsupportedRdbmsOperatorException 30.2014 + { 30.2015 + filter.openBracket(); 30.2016 + boolean check1 = expr.getLeftArg().getClass().getCanonicalName().equals("org.openrdf.sail.generaldb.algebra.GeneralDBSqlNull"); 30.2017 + if(check1) 30.2018 + { 30.2019 + this.append((GeneralDBSqlNull)expr.getLeftArg(), filter); 30.2020 + 30.2021 + } 30.2022 + else 30.2023 + { 30.2024 + char[][] intersectionPattern = null; 30.2025 + switch(func) 30.2026 + { 30.2027 + case SF_Contains: 30.2028 + intersectionPattern = new char[1][9]; 30.2029 + intersectionPattern[0][0] = 'T'; 30.2030 + intersectionPattern[0][1] = '*'; 30.2031 + intersectionPattern[0][2] = '*'; 30.2032 + intersectionPattern[0][3] = '*'; 30.2033 + intersectionPattern[0][4] = '*'; 30.2034 + intersectionPattern[0][5] = '*'; 30.2035 + intersectionPattern[0][6] = 'F'; 30.2036 + intersectionPattern[0][7] = 'F'; 30.2037 + intersectionPattern[0][8] = '*'; 30.2038 + break; 30.2039 + case SF_Crosses: 30.2040 + // FIXME BUG 30.2041 + // TODO a crosses b, they have some but not all interior points in common 30.2042 + // (and the dimension of the intersection is less than that of at least one 30.2043 + // of them). Mask selection rules are checked only when dim(a)≠dim(b), 30.2044 + // except by point/point inputs, otherwise is false. 30.2045 + // (II=0) for points, (II ∧ IE) when dim(a)<dim(b), (II ∧ EI) when dim(a)>dim(b) 30.2046 + intersectionPattern = new char[3][9]; 30.2047 + intersectionPattern[0][0] = 'T'; 30.2048 + intersectionPattern[0][1] = '*'; 30.2049 + intersectionPattern[0][2] = 'T'; 30.2050 + intersectionPattern[0][3] = '*'; 30.2051 + intersectionPattern[0][4] = '*'; 30.2052 + intersectionPattern[0][5] = '*'; 30.2053 + intersectionPattern[0][6] = '*'; 30.2054 + intersectionPattern[0][7] = '*'; 30.2055 + intersectionPattern[0][8] = '*'; 30.2056 + // 30.2057 + intersectionPattern[1][0] = 'T'; 30.2058 + intersectionPattern[1][1] = '*'; 30.2059 + intersectionPattern[1][2] = '*'; 30.2060 + intersectionPattern[1][3] = '*'; 30.2061 + intersectionPattern[1][4] = '*'; 30.2062 + intersectionPattern[1][5] = '*'; 30.2063 + intersectionPattern[1][6] = 'T'; 30.2064 + intersectionPattern[1][7] = '*'; 30.2065 + intersectionPattern[1][8] = '*'; 30.2066 + // 30.2067 + intersectionPattern[2][0] = '0'; 30.2068 + intersectionPattern[2][1] = '*'; 30.2069 + intersectionPattern[2][2] = '*'; 30.2070 + intersectionPattern[2][3] = '*'; 30.2071 + intersectionPattern[2][4] = '*'; 30.2072 + intersectionPattern[2][5] = '*'; 30.2073 + intersectionPattern[2][6] = '*'; 30.2074 + intersectionPattern[2][7] = '*'; 30.2075 + intersectionPattern[2][8] = '*'; 30.2076 + break; 30.2077 + case SF_Disjoint: 30.2078 + case EH_Disjoint: 30.2079 + intersectionPattern = new char[1][9]; 30.2080 + intersectionPattern[0][0] = 'F'; 30.2081 + intersectionPattern[0][1] = 'F'; 30.2082 + intersectionPattern[0][2] = '*'; 30.2083 + intersectionPattern[0][3] = 'F'; 30.2084 + intersectionPattern[0][4] = 'F'; 30.2085 + intersectionPattern[0][5] = '*'; 30.2086 + intersectionPattern[0][6] = '*'; 30.2087 + intersectionPattern[0][7] = '*'; 30.2088 + intersectionPattern[0][8] = '*'; 30.2089 + break; 30.2090 + case SF_Equals: 30.2091 + case EH_Equals: 30.2092 + case RCC8_Eq: 30.2093 + intersectionPattern = new char[1][9]; 30.2094 + intersectionPattern[0][0] = 'T'; 30.2095 + intersectionPattern[0][1] = 'F'; 30.2096 + intersectionPattern[0][2] = 'F'; 30.2097 + intersectionPattern[0][3] = 'F'; 30.2098 + intersectionPattern[0][4] = 'T'; 30.2099 + intersectionPattern[0][5] = 'F'; 30.2100 + intersectionPattern[0][6] = 'F'; 30.2101 + intersectionPattern[0][7] = 'F'; 30.2102 + intersectionPattern[0][8] = 'T'; 30.2103 + break; 30.2104 + case SF_Overlaps: 30.2105 + case EH_Overlap: 30.2106 + // FIXME BUG 30.2107 + // TODO a overlaps b, they have some but not all points in common, 30.2108 + // they have the same dimension, and the intersection of the 30.2109 + // interiors of the two geometries has the same dimension as the 30.2110 + // geometries themselves. Mask selection rules are checked 30.2111 + // only when dim(a)=dim(b), otherwise is false: 30.2112 + // (II ∧ IE ∧ EI) for points or surfaces, (II=1 ∧ IE ∧ EI) for lines 30.2113 + intersectionPattern = new char[2][9]; 30.2114 + intersectionPattern[0][0] = 'T'; 30.2115 + intersectionPattern[0][1] = '*'; 30.2116 + intersectionPattern[0][2] = 'T'; 30.2117 + intersectionPattern[0][3] = '*'; 30.2118 + intersectionPattern[0][4] = '*'; 30.2119 + intersectionPattern[0][5] = '*'; 30.2120 + intersectionPattern[0][6] = 'T'; 30.2121 + intersectionPattern[0][7] = '*'; 30.2122 + intersectionPattern[0][8] = '*'; 30.2123 + intersectionPattern[1][0] = '1'; 30.2124 + intersectionPattern[1][1] = '*'; 30.2125 + intersectionPattern[1][2] = 'T'; 30.2126 + intersectionPattern[1][3] = '*'; 30.2127 + intersectionPattern[1][4] = '*'; 30.2128 + intersectionPattern[1][5] = '*'; 30.2129 + intersectionPattern[1][6] = 'T'; 30.2130 + intersectionPattern[1][7] = '*'; 30.2131 + intersectionPattern[1][8] = '*'; 30.2132 + break; 30.2133 + case SF_Within: 30.2134 + intersectionPattern = new char[1][9]; 30.2135 + intersectionPattern[0][0] = 'T'; 30.2136 + intersectionPattern[0][1] = '*'; 30.2137 + intersectionPattern[0][2] = 'F'; 30.2138 + intersectionPattern[0][3] = '*'; 30.2139 + intersectionPattern[0][4] = '*'; 30.2140 + intersectionPattern[0][5] = 'F'; 30.2141 + intersectionPattern[0][6] = '*'; 30.2142 + intersectionPattern[0][7] = '*'; 30.2143 + intersectionPattern[0][8] = '*'; 30.2144 + break; 30.2145 + case EH_Covers: 30.2146 + intersectionPattern = new char[1][9]; 30.2147 + intersectionPattern[0][0] = 'T'; 30.2148 + intersectionPattern[0][1] = '*'; 30.2149 + intersectionPattern[0][2] = 'T'; 30.2150 + intersectionPattern[0][3] = 'F'; 30.2151 + intersectionPattern[0][4] = 'T'; 30.2152 + intersectionPattern[0][5] = '*'; 30.2153 + intersectionPattern[0][6] = 'F'; 30.2154 + intersectionPattern[0][7] = 'F'; 30.2155 + intersectionPattern[0][8] = '*'; 30.2156 + break; 30.2157 + case EH_CoveredBy: 30.2158 + intersectionPattern = new char[1][9]; 30.2159 + intersectionPattern[0][0] = 'T'; 30.2160 + intersectionPattern[0][1] = 'F'; 30.2161 + intersectionPattern[0][2] = 'F'; 30.2162 + intersectionPattern[0][3] = '*'; 30.2163 + intersectionPattern[0][4] = 'T'; 30.2164 + intersectionPattern[0][5] = 'F'; 30.2165 + intersectionPattern[0][6] = 'T'; 30.2166 + intersectionPattern[0][7] = '*'; 30.2167 + intersectionPattern[0][8] = '*'; 30.2168 + break; 30.2169 + case EH_Inside: 30.2170 + intersectionPattern = new char[1][9]; 30.2171 + intersectionPattern[0][0] = 'T'; 30.2172 + intersectionPattern[0][1] = 'F'; 30.2173 + intersectionPattern[0][2] = 'F'; 30.2174 + intersectionPattern[0][3] = '*'; 30.2175 + intersectionPattern[0][4] = 'F'; 30.2176 + intersectionPattern[0][5] = 'F'; 30.2177 + intersectionPattern[0][6] = 'T'; 30.2178 + intersectionPattern[0][7] = '*'; 30.2179 + intersectionPattern[0][8] = '*'; 30.2180 + break; 30.2181 + case EH_Contains: 30.2182 + intersectionPattern = new char[1][9]; 30.2183 + intersectionPattern[0][0] = 'T'; 30.2184 + intersectionPattern[0][1] = '*'; 30.2185 + intersectionPattern[0][2] = 'T'; 30.2186 + intersectionPattern[0][3] = 'F'; 30.2187 + intersectionPattern[0][4] = 'F'; 30.2188 + intersectionPattern[0][5] = '*'; 30.2189 + intersectionPattern[0][6] = 'F'; 30.2190 + intersectionPattern[0][7] = 'F'; 30.2191 + intersectionPattern[0][8] = '*'; 30.2192 + break; 30.2193 + case RCC8_Dc: 30.2194 + intersectionPattern = new char[1][9]; 30.2195 + intersectionPattern[0][0] = 'F'; 30.2196 + intersectionPattern[0][1] = 'F'; 30.2197 + intersectionPattern[0][2] = 'T'; 30.2198 + intersectionPattern[0][3] = 'F'; 30.2199 + intersectionPattern[0][4] = 'F'; 30.2200 + intersectionPattern[0][5] = 'T'; 30.2201 + intersectionPattern[0][6] = 'T'; 30.2202 + intersectionPattern[0][7] = 'T'; 30.2203 + intersectionPattern[0][8] = 'T'; 30.2204 + break; 30.2205 + case RCC8_Ec: 30.2206 + intersectionPattern = new char[1][9]; 30.2207 + intersectionPattern[0][0] = 'F'; 30.2208 + intersectionPattern[0][1] = 'F'; 30.2209 + intersectionPattern[0][2] = 'T'; 30.2210 + intersectionPattern[0][3] = 'F'; 30.2211 + intersectionPattern[0][4] = 'T'; 30.2212 + intersectionPattern[0][5] = 'T'; 30.2213 + intersectionPattern[0][6] = 'T'; 30.2214 + intersectionPattern[0][7] = 'T'; 30.2215 + intersectionPattern[0][8] = 'T'; 30.2216 + break; 30.2217 + case RCC8_Po: 30.2218 + intersectionPattern = new char[1][9]; 30.2219 + intersectionPattern[0][0] = 'T'; 30.2220 + intersectionPattern[0][1] = 'T'; 30.2221 + intersectionPattern[0][2] = 'T'; 30.2222 + intersectionPattern[0][3] = 'T'; 30.2223 + intersectionPattern[0][4] = 'T'; 30.2224 + intersectionPattern[0][5] = 'T'; 30.2225 + intersectionPattern[0][6] = 'T'; 30.2226 + intersectionPattern[0][7] = 'T'; 30.2227 + intersectionPattern[0][8] = 'T'; 30.2228 + break; 30.2229 + case RCC8_Tppi: 30.2230 + intersectionPattern = new char[1][9]; 30.2231 + intersectionPattern[0][0] = 'T'; 30.2232 + intersectionPattern[0][1] = 'T'; 30.2233 + intersectionPattern[0][2] = 'T'; 30.2234 + intersectionPattern[0][3] = 'F'; 30.2235 + intersectionPattern[0][4] = 'T'; 30.2236 + intersectionPattern[0][5] = 'T'; 30.2237 + intersectionPattern[0][6] = 'F'; 30.2238 + intersectionPattern[0][7] = 'F'; 30.2239 + intersectionPattern[0][8] = 'T'; 30.2240 + break; 30.2241 + case RCC8_Tpp: 30.2242 + intersectionPattern = new char[1][9]; 30.2243 + intersectionPattern[0][0] = 'T'; 30.2244 + intersectionPattern[0][1] = 'F'; 30.2245 + intersectionPattern[0][2] = 'F'; 30.2246 + intersectionPattern[0][3] = 'T'; 30.2247 + intersectionPattern[0][4] = 'T'; 30.2248 + intersectionPattern[0][5] = 'F'; 30.2249 + intersectionPattern[0][6] = 'T'; 30.2250 + intersectionPattern[0][7] = 'T'; 30.2251 + intersectionPattern[0][8] = 'T'; 30.2252 + break; 30.2253 + case RCC8_Ntpp: 30.2254 + intersectionPattern = new char[1][9]; 30.2255 + intersectionPattern[0][0] = 'T'; 30.2256 + intersectionPattern[0][1] = 'F'; 30.2257 + intersectionPattern[0][2] = 'F'; 30.2258 + intersectionPattern[0][3] = 'T'; 30.2259 + intersectionPattern[0][4] = 'F'; 30.2260 + intersectionPattern[0][5] = 'F'; 30.2261 + intersectionPattern[0][6] = 'T'; 30.2262 + intersectionPattern[0][7] = 'T'; 30.2263 + intersectionPattern[0][8] = 'T'; 30.2264 + break; 30.2265 + case RCC8_Ntppi: 30.2266 + intersectionPattern = new char[1][9]; 30.2267 + intersectionPattern[0][0] = 'T'; 30.2268 + intersectionPattern[0][1] = 'T'; 30.2269 + intersectionPattern[0][2] = 'T'; 30.2270 + intersectionPattern[0][3] = 'F'; 30.2271 + intersectionPattern[0][4] = 'F'; 30.2272 + intersectionPattern[0][5] = 'T'; 30.2273 + intersectionPattern[0][6] = 'F'; 30.2274 + intersectionPattern[0][7] = 'F'; 30.2275 + intersectionPattern[0][8] = 'T'; 30.2276 + break; 30.2277 + case SF_Intersects: 30.2278 + intersectionPattern = new char[4][9]; 30.2279 + intersectionPattern[0][0] = 'T'; 30.2280 + intersectionPattern[0][1] = '*'; 30.2281 + intersectionPattern[0][2] = '*'; 30.2282 + intersectionPattern[0][3] = '*'; 30.2283 + intersectionPattern[0][4] = '*'; 30.2284 + intersectionPattern[0][5] = '*'; 30.2285 + intersectionPattern[0][6] = '*'; 30.2286 + intersectionPattern[0][7] = '*'; 30.2287 + intersectionPattern[0][8] = '*'; 30.2288 + // 30.2289 + intersectionPattern[1][0] = '*'; 30.2290 + intersectionPattern[1][1] = 'T'; 30.2291 + intersectionPattern[1][2] = '*'; 30.2292 + intersectionPattern[1][3] = '*'; 30.2293 + intersectionPattern[1][4] = '*'; 30.2294 + intersectionPattern[1][5] = '*'; 30.2295 + intersectionPattern[1][6] = '*'; 30.2296 + intersectionPattern[1][7] = '*'; 30.2297 + intersectionPattern[1][8] = '*'; 30.2298 + // 30.2299 + intersectionPattern[2][0] = '*'; 30.2300 + intersectionPattern[2][1] = '*'; 30.2301 + intersectionPattern[2][2] = '*'; 30.2302 + intersectionPattern[2][3] = 'T'; 30.2303 + intersectionPattern[2][4] = '*'; 30.2304 + intersectionPattern[2][5] = '*'; 30.2305 + intersectionPattern[2][6] = '*'; 30.2306 + intersectionPattern[2][7] = '*'; 30.2307 + intersectionPattern[2][8] = '*'; 30.2308 + // 30.2309 + intersectionPattern[3][0] = '*'; 30.2310 + intersectionPattern[3][1] = '*'; 30.2311 + intersectionPattern[3][2] = '*'; 30.2312 + intersectionPattern[3][3] = '*'; 30.2313 + intersectionPattern[3][4] = 'T'; 30.2314 + intersectionPattern[3][5] = '*'; 30.2315 + intersectionPattern[3][6] = '*'; 30.2316 + intersectionPattern[3][7] = '*'; 30.2317 + intersectionPattern[3][8] = '*'; 30.2318 + break; 30.2319 + 30.2320 + case SF_Touches: 30.2321 + case EH_Meet: 30.2322 + intersectionPattern = new char[3][9]; 30.2323 + intersectionPattern[0][0] = 'F'; 30.2324 + intersectionPattern[0][1] = 'T'; 30.2325 + intersectionPattern[0][2] = '*'; 30.2326 + intersectionPattern[0][3] = '*'; 30.2327 + intersectionPattern[0][4] = '*'; 30.2328 + intersectionPattern[0][5] = '*'; 30.2329 + intersectionPattern[0][6] = '*'; 30.2330 + intersectionPattern[0][7] = '*'; 30.2331 + intersectionPattern[0][8] = '*'; 30.2332 + // 30.2333 + intersectionPattern[1][0] = 'F'; 30.2334 + intersectionPattern[1][1] = '*'; 30.2335 + intersectionPattern[1][2] = '*'; 30.2336 + intersectionPattern[1][3] = 'T'; 30.2337 + intersectionPattern[1][4] = '*'; 30.2338 + intersectionPattern[1][5] = '*'; 30.2339 + intersectionPattern[1][6] = '*'; 30.2340 + intersectionPattern[1][7] = '*'; 30.2341 + intersectionPattern[1][8] = '*'; 30.2342 + // 30.2343 + intersectionPattern[2][0] = 'F'; 30.2344 + intersectionPattern[2][1] = '*'; 30.2345 + intersectionPattern[2][2] = '*'; 30.2346 + intersectionPattern[2][3] = '*'; 30.2347 + intersectionPattern[2][4] = 'T'; 30.2348 + intersectionPattern[2][5] = '*'; 30.2349 + intersectionPattern[2][6] = '*'; 30.2350 + intersectionPattern[2][7] = '*'; 30.2351 + intersectionPattern[2][8] = '*'; 30.2352 + // 30.2353 + 30.2354 + } 30.2355 + 30.2356 + for(int i = 0; i < intersectionPattern.length ; i++) 30.2357 + { 30.2358 + appendRelate(expr, filter, intersectionPattern[i]); 30.2359 + if(i < intersectionPattern.length - 1) 30.2360 + { 30.2361 + //append OR and continue 30.2362 + filter.or(); 30.2363 + } 30.2364 + } 30.2365 + 30.2366 + //Also need bounding box intersection query to enable the usage of the Gist R-tree index 30.2367 + if(func != SpatialFunctionsPostGIS.SF_Disjoint && func != SpatialFunctionsPostGIS.EH_Disjoint && func != SpatialFunctionsPostGIS.RCC8_Dc) 30.2368 + { 30.2369 + filter.and(); 30.2370 + appendGeneralDBSpatialFunctionBinary(expr, filter,SpatialFunctionsPostGIS.ST_Intersects); 30.2371 + } 30.2372 + } 30.2373 + filter.closeBracket(); 30.2374 + } 30.2375 + 30.2376 + @Override 30.2377 + //GeoSPARQL 30.2378 + //XXX 30.2379 + 30.2380 + protected void appendRelate(BinaryGeneralDBOperator expr, GeneralDBSqlExprBuilder filter, char[] intersectionPattern) 30.2381 + throws UnsupportedRdbmsOperatorException 30.2382 + { 30.2383 + filter.openBracket(); 30.2384 + System.out.println(expr.getLeftArg().getClass().getCanonicalName()); 30.2385 + boolean check1 = expr.getLeftArg().getClass().getCanonicalName().equals("org.openrdf.sail.generaldb.algebra.GeneralDBSqlNull"); 30.2386 + if(check1) 30.2387 + { 30.2388 + this.append((GeneralDBSqlNull)expr.getLeftArg(), filter); 30.2389 + 30.2390 + } 30.2391 + else 30.2392 + { 30.2393 + filter.appendFunction("ST_Relate"); 30.2394 + 30.2395 + 30.2396 + filter.openBracket(); 30.2397 + if(expr.getLeftArg() instanceof GeneralDBStringValue) 30.2398 + { 30.2399 + appendWKT(expr.getLeftArg(),filter); 30.2400 + } 30.2401 + else if(expr.getLeftArg() instanceof GeneralDBSqlSpatialConstructBinary) 30.2402 + { 30.2403 + appendConstructFunction(expr.getLeftArg(), filter); 30.2404 + } 30.2405 + else if(expr.getLeftArg() instanceof GeneralDBSqlSpatialConstructUnary) 30.2406 + { 30.2407 + appendConstructFunction(expr.getLeftArg(), filter); 30.2408 + } 30.2409 + else if(expr.getLeftArg() instanceof GeneralDBSqlCase) 30.2410 + { 30.2411 + GeneralDBLabelColumn onlyLabel = (GeneralDBLabelColumn)((GeneralDBSqlCase)expr.getLeftArg()).getEntries().get(0).getResult(); 30.2412 + appendMBB(onlyLabel,filter); 30.2413 + } 30.2414 + else 30.2415 + { 30.2416 + appendMBB((GeneralDBLabelColumn)(expr.getLeftArg()),filter); 30.2417 + } 30.2418 + filter.appendComma(); 30.2419 + boolean check2 = expr.getRightArg().getClass().getCanonicalName().equals("org.openrdf.sail.generaldb.algebra.GeneralDBSqlNull"); 30.2420 + if(check2) 30.2421 + { 30.2422 + this.append((GeneralDBSqlNull)expr.getRightArg(), filter); 30.2423 + } 30.2424 + else 30.2425 + { 30.2426 + if(expr.getRightArg() instanceof GeneralDBStringValue) 30.2427 + { 30.2428 + appendWKT(expr.getRightArg(),filter); 30.2429 + } 30.2430 + else if(expr.getRightArg() instanceof GeneralDBSqlSpatialConstructUnary) 30.2431 + { 30.2432 + appendConstructFunction(expr.getRightArg(), filter); 30.2433 + } 30.2434 + else if(expr.getRightArg() instanceof GeneralDBSqlSpatialConstructBinary) 30.2435 + { 30.2436 + appendConstructFunction(expr.getRightArg(), filter); 30.2437 + } 30.2438 + else if(expr.getRightArg() instanceof GeneralDBSqlCase) 30.2439 + { 30.2440 + GeneralDBLabelColumn onlyLabel = (GeneralDBLabelColumn)((GeneralDBSqlCase)expr.getRightArg()).getEntries().get(0).getResult(); 30.2441 + appendMBB(onlyLabel,filter); 30.2442 + } 30.2443 + else if(expr.getRightArg() instanceof GeneralDBDoubleValue) //case met in buffer! 30.2444 + { 30.2445 + append(((GeneralDBDoubleValue)expr.getRightArg()), filter); 30.2446 + } 30.2447 + else if(expr.getRightArg() instanceof GeneralDBNumericColumn) //case met in buffer! 30.2448 + { 30.2449 + append(((GeneralDBNumericColumn)expr.getRightArg()), filter); 30.2450 + } 30.2451 + //case met in buffer when in select -> buffer(?spatial,?thematic) 30.2452 + else if(expr.getRightArg() instanceof GeneralDBLabelColumn && !((GeneralDBLabelColumn)expr.getRightArg()).isSpatial()) 30.2453 + { 30.2454 + appendCastToDoubleBefore(filter); 30.2455 + append(((GeneralDBLabelColumn)expr.getRightArg()),filter); 30.2456 + appendCastToDoubleAfter(filter); 30.2457 + } 30.2458 + else if(expr.getRightArg() instanceof GeneralDBSqlSpatialMetricBinary) 30.2459 + { 30.2460 + appendMetricFunction(expr.getRightArg(), filter); 30.2461 + } 30.2462 + else if(expr.getRightArg() instanceof GeneralDBSqlSpatialMetricUnary) 30.2463 + { 30.2464 + appendMetricFunction(expr.getRightArg(), filter); 30.2465 + } 30.2466 + else 30.2467 + { 30.2468 + appendMBB((GeneralDBLabelColumn)(expr.getRightArg()),filter); 30.2469 + } 30.2470 + 30.2471 + } 30.2472 + //3rd arg 30.2473 + filter.appendComma(); 30.2474 + 30.2475 + //must turn the table of characters I have to a valid sql value! 30.2476 + filter.append("'"); 30.2477 + for(int i = 0; i< intersectionPattern.length; i++) 30.2478 + { 30.2479 + filter.append(intersectionPattern[i]+""); 30.2480 + } 30.2481 + filter.append("'"); 30.2482 + 30.2483 + filter.closeBracket(); 30.2484 + } 30.2485 + 30.2486 + filter.closeBracket(); 30.2487 + } 30.2488 + 30.2489 +}
31.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 31.2 +++ b/sqlite/src/main/java/org/openrdf/sail/sqlite/evaluation/SqliteQueryBuilderFactory.java Tue Jun 04 18:06:42 2013 +0300 31.3 @@ -0,0 +1,46 @@ 31.4 +package org.openrdf.sail.sqlite.evaluation; 31.5 + 31.6 +import org.openrdf.sail.generaldb.evaluation.GeneralDBQueryBuilder; 31.7 +import org.openrdf.sail.generaldb.evaluation.GeneralDBQueryBuilderFactory; 31.8 +import org.openrdf.sail.generaldb.evaluation.GeneralDBSqlBracketBuilder; 31.9 +import org.openrdf.sail.generaldb.evaluation.GeneralDBSqlCastBuilder; 31.10 +import org.openrdf.sail.generaldb.evaluation.GeneralDBSqlExprBuilder; 31.11 +import org.openrdf.sail.generaldb.evaluation.GeneralDBSqlRegexBuilder; 31.12 + 31.13 +/** 31.14 + * Creates the SQL query building components. 31.15 + * 31.16 + * @author James Leigh 31.17 + * 31.18 + */ 31.19 +public class SqliteQueryBuilderFactory extends GeneralDBQueryBuilderFactory { 31.20 + 31.21 + @Override 31.22 + public GeneralDBQueryBuilder createQueryBuilder() { 31.23 + GeneralDBQueryBuilder query = new SqliteQueryBuilder(createSqlQueryBuilder()); 31.24 + query.setValueFactory(vf); 31.25 + query.setUsingHashTable(usingHashTable); 31.26 + return query; 31.27 + } 31.28 + 31.29 + @Override 31.30 + public GeneralDBSqlExprBuilder createSqlExprBuilder() { 31.31 + return new SqliteSqlExprBuilder(this); 31.32 + } 31.33 + 31.34 + @Override 31.35 + public GeneralDBSqlRegexBuilder createSqlRegexBuilder(GeneralDBSqlExprBuilder where) { 31.36 + return new SqliteSqlRegexBuilder(where, this); 31.37 + } 31.38 + 31.39 + @Override 31.40 + public GeneralDBSqlBracketBuilder createSqlBracketBuilder(GeneralDBSqlExprBuilder where) { 31.41 + return new SqliteSqlBracketBuilder(where, this); 31.42 + } 31.43 + 31.44 + @Override 31.45 + public GeneralDBSqlCastBuilder createSqlCastBuilder(GeneralDBSqlExprBuilder where, int type) { 31.46 + return new SqliteSqlCastBuilder(where, this, type); 31.47 + } 31.48 + 31.49 +} 31.50 \ No newline at end of file
32.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 32.2 +++ b/sqlite/src/main/java/org/openrdf/sail/sqlite/evaluation/SqliteSqlBracketBuilder.java Tue Jun 04 18:06:42 2013 +0300 32.3 @@ -0,0 +1,33 @@ 32.4 +package org.openrdf.sail.sqlite.evaluation; 32.5 + 32.6 +import org.openrdf.sail.generaldb.evaluation.GeneralDBQueryBuilderFactory; 32.7 +import org.openrdf.sail.generaldb.evaluation.GeneralDBSqlBracketBuilder; 32.8 +import org.openrdf.sail.generaldb.evaluation.GeneralDBSqlExprBuilder; 32.9 + 32.10 +public class SqliteSqlBracketBuilder extends SqliteSqlExprBuilder implements GeneralDBSqlBracketBuilder { 32.11 + 32.12 + private SqliteSqlExprBuilder where; 32.13 + 32.14 + private String closing = ")"; 32.15 + 32.16 + public SqliteSqlBracketBuilder(GeneralDBSqlExprBuilder where, GeneralDBQueryBuilderFactory factory) { 32.17 + super(factory); 32.18 + this.where = (SqliteSqlExprBuilder)where; 32.19 + append("("); 32.20 + } 32.21 + 32.22 + public String getClosing() { 32.23 + return closing; 32.24 + } 32.25 + 32.26 + public void setClosing(String closing) { 32.27 + this.closing = closing; 32.28 + } 32.29 + 32.30 + public SqliteSqlExprBuilder close() { 32.31 + append(closing); 32.32 + where.append(toSql()); 32.33 + where.addParameters(getParameters()); 32.34 + return where; 32.35 + } 32.36 +}
33.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 33.2 +++ b/sqlite/src/main/java/org/openrdf/sail/sqlite/evaluation/SqliteSqlCastBuilder.java Tue Jun 04 18:06:42 2013 +0300 33.3 @@ -0,0 +1,39 @@ 33.4 +package org.openrdf.sail.sqlite.evaluation; 33.5 + 33.6 +import java.sql.Types; 33.7 + 33.8 +import org.openrdf.sail.generaldb.evaluation.GeneralDBQueryBuilderFactory; 33.9 +import org.openrdf.sail.generaldb.evaluation.GeneralDBSqlCastBuilder; 33.10 +import org.openrdf.sail.generaldb.evaluation.GeneralDBSqlExprBuilder; 33.11 + 33.12 +public class SqliteSqlCastBuilder extends SqliteSqlExprBuilder implements GeneralDBSqlCastBuilder { 33.13 + 33.14 + protected GeneralDBSqlExprBuilder where; 33.15 + 33.16 + protected int jdbcType; 33.17 + 33.18 + public SqliteSqlCastBuilder(GeneralDBSqlExprBuilder where, GeneralDBQueryBuilderFactory factory, int jdbcType) { 33.19 + super(factory); 33.20 + this.where = where; 33.21 + this.jdbcType = jdbcType; 33.22 + append(" CAST("); 33.23 + } 33.24 + 33.25 + public GeneralDBSqlExprBuilder close() { 33.26 + append(" AS "); 33.27 + append(getSqlType(jdbcType)); 33.28 + append(")"); 33.29 + where.append(toSql()); 33.30 + where.addParameters(getParameters()); 33.31 + return where; 33.32 + } 33.33 + 33.34 + protected CharSequence getSqlType(int type) { 33.35 + switch (type) { 33.36 + case Types.VARCHAR: 33.37 + return "VARCHAR"; 33.38 + default: 33.39 + throw new AssertionError(type); 33.40 + } 33.41 + } 33.42 +}
34.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 34.2 +++ b/sqlite/src/main/java/org/openrdf/sail/sqlite/evaluation/SqliteSqlExprBuilder.java Tue Jun 04 18:06:42 2013 +0300 34.3 @@ -0,0 +1,91 @@ 34.4 +package org.openrdf.sail.sqlite.evaluation; 34.5 + 34.6 +import java.math.BigDecimal; 34.7 +import java.sql.SQLException; 34.8 + 34.9 +import org.openrdf.sail.generaldb.evaluation.GeneralDBQueryBuilderFactory; 34.10 +import org.openrdf.sail.generaldb.evaluation.GeneralDBSqlExprBuilder; 34.11 +import org.openrdf.sail.rdbms.exceptions.UnsupportedRdbmsOperatorException; 34.12 + 34.13 +/** 34.14 + * Assemblies an SQL expression. 34.15 + * 34.16 + * @author James Leigh 34.17 + * 34.18 + */ 34.19 +public class SqliteSqlExprBuilder extends GeneralDBSqlExprBuilder { 34.20 + 34.21 + public SqliteSqlExprBuilder(GeneralDBQueryBuilderFactory factory) { 34.22 + super(factory); 34.23 + } 34.24 + 34.25 + @Override 34.26 + public void appendBoolean(boolean booleanValue) { 34.27 + if (booleanValue) { 34.28 + where.append(" (1=1) "); 34.29 + } 34.30 + else { 34.31 + where.append(" (0=1) "); 34.32 + } 34.33 + } 34.34 + 34.35 + 34.36 + public void intersectsMBB() { 34.37 + 34.38 + //XXX 34.39 + //edw prepei na ginei allou eidous douleia!! oxi na mpei to mbbIntersects, 34.40 + //alla na prostethei kati pou tha mou pei o kwstis 34.41 + where.append(" MbrOverlaps "); 34.42 + } 34.43 + 34.44 + public void equalsMBB() { 34.45 + 34.46 + where.append("MbrEqual"); 34.47 + } 34.48 + 34.49 + public void containsMBB() { 34.50 + 34.51 + where.append("MbrContains"); 34.52 + } 34.53 + 34.54 + public void insideMBB() { 34.55 + 34.56 + //den xerw akoma ti symbolo xreiazetai 34.57 + where.append("MbrWithin"); 34.58 + } 34.59 + 34.60 + 34.61 + 34.62 + @Override 34.63 + public GeneralDBSqlExprBuilder appendNumeric(Number doubleValue) { 34.64 + where.append(" ? "); 34.65 + parameters.add(doubleValue); 34.66 + return this; 34.67 + } 34.68 + 34.69 + @Override 34.70 + public GeneralDBSqlExprBuilder number(Number time) { 34.71 + where.append(" ? "); 34.72 + parameters.add(time); 34.73 + return this; 34.74 + } 34.75 + 34.76 + @Override 34.77 + public GeneralDBSqlExprBuilder varchar(String stringValue) { 34.78 + if (stringValue == null) { 34.79 + appendNull(); 34.80 + } 34.81 + else { 34.82 + where.append(" ? "); 34.83 + parameters.add(stringValue); 34.84 + } 34.85 + return this; 34.86 + } 34.87 + 34.88 +// // TODO should this be overriden ?? 34.89 +// protected String getSqlNull() { 34.90 +//// return "false"; // FIXME 34.91 +// return NULL; 34.92 +// } 34.93 + 34.94 +}
35.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 35.2 +++ b/sqlite/src/main/java/org/openrdf/sail/sqlite/evaluation/SqliteSqlRegexBuilder.java Tue Jun 04 18:06:42 2013 +0300 35.3 @@ -0,0 +1,20 @@ 35.4 +package org.openrdf.sail.sqlite.evaluation; 35.5 + 35.6 +import org.openrdf.sail.generaldb.evaluation.GeneralDBQueryBuilderFactory; 35.7 +import org.openrdf.sail.generaldb.evaluation.GeneralDBSqlExprBuilder; 35.8 +import org.openrdf.sail.generaldb.evaluation.GeneralDBSqlRegexBuilder; 35.9 + 35.10 +public class SqliteSqlRegexBuilder extends GeneralDBSqlRegexBuilder { 35.11 + 35.12 + public SqliteSqlRegexBuilder(GeneralDBSqlExprBuilder where, GeneralDBQueryBuilderFactory factory) { 35.13 + super(where, factory); 35.14 + } 35.15 + 35.16 + @Override 35.17 + protected void appendRegExp(GeneralDBSqlExprBuilder where) { 35.18 + appendValue(where); 35.19 + where.append(" REGEXP ");//must define the corresponding function 35.20 + appendPattern(where); 35.21 + } 35.22 + 35.23 +} 35.24 \ No newline at end of file
36.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 36.2 +++ b/sqlite/src/main/java/org/openrdf/sail/sqlite/iteration/SqliteBindingIteration.java Tue Jun 04 18:06:42 2013 +0300 36.3 @@ -0,0 +1,52 @@ 36.4 +package org.openrdf.sail.sqlite.iteration; 36.5 + 36.6 +import java.sql.PreparedStatement; 36.7 +import java.sql.ResultSet; 36.8 +import java.sql.SQLException; 36.9 + 36.10 +import org.openrdf.query.BindingSet; 36.11 +import org.openrdf.query.algebra.evaluation.function.spatial.GeoConstants; 36.12 +import org.openrdf.sail.generaldb.iteration.GeneralDBBindingIteration; 36.13 +import org.openrdf.sail.rdbms.model.RdbmsValue; 36.14 + 36.15 +/** 36.16 + * Converts a {@link ResultSet} into a {@link BindingSet} in an iteration. 36.17 + * 36.18 + * @author Manos Karpathiotakis <mk@di.uoa.gr> 36.19 + * 36.20 + */ 36.21 +public class SqliteBindingIteration extends GeneralDBBindingIteration { 36.22 + 36.23 + public SqliteBindingIteration(PreparedStatement stmt) 36.24 + throws SQLException 36.25 + { 36.26 + super(stmt); 36.27 + } 36.28 + 36.29 + @Override 36.30 + protected RdbmsValue createGeoValue(ResultSet rs, int index) 36.31 + throws SQLException 36.32 + { 36.33 + Number id = ids.idOf(rs.getLong(index)); 36.34 + if (ids.isLiteral(id)) 36.35 + { 36.36 + byte[] label = rs.getBytes(index + 1); 36.37 + int srid = rs.getInt(index + 2); 36.38 + return vf.getRdbmsPolyhedron(id, GeoConstants.WKT, label, srid); 36.39 + 36.40 + } 36.41 + 36.42 + return createResource(rs, index); 36.43 + } 36.44 + 36.45 + @Override 36.46 + protected RdbmsValue createBinaryGeoValueForSelectConstructs(ResultSet rs, int index) 36.47 + throws SQLException 36.48 + { 36.49 + //Case of spatial constructs 36.50 + byte[] label = rs.getBytes(index + 1); 36.51 + int srid = rs.getInt(index + 2); 36.52 + return vf.getRdbmsPolyhedron(114, GeoConstants.WKT, label, srid); 36.53 + 36.54 + } 36.55 +} 36.56 \ No newline at end of file
37.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 37.2 +++ b/sqlite/src/main/java/org/openrdf/sail/sqlite/schema/SqliteGeoValueTable.java Tue Jun 04 18:06:42 2013 +0300 37.3 @@ -0,0 +1,46 @@ 37.4 +package org.openrdf.sail.sqlite.schema; 37.5 + 37.6 +import java.sql.PreparedStatement; 37.7 +import java.sql.ResultSet; 37.8 +import java.sql.SQLException; 37.9 +import java.util.ArrayList; 37.10 +import java.util.List; 37.11 + 37.12 +public class SqliteGeoValueTable extends org.openrdf.sail.generaldb.schema.GeoValueTable{ 37.13 + public List<Long> maxIds(int shift, int mod) 37.14 + throws SQLException 37.15 + { 37.16 + String column = "id"; 37.17 + StringBuilder expr = new StringBuilder(); 37.18 + expr.append("((").append(column); 37.19 + expr.append(" >> ").append(shift); 37.20 + expr.append(") + ").append(mod).append(") % "); 37.21 + expr.append(mod); 37.22 + expr.append(""); 37.23 + StringBuilder sb = new StringBuilder(); 37.24 + sb.append("SELECT "); 37.25 + sb.append("MAX("); 37.26 + sb.append(column); 37.27 + sb.append("), ").append(expr).append(" AS grp"); 37.28 + sb.append("\nFROM ").append(this.getName()); 37.29 + sb.append("\nGROUP BY grp"); 37.30 + String query = sb.toString(); 37.31 + PreparedStatement st = this.getRdbmsTable().prepareStatement(query); 37.32 + try { 37.33 + ResultSet rs = st.executeQuery(); 37.34 + try { 37.35 + List<Long> result = new ArrayList<Long>(); 37.36 + while (rs.next()) { 37.37 + result.add(rs.getLong(1)); 37.38 + } 37.39 + return result; 37.40 + } 37.41 + finally { 37.42 + rs.close(); 37.43 + } 37.44 + } 37.45 + finally { 37.46 + st.close(); 37.47 + } 37.48 + } 37.49 +}
38.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 38.2 +++ b/sqlite/src/main/java/org/openrdf/sail/sqlite/schema/SqliteValueTable.java Tue Jun 04 18:06:42 2013 +0300 38.3 @@ -0,0 +1,46 @@ 38.4 +package org.openrdf.sail.sqlite.schema; 38.5 + 38.6 +import java.sql.PreparedStatement; 38.7 +import java.sql.ResultSet; 38.8 +import java.sql.SQLException; 38.9 +import java.util.ArrayList; 38.10 +import java.util.List; 38.11 + 38.12 +public class SqliteValueTable extends org.openrdf.sail.generaldb.GeneralDBSqlValueTable{ 38.13 + public List<Long> maxIds(int shift, int mod) 38.14 + throws SQLException 38.15 + { 38.16 + String column = "id"; 38.17 + StringBuilder expr = new StringBuilder(); 38.18 + expr.append("((").append(column); 38.19 + expr.append(" >> ").append(shift); 38.20 + expr.append(") + ").append(mod).append(") % "); 38.21 + expr.append(mod); 38.22 + expr.append(""); 38.23 + StringBuilder sb = new StringBuilder(); 38.24 + sb.append("SELECT "); 38.25 + sb.append("MAX("); 38.26 + sb.append(column); 38.27 + sb.append("), ").append(expr).append(" AS grp"); 38.28 + sb.append("\nFROM ").append(getName()); 38.29 + sb.append("\nGROUP BY grp"); 38.30 + String query = sb.toString(); 38.31 + PreparedStatement st = this.getRdbmsTable().prepareStatement(query); 38.32 + try { 38.33 + ResultSet rs = st.executeQuery(); 38.34 + try { 38.35 + List<Long> result = new ArrayList<Long>(); 38.36 + while (rs.next()) { 38.37 + result.add(rs.getLong(1)); 38.38 + } 38.39 + return result; 38.40 + } 38.41 + finally { 38.42 + rs.close(); 38.43 + } 38.44 + } 38.45 + finally { 38.46 + st.close(); 38.47 + } 38.48 + } 38.49 +}
39.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 39.2 +++ b/sqlite/src/test/java/org/openrdf/sail/sqlite/AppTest.java Tue Jun 04 18:06:42 2013 +0300 39.3 @@ -0,0 +1,38 @@ 39.4 +package org.openrdf.sail.sqlite; 39.5 + 39.6 +import junit.framework.Test; 39.7 +import junit.framework.TestCase; 39.8 +import junit.framework.TestSuite; 39.9 + 39.10 +/** 39.11 + * Unit test for simple App. 39.12 + */ 39.13 +public class AppTest 39.14 + extends TestCase 39.15 +{ 39.16 + /** 39.17 + * Create the test case 39.18 + * 39.19 + * @param testName name of the test case 39.20 + */ 39.21 + public AppTest( String testName ) 39.22 + { 39.23 + super( testName ); 39.24 + } 39.25 + 39.26 + /** 39.27 + * @return the suite of tests being tested 39.28 + */ 39.29 + public static Test suite() 39.30 + { 39.31 + return new TestSuite( AppTest.class ); 39.32 + } 39.33 + 39.34 + /** 39.35 + * Rigourous Test :-) 39.36 + */ 39.37 + public void testApp() 39.38 + { 39.39 + assertTrue( true ); 39.40 + } 39.41 +}