@Test public final void testAddSubResource() throws WebApplicationException, IOException, ParserConfigurationException, SAXException { final Map<QueryParameter, String> queryParams = new HashMap<QueryParameter, String>(); queryParams.put(QueryParameter.OUTPUT, LITERALSTRUE); queryParams.put(QueryParameter.WRAP, LITERALSTRUE); final Map<QueryParameter, String> queryParamsComp = new HashMap<QueryParameter, String>(); queryParams.put(QueryParameter.OUTPUT, LITERALSTRUE); ByteArrayOutputStream outputStream; StreamingOutput result; Document doc; NodeList list; Node node; final InputStream newNode = new ByteArrayInputStream("<myNode><test>hello</test></myNode>".getBytes()); ridWorker.addSubResource(RESOURCENAME, NODEIDGETRESOURCE, newNode, EIdAccessType.FIRSTCHILD); result = ridWorker.getResourceByAT(RESOURCENAME, NODEIDGETRESOURCE, queryParamsComp, EIdAccessType.FIRSTCHILD); outputStream = new ByteArrayOutputStream(); result.write(outputStream); doc = DOMHelper.buildDocument(outputStream); list = doc.getElementsByTagName(NODENAME); node = list.item(0); outputStream.close(); assertNotNull("Test if first child exist after inserting", node); newNode.reset(); ridWorker.addSubResource(RESOURCENAME, NODEIDGETRESOURCE, newNode, EIdAccessType.LASTCHILD); result = ridWorker.getResourceByAT(RESOURCENAME, NODEIDGETRESOURCE, queryParamsComp, EIdAccessType.LASTCHILD); outputStream = new ByteArrayOutputStream(); result.write(outputStream); doc = DOMHelper.buildDocument(outputStream); list = doc.getElementsByTagName(NODENAME); node = list.item(0); outputStream.close(); assertNotNull("Test if last child exist after inserting", node); newNode.reset(); ridWorker.addSubResource(RESOURCENAME, NODEIDGETRESOURCE, newNode, EIdAccessType.LEFTSIBLING); result = ridWorker.getResourceByAT(RESOURCENAME, NODEIDGETRESOURCE, queryParamsComp, EIdAccessType.LEFTSIBLING); outputStream = new ByteArrayOutputStream(); result.write(outputStream); doc = DOMHelper.buildDocument(outputStream); list = doc.getElementsByTagName(NODENAME); node = list.item(0); outputStream.close(); assertNotNull("Test if left sibling exist after inserting", node); newNode.reset(); ridWorker.addSubResource(RESOURCENAME, NODEIDGETRESOURCE, newNode, EIdAccessType.RIGHTSIBLING); result = ridWorker.getResourceByAT(RESOURCENAME, NODEIDGETRESOURCE, queryParamsComp, EIdAccessType.RIGHTSIBLING); outputStream = new ByteArrayOutputStream(); result.write(outputStream); doc = DOMHelper.buildDocument(outputStream); list = doc.getElementsByTagName(NODENAME); node = list.item(0); outputStream.close(); assertNotNull("Test if right sibling exist after inserting", node); }
public void addSubResource(final String resourceName, final long nodeId, final InputStream input, final EIdAccessType type) throws JaxRxException { ISession session = null; INodeWriteTrx wtx = null; synchronized (resourceName) { boolean abort; if (mDatabase.existsResource(resourceName)) { abort = false; try { session = mDatabase.getSession(new SessionConfiguration(resourceName, StandardSettings.KEY)); wtx = new NodeWriteTrx(session, session.beginBucketWtx(), HashKind.Rolling); final boolean exist = wtx.moveTo(nodeId); if (exist) { if (type == EIdAccessType.FIRSTCHILD) { WorkerHelper.shredInputStream(wtx, input, EShredderInsert.ADDASFIRSTCHILD); } else if (type == EIdAccessType.RIGHTSIBLING) { WorkerHelper.shredInputStream(wtx, input, EShredderInsert.ADDASRIGHTSIBLING); } else if (type == EIdAccessType.LASTCHILD) { if (wtx.moveTo(((ITreeStructData)wtx.getNode()).getFirstChildKey())) { long last = wtx.getNode().getDataKey(); while (wtx.moveTo(((ITreeStructData)wtx.getNode()).getRightSiblingKey())) { last = wtx.getNode().getDataKey(); } wtx.moveTo(last); WorkerHelper.shredInputStream(wtx, input, EShredderInsert.ADDASRIGHTSIBLING); } else { throw new JaxRxException(404, NOTFOUND); } } else if (type == EIdAccessType.LEFTSIBLING && wtx.moveTo(((ITreeStructData)wtx.getNode()).getLeftSiblingKey())) { WorkerHelper.shredInputStream(wtx, input, EShredderInsert.ADDASRIGHTSIBLING); } } else { throw new JaxRxException(404, NOTFOUND); } } catch (final JaxRxException exce) { abort = true; throw exce; } catch (final Exception exce) { abort = true; throw new JaxRxException(exce); } finally { try { WorkerHelper.closeWTX(abort, wtx, session); } catch (final TTException exce) { throw new JaxRxException(exce); } } } } }
NodeIdRepresentation { public void addSubResource(final String resourceName, final long nodeId, final InputStream input, final EIdAccessType type) throws JaxRxException { ISession session = null; INodeWriteTrx wtx = null; synchronized (resourceName) { boolean abort; if (mDatabase.existsResource(resourceName)) { abort = false; try { session = mDatabase.getSession(new SessionConfiguration(resourceName, StandardSettings.KEY)); wtx = new NodeWriteTrx(session, session.beginBucketWtx(), HashKind.Rolling); final boolean exist = wtx.moveTo(nodeId); if (exist) { if (type == EIdAccessType.FIRSTCHILD) { WorkerHelper.shredInputStream(wtx, input, EShredderInsert.ADDASFIRSTCHILD); } else if (type == EIdAccessType.RIGHTSIBLING) { WorkerHelper.shredInputStream(wtx, input, EShredderInsert.ADDASRIGHTSIBLING); } else if (type == EIdAccessType.LASTCHILD) { if (wtx.moveTo(((ITreeStructData)wtx.getNode()).getFirstChildKey())) { long last = wtx.getNode().getDataKey(); while (wtx.moveTo(((ITreeStructData)wtx.getNode()).getRightSiblingKey())) { last = wtx.getNode().getDataKey(); } wtx.moveTo(last); WorkerHelper.shredInputStream(wtx, input, EShredderInsert.ADDASRIGHTSIBLING); } else { throw new JaxRxException(404, NOTFOUND); } } else if (type == EIdAccessType.LEFTSIBLING && wtx.moveTo(((ITreeStructData)wtx.getNode()).getLeftSiblingKey())) { WorkerHelper.shredInputStream(wtx, input, EShredderInsert.ADDASRIGHTSIBLING); } } else { throw new JaxRxException(404, NOTFOUND); } } catch (final JaxRxException exce) { abort = true; throw exce; } catch (final Exception exce) { abort = true; throw new JaxRxException(exce); } finally { try { WorkerHelper.closeWTX(abort, wtx, session); } catch (final TTException exce) { throw new JaxRxException(exce); } } } } } }
NodeIdRepresentation { public void addSubResource(final String resourceName, final long nodeId, final InputStream input, final EIdAccessType type) throws JaxRxException { ISession session = null; INodeWriteTrx wtx = null; synchronized (resourceName) { boolean abort; if (mDatabase.existsResource(resourceName)) { abort = false; try { session = mDatabase.getSession(new SessionConfiguration(resourceName, StandardSettings.KEY)); wtx = new NodeWriteTrx(session, session.beginBucketWtx(), HashKind.Rolling); final boolean exist = wtx.moveTo(nodeId); if (exist) { if (type == EIdAccessType.FIRSTCHILD) { WorkerHelper.shredInputStream(wtx, input, EShredderInsert.ADDASFIRSTCHILD); } else if (type == EIdAccessType.RIGHTSIBLING) { WorkerHelper.shredInputStream(wtx, input, EShredderInsert.ADDASRIGHTSIBLING); } else if (type == EIdAccessType.LASTCHILD) { if (wtx.moveTo(((ITreeStructData)wtx.getNode()).getFirstChildKey())) { long last = wtx.getNode().getDataKey(); while (wtx.moveTo(((ITreeStructData)wtx.getNode()).getRightSiblingKey())) { last = wtx.getNode().getDataKey(); } wtx.moveTo(last); WorkerHelper.shredInputStream(wtx, input, EShredderInsert.ADDASRIGHTSIBLING); } else { throw new JaxRxException(404, NOTFOUND); } } else if (type == EIdAccessType.LEFTSIBLING && wtx.moveTo(((ITreeStructData)wtx.getNode()).getLeftSiblingKey())) { WorkerHelper.shredInputStream(wtx, input, EShredderInsert.ADDASRIGHTSIBLING); } } else { throw new JaxRxException(404, NOTFOUND); } } catch (final JaxRxException exce) { abort = true; throw exce; } catch (final Exception exce) { abort = true; throw new JaxRxException(exce); } finally { try { WorkerHelper.closeWTX(abort, wtx, session); } catch (final TTException exce) { throw new JaxRxException(exce); } } } } } NodeIdRepresentation(final IStorage pDatabase); }
NodeIdRepresentation { public void addSubResource(final String resourceName, final long nodeId, final InputStream input, final EIdAccessType type) throws JaxRxException { ISession session = null; INodeWriteTrx wtx = null; synchronized (resourceName) { boolean abort; if (mDatabase.existsResource(resourceName)) { abort = false; try { session = mDatabase.getSession(new SessionConfiguration(resourceName, StandardSettings.KEY)); wtx = new NodeWriteTrx(session, session.beginBucketWtx(), HashKind.Rolling); final boolean exist = wtx.moveTo(nodeId); if (exist) { if (type == EIdAccessType.FIRSTCHILD) { WorkerHelper.shredInputStream(wtx, input, EShredderInsert.ADDASFIRSTCHILD); } else if (type == EIdAccessType.RIGHTSIBLING) { WorkerHelper.shredInputStream(wtx, input, EShredderInsert.ADDASRIGHTSIBLING); } else if (type == EIdAccessType.LASTCHILD) { if (wtx.moveTo(((ITreeStructData)wtx.getNode()).getFirstChildKey())) { long last = wtx.getNode().getDataKey(); while (wtx.moveTo(((ITreeStructData)wtx.getNode()).getRightSiblingKey())) { last = wtx.getNode().getDataKey(); } wtx.moveTo(last); WorkerHelper.shredInputStream(wtx, input, EShredderInsert.ADDASRIGHTSIBLING); } else { throw new JaxRxException(404, NOTFOUND); } } else if (type == EIdAccessType.LEFTSIBLING && wtx.moveTo(((ITreeStructData)wtx.getNode()).getLeftSiblingKey())) { WorkerHelper.shredInputStream(wtx, input, EShredderInsert.ADDASRIGHTSIBLING); } } else { throw new JaxRxException(404, NOTFOUND); } } catch (final JaxRxException exce) { abort = true; throw exce; } catch (final Exception exce) { abort = true; throw new JaxRxException(exce); } finally { try { WorkerHelper.closeWTX(abort, wtx, session); } catch (final TTException exce) { throw new JaxRxException(exce); } } } } } NodeIdRepresentation(final IStorage pDatabase); StreamingOutput getResource(final String resourceName, final long nodeId,
        final Map<QueryParameter, String> queryParams); StreamingOutput getResourceByAT(final String resourceName, final long nodeId,
        final Map<QueryParameter, String> queryParams, final EIdAccessType accessType); StreamingOutput performQueryOnResource(final String resourceName, final long nodeId,
        final String query, final Map<QueryParameter, String> queryParams); void deleteResource(final String resourceName, final long nodeId); void modifyResource(final String resourceName, final long nodeId, final InputStream newValue); void addSubResource(final String resourceName, final long nodeId, final InputStream input,
        final EIdAccessType type); }
