Java Code Examples for com.googlecode.cqengine.query.option.QueryOptions#get()

The following examples show how to use com.googlecode.cqengine.query.option.QueryOptions#get() . 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: OffHeapPersistence.java    From cqengine with Apache License 2.0 5 votes vote down vote up
/**
 * Closes a {@link RequestScopeConnectionManager} if it is present in the given query options with key
 * {@link ConnectionManager}.
 *
 * @param queryOptions The query options supplied with the request into CQEngine.
 */
@Override
public void closeRequestScopeResources(QueryOptions queryOptions) {
    ConnectionManager connectionManager = queryOptions.get(ConnectionManager.class);
    if (connectionManager instanceof RequestScopeConnectionManager) {
        ((RequestScopeConnectionManager) connectionManager).close();
        queryOptions.remove(ConnectionManager.class);
    }
}
 
Example 2
Source File: DiskPersistence.java    From cqengine with Apache License 2.0 5 votes vote down vote up
/**
 * Closes a {@link RequestScopeConnectionManager} if it is present in the given query options with key
 * {@link ConnectionManager}.
 *
 * @param queryOptions The query options supplied with the request into CQEngine.
 */
@Override
public void closeRequestScopeResources(QueryOptions queryOptions) {
    ConnectionManager connectionManager = queryOptions.get(ConnectionManager.class);
    if (connectionManager instanceof RequestScopeConnectionManager) {
        ((RequestScopeConnectionManager) connectionManager).close();
        queryOptions.remove(ConnectionManager.class);
    }
}
 
Example 3
Source File: CompositePersistence.java    From cqengine with Apache License 2.0 5 votes vote down vote up
/**
 * Closes a {@link RequestScopeConnectionManager} if it is present in the given query options with key
 * {@link ConnectionManager}.
 *
 * @param queryOptions The query options supplied with the request into CQEngine.
 */
@Override
public void closeRequestScopeResources(QueryOptions queryOptions) {
    ConnectionManager connectionManager = queryOptions.get(ConnectionManager.class);
    if (connectionManager instanceof RequestScopeConnectionManager) {
        ((RequestScopeConnectionManager) connectionManager).close();
        queryOptions.remove(ConnectionManager.class);
    }
}
 
Example 4
Source File: PartialIndex.java    From cqengine with Apache License 2.0 5 votes vote down vote up
/**
 * Returns true if this partial index can answer this branch of the query.
 * <p/>
 * See the class JavaDoc for the conditions which must be satisfied for this method to return true.
 *
 * @param query The query supplied by the query engine, which is typically a branch of the overall query being
 *              evaluated.
 */
@Override
public boolean supportsQuery(Query<O> query, QueryOptions queryOptions) {
    // Extract the root query from the query options, and check if it contains the filter query...
    @SuppressWarnings("unchecked")
    Query<O> rootQuery = (Query<O>) queryOptions.get(CollectionQueryEngine.ROOT_QUERY);

    return supportsQueryInternal(backingIndex(), filterQuery, rootQuery, query, queryOptions);
}
 
Example 5
Source File: CloseableRequestResources.java    From cqengine with Apache License 2.0 5 votes vote down vote up
/**
 * Returns an existing {@link CloseableRequestResources} from the QueryOptions, or adds a new
 * instance to the query options and returns that.
 *
 * @param queryOptions The {@link QueryOptions}
 * @return The existing QueryOptions's CloseableRequestResources or a new instance.
 */
public static CloseableRequestResources forQueryOptions(final QueryOptions queryOptions) {
    CloseableRequestResources closeableRequestResources = queryOptions.get(CloseableRequestResources.class);
    if (closeableRequestResources == null) {
        closeableRequestResources = new CloseableRequestResources();
        queryOptions.put(CloseableRequestResources.class, closeableRequestResources);
    }
    return closeableRequestResources;
}
 
Example 6
Source File: SimplifiedSQLiteIndex.java    From cqengine with Apache License 2.0 5 votes vote down vote up
static <O, K extends Comparable<K>> Persistence<O, K> getPersistenceFromQueryOptions(QueryOptions queryOptions) {
    @SuppressWarnings("unchecked")
    Persistence<O, K> persistence = (Persistence<O, K>) queryOptions.get(Persistence.class);
    if (persistence == null) {
        throw new IllegalStateException("A required Persistence object was not supplied in query options");
    }
    return persistence;
}
 
