com.orientechnologies.orient.core.storage.ORecordDuplicatedException Java Examples

The following examples show how to use com.orientechnologies.orient.core.storage.ORecordDuplicatedException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: OrientKeyStoreDataEntityAdapterTest.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@Test(expected = ORecordDuplicatedException.class)
public void testIndex_EnforceUniqueName() {
  try (ODatabaseDocumentTx db = database.getInstance().connect()) {
    entityAdapter.register(db);

    OrientKeyStoreData entity = new OrientKeyStoreData();
    entity.setName(KEY_STORE_NAME);
    entity.setBytes(KEY_STORE_DATA);
    entityAdapter.save(db, entity);

    entity = new OrientKeyStoreData();
    entity.setName(KEY_STORE_NAME);
    entity.setBytes(KEY_STORE_DATA);
    entityAdapter.addEntity(db, entity);
  }
}
 
Example #2
Source File: OrientApiKeyStore.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@Override
@Guarded(by = STARTED)
public char[] createApiKey(final String domain, final PrincipalCollection principals) {
  checkNotNull(domain);
  checkNotNull(principals);
  try {
    final char[] apiKeyCharArray = makeApiKey(domain, principals);
    persistApiKey(domain, principals, apiKeyCharArray);
    return apiKeyCharArray;
  }
  catch (ORecordDuplicatedException e) { // NOSONAR
    // There is a chance here that if multiple threads enter this method for the same principal that create can be
    // called multiple times resulting in a ORecordDuplicatedException. In that case we know the record must already
    // exist and can call getApiKey again. This avoids locking and gives us eventual-consistency.
    return getApiKey(domain, principals);
  }
}
 
Example #3
Source File: OrientSecurityConfigurationSource.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void addRole(final CRole role) {
  checkNotNull(role);
  checkNotNull(role.getId());
  checkRole(role);
  log.trace("Adding role: {}", role.getId());

  try {
    inTxRetry(databaseInstance).run(db -> {
      if (roleEntityAdapter.read(db, role.getId()) != null) {
        throw new DuplicateRoleException(role.getId());
      }
      roleEntityAdapter.addEntity(db, (OrientCRole) role);
    });
  }
  catch (ORecordDuplicatedException e) {
    throw new DuplicateRoleException(role.getId(), e);
  }
}
 
Example #4
Source File: OVertexTransformer.java    From orientdb-etl with Apache License 2.0 6 votes vote down vote up
@Override
public Object executeTransform(final Object input) {
  vertexClass = (String) resolve(vertexClass);
  if (vertexClass != null) {
    final OClass cls = pipeline.getGraphDatabase().getVertexType(vertexClass);
    if (cls == null)
      pipeline.getGraphDatabase().createVertexType(vertexClass);
  }

  final OrientVertex v = pipeline.getGraphDatabase().getVertex(input);
  if (v == null)
    return null;

  if (vertexClass != null && !vertexClass.equals(v.getRecord().getClassName()))
    try {
      v.setProperty("@class", vertexClass);
    } catch (ORecordDuplicatedException e) {
      if (skipDuplicates) {
        return null;
      } else {
        throw e;
      }
    }
  return v;
}
 
Example #5
Source File: OrientCleanupPolicyStorageTest.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Test(expected = ORecordDuplicatedException.class)
public void whenUsingDuplicateNameShouldNotBeCreated() throws Exception {
  underTest.add(item);

  underTest.add(
      new OrientCleanupPolicy(item.getName(), "abcd", "OtherFormat", "OtherMode",
          newHashMap()));
}
 
Example #6
Source File: OrientBrowseNodeStoreImpl.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Override
@Guarded(by = STARTED)
public void createComponentNode(final String repositoryName,
                                final String format,
                                final List<BrowsePath> paths,
                                final Component component)
{
  inTxRetry(databaseInstance)
      // handle case where assets try to create the exact same component-level path at once
      .retryOn(ONeedRetryException.class, ORecordDuplicatedException.class)
      .run(db -> entityAdapter.createComponentNode(db, repositoryName, format, paths, component));
}
 
