org.apache.jackrabbit.core.data.DataStore.getRecordIfStored()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(11.7k)|赞(0)|评价(0)|浏览(123)

本文整理了Java中org.apache.jackrabbit.core.data.DataStore.getRecordIfStored()方法的一些代码示例,展示了DataStore.getRecordIfStored()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。DataStore.getRecordIfStored()方法的具体详情如下:
包路径:org.apache.jackrabbit.core.data.DataStore
类名称:DataStore
方法名:getRecordIfStored

DataStore.getRecordIfStored介绍

[英]Check if a record for the given identifier exists, and return it if yes. If no record exists, this method returns null.
[中]检查给定标识符的记录是否存在,如果存在则返回。如果不存在记录,此方法将返回null。

代码示例

代码示例来源:origin: org.apache.jackrabbit/jackrabbit-data

/**
 * Check if a record for the given identifier exists in the primary data
 * store. If not found there it will be returned from the archive data
 * store. If no record exists, this method returns null.
 * 
 * @param identifier
 *            data identifier
 * @return the record if found, and null if not
 */
public DataRecord getRecordIfStored(DataIdentifier identifier) throws DataStoreException {
  if (moveDataTaskRunning) {
    moveDataTaskLock.lock();
  }
  try {
    DataRecord dataRecord = primaryDataStore.getRecordIfStored(identifier);
    if (dataRecord == null) {
      dataRecord = archiveDataStore.getRecordIfStored(identifier);
    }
    return dataRecord;
  } finally {
    if (moveDataTaskRunning) {
      moveDataTaskLock.unlock();
    }
  }
}

代码示例来源:origin: apache/jackrabbit

/**
 * Check if a record for the given identifier exists in the primary data
 * store. If not found there it will be returned from the archive data
 * store. If no record exists, this method returns null.
 * 
 * @param identifier
 *            data identifier
 * @return the record if found, and null if not
 */
public DataRecord getRecordIfStored(DataIdentifier identifier) throws DataStoreException {
  if (moveDataTaskRunning) {
    moveDataTaskLock.lock();
  }
  try {
    DataRecord dataRecord = primaryDataStore.getRecordIfStored(identifier);
    if (dataRecord == null) {
      dataRecord = archiveDataStore.getRecordIfStored(identifier);
    }
    return dataRecord;
  } finally {
    if (moveDataTaskRunning) {
      moveDataTaskLock.unlock();
    }
  }
}

代码示例来源:origin: org.apache.sling/org.apache.sling.testing.sling-mock-oak

/**
 * Check if a record for the given identifier exists in the primary data
 * store. If not found there it will be returned from the archive data
 * store. If no record exists, this method returns null.
 * 
 * @param identifier
 *            data identifier
 * @return the record if found, and null if not
 */
public DataRecord getRecordIfStored(DataIdentifier identifier) throws DataStoreException {
  if (moveDataTaskRunning) {
    moveDataTaskLock.lock();
  }
  try {
    DataRecord dataRecord = primaryDataStore.getRecordIfStored(identifier);
    if (dataRecord == null) {
      dataRecord = archiveDataStore.getRecordIfStored(identifier);
    }
    return dataRecord;
  } finally {
    if (moveDataTaskRunning) {
      moveDataTaskLock.unlock();
    }
  }
}

代码示例来源:origin: apache/jackrabbit-oak

@Override
public String getReference(@NotNull String encodedBlobId) {
  checkNotNull(encodedBlobId);
  String blobId = extractBlobId(encodedBlobId);
  //Reference are not created for in memory record
  if (InMemoryDataRecord.isInstance(blobId)) {
    return null;
  }
  DataRecord record;
  try {
    record = delegate.getRecordIfStored(new DataIdentifier(blobId));
    if (record != null) {
      return record.getReference();
    } else {
      log.debug("No blob found for id [{}]", blobId);
    }
  } catch (DataStoreException e) {
    log.warn("Unable to access the blobId for  [{}]", blobId, e);
  }
  return  null;
}

代码示例来源:origin: org.apache.jackrabbit/oak-blob-plugins

@Override
public String getReference(@NotNull String encodedBlobId) {
  checkNotNull(encodedBlobId);
  String blobId = extractBlobId(encodedBlobId);
  //Reference are not created for in memory record
  if (InMemoryDataRecord.isInstance(blobId)) {
    return null;
  }
  DataRecord record;
  try {
    record = delegate.getRecordIfStored(new DataIdentifier(blobId));
    if (record != null) {
      return record.getReference();
    } else {
      log.debug("No blob found for id [{}]", blobId);
    }
  } catch (DataStoreException e) {
    log.warn("Unable to access the blobId for  [{}]", blobId, e);
  }
  return  null;
}

代码示例来源:origin: org.apache.jackrabbit/oak-upgrade

