@Override public void initialiseInternal(final DataAccessLayerFactory factory) throws InitialisationException { _soIndex = new BIndex("DICT_SO"); _soIndex.initialise(factory); _pIndex = new BIndex("DICT_P"); _pIndex.initialise(factory); }
@Override protected byte[] getIdInternal(final String value, final boolean p) throws DataAccessLayerException { if (value.trim().length() == 0) { return EMPTY_VALUE; } byte[] id = null; synchronized (this) { id = _index.get(value); if (id[0] == NOT_SET[0]) { id = newId(value, _index); _index.putQuick(value, id); } } RUNTIME_CONTEXTS.get().isFirstLevelResult = true; return id; }
@Override protected String getValueInternal(final byte[] id, final boolean p) throws DataAccessLayerException { RUNTIME_CONTEXTS.get().isFirstLevelResult = true; return _index.getQuick(id); } }
/** * Positive test for getID() method. * * @throws Exception never otherwise the test fails. */ @Test public void getIDNotPreviouslySet() throws Exception { when(_dummyIndex.contains(any(byte[].class))).thenReturn(false); final String aValue = randomString(); when(_dummyIndex.get(aValue)).thenReturn(IDictionary.NOT_SET); byte[] result = _cut.getID(aValue, RANDOMIZER.nextBoolean()); assertEquals(PersistentStringDictionary.ID_LENGTH, result.length); verify(_dummyIndex).get(aValue); verify(_dummyIndex).putQuick(aValue, result); }
@Override public void removeValue(final String value, final boolean p) throws DataAccessLayerException { _index.remove(value); } }
/** * 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); }
/** * Returns the identifier of a given N3 resource. * * @param n3 the resource (N3 representation). * @param p a flag indicating if the resource is a predicate. * @return the identifier of the given resource. * @throws DataAccessLayerException in case of data access failure. */ protected byte[] getID(final String n3, final boolean p) throws DataAccessLayerException { return (n3 == null || n3.isEmpty() || n3.charAt(0) == '?') ? null : p ? _pIndex.get(n3) : _soIndex.get(n3); }
/** * Creates and initializes the underlying index. * * @return the underlying index. */ protected BIndex createIndex() { return new BIndex(_indexName); }
/** * Creates a new identifier for a given resource. * The method takes care about (eventual) hash collision. * * @param value the resource. * @param n3 the N3 representation of resource. * @param index the dictionary index that could already hold that resource / id. * @return a new identifier for the given resource. * @throws DataAccessLayerException in case of data access failure. */ private byte[] newId(final Value value, final String n3, final BIndex index) throws DataAccessLayerException { byte[] id = makeNewHashID(value, n3); for (int i = 0; index.contains(id) && i <= 100; i++) { id = resolveHashCollision(id, i); if (i == 100) { _log.error(MessageCatalog._00071_UNABLE_TO_RESOLVE_COLLISION, n3, i); } } return id; }
@Override protected byte[] getIdInternal(final Value value, final boolean p) throws DataAccessLayerException { final String n3 = NTriplesUtil.toNTriplesString(value); byte[] id = null; synchronized (this) { id = value != null ? getID(NTriplesUtil.toNTriplesString(value), p) : null; if (id[0] == NOT_SET[0]) { final BIndex index = p ? _pIndex : _soIndex; id = newId(value, n3, index); index.putQuick(n3, id); } } return id; }
@Override protected final void initialiseInternal(final DataAccessLayerFactory factory) throws InitialisationException { _index = createIndex(); _index.initialise(factory); }
@Override public void removeValue(final String value, final boolean p) throws DataAccessLayerException { _index.remove(value); } }
/** * Returns the identifier of a given N3 resource. * * @param n3 the resource (N3 representation). * @param p a flag indicating if the resource is a predicate. * @return the identifier of the given resource. * @throws DataAccessLayerException in case of data access failure. */ protected byte[] getID(final String n3, final boolean p) throws DataAccessLayerException { return (n3 == null || n3.isEmpty() || n3.charAt(0) == '?') ? null : p ? _pIndex.get(n3) : _soIndex.get(n3); }
/** * Creates the underlying index. * * @return the underlying index. */ protected BIndex createIndex() { return new BIndex(_indexName); }
/** * Creates a new identifier for a given resource. * The method takes care about (eventual) hash collision. * * @param n3 the N3 representation of resource. * @param index the dictionary index that could already hold that resource / id. * @return a new identifier for the given resource. * @throws DataAccessLayerException in case of data access failure. */ protected byte[] newId(final String n3, final BIndex index) throws DataAccessLayerException { byte[] id = makeNewHashID(n3); for (int i = 0; index.contains(id) && i <= 100; i++) { id = resolveHashCollision(id, i); if (i == 100) { _log.error(MessageCatalog._00071_UNABLE_TO_RESOLVE_COLLISION, n3, i); } } return id; }
@Override protected byte[] getIdInternal(final Value value, final boolean p) throws DataAccessLayerException { final String n3 = NTriplesUtil.toNTriplesString(value); byte[] id = null; synchronized (this) { id = value != null ? getID(NTriplesUtil.toNTriplesString(value), p) : null; if (id[0] == NOT_SET[0]) { final BIndex index = p ? _pIndex : _soIndex; id = newId(value, n3, index); index.putQuick(n3, id); } } return id; }
@Override protected void initialiseInternal(final DataAccessLayerFactory factory) throws InitialisationException { _index = createIndex(); _index.initialise(factory); }
@Override protected byte[] getIdInternal(final String value, final boolean p) throws DataAccessLayerException { if (value.trim().length() == 0) { return EMPTY_VALUE; } byte[] id = null; synchronized (this) { id = _index.get(value); if (id[0] == NOT_SET[0]) { id = newId(value, _index); _index.putQuick(value, id); } } RUNTIME_CONTEXTS.get().isFirstLevelResult = true; return id; }
@Override protected String getValueInternal(final byte[] id, final boolean p) throws DataAccessLayerException { RUNTIME_CONTEXTS.get().isFirstLevelResult = true; return _index.getQuick(id); } }