com.orientechnologies.orient.core.command.OCommandRequest Java Examples

The following examples show how to use com.orientechnologies.orient.core.command.OCommandRequest. 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: ContentExpressionFunctionTest.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
@Before
public void setup() {
  when(variableResolverAdapterManager.get(FORMAT)).thenReturn(assetVariableResolver);
  when(assetVariableResolver.fromDocument(assetDocument)).thenReturn(variableSource);

  when(bucketDocument.getRecord()).thenReturn(bucketDocument);
  when(bucketDocument.field("repository_name", String.class)).thenReturn(REPOSITORY_NAME);
  when(bucketDocument.getIdentity()).thenReturn(mock(ORID.class));

  when(assetDocument.getClassName()).thenReturn("asset");
  when(assetDocument.getRecord()).thenReturn(assetDocument);
  when(assetDocument.field("bucket", OIdentifiable.class)).thenReturn(bucketDocument);
  when(assetDocument.field("name", String.class)).thenReturn(PATH);
  when(assetDocument.field("format", String.class)).thenReturn(FORMAT);

  when(commandRequest.execute(any(Map.class))).thenReturn(Collections.singletonList(assetDocument));
  when(database.command(any(OCommandRequest.class))).thenReturn(commandRequest);

  when(selectorManager.newSelectorConfiguration()).thenAnswer(invocation -> new OrientSelectorConfiguration());

  underTest = new ContentExpressionFunction(variableResolverAdapterManager, selectorManager, contentAuthHelper);
}
 
Example #2
Source File: PurgeUnusedSnapshotsFacetImplTest.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
private void mockPagesOfComponents() {
  OCommandRequest oCommandRequest1 = getCommandRequest(10,
      testData(taskOlderThan.minusDays(1), "my.company", "foo", "1.0-SNAPSHOT"),
      testData(taskOlderThan.minusDays(2), "my.company", "bar", "2.0-SNAPSHOT"));
  OCommandRequest oCommandRequest2 = getCommandRequest(10,
      // non-match, not a snapshot
      testData(taskOlderThan.minusDays(1), "your.company", "biz", "1.0")
  );
  OCommandRequest oCommandRequest3 = getCommandRequest(10,
      testData(taskOlderThan.minusDays(2), "this.company", "baz", "3.0-SNAPSHOT")
  );
  OCommandRequest oCommandRequest4 = getCommandRequest(5,
      testData(taskOlderThan.minusDays(3), "my.company", "foo", "0.1-SNAPSHOT"),
      testData(taskOlderThan.minusDays(6), "your.company", "biz", "1.0-SNAPSHOT"),
      // non-match, this is same day
      testData(taskOlderThan, "that.company", "fizz", "1.2.3-SNAPSHOT")
  );

  when(oDatabaseDocumentTx.command(any(OCommandScript.class)))
      .thenReturn(oCommandRequest1, oCommandRequest2, oCommandRequest3, oCommandRequest4);
}
 
Example #3
Source File: AbstractCommandExtension.java    From guice-persist-orient with MIT License 6 votes vote down vote up
@Override
public Object execute(final T descriptor, final Object repositoryInstance,
                      final Object... arguments) throws Throwable {
    final SqlCommandDescriptor desc;
    final OCommandRequest query;
    try {
        desc = createQueryDescriptor(descriptor, arguments);
        amendCommandDescriptor(desc, descriptor, repositoryInstance, arguments);

        query = createQueryCommand(descriptor, desc);
        amendCommand(query, descriptor, repositoryInstance, arguments);
    } catch (Exception ex) {
        throw new CommandMethodException(String.format("Failed to prepare command '%s' execution",
                descriptor.command), ex);
    }

    return executeCommand(descriptor, desc, query);
}
 
Example #4
Source File: ReadEntitiesByPropertyActionTest.java    From nexus-public with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void testExecute() {
  Set<String> params = ImmutableSet.of("1", "2");

  ArgumentCaptor<OSQLSynchQuery> argumentCaptor = ArgumentCaptor.forClass(OSQLSynchQuery.class);
  OCommandRequest oCommandRequest = mock(OCommandRequest.class);
  when(db.command(argumentCaptor.capture())).thenReturn(oCommandRequest);
  when(oCommandRequest.execute(params)).thenReturn(newArrayList(new ODocument(), new ODocument()));

  List<Entity> results = underTest.execute(db, params);

  assertThat(argumentCaptor.getValue().getText(), equalTo("SELECT FROM test WHERE test IN['1','2']"));
  assertThat(results, notNullValue());
  assertThat(results.size(), equalTo(2));
}
 