@Override
public String getReference(@NotNull String encodedBlobId) {
  checkNotNull(encodedBlobId);
  String blobId = extractBlobId(encodedBlobId);
  //Reference are not created for in memory record
  if (InMemoryDataRecord.isInstance(blobId)) {
    return null;
  }
  DataRecord record;
  try {
    record = delegate.getRecordIfStored(new DataIdentifier(blobId));
    if (record != null) {
      return record.getReference();
    } else {
      log.debug("No blob found for id [{}]", blobId);
    }
  } catch (DataStoreException e) {
    log.warn("Unable to access the blobId for  [{}]", blobId, e);
  }
  return  null;
}

代码示例来源:origin: apache/jackrabbit-oak

@Override
public String getReference(@NotNull String encodedBlobId) {
  checkNotNull(encodedBlobId);
  String blobId = extractBlobId(encodedBlobId);
  //Reference are not created for in memory record
  if (InMemoryDataRecord.isInstance(blobId)) {
    return null;
  }
  DataRecord record;
  try {
    record = delegate.getRecordIfStored(new DataIdentifier(blobId));
    if (record != null) {
      return record.getReference();
    } else {
      log.debug("No blob found for id [{}]", blobId);
    }
  } catch (DataStoreException e) {
    log.warn("Unable to access the blobId for  [{}]", blobId, e);
  }
  return  null;
}

代码示例来源:origin: apache/jackrabbit-oak

@Override
public DataRecord getRecordIfStored(DataIdentifier identifier) throws DataStoreException {
  if (isInMemoryRecord(identifier)) {
    return getDataRecord(identifier.toString());
  }
  return delegate.getRecordIfStored(identifier);
}

代码示例来源:origin: apache/jackrabbit-oak

@Override
  protected DataRecord getDataRecord(String blobId) throws DataStoreException {
    DataRecord id;
    if (InMemoryDataRecord.isInstance(blobId)) {
      id = InMemoryDataRecord.getInstance(blobId);
    } else {
      id = delegate.getRecordIfStored(new DataIdentifier(blobId));
    }
    return id;
  }
}

代码示例来源:origin: org.apache.sling/org.apache.sling.testing.sling-mock-oak

@Override
public String getReference(@Nonnull String encodedBlobId) {
  checkNotNull(encodedBlobId);
  String blobId = extractBlobId(encodedBlobId);
  //Reference are not created for in memory record
  if (InMemoryDataRecord.isInstance(blobId)) {
    return null;
  }
  DataRecord record;
  try {
    record = delegate.getRecordIfStored(new DataIdentifier(blobId));
    if (record != null) {
      return record.getReference();
    } else {
      log.debug("No blob found for id [{}]", blobId);
    }
  } catch (DataStoreException e) {
    log.warn("Unable to access the blobId for  [{}]", blobId, e);
  }
  return  null;
}

代码示例来源:origin: org.apache.jackrabbit/oak-blob-plugins

@Override
public DataRecord getRecordIfStored(DataIdentifier identifier) throws DataStoreException {
  if (isInMemoryRecord(identifier)) {
    return getDataRecord(identifier.toString());
  }
  return delegate.getRecordIfStored(identifier);
}

代码示例来源:origin: org.apache.sling/org.apache.sling.testing.sling-mock-oak

@Override
public DataRecord getRecordIfStored(DataIdentifier identifier) throws DataStoreException {
  if (isInMemoryRecord(identifier)) {
    return getDataRecord(identifier.toString());
  }
  return delegate.getRecordIfStored(identifier);
}

代码示例来源:origin: org.apache.jackrabbit/oak-upgrade

@Override
  protected DataRecord getDataRecord(String blobId) throws DataStoreException {
    DataRecord id;
    if (InMemoryDataRecord.isInstance(blobId)) {
      id = InMemoryDataRecord.getInstance(blobId);
    } else {
      id = delegate.getRecordIfStored(new DataIdentifier(blobId));
    }
    return id;
  }
}

代码示例来源:origin: apache/jackrabbit-oak

@Override
public DataRecord getRecordIfStored(DataIdentifier dataIdentifier) throws DataStoreException {
  if (existingMappings.containsKey(dataIdentifier.toString())) {
    return new DelegateDataRecord(this, dataIdentifier, existingMappings);
  } else if (newMappings.containsKey(dataIdentifier.toString())) {
    return new DelegateDataRecord(this, dataIdentifier, newMappings);
  }
  DataRecord result = getDelegate().getRecordIfStored(dataIdentifier);
  addNewMapping(result);
  return result;
}

代码示例来源:origin: org.apache.jackrabbit/oak-upgrade

@Override
public DataRecord getRecordIfStored(DataIdentifier dataIdentifier) throws DataStoreException {
  if (existingMappings.containsKey(dataIdentifier.toString())) {
    return new DelegateDataRecord(this, dataIdentifier, existingMappings);
  } else if (newMappings.containsKey(dataIdentifier.toString())) {
    return new DelegateDataRecord(this, dataIdentifier, newMappings);
  }
  DataRecord result = getDelegate().getRecordIfStored(dataIdentifier);
  addNewMapping(result);
  return result;
}

代码示例来源:origin: apache/jackrabbit

/**
 * Get the internal value for this blob.
 *
 * @param identifier the identifier
 * @param store the data store
 * @param verify verify if the record exists, and return null if not
 * @return the internal value or null
 */
