com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx Java Examples

The following examples show how to use com.orientechnologies.orient.core.db.document.ODatabaseDocumentTx. 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: SecurityDatabaseUpgrade_1_3Test.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void testApply() {
  try (ODatabaseDocumentTx securityDb = securityDatabase.getInstance().connect()) {
    createPrivilege("a_test_priv", "read,edit,delete,add");
    createPrivilege("b_test_priv", "mark,read,edit,delete");
    createPrivilege("c_test_priv", "create,read,edit,delete,add");
    createPrivilege("d_test_priv", "mark,read,edit,delete,create");
  }

  underTest.apply();

  try (ODatabaseDocumentTx securityDb = securityDatabase.getInstance().connect()) {
    List<ODocument> result = securityDb.command(new OCommandSQL("select from privilege")).execute();
    assertThat(result.size(), is(4));
    assertThat(result.get(0).field(P_NAME), is("a_test_priv"));
    assertThat(result.get(0).field(P_PROPERTIES), hasEntry(is("actions"), is("read,edit,delete,create")));
    assertThat(result.get(1).field(P_NAME), is("b_test_priv"));
    assertThat(result.get(1).field(P_PROPERTIES), hasEntry(is("actions"), is("read,edit,delete,create")));
    assertThat(result.get(2).field(P_NAME), is("c_test_priv"));
    assertThat(result.get(2).field(P_PROPERTIES), hasEntry(is("actions"), is("create,read,edit,delete")));
    assertThat(result.get(3).field(P_NAME), is("d_test_priv"));
    assertThat(result.get(3).field(P_PROPERTIES), hasEntry(is("actions"), is("read,edit,delete,create")));
  }
}
 
Example #2
Source File: ComponentDatabaseUpgrade_1_2_Test.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@Before
public void setUp() {
  try (ODatabaseDocumentTx db = componentDatabase.getInstance().connect()) {
    OSchema schema = db.getMetadata().getSchema();

    OClass bucketType = schema.createClass(BUCKET_CLASS);

    OClass componentType = schema.createClass(COMPONENT_CLASS);

    componentType.createProperty(P_GROUP, OType.STRING);
    componentType.createProperty(P_NAME, OType.STRING)
        .setMandatory(true)
        .setNotNull(true);
    componentType.createProperty(P_VERSION, OType.STRING);
    componentType.createProperty(P_BUCKET, OType.LINK, bucketType).setMandatory(true).setNotNull(true);
  }

  underTest = new ComponentDatabaseUpgrade_1_2(componentDatabase.getInstanceProvider());
}
 
Example #3
Source File: RebuildAssetUploadMetadataTaskTest.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@Before
public void setUp() {
  BucketEntityAdapter bucketEntityAdapter = new BucketEntityAdapter();
  ComponentFactory componentFactory = new ComponentFactory(emptySet());
  ComponentEntityAdapter componentEntityAdapter = new ComponentEntityAdapter(bucketEntityAdapter, componentFactory,
      emptySet());
  assetEntityAdapter = new AssetEntityAdapter(bucketEntityAdapter, componentEntityAdapter);

  try (ODatabaseDocumentTx db = database.getInstance().connect()) {
    bucketEntityAdapter.register(db);
    componentEntityAdapter.register(db);
    assetEntityAdapter.register(db);

    bucket = bucketEntityAdapter.newEntity();
    bucket.attributes(new NestedAttributesMap(P_ATTRIBUTES, new HashMap<>()));
    bucket.setRepositoryName(REPOSITORY_NAME);
    bucketEntityAdapter.addEntity(db, bucket);
  }

  assetStore = new AssetStoreImpl(database.getInstanceProvider(), assetEntityAdapter);

  task = new RebuildAssetUploadMetadataTask(assetStore, blobStoreManager, configuration);
  when(blobStoreManager.get(any())).thenReturn(blobStore);
}
 
