Search in sources :

Example 6 with DLN

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();
    }
}
Also used : DLN(org.exist.numbering.DLN) Geometry(com.vividsolutions.jts.geom.Geometry) NodeId(org.exist.numbering.NodeId) PermissionDeniedException(org.exist.security.PermissionDeniedException) ParseException(com.vividsolutions.jts.io.ParseException)

Example 7 with DLN

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);
}
Also used : DLN(org.exist.numbering.DLN) Test(org.junit.Test)

Example 8 with DLN

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);
}
Also used : DLN(org.exist.numbering.DLN) Test(org.junit.Test)

Example 9 with DLN

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);
}
Also used : DLN(org.exist.numbering.DLN) Test(org.junit.Test)

Example 10 with DLN

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);
}
Also used : DLN(org.exist.numbering.DLN) Test(org.junit.Test)

Aggregations

DLN (org.exist.numbering.DLN)16 Test (org.junit.Test)12 NodeId (org.exist.numbering.NodeId)8 DocumentImpl (org.exist.dom.persistent.DocumentImpl)4 NodeProxy (org.exist.dom.persistent.NodeProxy)4 PermissionDeniedException (org.exist.security.PermissionDeniedException)4 Geometry (com.vividsolutions.jts.geom.Geometry)3 ParseException (com.vividsolutions.jts.io.ParseException)3 ValueSequence (org.exist.xquery.value.ValueSequence)3 Item (org.exist.xquery.value.Item)2 Sequence (org.exist.xquery.value.Sequence)2 UnsynchronizedByteArrayInputStream (org.apache.commons.io.input.UnsynchronizedByteArrayInputStream)1 Base64BinaryValueType (org.exist.xquery.value.Base64BinaryValueType)1 BooleanValue (org.exist.xquery.value.BooleanValue)1 DoubleValue (org.exist.xquery.value.DoubleValue)1 StringValue (org.exist.xquery.value.StringValue)1