Search in sources :

Example 21 with Watch

use of sirius.kernel.commons.Watch in project sirius-biz by scireum.

the class ConversionEngine method performConversion.

/**
 * Invokes the {@link Converter} which has been configured for the given variant to perform the actual conversion.
 *
 * @param conversionProcess the conversion to perform
 * @return a future which is fulfilled once the conversion is completed
 */
public Future performConversion(ConversionProcess conversionProcess) {
    Future result = new Future();
    Watch queueWatch = Watch.start();
    tasks.executor(EXECUTOR_STORAGE_CONVERSION).dropOnOverload(() -> result.fail(new IllegalStateException("Conversion subsystem overloaded!"))).fork(() -> doConversion(conversionProcess, result, queueWatch));
    return result;
}
Also used : Watch(sirius.kernel.commons.Watch) Future(sirius.kernel.async.Future)

Example 22 with Watch

use of sirius.kernel.commons.Watch in project sirius-biz by scireum.

the class BasePageHelper method asPage.

/**
 * Wraps the given data into a {@link Page} which can be used to render a table, filterbox and support pagination.
 * <p>
 * This can only be done if a web context has been provided via {@link #withContext(WebContext)}.
 *
 * @return the given data wrapped as <tt>Page</tt>
 */
public Page<E> asPage() {
    Objects.requireNonNull(webContext);
    Watch w = Watch.start();
    Page<E> result = new Page<E>().withStart(1).withPageSize(pageSize);
    result.bindToRequest(webContext);
    applyQuery(result.getQuery());
    applyFacets(result);
    try {
        setupPaging(result);
        List<E> items = executeQuery();
        enforcePaging(result, items);
        fillPage(w, result, items);
        if (debugging) {
            UserContext.message(Message.info().withTextMessage(Strings.apply("Effective Query: %s (Matches: %s, Duration: %s ms)", baseQuery, baseQuery.count(), w.elapsedMillis())));
        }
    } catch (Exception e) {
        UserContext.handle(e);
    }
    return result;
}
Also used : Watch(sirius.kernel.commons.Watch) Page(sirius.web.controller.Page)

Example 23 with Watch

use of sirius.kernel.commons.Watch in project sirius-biz by scireum.

the class EntityExportJob method handleTemplateRow.

/**
 * Enhances a data row read from the template.
 *
 * @param row the row data to process
 */
private void handleTemplateRow(Values row) {
    Watch w = Watch.start();
    errorContext.handle(() -> {
        Context data = dictionary.load(row, false);
        if (contextExtender != null) {
            contextExtender.accept(data);
        }
        Optional<E> entity = importer.tryFind(type, data);
        if (entity.isPresent()) {
            export.addRow(exportAsRow(row, entity.get()));
        } else {
            export.addRow(row.asList());
        }
    });
    process.addTiming(descriptor.getPluralLabel(), w.elapsedMillis());
}
Also used : ProcessContext(sirius.biz.process.ProcessContext) Context(sirius.kernel.commons.Context) Watch(sirius.kernel.commons.Watch)

Example 24 with Watch

use of sirius.kernel.commons.Watch in project sirius-biz by scireum.

the class RelationalEntityImportJob method commitImportTransaction.

/**
 * Commits the import transaction by deleting all untouched entities.
 */
@SuppressWarnings("unchecked")
protected void commitImportTransaction() {
    if (mode != SyncMode.SYNC) {
        return;
    }
    Watch watch = Watch.start();
    importTransactionHelper.deleteUnmarked(type, query -> tuneImportTransactionDeleteQuery((Q) query), entity -> {
        process.addTiming(NLS.get("EntityImportJob.entityDeleted"), watch.elapsed(TimeUnit.MILLISECONDS, true));
    });
}
Also used : Watch(sirius.kernel.commons.Watch)

Example 25 with Watch

use of sirius.kernel.commons.Watch in project sirius-biz by scireum.

the class QueryController method executeQuery.

@SuppressWarnings("unchecked")
private <C extends Constraint, Q extends Query<Q, ?, C>> List<BaseEntity<?>> executeQuery(EntityDescriptor descriptor, String queryString, int limit) {
    try {
        // As Query is a self-referential type, we have to use a custom generic type here...
        Q baseQuery = (Q) descriptor.getMapper().select((Class<BaseEntity<?>>) descriptor.getType());
        // Compile the query string and extract the debug flag...
        Tuple<Constraint, Boolean> constraintAndDebugFlag = descriptor.getMapper().filters().compileString(descriptor, queryString, Collections.emptyList());
        baseQuery.where((C) constraintAndDebugFlag.getFirst());
        // Log effective query if desired...
        if (Boolean.TRUE.equals(constraintAndDebugFlag.getSecond())) {
            UserContext.message(Message.info().withTextMessage("Effective Query: " + baseQuery));
        }
        // Elastic entities might be routed - we ignore this here and access all shards anyway...
        if (baseQuery instanceof ElasticQuery) {
            ((ElasticQuery<?>) baseQuery).deliberatelyUnrouted();
        }
        long numberOfEntities = getTotalCount(limit, baseQuery);
        // Actually perform the query...
        List<BaseEntity<?>> result = new ArrayList<>();
        if (numberOfEntities > 0) {
            Watch watch = Watch.start();
            baseQuery.limit(limit).iterateAll(result::add);
            UserContext.message(Message.info().withTextMessage(Strings.apply("Showing %s of %s results - Query took %sms", result.size(), numberOfEntities, watch.elapsedMillis())));
        }
        return result;
    } catch (IllegalArgumentException e) {
        // The QueryCompiler generates an IllegalArgumentException for invalid fields and tokens.
        // In our case we don't want to write them into the syslog but just output the message...
        UserContext.message(Message.error().withTextMessage(e.getMessage()));
    } catch (Exception e) {
        handle(e);
    }
    return Collections.emptyList();
}
Also used : Constraint(sirius.db.mixing.query.constraints.Constraint) BaseEntity(sirius.db.mixing.BaseEntity) ArrayList(java.util.ArrayList) ElasticQuery(sirius.db.es.ElasticQuery) Watch(sirius.kernel.commons.Watch)

Aggregations

Watch (sirius.kernel.commons.Watch)53 PreparedStatement (java.sql.PreparedStatement)8 SQLException (java.sql.SQLException)8 Connection (java.sql.Connection)6 HandledException (sirius.kernel.health.HandledException)6 Document (org.bson.Document)5 ResultSet (java.sql.ResultSet)4 TaskContext (sirius.kernel.async.TaskContext)4 ArrayList (java.util.ArrayList)3 OMA (sirius.db.jdbc.OMA)3 Property (sirius.db.mixing.Property)3 BasicDBObject (com.mongodb.BasicDBObject)2 ProcessContext (sirius.biz.process.ProcessContext)2 ObjectStorageSpace (sirius.biz.storage.layer1.ObjectStorageSpace)2 Operator (sirius.db.jdbc.Operator)2 Operation (sirius.kernel.async.Operation)2 Context (sirius.kernel.commons.Context)2 Limit (sirius.kernel.commons.Limit)2 AS400 (com.ibm.as400.access.AS400)1 ProgramCall (com.ibm.as400.access.ProgramCall)1