Example #4
Source File: ConfigDatabaseUpgrade_1_2.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@VisibleForTesting
void updateBlobStoreJobs(Map<String, String> renamedBlobStores) {
  try (ODatabaseDocumentTx db = configDatabaseInstance.get().connect()) {

    stream(db.browseClass("quartz_job_detail").spliterator(), false)
        .forEach(doc -> {

          Map<String, Map<String, Object>> valueData = doc.field("value_data");

          Map<String, Object> jobDataMap = getJobData(doc, valueData);
          if (jobDataMap == null) {
            return;
          }

          String blobStoreName = (String) jobDataMap.get(BLOBSTORE_NAME_DETAIL_FIELD);
          if (renamedBlobStores.containsKey(blobStoreName)) {
            jobDataMap.put(BLOBSTORE_NAME_DETAIL_FIELD, renamedBlobStores.get(blobStoreName));
            doc.field("value_data", valueData).save();
          }
        });
  }
}
 
Example #5
Source File: DatabasePoolSupport.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
private void replaceStorage(ODatabaseDocumentTx db, final OStorage storage) {
  db.replaceStorage(storage);
  if (!db.isClosed()) {
    try {
      // reload metadata for active connections if old schema is gone
      if (db.getMetadata().getSchema().countClasses() == 0) {
        log.debug("Reloading metadata for {} as storage has changed", db.getName());
        db.activateOnCurrentThread();
        db.getMetadata().reload();
      }
    }
    catch (Exception e) {
      log.warn("Problem reloading metadata for {}", db.getName(), e);
    }
  }
}
 
Example #6
Source File: LuceneInsertMultithreadTest.java    From orientdb-lucene with Apache License 2.0 6 votes vote down vote up
@Override
public void run() {

  db = new ODatabaseDocumentTx(url);
  db.open("admin", "admin");
  db.declareIntent(new OIntentMassiveInsert());
  db.begin();
  for (int i = 0; i < cycle; i++) {
    ODocument doc = new ODocument("City");

    doc.field("name", "Rome");

    db.save(doc);
    if (i % commitBuf == 0) {
      db.commit();
      db.begin();
    }

  }

  db.close();
}
 
Example #7
Source File: MetadataNodeEntityAdapter.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
private Iterable<T> browseByQuery(final ODatabaseDocumentTx db,
                                  @Nullable final String whereClause,
                                  @Nullable final Map<String, Object> parameters,
                                  @Nullable final Iterable<Bucket> buckets,
                                  @Nullable final String querySuffix,
                                  final boolean async)
{
  String query = buildQuery(false, whereClause, buckets, querySuffix);

  if (isBlank(query)) {
    log.debug("Skipped finding {}s as query is empty, parameters: {}", getTypeName(), parameters);
    return Collections.emptyList();
  }

  log.debug("Finding {}s with query: {}, parameters: {}", getTypeName(), query, parameters);

  if (async) {
    return transform(OrientAsyncHelper.asyncIterable(db, query, parameters));
  }
  else {
    Iterable<ODocument> docs = db.command(new OCommandSQL(query)).execute(parameters);
    return transform(docs);
  }
}
 
Example #8
Source File: LegacyKeyStoreUpgradeServiceTest.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void testUpgradeSchema_TypeDoesNotYetExist() throws Exception {
  service.upgradeSchema();
  try (ODatabaseDocumentTx db = database.getInstance().connect()) {
    OSchema schema = db.getMetadata().getSchema();
    OClass type = schema.getClass("key_store");
    assertThat(type, is(notNullValue()));
    OProperty prop = type.getProperty("name");
    assertThat(prop, is(notNullValue()));
    assertThat(prop.isMandatory(), is(true));
    assertThat(prop.isNotNull(), is(true));
    assertThat(prop.getType(), is(OType.STRING));
    prop = type.getProperty("bytes");
    assertThat(prop, is(notNullValue()));
    assertThat(prop.isMandatory(), is(true));
    assertThat(prop.isNotNull(), is(true));
    assertThat(prop.getType(), is(OType.BINARY));
    assertThat(type.getInvolvedIndexes("name"), hasSize(1));
    assertThat(type.getInvolvedIndexes("name").iterator().next().getType(), is("UNIQUE"));
  }
}
 
Example #9
Source File: ComponentStoreImplTest.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void getNextPageStopsAtNullEntry() {
  int limit = 2;

  Component entity1 = createComponent(bucket, "group1", "name1", "version1");

  try (ODatabaseDocumentTx db = database.getInstance().connect()) {
    entityAdapter.addEntity(db, entity1);
  }

  OIndexCursor cursor = underTest.getIndex(ComponentEntityAdapter.I_GROUP_NAME_VERSION_INSENSITIVE).cursor();

  List<Entry<OCompositeKey, EntityId>> page1 = underTest.getNextPage(cursor, limit);

  assertThat(page1.size(), is(1));
  assertThat(page1.get(0).getValue(), is(EntityHelper.id(entity1)));
}
 