Example 7
Source File: SimplifiedSQLiteIndex.java    From cqengine with Apache License 2.0 5 votes vote down vote up
static <O> QueryEngine<O> getQueryEngineFromQueryOptions(QueryOptions queryOptions) {
    @SuppressWarnings("unchecked")
    QueryEngine<O> queryEngine = (QueryEngine<O>) queryOptions.get(QueryEngine.class);
    if (queryEngine == null) {
        throw new IllegalStateException("The QueryEngine was not supplied in query options");
    }
    return queryEngine;
}
 
Example 8
Source File: SQLiteIndex.java    From cqengine with Apache License 2.0 5 votes vote down vote up
@Override
public boolean removeAll(final ObjectSet<O> objectSet, final QueryOptions queryOptions) {
    try {
        ConnectionManager connectionManager = getConnectionManager(queryOptions);
        if (!connectionManager.isApplyUpdateForIndexEnabled(this)) {
            return false;
        }

        final Connection connection = connectionManager.getConnection(this, queryOptions);
        final boolean isBulkImport = queryOptions.get(BulkImportExternallyManged.class) != null || FlagsEnabled.isFlagEnabled(queryOptions, SQLiteIndexFlags.BULK_IMPORT);
        if (isBulkImport) {
            // It's a bulk import, avoid creating the index on the SQLite table...
            DBQueries.createIndexTable(tableName, primaryKeyAttribute.getAttributeType(), getAttribute().getAttributeType(), connection);
        }
        else {
            // It's NOT a bulk import, create both table and index on the table...
            createTableIndexIfNeeded(connection);
        }

        Iterable<K> objectKeys = objectKeyIterable(objectSet, primaryKeyAttribute, queryOptions);

        if (canModifySyncAndJournaling) {
            // Explicitly (re-)set the configured sync and journaling settings,
            // because we performed some DDL operations above. Because, it seems performing some
            // DDL operations can cause the previous sync and journaling settings settings to be lost.
            // For more details see: https://github.com/npgall/cqengine/issues/227
            DBQueries.setSyncAndJournaling(connection, pragmaSynchronous, pragmaJournalMode);
        }

        int rowsModified = DBQueries.bulkRemove(objectKeys, tableName, connection);
        return rowsModified > 0;
    }
    finally {
        objectSet.close();
    }
}
 
Example 9
Source File: SQLiteIndex.java    From cqengine with Apache License 2.0 4 votes vote down vote up
boolean doAddAll(final ObjectSet<O> objectSet, final QueryOptions queryOptions, boolean isInit) {
    try {
        ConnectionManager connectionManager = getConnectionManager(queryOptions);
        if (!connectionManager.isApplyUpdateForIndexEnabled(this)) {
            return false;
        }

        final Connection connection = connectionManager.getConnection(this, queryOptions);

        if (!FORCE_REINIT_OF_PREEXISTING_INDEXES) {
            if (isInit && DBQueries.indexTableExists(tableName, connection)) {
                // init() was called, but index table already exists. Skip initializing it...
                return false;
            }
        }

        // Create table if it doesn't exists...
        DBQueries.createIndexTable(tableName, primaryKeyAttribute.getAttributeType(), getAttribute().getAttributeType(), connection);

        // Handle the SQLite indexes on the table
        final BulkImportExternallyManged bulkImportExternallyManged = queryOptions.get(BulkImportExternallyManged.class);
        final boolean isBulkImport = bulkImportExternallyManged == null && FlagsEnabled.isFlagEnabled(queryOptions, SQLiteIndexFlags.BULK_IMPORT);
        final boolean isSuspendSyncAndJournaling = FlagsEnabled.isFlagEnabled(queryOptions, SQLiteIndexFlags.BULK_IMPORT_SUSPEND_SYNC_AND_JOURNALING);
        if ((bulkImportExternallyManged != null || isBulkImport) && !objectSet.isEmpty()) {
            // Drop the SQLite index temporarily (if any) to speed up bulk import...
            DBQueries.dropIndexOnTable(tableName, connection);

            if (isSuspendSyncAndJournaling) {
                if (!canModifySyncAndJournaling) {
                    throw new IllegalStateException("Cannot suspend sync and journaling because it was not possible to read the original 'synchronous' and 'journal_mode' pragmas during the index initialization.");
                }
                DBQueries.suspendSyncAndJournaling(connection);
            } else if (canModifySyncAndJournaling) {
                // Explicitly (re-)set the configured sync and journaling settings,
                // because we performed some DDL operations above. Because, it seems performing some
                // DDL operations can cause the previous sync and journaling settings settings to be lost.
                // For more details see: https://github.com/npgall/cqengine/issues/227
                DBQueries.setSyncAndJournaling(connection, pragmaSynchronous, pragmaJournalMode);
            }

        } else {
            // Not a bulk import, create indexes...
            DBQueries.createIndexOnTable(tableName, connection);
            if (canModifySyncAndJournaling) {
                // Explicitly (re-)set the configured sync and journaling settings,
                // because we performed some DDL operations above. Because, it seems performing some
                // DDL operations can cause the previous sync and journaling settings settings to be lost.
                // For more details see: https://github.com/npgall/cqengine/issues/227
                DBQueries.setSyncAndJournaling(connection, pragmaSynchronous, pragmaJournalMode);
            }
        }

        Iterable<Row<K, A>> rows = rowIterable(objectSet, primaryKeyAttribute, getAttribute(), queryOptions);
        final int rowsModified = DBQueries.bulkAdd(rows, tableName, connection);

        if (isBulkImport || LAST.equals(bulkImportExternallyManged)) {
            // Bulk import finished, recreate the SQLite index...
            DBQueries.createIndexOnTable(tableName, connection);

            if (isSuspendSyncAndJournaling) {
                DBQueries.setSyncAndJournaling(connection, pragmaSynchronous, pragmaJournalMode);
            }

        }

        return rowsModified > 0;
    }
    finally {
        objectSet.close();
    }
}
 
