Java Code Examples for com.googlecode.cqengine.resultset.ResultSet#getMergeCost()
The following examples show how to use
com.googlecode.cqengine.resultset.ResultSet#getMergeCost() .
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: QueryCostComparators.java From cqengine with Apache License 2.0 | 5 votes |
@Override public int compare(ResultSet o1, ResultSet o2) { final int o1MergeCost = o1.getMergeCost(); final int o2MergeCost = o2.getMergeCost(); if (o1MergeCost < o2MergeCost) { return -1; } else if (o1MergeCost > o2MergeCost) { return +1; } else { return 0; } }
Example 2
Source File: ResultSetUnionAll.java From cqengine with Apache License 2.0 | 5 votes |
/** * Returns the sum of the merge costs of the the underlying {@code ResultSet}s. * @return the sum of the merge costs of the the underlying {@code ResultSet}s */ @Override public int getMergeCost() { long mergeCost = 0; for (ResultSet<O> resultSet : this.resultSets) { mergeCost = mergeCost + resultSet.getMergeCost(); } return (int)Math.min(mergeCost, Integer.MAX_VALUE); }
Example 3
Source File: ResultSetIntersection.java From cqengine with Apache License 2.0 | 5 votes |
/** * Returns the merge cost from the underlying {@code ResultSet} with the lowest merge cost. * @return the merge cost from the underlying {@code ResultSet} with the lowest merge cost */ @Override public int getMergeCost() { if (resultSets.isEmpty()) { return 0; } else { ResultSet<O> lowestMergeCostResultSet = resultSets.get(0); return lowestMergeCostResultSet.getMergeCost(); } }
Example 4
Source File: ResultSetUnion.java From cqengine with Apache License 2.0 | 5 votes |
/** * Returns the sum of the merge costs of the the underlying {@code ResultSet}s. * @return the sum of the merge costs of the the underlying {@code ResultSet}s */ @Override public int getMergeCost() { long mergeCost = 0; for (ResultSet<O> resultSet : this.resultSets) { mergeCost = mergeCost + resultSet.getMergeCost(); } return (int)Math.min(mergeCost, Integer.MAX_VALUE); }
Example 5
Source File: SQLiteIndexTest.java From cqengine with Apache License 2.0 | 5 votes |
@Test public void testNewResultSet_GetMergeCost() 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(objectKey) FROM " + TABLE_NAME + " WHERE value = ?;")).thenReturn(preparedStatement); when(preparedStatement.executeQuery()).thenReturn(resultSet); when(resultSet.getStatement()).thenReturn(preparedStatement); when(resultSet.next()).thenReturn(true); when(resultSet.getInt(1)).thenReturn(3); // Iterator 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.getMergeCost(); assertEquals(3, size); verify(connection, times(0)).close(); }
Example 6
Source File: SQLiteIndexTest.java From cqengine with Apache License 2.0 | 5 votes |
@Test public void testNewResultSet_FilterQuery_GetMergeCost() throws Exception{ // Mocks FilterQuery<Car, String> filterQuery = mockFilterQuery(); 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(objectKey) FROM " + TABLE_NAME + " ;")).thenReturn(preparedStatement); when(preparedStatement.executeQuery()).thenReturn(resultSet); when(resultSet.getStatement()).thenReturn(preparedStatement); when(resultSet.next()).thenReturn(true); when(resultSet.getInt(1)).thenReturn(3); // Iterator ResultSet<Car> cars = new SQLiteIndex<String, Car, Integer>( Car.FEATURES, OBJECT_TO_ID, ID_TO_OBJECT, "") .retrieve(filterQuery, createQueryOptions(connectionManager)); assertNotNull(cars); int mergeCost = cars.getMergeCost(); assertEquals(3, mergeCost); verify(connection, times(0)).close(); }