Example #10
Source File: DeconflictAssetMetadataTest.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
private boolean tryConflictingUpdate(final Asset asset) {
  try (ODatabaseDocumentTx db = database.getInstance().acquire()) {
    db.begin();

    ODocument copy = initialAssetRecord.copy();
    assetEntityAdapter.writeFields(copy, asset);
    copy.save();

    try {
      db.commit();
      return true;
    }
    catch (OConcurrentModificationException e) {
      logger.debug("Update denied due to conflict", e);
      return false;
    }
  }
  finally {
    try (ODatabaseDocumentTx db = database.getInstance().acquire()) {
      assetEntityAdapter.readFields(db.load(assetEntityAdapter.recordIdentity(asset)), asset);
    }
  }
}
 
Example #11
Source File: ComponentStoreImpl.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@Override
@Guarded(by = STARTED)
public <T> List<Entry<T, EntityId>> getNextPage(final OIndexCursor cursor, final int limit) {
  List<Entry<T, EntityId>> page = new ArrayList<>(limit);

  // For reasons unknown Orient needs the connection despite the code not using it
  try (ODatabaseDocumentTx db = databaseInstance.get().acquire()) {
    cursor.setPrefetchSize(limit);
    while (page.size() < limit) {
      Entry<Object, OIdentifiable> entry = cursor.nextEntry();
      if (entry == null) {
        break;
      }

      @SuppressWarnings("unchecked")
      T key = (T) entry.getKey();
      EntityId value = new AttachedEntityId(entityAdapter, entry.getValue().getIdentity());
      page.add(new SimpleEntry<>(key, value));
    }
  }

  return page;
}
 
Example #12
Source File: BucketDeleter.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
private void commitBatch(final ODatabaseDocumentTx db,
                         final List<BlobRef> deletedBlobs,
                         final Set<String> deletedBlobStores)
{
  checkNotNull(db);
  checkNotNull(deletedBlobs);
  checkNotNull(deletedBlobStores);

  db.commit();

  for (BlobRef blobRef : deletedBlobs) {
    deleteBlob(deletedBlobStores, blobRef);
  }

  deletedBlobs.clear();
}
 
Example #13
Source File: OIndexBuilder.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
public OIndex build(final ODatabaseDocumentTx db) {
  checkState(!propertyNames.isEmpty(), "At least one property is required");
  checkState(propertyTypes.size() == propertyNames.size(), "A type must be defined for each property");

  List<OCollate> collates = null;
  if (caseInsensitive) {
    collates = Lists.transform(propertyNames, n -> new OCaseInsensitiveCollate());
  }

  ODocument metadata = new ODocument();
  if (ignoreNullValues) {
    metadata.field("ignoreNullValues", true);
  }

  OIndexDefinition indexDefinition = OIndexDefinitionFactory.createIndexDefinition(type, propertyNames, propertyTypes,
      collates, indexType.name(), null);

  return db.getMetadata().getIndexManager().createIndex(name, indexType.name(), indexDefinition,
      type.getPolymorphicClusterIds(), null, metadata.fields() > 0 ? metadata : null);
}
 
Example #14
Source File: DatabaseExternalizerTest.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
private void createSampleDb() {
  try (ODatabaseDocumentTx db = database.getInstance().connect()) {
    OSchema schema = db.getMetadata().getSchema();

    OClass cityType = schema.createClass("City");
    cityType.createProperty("name", OType.STRING);
    cityType.createProperty("country", OType.STRING);
    cityType.createIndex("name_country_idx", INDEX_TYPE.UNIQUE, "name", "country");

    OClass personType = schema.createClass("Person");
    personType.createProperty("name", OType.STRING);
    personType.createProperty("surname", OType.STRING);
    personType.createIndex("name_surname_idx", INDEX_TYPE.UNIQUE, "name", "surname");

    ODocument doc = db.newInstance("Person");
    doc.field("name", "Luke")
        .field("surname", "Skywalker")
        .field("city", new ODocument("City")
            .field("name", "Rome")
            .field("country", "Italy"));
    doc.save();
  }
}
 