NodeIdRepresentation { public void addSubResource(final String resourceName, final long nodeId, final InputStream input, final EIdAccessType type) throws JaxRxException { ISession session = null; INodeWriteTrx wtx = null; synchronized (resourceName) { boolean abort; if (mDatabase.existsResource(resourceName)) { abort = false; try { session = mDatabase.getSession(new SessionConfiguration(resourceName, StandardSettings.KEY)); wtx = new NodeWriteTrx(session, session.beginBucketWtx(), HashKind.Rolling); final boolean exist = wtx.moveTo(nodeId); if (exist) { if (type == EIdAccessType.FIRSTCHILD) { WorkerHelper.shredInputStream(wtx, input, EShredderInsert.ADDASFIRSTCHILD); } else if (type == EIdAccessType.RIGHTSIBLING) { WorkerHelper.shredInputStream(wtx, input, EShredderInsert.ADDASRIGHTSIBLING); } else if (type == EIdAccessType.LASTCHILD) { if (wtx.moveTo(((ITreeStructData)wtx.getNode()).getFirstChildKey())) { long last = wtx.getNode().getDataKey(); while (wtx.moveTo(((ITreeStructData)wtx.getNode()).getRightSiblingKey())) { last = wtx.getNode().getDataKey(); } wtx.moveTo(last); WorkerHelper.shredInputStream(wtx, input, EShredderInsert.ADDASRIGHTSIBLING); } else { throw new JaxRxException(404, NOTFOUND); } } else if (type == EIdAccessType.LEFTSIBLING && wtx.moveTo(((ITreeStructData)wtx.getNode()).getLeftSiblingKey())) { WorkerHelper.shredInputStream(wtx, input, EShredderInsert.ADDASRIGHTSIBLING); } } else { throw new JaxRxException(404, NOTFOUND); } } catch (final JaxRxException exce) { abort = true; throw exce; } catch (final Exception exce) { abort = true; throw new JaxRxException(exce); } finally { try { WorkerHelper.closeWTX(abort, wtx, session); } catch (final TTException exce) { throw new JaxRxException(exce); } } } } } NodeIdRepresentation(final IStorage pDatabase); StreamingOutput getResource(final String resourceName, final long nodeId,
        final Map<QueryParameter, String> queryParams); StreamingOutput getResourceByAT(final String resourceName, final long nodeId,
        final Map<QueryParameter, String> queryParams, final EIdAccessType accessType); StreamingOutput performQueryOnResource(final String resourceName, final long nodeId,
        final String query, final Map<QueryParameter, String> queryParams); void deleteResource(final String resourceName, final long nodeId); void modifyResource(final String resourceName, final long nodeId, final InputStream newValue); void addSubResource(final String resourceName, final long nodeId, final InputStream input,
        final EIdAccessType type);  }