org.apache.gora.query.Query.execute()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(8.1k)|赞(0)|评价(0)|浏览(165)

本文整理了Java中org.apache.gora.query.Query.execute方法的一些代码示例,展示了Query.execute的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Query.execute方法的具体详情如下:
包路径:org.apache.gora.query.Query
类名称:Query
方法名:execute

Query.execute介绍

[英]Executes the Query on the DataStore and returns the results.
[中]在数据存储上执行查询并返回结果。

代码示例

代码示例来源:origin: org.apache.gora/gora-core

public void executeQuery() throws Exception {
 this.result = query.execute();
}

代码示例来源:origin: apache/gora

public void executeQuery() throws Exception {
 this.result = query.execute();
}

代码示例来源:origin: apache/gora

/** Queries and prints a single pageview object */
private void query(long key) throws Exception {
 //Queries are constructed from the data store
 Query<Long, Pageview> query = dataStore.newQuery();
 query.setKey(key);
 
 Result<Long, Pageview> result = query.execute(); //Actually executes the query.
 // alternatively dataStore.execute(query); can be used
 
 printResult(result);
}

代码示例来源:origin: org.apache.gora/gora-aerospike

/**
 * {@inheritDoc}
 *
 * @param query matching records to this query will be deleted
 * @return the number of deleted records
 */
@Override
public long deleteByQuery(Query<K, T> query) {
 Result<K, T> result = query.execute();
 int deleteCount = 0;
 try {
  while (result.next()) {
   if (aerospikeClient.delete(null, getAerospikeKey(result.getKey()))) {
    deleteCount++;
   }
  }
  return deleteCount;
 } catch (Exception e) {
  LOG.error(e.getMessage(), e);
  return -1;
 }
}

代码示例来源:origin: com.argonio.gora/gora-hbase

@Override
public long deleteByQuery(Query<K, T> query) {
 try {
  String[] fields = getFieldsToQuery(query.getFields());
  //find whether all fields are queried, which means that complete
  //rows will be deleted
  boolean isAllFields = Arrays.equals(fields, getFields());

  org.apache.gora.query.Result<K, T> result = null;
  result = query.execute();
  ArrayList<Delete> deletes = new ArrayList<Delete>();
  while(result.next()) {
   Delete delete = new Delete(toBytes(result.getKey()));
   deletes.add(delete);
   if(!isAllFields) {
    addFields(delete, query);
   }
  }
  table.delete(deletes);
  return deletes.size();
 } catch (Exception ex) {
  LOG.error(ex.getMessage());
  LOG.error(ex.getStackTrace().toString());
  return -1;
 }
}

代码示例来源:origin: apache/gora

/**
 * Queries and prints pageview object that have keys between startKey and endKey
 */
private void query(long startKey, long endKey) throws Exception {
 Query<Long, Pageview> query = cacheStore.newQuery();
 //set the properties of query
 query.setStartKey(startKey);
 query.setEndKey(endKey);
 Result<Long, Pageview> result = query.execute();
 printResult(result);
}

代码示例来源:origin: apache/gora

/** Queries and prints pageview object that have keys between startKey and endKey*/
private void query(long startKey, long endKey) throws Exception {
 Query<Long, Pageview> query = dataStore.newQuery();
 //set the properties of query
 query.setStartKey(startKey);
 query.setEndKey(endKey);
 
 Result<Long, Pageview> result = query.execute();
 
 printResult(result);
}

代码示例来源:origin: apache/gora

@Override
public long deleteByQuery(Query<K, T> query) throws GoraException {
 try {
  String[] fields = getFieldsToQuery(query.getFields());
  //find whether all fields are queried, which means that complete
  //rows will be deleted
  boolean isAllFields = Arrays.equals(fields, getFields());

  org.apache.gora.query.Result<K, T> result = null;
  result = query.execute();
  ArrayList<Delete> deletes = new ArrayList<>();
  while(result.next()) {
   Delete delete = new Delete(toBytes(result.getKey()));
   deletes.add(delete);
   if(!isAllFields) {
    addFields(delete, query);
   }
  }
  table.delete(deletes);
  return deletes.size();
 } catch (GoraException e) {
  throw e;
 } catch (Exception e) {
  throw new GoraException(e);
 }
}

代码示例来源:origin: org.apache.gora/gora-jcache