Example #15
Source File: EntityHookTest.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void eventsAreFlushedOutsideOfTransaction() {
  TestEntity entity = new TestEntity();
  EntityEvent event;

  try (ODatabaseDocumentTx db = sendingDatabase.getInstance().acquire()) {
    entityHook.onOpen(db);
    entityAdapter.register(db);

    entity.text = "A";
    entityAdapter.addEntity(db, entity);
    entity.text = "B";
    entityAdapter.editEntity(db, entity);
    entity.text = "C";
    entityAdapter.editEntity(db, entity);

    entityHook.onClose(db);

    assertThat(subscriber.events, hasSize(1));

    event = subscriber.events.get(0);
    assertThat(event.getClass().getSimpleName(), is("EntityCreatedEvent"));
    assertThat(event.<TestEntity> getEntity().text, is("C"));
  }
}
 
Example #16
Source File: ComponentDatabaseUpgrade_1_10.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
private void fixComponentBatch(final ODatabaseDocumentTx db, final OIdentifiable bucket) {
  log.debug("Processing batch of {} yum component records...", BATCH_SIZE);

  OSQLSynchQuery<Object> query = new OSQLSynchQuery<>(SELECT_COMPONENT_BATCH_SQL);

  List<ODocument> components = db.query(query, bucket, new ORecordId());

  while (!components.isEmpty()) {
    ORID last = components.get(components.size() - 1).getIdentity();

    for (ODocument component : components) {
      fixComponent(db, component, bucket);
    }

    components = db.query(query, bucket, last);
  }
}
 
Example #17
Source File: DatabaseExternalizerImpl.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void import_(final InputStream input, final boolean overwrite) throws IOException {
  checkNotNull(input);

  log.debug("Importing database: {}", name);

  try (ODatabaseDocumentTx db = openDb()) {
    if (db.exists()) {
      checkState(overwrite, "Database already exists: %s", name);
    }
    else {
      db.create();
    }

    import_(db, input);
  }
}
 
Example #18
Source File: BaseRemoteLuceneTest.java    From orientdb-lucene with Apache License 2.0 6 votes vote down vote up
@Test(enabled = false)
public void initDB() {

  try {
    server = OServerMain.create();
    server.startup(ClassLoader.getSystemResourceAsStream("orientdb-server-config.xml"));
    server.activate();
  } catch (Exception e) {
    e.printStackTrace();
  }
  databaseDocumentTx = new ODatabaseDocumentTx(url);
  if (!databaseDocumentTx.exists()) {
    databaseDocumentTx = Orient.instance().getDatabaseFactory().createDatabase("graph", url);
    databaseDocumentTx.create();
  } else {
    databaseDocumentTx.open("admin", "admin");
  }
}
 
Example #19
Source File: BrowseNodeEntityAdapter.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Removes any {@link BrowseNode}s associated with the given component id.
 */
public void deleteComponentNode(final ODatabaseDocumentTx db, final EntityId componentId) {
  // some formats have the same component appearing on different branches of the tree
  Iterable<ODocument> documents =
      db.command(new OCommandSQL(FIND_BY_COMPONENT)).execute(
          ImmutableMap.of(P_COMPONENT_ID, recordIdentity(componentId)));

  documents.forEach(document -> {
    if (document.containsField(P_ASSET_ID)) {
      // asset still exists, just remove component details
      document.removeField(P_COMPONENT_ID);
      document.save();
    }
    else {
      maybeDeleteParents(db, document.field(P_REPOSITORY_NAME), document.field(P_PARENT_PATH));
      document.delete();
    }
  });
}
 
Example #20
Source File: MetadataNodeEntityAdapter.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
Iterable<T> browseByQueryAsync(final ODatabaseDocumentTx db,
                               @Nullable final String whereClause,
                               @Nullable final Map<String, Object> parameters,
                               @Nullable final Iterable<Bucket> buckets,
                               @Nullable final String querySuffix)
{
  return browseByQuery(db, whereClause, parameters, buckets, querySuffix, true);
}
 
Example #21
Source File: BrowseNodeEntityAdapter.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Associates a {@link OrientBrowseNode} with the given {@link Asset}.
 */
