/** * Returns the value associated with the given identifier. * * @param id the identifier. * @return the value associated with the given identifier, null in case no value is found. * @throws DataAccessLayerException in case of data access failure. */ private Value getValue(final byte[] id) throws DataAccessLayerException { return _dict.getValue(id, _p); }
/** * Returns the value associated with the given identifier. * * @param id the identifier. * @return the value associated with the given identifier, null in case no value is found. * @throws DataAccessLayerException in case of data access failure. */ private Value getValue(final byte[] id) throws DataAccessLayerException { return _dict.getValue(id, _p); }
@Override protected Value getValueInternal(final byte[] id, final boolean p) throws DataAccessLayerException { final ByteBuffer key = ByteBuffer.wrap(id); Value value = _id2node_cache.get(key); if (value == null) { value = _decoratee.getValue(id, p); _cacheStrategy.cacheId(key, value); } else { _valueHitsCount.incrementAndGet(); } return value; }
@Override protected Value getValueInternal(final byte[] id, final boolean p) throws DataAccessLayerException { final ByteBuffer key = ByteBuffer.wrap(id); Value value = _id2node_cache.get(key); if (value == null) { value = _decoratee.getValue(id, p); _cacheStrategy.cacheId(key, value); } else { _valueHitsCount.incrementAndGet(); } return value; }
@Override protected Value getValueInternal(final byte[] id, final boolean p) throws DataAccessLayerException { if (id[0] == KNOWN_URI_MARKER && id.length == ID_LENGTH) { RUNTIME_CONTEXTS.get().isFirstLevelResult = true; _valueknownURIsHitsCount.incrementAndGet(); return NTriplesUtil.parseResource(getN3(id, p), SESAME_VALUE_FACTORY); } else { RUNTIME_CONTEXTS.get().isFirstLevelResult = false; return _decoratee.getValue(id, p); } }
@Override protected Value getValueInternal(final byte[] id, final boolean p) throws DataAccessLayerException { if (id[0] == KNOWN_URI_MARKER && id.length == ID_LENGTH) { RUNTIME_CONTEXTS.get().isFirstLevelResult = true; _valueknownURIsHitsCount.incrementAndGet(); return NTriplesUtil.parseResource(getN3(id, p), SESAME_VALUE_FACTORY); } else { RUNTIME_CONTEXTS.get().isFirstLevelResult = false; return _decoratee.getValue(id, p); } }
@Override public Value getValueInternal(final byte[] id, final boolean p) throws DataAccessLayerException { switch (id[0]) { case THRESHOLD_EXCEEDED: RUNTIME_CONTEXTS.get().isFirstLevelResult = false; return _longLiteralsDictionary.getValue(subarray(id, 1, id.length - 1), p); default: RUNTIME_CONTEXTS.get().isFirstLevelResult = true; final String n3 = new String(id, 2, id.length - 2, CHARSET_UTF8); if (id[1] == RESOURCE_BYTE_FLAG) { return NTriplesUtil.parseResource(n3, SESAME_VALUE_FACTORY); } else if (id[1] == LITERAL_BYTE_FLAG) { return NTriplesUtil.parseLiteral(n3, SESAME_VALUE_FACTORY); } else { return NTriplesUtil.parseBNode(n3, SESAME_VALUE_FACTORY); } } }
@Override public Value getValueInternal(final byte[] id, final boolean p) throws DataAccessLayerException { switch (id[0]) { case THRESHOLD_EXCEEDED: RUNTIME_CONTEXTS.get().isFirstLevelResult = false; return _longLiteralsDictionary.getValue(subarray(id, 1, id.length - 1), p); default: RUNTIME_CONTEXTS.get().isFirstLevelResult = true; final String n3 = new String(id, 2, id.length - 2, CHARSET_UTF8); if (id[1] == RESOURCE_BYTE_FLAG) { return NTriplesUtil.parseResource(n3, SESAME_VALUE_FACTORY); } else if (id[1] == LITERAL_BYTE_FLAG) { return NTriplesUtil.parseLiteral(n3, SESAME_VALUE_FACTORY); } else { return NTriplesUtil.parseBNode(n3, SESAME_VALUE_FACTORY); } } }
/** * Loads data associated with this URI. */ private synchronized void load() { if (_has_data) { return; } // load data ... try { final URI uri = (URI) _dictionary.getValue(_internalID, _p); super.setURIString(uri.stringValue()); } catch (final Exception exception) { _log.error(MessageCatalog._00075_COULDNT_LOAD_NODE, exception, Arrays.toString(_internalID)); super.setURIString("http://cumulus/internal/" + Arrays.toString(_internalID)); } _has_data = true; }
/** * Loads data associated with this blank node. */ private synchronized void load() { if (_has_data) { return; } // load data ... try { final BNode bnode = (BNode) _dict.getValue(_internalID, false); super.setID(bnode.getID()); } catch (final Exception exception) { _log.error(MessageCatalog._00075_COULDNT_LOAD_NODE, exception, Arrays.toString(_internalID)); super.setID("cumulus/internal/" + Arrays.toString(_internalID)); } _has_data = true; }
/** * Loads data associated with this blank node. */ private synchronized void load() { if (_has_data) { return; } // load data ... try { final BNode bnode = (BNode) _dict.getValue(_internalID, false); super.setID(bnode.getID()); } catch (final Exception exception) { _log.error(MessageCatalog._00075_COULDNT_LOAD_NODE, exception, Arrays.toString(_internalID)); super.setID("cumulus/internal/" + Arrays.toString(_internalID)); } _has_data = true; }
/** * Loads data associated with this URI. */ private synchronized void load() { if (_has_data) { return; } // load data ... try { final URI uri = (URI) _dictionary.getValue(_internalID, _p); super.setURIString(uri.stringValue()); } catch (final Exception exception) { _log.error(MessageCatalog._00075_COULDNT_LOAD_NODE, exception, Arrays.toString(_internalID)); super.setURIString("http://cumulus/internal/" + Arrays.toString(_internalID)); } _has_data = true; }
/** * Identifiers for bnodes and literals must be handled by the decoratee. * * @throws Exception never otherwise the test fails. */ @Test public void getValueWithIgnorableId() throws Exception { final int length = RANDOMIZER.nextInt(KnownURIsDictionary.ID_LENGTH) + 10; byte[] ignorableId = new byte[length]; RANDOMIZER.nextBytes(ignorableId); _cut.getValue(ignorableId, _isPredicate); verify(_decoratee).getValue(ignorableId, _isPredicate); }
/** * Tests ID creation and caching. * * @throws Exception never otherwise the test fails. */ @Test public void getValue() throws Exception { when(_decoratee.getValue(_id, false)).thenReturn(_aValue); assertTrue(_cut._id2node_cache.isEmpty()); assertEquals(_aValue, _cut.getValue(_id, false)); assertEquals(_aValue, _cut._id2node_cache.get(ByteBuffer.wrap(_id))); verify(_decoratee).getValue(_id, false); }
@Override protected Value getValueInternal(final byte[] id, final boolean p) throws DataAccessLayerException { if (id[0] == MARKER) { return SESAME_VALUE_FACTORY.createURI( _namespaces.getValue(subarray(id, 1, 8), p), _localNames.getValue(subarray(id, 9, id.length - 9), p)); } else { return _bNodesAndLiterals.getValue(id, p); } }
@Override protected Value getValueInternal(final byte[] id, final boolean p) throws DataAccessLayerException { if (id[0] == MARKER) { return SESAME_VALUE_FACTORY.createURI( _namespaces.getValue(subarray(id, 1, 8), p), _localNames.getValue(subarray(id, 9, id.length - 9), p)); } else { return _bNodesAndLiterals.getValue(id, p); } }
/** * Loads data associated with this literal. */ private synchronized void load() { if (_has_data) { return; } // load data ... try { Literal lit = (Literal) _dict.getValue(_internalID, false); super.setDatatype(lit.getDatatype()); super.setLabel(lit.getLabel()); super.setLanguage(lit.getLanguage()); } catch (final Exception exception) { _log.error(MessageCatalog._00075_COULDNT_LOAD_NODE, exception, Arrays.toString(_internalID)); super.setLabel("cumulus/internal/" + Arrays.toString(_internalID)); } _has_data = true; }
/** * Loads data associated with this literal. */ private synchronized void load() { if (_has_data) { return; } // load data ... try { Literal lit = (Literal) _dict.getValue(_internalID, false); super.setDatatype(lit.getDatatype()); super.setLabel(lit.getLabel()); super.setLanguage(lit.getLanguage()); } catch (final Exception exception) { _log.error(MessageCatalog._00075_COULDNT_LOAD_NODE, exception, Arrays.toString(_internalID)); super.setLabel("cumulus/internal/" + Arrays.toString(_internalID)); } _has_data = true; }
/** * Identifiers for managed URI must be be directly served by the dictionary, without involving the decoratee. * * @throws Exception never otherwise the test fails. */ @Test public void getURIWithManagedId() throws Exception { final URI managedUri = buildResource(FOAF.NAMESPACE + System.currentTimeMillis()); final String n3 = NTriplesUtil.toNTriplesString(managedUri); when(_dummyIndex.getQuick(any(byte[].class))).thenReturn(n3); when(_dummyIndex.get(n3)).thenReturn(ValueDictionaryBase.NOT_SET); byte[] id = _cut.getID(managedUri, _isPredicate); final Value value = _cut.getValue(id, _isPredicate); assertEquals(managedUri, value); verify(_decoratee, times(0)).getValue(id, _isPredicate); }
final Literal lit = (Literal) _dictionary.getValue(ids[2], false); final URI dt = lit.getDatatype();