static InternalValue getInternalValue(DataIdentifier identifier, DataStore store, boolean verify) throws DataStoreException {
  if (verify) {
    if (store.getRecordIfStored(identifier) == null) {
      return null;
    }
  } else {
    // access the record to ensure it is not garbage collected
    store.getRecord(identifier);
  }
  // it exists - so we don't need to stream it again
  // but we need to create a new object because the original
  // one might be in a different data store (repository)
  BLOBFileValue blob = BLOBInDataStore.getInstance(store, identifier);
  return new InternalValue(blob);
}

代码示例来源:origin: org.apache.jackrabbit/jackrabbit-core

/**
 * Get the internal value for this blob.
 *
 * @param identifier the identifier
 * @param store the data store
 * @param verify verify if the record exists, and return null if not
 * @return the internal value or null
 */
static InternalValue getInternalValue(DataIdentifier identifier, DataStore store, boolean verify) throws DataStoreException {
  if (verify) {
    if (store.getRecordIfStored(identifier) == null) {
      return null;
    }
  } else {
    // access the record to ensure it is not garbage collected
    store.getRecord(identifier);
  }
  // it exists - so we don't need to stream it again
  // but we need to create a new object because the original
  // one might be in a different data store (repository)
  BLOBFileValue blob = BLOBInDataStore.getInstance(store, identifier);
  return new InternalValue(blob);
}

代码示例来源:origin: apache/jackrabbit-oak

/**
 * Test {@link MultiDataStoreAware#deleteRecord(DataIdentifier)}.
 */
protected void doDeleteRecordTest() throws Exception {
  Random random = randomGen;
  byte[] data1 = new byte[dataLength];
  random.nextBytes(data1);
  DataRecord rec1 = ds.addRecord(new ByteArrayInputStream(data1));
  byte[] data2 = new byte[dataLength];
  random.nextBytes(data2);
  DataRecord rec2 = ds.addRecord(new ByteArrayInputStream(data2));
  byte[] data3 = new byte[dataLength];
  random.nextBytes(data3);
  DataRecord rec3 = ds.addRecord(new ByteArrayInputStream(data3));
  ((MultiDataStoreAware)ds).deleteRecord(rec1.getIdentifier());
  assertNull("rec1 should be null",
    ds.getRecordIfStored(rec1.getIdentifier()));
  assertEquals(new ByteArrayInputStream(data2),
    ds.getRecord(rec2.getIdentifier()).getStream());
  assertEquals(new ByteArrayInputStream(data3),
    ds.getRecord(rec3.getIdentifier()).getStream());
}

代码示例来源:origin: apache/jackrabbit-oak

@Test
public void testReference() throws DataStoreException, IOException {
  String reference = "testReference";
  String blobId = "test";
  DataIdentifier testDI = new DataIdentifier(blobId);
  DataRecord testDR = new ByteArrayDataRecord("foo".getBytes(), testDI, reference);
  DataStore mockedDS = mock(DataStore.class);
  when(mockedDS.getRecordFromReference(reference)).thenReturn(testDR);
  when(mockedDS.getRecord(testDI)).thenReturn(testDR);
  when(mockedDS.getRecordIfStored(testDI)).thenReturn(testDR);
  DataStoreBlobStore ds = new DataStoreBlobStore(mockedDS);
  assertEquals(reference,ds.getReference(blobId));
  assertEquals(blobId, BlobId.of(ds.getBlobId(reference)).blobId);
  assertEquals(BlobId.of(testDR).encodedValue(),ds.getBlobId(reference));
  String inMemBlobId = InMemoryDataRecord.getInstance("foo".getBytes())
      .getIdentifier().toString();
  //For in memory record the reference should be null
  assertNull(ds.getReference(inMemBlobId));
}

代码示例来源:origin: apache/jackrabbit

/**
 * Test {@link MultiDataStoreAware#deleteRecord(DataIdentifier)}.
 */
protected void doDeleteRecordTest() throws Exception {
  ds = createDataStore();
  Random random = randomGen;
  byte[] data1 = new byte[dataLength];
  random.nextBytes(data1);
  DataRecord rec1 = ds.addRecord(new ByteArrayInputStream(data1));
  byte[] data2 = new byte[dataLength];
  random.nextBytes(data2);
  DataRecord rec2 = ds.addRecord(new ByteArrayInputStream(data2));
  byte[] data3 = new byte[dataLength];
  random.nextBytes(data3);
  DataRecord rec3 = ds.addRecord(new ByteArrayInputStream(data3));
  ((MultiDataStoreAware)ds).deleteRecord(rec2.getIdentifier());
  assertNull("rec2 should be null",
    ds.getRecordIfStored(rec2.getIdentifier()));
  assertEquals(new ByteArrayInputStream(data1),
    ds.getRecord(rec1.getIdentifier()).getStream());
  assertEquals(new ByteArrayInputStream(data3),
    ds.getRecord(rec3.getIdentifier()).getStream());
  ds.close();
}

相关文章