public void createAssetNode(final ODatabaseDocumentTx db,
                            final String repositoryName,
                            final String format,
                            final List<? extends BrowsePath> paths,
                            final Asset asset)
{
  //create any parent folder nodes for this asset if not already existing
  maybeCreateParentNodes(db, repositoryName, format, paths.subList(0, paths.size() - 1));

  //now create the asset node
  OrientBrowseNode node = newNode(repositoryName, format, paths);
  ODocument document = findNodeRecord(db, node);
  if (document == null) {
    // complete the new entity before persisting
    node.setAssetId(EntityHelper.id(asset));
    addEntity(db, node);
  }
  else {
    ORID oldAssetId = document.field(P_ASSET_ID, ORID.class);
    ORID newAssetId = assetEntityAdapter.recordIdentity(asset);
    if (oldAssetId == null) {
      // shortcut: merge new information directly into existing record
      document.field(P_ASSET_ID, newAssetId);
      String path = document.field(P_PATH, OType.STRING);

      //if this node is now an asset, we don't want a trailing slash
      if (!asset.name().endsWith("/") && path.endsWith("/")) {
        path = path.substring(0, path.length() - 1);
        document.field(P_PATH, path);
      }
      document.save();
    }
    else if (!oldAssetId.equals(newAssetId)) {
      // retry in case this is due to an out-of-order delete event
      throw new BrowseNodeCollisionException("Node already has an asset");
    }
  }
}
 
Example #22
Source File: JobStoreImpl.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
private boolean canBeAcquired(final TriggerEntity entity,
                              final ODatabaseDocumentTx db,
                              final long timeWindowStart,
                              final long timeWindowEnd)
{
  OperableTrigger trigger = entity.getValue();

  // skip triggers which have no next fire time
  if (trigger.getNextFireTime() == null) {
    return false;
  }

  // skip triggers which match misfire fudge logic (if the trigger will no longer fire)
  // NOTE: applyMisfire(...) may modify trigger.getNextFireTime()
  if (applyMisfire(db, entity) && trigger.getNextFireTime() == null) {
    return false;
  }

  // skip triggers which fire outside of requested window
  if (trigger.getNextFireTime().getTime() > timeWindowEnd) {
    return false;
  }

  // skip triggers which fire outside of requested window
  if (trigger.getMisfireInstruction() != Trigger.MISFIRE_INSTRUCTION_IGNORE_MISFIRE_POLICY &&
      trigger.getNextFireTime().getTime() < timeWindowStart) {
    return false;
  }

  // check after misfire logic to avoid repeated log-spam
  if (isClustered() && isLimitedToMissingNode(entity)) {
    return false;
  }

  return true;
}
 
Example #23
Source File: BrowseEntitiesByPropertyAction.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
public Iterable<T> execute(final ODatabaseDocumentTx db, final Object... values) {
  checkNotNull(db);
  checkArgument(values.length > 0);

  Iterable<ODocument> results = db.command(new OSQLSynchQuery<>(query))
      .execute(values);

  return adapter.transform(results);
}
 
Example #24
Source File: ClusteredModelVersionsEntityAdapterTest.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void testSaveAndLoad() {
  try (ODatabaseDocumentTx db = database.getInstance().connect()) {
    entityAdapter.register(db);

    ClusteredModelVersions entity = entityAdapter.get(db);
    assertThat(entity, is(notNullValue()));
    assertThat(entity.getModelVersions().entrySet(), hasSize(0));
    assertThat(entity.isDirty(), is(false));

    entity = new ClusteredModelVersions();
    assertThat(entity.isDirty(), is(false));
    entity.put("model-a", "1.2");
    entity.put("model-b", "2.1");
    assertThat(entity.isDirty(), is(true));
    entityAdapter.set(db, entity);

    entity = entityAdapter.get(db);
    assertThat(entity, is(notNullValue()));
    assertThat(entity.getModelVersions(), hasEntry("model-a", "1.2"));
    assertThat(entity.getModelVersions(), hasEntry("model-b", "2.1"));
    assertThat(entity.getModelVersions().entrySet(), hasSize(2));

    assertThat(entity.isDirty(), is(false));
    entity.put("model-a", "1.3");
    assertThat(entity.isDirty(), is(true));
    entityAdapter.set(db, entity);

    entity = entityAdapter.get(db);
    assertThat(entity, is(notNullValue()));
    assertThat(entity.getModelVersions(), hasEntry("model-a", "1.3"));
    assertThat(entity.getModelVersions(), hasEntry("model-b", "2.1"));
    assertThat(entity.getModelVersions().entrySet(), hasSize(2));
    assertThat(entity.isDirty(), is(false));
  }
}
 