Example #5
Source File: LiveListenerParameterSupport.java    From guice-persist-orient with MIT License 5 votes vote down vote up
@Override
public OCommandResultListener processListener(final OCommandRequest command,
                                              final Object listener,
                                              final Injector injector,
                                              final Class<?> conversionTarget) {
    checkExec(command instanceof OLiveQuery,
            "Live listener (@%s parameter) can only be used with @%s",
            Listen.class.getSimpleName(), LiveQuery.class.getSimpleName());
    return wrap(listener, injector, conversionTarget);
}
 
Example #6
Source File: ListenParamExtension.java    From guice-persist-orient with MIT License 5 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public void amendCommand(final OCommandRequest query, final CommandMethodDescriptor descriptor,
                         final Object instance, final Object... arguments) {
    final ListenParamDescriptor extDesc = (ListenParamDescriptor) descriptor
            .extDescriptors.get(ListenParamExtension.KEY);
    final Object listener = arguments[extDesc.position];
    // null listener makes no sense: method is void and results are not handled anywhere
    checkExec(listener != null, "Listener can't be null");

    ((OCommandRequestAbstract) query).setResultListener(extDesc.handler
            .processListener(query, listener, injector, resolveTargetType(listener.getClass(), extDesc.generic)));
}
 
Example #7
Source File: AbstractCommandExtension.java    From guice-persist-orient with MIT License 5 votes vote down vote up
@SuppressWarnings("unchecked")
private void amendCommand(final OCommandRequest query, final T descriptor,
                          final Object instance, final Object... arguments) {
    for (CommandExtension ext : descriptor.amendExtensions) {
        ext.amendCommand(query, descriptor, instance, arguments);
    }
}
 
Example #8
Source File: AsyncQueryListenerParameterSupport.java    From guice-persist-orient with MIT License 5 votes vote down vote up
@Override
public OCommandResultListener processListener(final OCommandRequest command,
                                              final Object listener,
                                              final Injector injector,
                                              final Class<?> conversionTarget) {
    checkExec(command instanceof OCommandRequestAbstract,
            "@%s can't be applied to query, because command object %s doesn't support it",
            Listen.class.getSimpleName(), command.getClass().getName());
    return wrap(listener, injector, conversionTarget, ((OSQLQuery) command).getText());
}
 
Example #9
Source File: AsyncQueryMethodExtension.java    From guice-persist-orient with MIT License 5 votes vote down vote up
@Override
protected OCommandRequest createQueryCommand(final CommandMethodDescriptor descriptor,
                                             final SqlCommandDescriptor desc) {
    final boolean blocking = (Boolean) descriptor.extDescriptors.get(EXT_BLOCKING);
    // correct listener will be set by @Listen extension
    if (blocking) {
        return new OSQLAsynchQuery(desc.command);
    } else {
        return new OSQLNonBlockingQuery(desc.command, null);
    }
}
 
Example #10
Source File: VarParamExtension.java    From guice-persist-orient with MIT License 5 votes vote down vote up
@Override
public void amendCommand(final OCommandRequest query, final CommandMethodDescriptor descriptor,
                         final Object instance, final Object... arguments) {
    @SuppressWarnings("unchecked")
    final Map<String, Integer> vars = (Map<String, Integer>) descriptor.extDescriptors.get(KEY);
    final OCommandContext context = query.getContext();
    for (Map.Entry<String, Integer> entry : vars.entrySet()) {
        context.setVariable(entry.getKey(), arguments[entry.getValue()]);
    }
}
 
Example #11
Source File: ObjectRepositoryExecutor.java    From guice-persist-orient with MIT License 4 votes vote down vote up
@Override
public OCommandRequest wrapCommand(final OCommandRequest command) {
    return provider.get().command(command);
}
 
Example #12
Source File: GraphRepositoryExecutor.java    From guice-persist-orient with MIT License 4 votes vote down vote up
@Override
public OCommandRequest wrapCommand(final OCommandRequest command) {
    return provider.get().command(command);
}
 
Example #13
Source File: DocumentRepositoryExecutor.java    From guice-persist-orient with MIT License 4 votes vote down vote up
@Override
public OCommandRequest wrapCommand(final OCommandRequest command) {
    return provider.get().command(command);
}
 
Example #14
Source File: ElVarParamExtension.java    From guice-persist-orient with MIT License 4 votes vote down vote up
@Override
public void amendCommand(final OCommandRequest query, final CommandMethodDescriptor descriptor,
                         final Object instance, final Object... arguments) {
    // not needed
}
 
