@Test public void testReadWriteQuery() throws Exception { final int NEMPLOYEE = 100; Utils.populateEmployeeStore(employeeStore, NEMPLOYEE); InfinispanQuery<String,Employee> query; int retrieved = 0; query = new InfinispanQuery<>(employeeDataStore); query.build(); for (PartitionQuery<String,Employee> q : employeeDataStore.getPartitions(query)) { retrieved+=((InfinispanQuery<String,Employee>) q).list().size(); } assert retrieved==NEMPLOYEE; query = new InfinispanQuery<>(employeeDataStore); SingleFieldValueFilter<String, Employee> filter = new SingleFieldValueFilter<String, Employee>(); filter.setFieldName("name"); filter.setFilterOp(FilterOp.EQUALS); List<Object> operaands = new ArrayList<>(); operaands.add("*"); filter.setOperands(operaands); query.setFilter(filter); query.build(); List<Employee> result = new ArrayList<>(); for (PartitionQuery<String,Employee> q : employeeDataStore.getPartitions(query)) { result.addAll(((InfinispanQuery<String,Employee>)q).list()); } assertEquals(NEMPLOYEE,result.size()); query = new InfinispanQuery<>(employeeDataStore); filter = new SingleFieldValueFilter<String, Employee>(); filter.setFieldName("name"); filter.setFilterOp(FilterOp.NOT_EQUALS); operaands.clear(); operaands.add("*"); filter.setOperands(operaands); query.setFilter(filter); query.build(); assertEquals(0,query.list().size()); }
@Override public List<PartitionQuery<K, T>> getPartitions(Query<K, T> query) throws IOException { LOG.debug("getPartitions()"); List<PartitionQuery<K,T>> locations = ((InfinispanQuery<K,T>)query).split(); List<PartitionQuery<K,T>> splitLocations = new ArrayList<>(); for(PartitionQuery<K,T> location : locations) { LOG.trace("location: "+ ((InfinispanQuery<K, T>)location).getLocation().toString()); InfinispanQuery<K,T> sizeQuery = (InfinispanQuery<K, T>) ((InfinispanQuery<K, T>) location).clone(); sizeQuery.setFields(primaryFieldName); sizeQuery.setLimit(1); sizeQuery.rebuild(); int resultSize = sizeQuery.getResultSize(); long queryLimit = query.getLimit(); long splitLimit = queryLimit>0 ? Math.min((long)resultSize,queryLimit) : resultSize; LOG.trace("split limit: "+ splitLimit); LOG.trace("split size: "+ splitSize); if (splitLimit <= splitSize) { LOG.trace("location returned"); splitLocations.add(location); continue; } for(int i=0; i<Math.ceil((double)splitLimit/(double)splitSize); i++) { InfinispanQuery<K, T> split = (InfinispanQuery<K, T>) ((InfinispanQuery<K, T>) location).clone(); split.setOffset(i * splitSize); split.setLimit(splitSize); split.rebuild(); splitLocations.add(split); } } return splitLocations; }
InfinispanStore extends DataStoreBase<K, T> { @Override public List<PartitionQuery<K, T>> getPartitions(Query<K, T> query) throws IOException { LOG.debug("getPartitions()"); List<PartitionQuery<K,T>> locations = ((InfinispanQuery<K,T>)query).split(); List<PartitionQuery<K,T>> splitLocations = new ArrayList<>(); for(PartitionQuery<K,T> location : locations) { LOG.trace("location: "+ ((InfinispanQuery<K, T>)location).getLocation().toString()); InfinispanQuery<K,T> sizeQuery = (InfinispanQuery<K, T>) ((InfinispanQuery<K, T>) location).clone(); sizeQuery.setFields(primaryFieldName); sizeQuery.setLimit(1); sizeQuery.rebuild(); int resultSize = sizeQuery.getResultSize(); long queryLimit = query.getLimit(); long splitLimit = queryLimit>0 ? Math.min((long)resultSize,queryLimit) : resultSize; LOG.trace("split limit: "+ splitLimit); LOG.trace("split size: "+ splitSize); if (splitLimit <= splitSize) { LOG.trace("location returned"); splitLocations.add(location); continue; } for(int i=0; i<Math.ceil((double)splitLimit/(double)splitSize); i++) { InfinispanQuery<K, T> split = (InfinispanQuery<K, T>) ((InfinispanQuery<K, T>) location).clone(); split.setOffset(i * splitSize); split.setLimit(splitSize); split.rebuild(); splitLocations.add(split); } } return splitLocations; } }
InfinispanStore extends DataStoreBase<K, T> { @Override public List<PartitionQuery<K, T>> getPartitions(Query<K, T> query) throws IOException { LOG.debug("getPartitions()"); List<PartitionQuery<K,T>> locations = ((InfinispanQuery<K,T>)query).split(); List<PartitionQuery<K,T>> splitLocations = new ArrayList<>(); for(PartitionQuery<K,T> location : locations) { LOG.trace("location: "+ ((InfinispanQuery<K, T>)location).getLocation().toString()); InfinispanQuery<K,T> sizeQuery = (InfinispanQuery<K, T>) ((InfinispanQuery<K, T>) location).clone(); sizeQuery.setFields(primaryFieldName); sizeQuery.setLimit(1); sizeQuery.rebuild(); int resultSize = sizeQuery.getResultSize(); long queryLimit = query.getLimit(); long splitLimit = queryLimit>0 ? Math.min((long)resultSize,queryLimit) : resultSize; LOG.trace("split limit: "+ splitLimit); LOG.trace("split size: "+ splitSize); if (splitLimit <= splitSize) { LOG.trace("location returned"); splitLocations.add(location); continue; } for(int i=0; i<Math.ceil((double)splitLimit/(double)splitSize); i++) { InfinispanQuery<K, T> split = (InfinispanQuery<K, T>) ((InfinispanQuery<K, T>) location).clone(); split.setOffset(i * splitSize); split.setLimit(splitSize); split.rebuild(); splitLocations.add(split); } } return splitLocations; } InfinispanStore(); }
InfinispanStore extends DataStoreBase<K, T> { @Override public List<PartitionQuery<K, T>> getPartitions(Query<K, T> query) throws IOException { LOG.debug("getPartitions()"); List<PartitionQuery<K,T>> locations = ((InfinispanQuery<K,T>)query).split(); List<PartitionQuery<K,T>> splitLocations = new ArrayList<>(); for(PartitionQuery<K,T> location : locations) { LOG.trace("location: "+ ((InfinispanQuery<K, T>)location).getLocation().toString()); InfinispanQuery<K,T> sizeQuery = (InfinispanQuery<K, T>) ((InfinispanQuery<K, T>) location).clone(); sizeQuery.setFields(primaryFieldName); sizeQuery.setLimit(1); sizeQuery.rebuild(); int resultSize = sizeQuery.getResultSize(); long queryLimit = query.getLimit(); long splitLimit = queryLimit>0 ? Math.min((long)resultSize,queryLimit) : resultSize; LOG.trace("split limit: "+ splitLimit); LOG.trace("split size: "+ splitSize); if (splitLimit <= splitSize) { LOG.trace("location returned"); splitLocations.add(location); continue; } for(int i=0; i<Math.ceil((double)splitLimit/(double)splitSize); i++) { InfinispanQuery<K, T> split = (InfinispanQuery<K, T>) ((InfinispanQuery<K, T>) location).clone(); split.setOffset(i * splitSize); split.setLimit(splitSize); split.rebuild(); splitLocations.add(split); } } return splitLocations; } InfinispanStore(); @Override synchronized void initialize(Class<K> keyClass, Class<T> persistentClass, Properties properties); @Override void close(); @Override void createSchema(); @Override boolean delete(K key); @Override long deleteByQuery(Query<K, T> query); @Override void deleteSchema(); @Override Result<K, T> execute(Query<K, T> query); @Override T get(K key); @Override boolean exists(K key); @Override T get(K key, String[] fields); @Override List<PartitionQuery<K, T>> getPartitions(Query<K, T> query); @Override void flush(); @Override String getSchemaName(); @Override Query<K, T> newQuery(); @Override void put(K key, T obj); @Override boolean schemaExists(); InfinispanClient<K, T> getClient(); String getPrimaryFieldName(); void setPrimaryFieldName(String name); int getPrimaryFieldPos(); void setPrimaryFieldPos(int p); }
InfinispanStore extends DataStoreBase<K, T> { @Override public List<PartitionQuery<K, T>> getPartitions(Query<K, T> query) throws IOException { LOG.debug("getPartitions()"); List<PartitionQuery<K,T>> locations = ((InfinispanQuery<K,T>)query).split(); List<PartitionQuery<K,T>> splitLocations = new ArrayList<>(); for(PartitionQuery<K,T> location : locations) { LOG.trace("location: "+ ((InfinispanQuery<K, T>)location).getLocation().toString()); InfinispanQuery<K,T> sizeQuery = (InfinispanQuery<K, T>) ((InfinispanQuery<K, T>) location).clone(); sizeQuery.setFields(primaryFieldName); sizeQuery.setLimit(1); sizeQuery.rebuild(); int resultSize = sizeQuery.getResultSize(); long queryLimit = query.getLimit(); long splitLimit = queryLimit>0 ? Math.min((long)resultSize,queryLimit) : resultSize; LOG.trace("split limit: "+ splitLimit); LOG.trace("split size: "+ splitSize); if (splitLimit <= splitSize) { LOG.trace("location returned"); splitLocations.add(location); continue; } for(int i=0; i<Math.ceil((double)splitLimit/(double)splitSize); i++) { InfinispanQuery<K, T> split = (InfinispanQuery<K, T>) ((InfinispanQuery<K, T>) location).clone(); split.setOffset(i * splitSize); split.setLimit(splitSize); split.rebuild(); splitLocations.add(split); } } return splitLocations; } InfinispanStore(); @Override synchronized void initialize(Class<K> keyClass, Class<T> persistentClass, Properties properties); @Override void close(); @Override void createSchema(); @Override boolean delete(K key); @Override long deleteByQuery(Query<K, T> query); @Override void deleteSchema(); @Override Result<K, T> execute(Query<K, T> query); @Override T get(K key); @Override boolean exists(K key); @Override T get(K key, String[] fields); @Override List<PartitionQuery<K, T>> getPartitions(Query<K, T> query); @Override void flush(); @Override String getSchemaName(); @Override Query<K, T> newQuery(); @Override void put(K key, T obj); @Override boolean schemaExists(); InfinispanClient<K, T> getClient(); String getPrimaryFieldName(); void setPrimaryFieldName(String name); int getPrimaryFieldPos(); void setPrimaryFieldPos(int p); static final Logger LOG; }