use of org.exist.numbering.DLN in project exist by eXist-db.
the class GMLHSQLIndexWorker method getGeometriesForNodes.
@Override
protected Geometry[] getGeometriesForNodes(DBBroker broker, NodeSet contextSet, boolean getEPSG4326, Connection conn) throws SQLException {
// TODO : generate it in AbstractGMLJDBCIndexWorker
String docConstraint = "";
boolean refine_query_on_doc = false;
if (contextSet != null) {
if (contextSet.getDocumentSet().getDocumentCount() <= index.getMaxDocsInContextToRefineQuery()) {
DocumentImpl doc;
Iterator<DocumentImpl> it = contextSet.getDocumentSet().getDocumentIterator();
doc = it.next();
docConstraint = "(DOCUMENT_URI = '" + doc.getURI().toString() + "')";
while (it.hasNext()) {
doc = it.next();
docConstraint = docConstraint + " OR (DOCUMENT_URI = '" + doc.getURI().toString() + "')";
}
}
}
if (LOG.isDebugEnabled()) {
LOG.debug("Refine query on documents is {}", refine_query_on_doc ? "enabled." : "disabled.");
}
PreparedStatement ps = conn.prepareStatement("SELECT " + (getEPSG4326 ? "EPSG4326_WKB" : "WKB") + ", DOCUMENT_URI, NODE_ID_UNITS, NODE_ID" + " FROM " + GMLHSQLIndex.TABLE_NAME + (refine_query_on_doc ? " WHERE " + docConstraint : ""));
ResultSet rs = null;
try {
rs = ps.executeQuery();
Geometry[] result = new Geometry[contextSet.getLength()];
int index = 0;
while (rs.next()) {
DocumentImpl doc = null;
try {
doc = (DocumentImpl) broker.getXMLResource(XmldbURI.create(rs.getString("DOCUMENT_URI")));
} catch (PermissionDeniedException e) {
LOG.debug(e);
result[index++] = null;
// Ignore since the broker has no right on the document
continue;
}
if (contextSet == null || refine_query_on_doc || contextSet.getDocumentSet().contains(doc.getDocId())) {
NodeId nodeId = new DLN(rs.getInt("NODE_ID_UNITS"), rs.getBytes("NODE_ID"), 0);
NodeProxy p = new NodeProxy(doc, nodeId);
// VirtualNodeSet when on the DESCENDANT_OR_SELF axis
if (contextSet.get(p) != null) {
Geometry geometry = wkbReader.read(rs.getBytes(1));
result[index++] = geometry;
}
}
}
return result;
} catch (ParseException e) {
// Transforms the exception into an SQLException.
// Very unlikely to happen though...
SQLException ee = new SQLException(e.getMessage());
ee.initCause(e);
throw ee;
} finally {
if (rs != null)
rs.close();
if (ps != null)
ps.close();
}
}
use of org.exist.numbering.DLN in project exist by eXist-db.
the class TextImplTest method isSameNode_differentText.
@Test
public void isSameNode_differentText() {
final DocumentImpl doc = EasyMock.createMock(DocumentImpl.class);
replay(doc);
final TextImpl text = new TextImpl("hello");
text.setOwnerDocument(doc);
text.setNodeId(new DLN("1.2.1"));
final TextImpl text2 = new TextImpl("hello");
text2.setOwnerDocument(doc);
text2.setNodeId(new DLN("1.7.9"));
assertFalse(text.isSameNode(text2));
verify(doc);
}
use of org.exist.numbering.DLN in project exist by eXist-db.
the class TextImplTest method isSameNode_differentTextDifferentDoc.
@Test
public void isSameNode_differentTextDifferentDoc() {
final DocumentImpl doc = EasyMock.createMock(DocumentImpl.class);
expect(doc.getDocId()).andReturn(21);
final DocumentImpl doc2 = EasyMock.createMock(DocumentImpl.class);
expect(doc2.getDocId()).andReturn(67);
replay(doc, doc2);
final TextImpl text = new TextImpl("hello");
text.setOwnerDocument(doc);
text.setNodeId(new DLN("1.2.1"));
final TextImpl text2 = new TextImpl("hello");
text2.setOwnerDocument(doc2);
text2.setNodeId(new DLN("1.2.1"));
assertFalse(text.isSameNode(text2));
verify(doc, doc2);
}
use of org.exist.numbering.DLN in project exist by eXist-db.
the class TextImplTest method isSameNode_nonText.
@Test
public void isSameNode_nonText() {
final DocumentImpl doc = EasyMock.createMock(DocumentImpl.class);
replay(doc);
final TextImpl text = new TextImpl("hello");
text.setOwnerDocument(doc);
text.setNodeId(new DLN("1.2.1"));
final ElementImpl elem = new ElementImpl();
elem.setOwnerDocument(doc);
elem.setNodeId(new DLN("1.2"));
assertFalse(text.isSameNode(elem));
verify(doc);
}
use of org.exist.numbering.DLN in project exist by eXist-db.
the class TextImplTest method isSameNode_sameText.
@Test
public void isSameNode_sameText() {
final DocumentImpl doc = EasyMock.createMock(DocumentImpl.class);
expect(doc.getDocId()).andReturn(21).times(2);
replay(doc);
final TextImpl text = new TextImpl("hello");
text.setOwnerDocument(doc);
text.setNodeId(new DLN("1.2.1"));
assertTrue(text.isSameNode(text));
verify(doc);
}
Aggregations