Example 10
Source File: OffHeapPersistence.java    From cqengine with Apache License 2.0 3 votes vote down vote up
/**
 * Creates a new {@link RequestScopeConnectionManager} and adds it to the given query options with key
 * {@link ConnectionManager}, if an only if no object with that key is already in the query options.
 * This allows the application to supply its own implementation of {@link ConnectionManager} to override the default
 * if necessary.
 *
 * @param queryOptions The query options supplied with the request into CQEngine.
 */
@Override
public void openRequestScopeResources(QueryOptions queryOptions) {
    if (queryOptions.get(ConnectionManager.class) == null) {
        queryOptions.put(ConnectionManager.class, new RequestScopeConnectionManager(this));
    }
}
 
Example 11
Source File: DiskPersistence.java    From cqengine with Apache License 2.0 3 votes vote down vote up
/**
 * Creates a new {@link RequestScopeConnectionManager} and adds it to the given query options with key
 * {@link ConnectionManager}, if an only if no object with that key is already in the query options.
 * This allows the application to supply its own implementation of {@link ConnectionManager} to override the default
 * if necessary.
 *
 * @param queryOptions The query options supplied with the request into CQEngine.
 */
@Override
public void openRequestScopeResources(QueryOptions queryOptions) {
    if (queryOptions.get(ConnectionManager.class) == null) {
        queryOptions.put(ConnectionManager.class, new RequestScopeConnectionManager(this));
    }
}
 
Example 12
Source File: CompositePersistence.java    From cqengine with Apache License 2.0 3 votes vote down vote up
/**
 * Creates a new {@link RequestScopeConnectionManager} and adds it to the given query options with key
 * {@link ConnectionManager}, if an only if no object with that key is already in the query options.
 * This allows the application to supply its own implementation of {@link ConnectionManager} to override the default
 * if necessary.
 *
 * @param queryOptions The query options supplied with the request into CQEngine.
 */
@Override
public void openRequestScopeResources(QueryOptions queryOptions) {
    if (queryOptions.get(ConnectionManager.class) == null) {
        queryOptions.put(ConnectionManager.class, new RequestScopeConnectionManager(this));
    }
}
 
Example 13
Source File: SQLiteIndex.java    From cqengine with Apache License 2.0 3 votes vote down vote up
/**
 * Utility method to extract the {@link ConnectionManager} from QueryOptions.
 *
 * @param queryOptions The {@link QueryOptions}.
 * @return The {@link ConnectionManager}
 *
 * @throws IllegalStateException if the ConnectionManager is not found.
 */
ConnectionManager getConnectionManager(final QueryOptions queryOptions){
    ConnectionManager connectionManager = queryOptions.get(ConnectionManager.class);
    if (connectionManager == null)
        throw new IllegalStateException("A ConnectionManager is required but was not provided in the QueryOptions.");
    return connectionManager;
}