Java Code Examples for com.googlecode.cqengine.resultset.ResultSet#size()

The following examples show how to use com.googlecode.cqengine.resultset.ResultSet#size() . 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: ResultSets.java    From cqengine with Apache License 2.0 6 votes vote down vote up
/**
 * Returns a Collection-like view of the given ResultSet.
 * <p/>
 * The collection simply delegates to the ResultSet, which in turn will reflect
 * any changes made to the underlying IndexedCollection by other threads.
 * For example consecutive calls to the size() method
 * may return different values if objects are added to or removed from the IndexedCollection.
 *
 * @param resultSet The ResultSet to wrap
 * @return A Collection-like view of the given ResultSet
 */
public static <O> Collection<O> asCollection(final ResultSet<O> resultSet) {
    return new AbstractCollection<O>() {
        @Override
        public Iterator<O> iterator() {
            return resultSet.iterator();
        }
        @Override
        public int size() {
            return resultSet.size();
        }

        @Override
        public boolean contains(Object o) {
            @SuppressWarnings("unchecked")
            O object = (O)o;
            return resultSet.contains(object);
        }

        @Override
        public boolean isEmpty() {
            return resultSet.isEmpty();
        }
    };
}
 
Example 2
Source File: SQLiteIndexTest.java    From cqengine with Apache License 2.0 5 votes vote down vote up
@Test
public void testNewResultSet_FilterQuery_Size() throws Exception{

    // Mocks
    FilterQuery<Car, String> filterQuery = mockFilterQuery();
    ConnectionManager connectionManager = mock(ConnectionManager.class);
    Connection connection = mock(Connection.class);
    Statement statement = mock(PreparedStatement.class);
    java.sql.ResultSet resultSet = mock(java.sql.ResultSet.class);

    // Behaviour//
    when(connectionManager.getConnection(any(SQLiteIndex.class), anyQueryOptions())).thenReturn(connection);
    when(connection.createStatement()).thenReturn(statement);
    when(statement.executeQuery("SELECT objectKey, value FROM " + TABLE_NAME + " ORDER BY objectKey;")).thenReturn(resultSet);
    when(resultSet.getStatement()).thenReturn(statement);
    when(resultSet.next()).thenReturn(true).thenReturn(true).thenReturn(true).thenReturn(true).thenReturn(true).thenReturn(true).thenReturn(false);
    when(resultSet.getInt(1)).thenReturn(1).thenReturn(1).thenReturn(2).thenReturn(3).thenReturn(4).thenReturn(5);
    when(resultSet.getString(2)).thenReturn("abs").thenReturn("gps").thenReturn("airbags").thenReturn("abs").thenReturn("").thenReturn("gps");

    ResultSet<Car> carsWithAbs = new SQLiteIndex<String, Car, Integer>(
            Car.FEATURES,
            OBJECT_TO_ID,
            ID_TO_OBJECT,
            "")

            .retrieve(filterQuery, createQueryOptions(connectionManager));


    assertNotNull(carsWithAbs);
    int size = carsWithAbs.size();

    assertEquals(3, size);
    verify(connection, times(0)).close();

}
 
Example 3
Source File: QueryableShipData.java    From Valkyrien-Skies with Apache License 2.0 5 votes vote down vote up
public Optional<ShipData> getShipFromChunk(long chunkLong) {
    Query<ShipData> query = equal(ShipData.CHUNKS, chunkLong);
    ResultSet<ShipData> resultSet = allShips.retrieve(query);

    if (resultSet.size() > 1) {
        throw new IllegalStateException("How the heck did we get 2 or more ships both managing the chunk at " + chunkLong);
    }
    if (resultSet.isEmpty()) {
        return Optional.empty();
    } else {
        return Optional.of(resultSet.uniqueResult());
    }
}
 
Example 4
Source File: SQLiteIndexTest.java    From cqengine with Apache License 2.0 5 votes vote down vote up
@Test
public void testNewResultSet_Size() throws Exception{

    // Mocks
    ConnectionManager connectionManager = mock(ConnectionManager.class);
    Connection connection = mock(Connection.class);
    PreparedStatement preparedStatement = mock(PreparedStatement.class);
    java.sql.ResultSet resultSet = mock(java.sql.ResultSet.class);

    // Behaviour
    when(connectionManager.getConnection(any(SQLiteIndex.class), anyQueryOptions())).thenReturn(connection);
    when(connection.prepareStatement("SELECT COUNT(1) AS countDistinct FROM (SELECT objectKey FROM " + TABLE_NAME + " WHERE value = ? GROUP BY objectKey);")).thenReturn(preparedStatement);
    when(preparedStatement.executeQuery()).thenReturn(resultSet);
    when(resultSet.getStatement()).thenReturn(preparedStatement);
    when(resultSet.next()).thenReturn(true);
    when(resultSet.getInt(1)).thenReturn(3);

    ResultSet<Car> carsWithAbs = new SQLiteIndex<String, Car, Integer>(
            Car.FEATURES,
            OBJECT_TO_ID,
            ID_TO_OBJECT,
            "")

            .retrieve(equal(Car.FEATURES, "abs"), createQueryOptions(connectionManager));


    assertNotNull(carsWithAbs);
    int size = carsWithAbs.size();

    assertEquals(3, size);
    verify(connection, times(0)).close();

}
 