try {
 long deletedRows = 0;
 Result<K, T> result = query.execute();
 String[] fields = getFieldsToQuery(query.getFields());
 boolean isAllFields = Arrays.equals(fields, getFields());

代码示例来源:origin: apache/gora

this.hazelcastInstance.getCluster().getMembers().toArray(clusterMembers);
for (Member member : clusterMembers) {
 JCacheResult<K, T> result = ((JCacheResult<K, T>) query.execute());
 ConcurrentSkipListSet<K> memberOwnedCacheEntries = new ConcurrentSkipListSet<>();
 while (result.next()) {

代码示例来源:origin: org.apache.gora/gora-core

try {
 long deletedRows = 0;
 Result<K, T> result = query.execute();

代码示例来源:origin: org.apache.gora/gora-jcache

@Override
public List<PartitionQuery<K, T>> getPartitions(Query<K, T> query) throws IOException {
 List<PartitionQuery<K, T>> partitions = new ArrayList<>();
 try {
  Member[] clusterMembers = new Member[hazelcastInstance.getCluster().getMembers().size()];
  this.hazelcastInstance.getCluster().getMembers().toArray(clusterMembers);
  for (Member member : clusterMembers) {
   JCacheResult<K, T> result = ((JCacheResult<K, T>) query.execute());
   ConcurrentSkipListSet<K> memberOwnedCacheEntries = new ConcurrentSkipListSet<>();
   while (result.next()) {
    K key = result.getKey();
    Partition partition = hazelcastInstance.getPartitionService().getPartition(key);
    if (partition.getOwner().getUuid().equals(member.getUuid())) {
     memberOwnedCacheEntries.add(key);
    }
   }
   PartitionQueryImpl<K, T> partition = new PartitionQueryImpl<>(
       query, memberOwnedCacheEntries.first(),
       memberOwnedCacheEntries.last(), member.getSocketAddress().getHostString());
   partition.setConf(this.getConf());
   partitions.add(partition);
  }
 } catch (java.lang.Exception ex) {
  LOG.error("Exception occurred while partitioning the query based on Hazelcast partitions.", ex);
  return null;
 }
 LOG.info("Query is partitioned to {} number of partitions.", partitions.size());
 return partitions;
}

代码示例来源:origin: apache/gora

try {
 long deletedRows = 0;
 Result<K, T> result = query.execute();

代码示例来源:origin: apache/gora

try {
 long deletedRows = 0;
 Result<K, T> result = query.execute();
 String[] fields = getFieldsToQuery(query.getFields());
 boolean isAllFields = Arrays.equals(fields, getFields());

代码示例来源:origin: apache/gora

/**
 * {@inheritDoc}
 *
 * @param query matching records to this query will be deleted
 * @return the number of deleted records
 */
@Override
public long deleteByQuery(Query<K, T> query) throws GoraException {
 int deleteCount = 0;
 try {
  Result<K, T> result = query.execute();
  while (result.next()) {
   if (aerospikeClient.delete(null, getAerospikeKey(result.getKey()))) {
    deleteCount++;
   }
  }
  return deleteCount;
 } catch (Exception e) {
  throw new GoraException(e);
 }
}

代码示例来源:origin: apache/gora

public static<K,T extends Persistent> void assertNumResults(Query<K, T>query
  , long numResults) throws Exception {
 Result<K, T> result = query.execute();
 int actualNumResults = 0;
 while(result.next()) {
  actualNumResults++;
 }
 result.close();
 assertEquals(numResults, actualNumResults);
}

代码示例来源:origin: apache/gora

public static void testQueryWebPages(DataStore<String, WebPage> store)
throws Exception {
 Query<String, WebPage> query = store.newQuery();
 Result<String, WebPage> result = query.execute();
 int i=0;
 while(result.next()) {
  WebPage page = result.get();
  DataStoreTestUtil.assertWebPage(page, URL_INDEXES.get(page.getUrl().toString()));
  i++;
 }
 assertEquals(i, URLS.length);
}

代码示例来源:origin: apache/gora

if(setEndKeys)
 query.setEndKey(sortedUrls.get(j));
Result<String, WebPage> result = query.execute();

代码示例来源:origin: apache/gora

/**
 * Creates an WebPage object in-memory setting several fields to dirty.
 * Run a query over the persistent data.
 * Asserts that the results can be serialized and
 * deserialzed without loosing data. We do this by asserting
 * what we get 'before' and 'after' (de)serialization processes.
 * Also simple assertion for equal number of URL's in WebPage
 * and results.
 * @throws Exception
 */
@SuppressWarnings("unchecked")
@Test
public void testSerdeWebPage() throws Exception {
 MemStore<String, WebPage> store = DataStoreFactory.getDataStore(
     MemStore.class, String.class, WebPage.class, new Configuration());
 WebPageDataCreator.createWebPageData(store);
 Result<String, WebPage> result = store.newQuery().execute();
 int i = 0;
 while (result.next()) {
  WebPage page = result.get();
  TestIOUtils.testSerializeDeserialize(page);
  i++;
 }
 assertEquals(WebPageDataCreator.URLS.length, i);
}

代码示例来源:origin: apache/gora

private static void testQueryWebPageSingleKey(DataStore<String, WebPage> store
  , String[] fields) throws Exception {
 createWebPageData(store);
 for(int i=0; i<URLS.length; i++) {
  Query<String, WebPage> query = store.newQuery();
  query.setFields(fields);
  query.setKey(URLS[i]);
  Result<String, WebPage> result = query.execute();
  assertTrue(result.next());
  WebPage page = result.get();
  assertWebPage(page, i);
  assertFalse(result.next());
 }
}

相关文章