Example #25
Source File: ConfigDatabaseUpgrade_1_4.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
private void migrateProperties(final ODatabaseDocumentTx db) throws Exception {
  File propFile = new File(applicationDirectories.getWorkDirectory("etc"), HEALTHCHECK_PROPERTIES);
  if (propFile.exists()) {
    Properties properties = new Properties();
    try (Reader reader = new InputStreamReader(new FileInputStream(propFile), RHC_PROPERTY_FILE_CHARSET)) {
      properties.load(reader);
    }

    // only migrate if the MIGRATED property isn't present
    if (!Boolean.parseBoolean(properties.getProperty(MIGRATED))) {
      log.info("migrating {} properties from {} into configuration database",
          properties.size(), propFile.getAbsolutePath());

      for (String name : uniqueCIPropertyNames(properties.stringPropertyNames())) {
        final String value = properties.getProperty(name);
        ODocument config = Iterables.getFirst(db.command(PROPERTY_QUERY).execute(name),
            db.newInstance(C_HEALTHCHECKCONFIG)
                .field(P_PROPERTY_NAME, name)
                .field(P_PROPERTY_VALUE, value));
        if (config != null) {
          final String current = config.field(P_PROPERTY_VALUE);
          if (current == null ? value != null : !current.equals(value)){
            config.field(P_PROPERTY_VALUE, value);
          }
          config.save();
        }
      }

      // prefer to retain the file on disk for support if needed
      // presence of MIGRATED property will prevent it from being imported again
      properties.setProperty(MIGRATED, "true");
      try (Writer writer = new OutputStreamWriter(new FileOutputStream(propFile), RHC_PROPERTY_FILE_CHARSET)) {
        properties.store(writer, "completed ConfigDatabaseUpgrade_1_4 at " + new Date());
      }
    }
  }
}
 
Example #26
Source File: OrientComponentAssetTestHelper.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public List<String> findAssetPaths(final String repositoryName) {
  String sql = "SELECT * FROM asset WHERE bucket.repository_name = ?";
  try (ODatabaseDocumentTx tx = databaseInstanceProvider.get().acquire()) {
    tx.begin();
    List<ODocument> results = tx.command(new OCommandSQL(sql)).execute(repositoryName);
    return results.stream().map(doc -> doc.field("name", String.class).toString()).collect(toList());
  }
}
 
Example #27
Source File: TestPeopleDao.java    From thorntail with Apache License 2.0 5 votes vote down vote up
public ODocument addPerson(String name) {
    try (ODatabaseDocumentTx database = databasePool.acquire()) {
        ODocument document = new ODocument("Person");
        document.field("name", name);
        database.commit();
        return document.save();
    }
}
 
Example #28
Source File: ConfigDatabaseUpgrade_1_7_Test.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Before
public void setUp() {
  underTest = new ConfigDatabaseUpgrade_1_7(configDatabase.getInstanceProvider());
  try (ODatabaseDocumentTx db = configDatabase.getInstance().connect()) {
    OSchema schema = db.getMetadata().getSchema();
    OClass dbClass = schema.createClass(DB_CLASS);
    dbClass.createProperty(P_REPOSITORY_NAME, OType.STRING);

    ODocument document = db.newInstance(DB_CLASS);
    document.save();
  }
}
 
Example #29
Source File: DeleteEntityByKeyAction.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
public boolean execute(final ODatabaseDocumentTx db, final Key key) {
  checkNotNull(db);
  checkNotNull(key);

  int records = db.command(new OCommandSQL(query))
      .execute(key.getName(), key.getGroup());

  return records == 1;
}
 
Example #30
Source File: ComponentDatabaseUpgrade_1_2.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
private void createBucketNameIndex() {
  try (ODatabaseDocumentTx db = componentDatabaseInstance.get().connect()) {
    if (db.getMetadata().getIndexManager().getIndex(I_BUCKET_NAME_VERSION) == null) {
      OSchema schema = db.getMetadata().getSchema();
      OClass type = schema.getClass(COMPONENT_CLASS);
      if (type != null) {
        type.createIndex(I_BUCKET_NAME_VERSION, INDEX_TYPE.NOTUNIQUE, new String[] { P_BUCKET, P_NAME, P_VERSION });
      }
    }
  }
}