Example 5
Source File: Quantized_HashIndex_CarId.java    From cqengine with Apache License 2.0 4 votes vote down vote up
@Override
public int runQueryCountResults_CQEngineStatistics() {
    ResultSet<Car> results = indexedCollection.retrieve(query);
    return results.size();
}
 
Example 6
Source File: NonOptimalIndexes_ManufacturerToyotaColorBlueDoorsThree.java    From cqengine with Apache License 2.0 4 votes vote down vote up
@Override
public int runQueryCountResults_CQEngineStatistics() {
    ResultSet<Car> results = indexedCollection.retrieve(query);
    return results.size();
}
 
Example 7
Source File: NoIndexes_ModelFocus.java    From cqengine with Apache License 2.0 4 votes vote down vote up
@Override
public int runQueryCountResults_CQEngineStatistics() {
    ResultSet<Car> results = indexedCollection.retrieve(query);
    return results.size();
}
 
Example 8
Source File: HashIndex_CarId.java    From cqengine with Apache License 2.0 4 votes vote down vote up
@Override
public int runQueryCountResults_CQEngineStatistics() {
    ResultSet<Car> results = indexedCollection.retrieve(query);
    return results.size();
}
 
Example 9
Source File: HashIndex_ManufacturerFord.java    From cqengine with Apache License 2.0 4 votes vote down vote up
@Override
public int runQueryCountResults_CQEngineStatistics() {
    ResultSet<Car> results = indexedCollection.retrieve(query);
    return results.size();
}
 
Example 10
Source File: CompoundIndex_ManufacturerToyotaColorBlueDoorsThree.java    From cqengine with Apache License 2.0 4 votes vote down vote up
@Override
public int runQueryCountResults_CQEngineStatistics() {
    ResultSet<Car> results = indexedCollection.retrieve(query);
    return results.size();
}
 
Example 11
Source File: NavigableIndex_PriceBetween.java    From cqengine with Apache License 2.0 4 votes vote down vote up
@Override
public int runQueryCountResults_CQEngineStatistics() {
    ResultSet<Car> results = indexedCollection.retrieve(query);
    return results.size();
}
 
Example 12
Source File: StandingQueryIndex_ManufacturerToyotaColorBlueDoorsNotFive.java    From cqengine with Apache License 2.0 4 votes vote down vote up
@Override
public int runQueryCountResults_CQEngineStatistics() {
    ResultSet<Car> results = indexedCollection.retrieve(query);
    return results.size();
}
 
Example 13
Source File: Quantized_NavigableIndex_CarId.java    From cqengine with Apache License 2.0 4 votes vote down vote up
@Override
public int runQueryCountResults_CQEngineStatistics() {
    ResultSet<Car> results = indexedCollection.retrieve(query);
    return results.size();
}
 
Example 14
Source File: SuffixTreeIndex_ModelContainsG.java    From cqengine with Apache License 2.0 4 votes vote down vote up
@Override
public int runQueryCountResults_CQEngineStatistics() {
    ResultSet<Car> results = indexedCollection.retrieve(query);
    return results.size();
}
 
Example 15
Source File: UniqueIndex_CarId.java    From cqengine with Apache License 2.0 4 votes vote down vote up
@Override
public int runQueryCountResults_CQEngineStatistics() {
    ResultSet<Car> results = indexedCollection.retrieve(query);
    return results.size();
}
 
Example 16
Source File: RadixTreeIndex_ModelStartsWithP.java    From cqengine with Apache License 2.0 4 votes vote down vote up
@Override
public int runQueryCountResults_CQEngineStatistics() {
    ResultSet<Car> results = indexedCollection.retrieve(query);
    return results.size();
}
 
Example 17
Source File: HashIndex_ModelFocus.java    From cqengine with Apache License 2.0 4 votes vote down vote up
@Override
public int runQueryCountResults_CQEngineStatistics() {
    ResultSet<Car> results = indexedCollection.retrieve(query);
    return results.size();
}