Example #15
Source File: RidElVarParamExtension.java    From guice-persist-orient with MIT License 4 votes vote down vote up
@Override
public void amendCommand(final OCommandRequest query, final CommandMethodDescriptor descriptor,
                         final Object instance, final Object... arguments) {
    // not used
}
 
Example #16
Source File: LimitParamExtension.java    From guice-persist-orient with MIT License 4 votes vote down vote up
@Override
public void amendCommand(final OCommandRequest query, final CommandMethodDescriptor descriptor,
                         final Object instance, final Object... arguments) {
    // not needed
}
 
Example #17
Source File: SkipParamExtension.java    From guice-persist-orient with MIT License 4 votes vote down vote up
@Override
public void amendCommand(final OCommandRequest query, final CommandMethodDescriptor descriptor,
                         final Object instance, final Object... arguments) {
    // not needed
}
 
Example #18
Source File: FetchPlanParamExtension.java    From guice-persist-orient with MIT License 4 votes vote down vote up
@Override
public void amendCommand(final OCommandRequest query, final CommandMethodDescriptor descriptor,
                         final Object instance, final Object... arguments) {
    // not needed
}
 
Example #19
Source File: TimeoutAmendExtension.java    From guice-persist-orient with MIT License 4 votes vote down vote up
@Override
public void amendCommand(final OCommandRequest query, final CommandMethodDescriptor descriptor,
                         final Object instance, final Object... arguments) {
    // not needed
}
 
Example #20
Source File: DynamicParamsExtension.java    From guice-persist-orient with MIT License 4 votes vote down vote up
@Override
public void amendCommand(final OCommandRequest query, final CommandMethodDescriptor descriptor,
                         final Object instance, final Object... arguments) {
    // not required
}
 
Example #21
Source File: LiveQueryMethodExtension.java    From guice-persist-orient with MIT License 4 votes vote down vote up
@Override
protected OCommandRequest createQueryCommand(final CommandMethodDescriptor descriptor,
                                             final SqlCommandDescriptor desc) {
    // live listener will be applied by @Listen extension
    return new OLiveQuery<Object>(desc.command, null);
}
 
Example #22
Source File: FunctionMethodExtension.java    From guice-persist-orient with MIT License 4 votes vote down vote up
@Override
protected OCommandRequest createQueryCommand(final CommandMethodDescriptor descriptor,
                                             final SqlCommandDescriptor desc) {
    return new OCommandFunction(desc.command);
}
 
Example #23
Source File: ScriptMethodExtension.java    From guice-persist-orient with MIT License 4 votes vote down vote up
@Override
protected OCommandRequest createQueryCommand(final ScriptCommandMethodDescriptor descriptor,
                                             final SqlCommandDescriptor desc) {
    return new OCommandScript(descriptor.language, desc.command);
}
 
Example #24
Source File: ListenerParameterSupport.java    From guice-persist-orient with MIT License 2 votes vote down vote up
/**
 * Checks listener compatibility with command object and wraps listener if required.
 *
 * @param command          command object
 * @param listener         listener instance (passed in annotated parameter)
 * @param injector         injector instance
 * @param conversionTarget target conversion type or null if no conversion required
 * @return processed listener to apply to command
 */
OCommandResultListener processListener(OCommandRequest command,
                                       Object listener,
                                       Injector injector,
                                       Class<?> conversionTarget);
 
Example #25
Source File: AbstractCommandExtension.java    From guice-persist-orient with MIT License 2 votes vote down vote up
/**
 * Actual command object depends on query type and have to be chosen by exact extension.
 *
 * @param descriptor repository method descriptor
 * @param desc       query descriptor
 * @return query command request object
 */
protected abstract OCommandRequest createQueryCommand(T descriptor, SqlCommandDescriptor desc);
 
Example #26
Source File: CommandExtension.java    From guice-persist-orient with MIT License 2 votes vote down vote up
/**
 * Called after query object creation. Use it to modify request command object.
 * <p>
 * Note: this is raw command object, not tied to connection. After extension command attached to
 * exact connection type, which wraps command object with another command (to apply security,
 * result conversions etc).
 *
 * @param query      query command request
 * @param descriptor repository method descriptor
 * @param instance   repository instance
 * @param arguments  method execution arguments
 */
void amendCommand(OCommandRequest query, T descriptor, Object instance, Object... arguments);
 
Example #27
Source File: RepositoryExecutor.java    From guice-persist-orient with MIT License 2 votes vote down vote up
/**
 * Called to bind command to connection.
 * Query will work without wrapping in document mode. Wrapped commend ties result to connection specific objects.
 *
 * @param command command
 * @return command bound to connection
 */
OCommandRequest wrapCommand(OCommandRequest command);