Example #7
Source File: OrientBrowseNodeStoreImpl.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Override
@Guarded(by = STARTED)
public void createAssetNode(final String repositoryName,
                            final String format,
                            final List<BrowsePath> paths,
                            final Asset asset)
{
  inTxRetry(databaseInstance)
      // handle case where an asset and its component try to create the exact same path at once
      .retryOn(ONeedRetryException.class, ORecordDuplicatedException.class)
      .run(db -> entityAdapter.createAssetNode(db, repositoryName, format, paths, asset));
}
 
Example #8
Source File: OrientSecurityConfigurationSource.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public CPrivilege addPrivilege(final CPrivilege privilege) {
  checkNotNull(privilege);
  checkNotNull(privilege.getId());
  log.trace("Adding privilege: {}", privilege.getId());

  try {
    OrientCPrivilege persistedPrivilege = convert(privilege);
    inTxRetry(databaseInstance).run(db -> privilegeEntityAdapter.addEntity(db, persistedPrivilege));
    return persistedPrivilege;
  }
  catch (ORecordDuplicatedException e) {
    throw new DuplicatePrivilegeException(privilege.getId(), e);
  }
}
 
Example #9
Source File: OrientRoutingRuleStore.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
private void persist(BiConsumer<ODatabaseDocumentTx, OrientRoutingRule> entityFunction, RoutingRule rule) {
  try {
    inTxRetry(databaseInstance).run(db -> entityFunction.accept(db, castToOrientRoutingRule(rule)));
  }
  catch (ORecordDuplicatedException e) {
    if (OrientRoutingRuleEntityAdapter.I_NAME.equals(e.getIndexName())) {
      throw new ValidationErrorsException("name", "A rule with the same name already exists. Name must be unique.");
    }
    throw e;
  }
}
 
Example #10
Source File: Module.java    From Orienteer with Apache License 2.0 5 votes vote down vote up
private void makeDataItem(String oClass, String name, String alias){
	try {
		ODocument doc = new ODocument(oClass);
		doc.field("name",name);
		doc.field("alias",alias);
		doc.save();		
	} catch (ORecordDuplicatedException e) {
		//ignore duplication
	}
}
 
Example #11
Source File: StorageFacetImplIT.java    From nexus-public with Eclipse Public License 1.0 4 votes vote down vote up
@Test(expected = ORecordDuplicatedException.class)
public void duplicateComponentName() throws Exception {
  createComponent(null, "name", null);
  createComponent(null, "name", null);
}
 
Example #12
Source File: StorageFacetImplIT.java    From nexus-public with Eclipse Public License 1.0 4 votes vote down vote up
@Test(expected = ORecordDuplicatedException.class)
public void duplicateComponentGroupName() throws Exception {
  createComponent("group", "name", null);
  createComponent("group", "name", null);
}
 
Example #13
Source File: StorageFacetImplIT.java    From nexus-public with Eclipse Public License 1.0 4 votes vote down vote up
@Test(expected = ORecordDuplicatedException.class)
public void duplicateComponentNameVersion() throws Exception {
  createComponent(null, "name", "1");
  createComponent(null, "name", "1");
}
 
Example #14
Source File: StorageFacetImplIT.java    From nexus-public with Eclipse Public License 1.0 4 votes vote down vote up
@Test(expected = ORecordDuplicatedException.class)
public void duplicateComponentGroupNameVersion() throws Exception {
  createComponent("group", "name", "1");
  createComponent("group", "name", "1");
}
 
Example #15
Source File: StorageFacetImplIT.java    From nexus-public with Eclipse Public License 1.0 4 votes vote down vote up
@Test(expected = ORecordDuplicatedException.class)
public void duplicateAssetComponentName() throws Exception {
  Component component = createComponent("group", "name", "1");
  createAsset(component, "name");
  createAsset(component, "name");
}
 
Example #16
Source File: StorageFacetImplIT.java    From nexus-public with Eclipse Public License 1.0 4 votes vote down vote up
@Test(expected = ORecordDuplicatedException.class)
public void duplicateAssetName() throws Exception {
  createAsset(null, "name");
  createAsset(null, "name");
}