• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java Query类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.infinispan.query.dsl.Query的典型用法代码示例。如果您正苦于以下问题:Java Query类的具体用法?Java Query怎么用?Java Query使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Query类属于org.infinispan.query.dsl包,在下文中一共展示了Query类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: main

import org.infinispan.query.dsl.Query; //导入依赖的package包/类
public static void main(String[] args) {
   ConfigurationBuilder builder = new ConfigurationBuilder();
   builder.indexing().index(Index.ALL)
      .addProperty("default.directory_provider", "ram")
      .addProperty("lucene_version", "LUCENE_CURRENT");
   // Construct a simple local cache manager with default configuration
   DefaultCacheManager cacheManager = new DefaultCacheManager(builder.build());
   // Obtain the default cache
   Cache<String, Person> cache = cacheManager.getCache();
   // Store some entries
   cache.put("person1", new Person("William", "Shakespeare"));
   cache.put("person2", new Person("William", "Wordsworth"));
   cache.put("person3", new Person("John", "Milton"));
   // Obtain a query factory for the cache
   QueryFactory queryFactory = Search.getQueryFactory(cache);
   // Construct a query
   Query query = queryFactory.from(Person.class).having("name").eq("William").toBuilder().build();
   // Execute the query
   List<Person> matches = query.list();
   // List the results
   matches.forEach(person -> System.out.printf("Match: %s", person));
   // Stop the cache manager and release all resources
   cacheManager.stop();
}
 
开发者ID:infinispan,项目名称:infinispan-simple-tutorials,代码行数:25,代码来源:InfinispanQuery.java


示例2: split

import org.infinispan.query.dsl.Query; //导入依赖的package包/类
public Collection<RemoteQuery> split(Query query) {
   TransportFactory transportFactory
         = ((OperationsFactory)cache.getOperationsFactory()).getTransportFactory();
   if (!(query instanceof RemoteQuery))
      throw new CacheException("need an AvroRemoteQuery");
   if (!(transportFactory instanceof  TcpTransportFactory))
      throw new CacheException("need a TcpTransportFactory");
   Collection<SocketAddress> servers = ((TcpTransportFactory)transportFactory).getServers();
   Collection<RemoteQuery> results = new ArrayList<>();
   for (SocketAddress addr: servers) {
      InetSocketAddress address = (InetSocketAddress) addr;
      try {
         RemoteQuery q = (RemoteQuery) ((RemoteQuery) query).clone();
         q.setLocation(address);
         results.add(q);
      } catch (CloneNotSupportedException e) {
         e.printStackTrace();
         // not reachable.
      }
   }
   return results;
}
 
开发者ID:leads-project,项目名称:infinispan-avro,代码行数:23,代码来源:QueryBuilder.java


示例3: testProjections

import org.infinispan.query.dsl.Query; //导入依赖的package包/类
@Test
public void testProjections() throws Exception {
   employeeCache.put(1, Utils.createEmployee1());
   employeeCache.put(2, Utils.createEmployee2());

   // get Employee back from remote cache and check its attributes
   Employee fromCache = employeeCache.get(1);
   Utils.assertEmployee(fromCache);

   // get Employee back from remote cache via query and check its attributes
   Query query = employeeQF.from(Employee.class)
         .setProjection("name")
         .having("name").eq("Tom").toBuilder()
         .build();

   List<Employee> list = query.list();
   assertNotNull(list);
   assertEquals(1, list.size());
   assertEquals("Tom", list.get(0).getName());
}
 
开发者ID:leads-project,项目名称:infinispan-avro,代码行数:21,代码来源:QueryTest.java


示例4: testAttributeQuery

import org.infinispan.query.dsl.Query; //导入依赖的package包/类
@Test
public void testAttributeQuery() throws Exception {

   remoteCache0.put(1, createEmployee1());
   remoteCache0.put(2, createEmployee2());

   QueryFactory qf = Search.getQueryFactory(remoteCache1);

   Query query = qf.from(Employee.class)
         .having("ssn").eq("12357").toBuilder()
         .build();
   List<Employee> list = query.list();
   assertNotNull(list);
   assertEquals(1, list.size());

}
 
开发者ID:leads-project,项目名称:infinispan-avro,代码行数:17,代码来源:MultiHotRodQueryTest.java


示例5: getResources

import org.infinispan.query.dsl.Query; //导入依赖的package包/类
@Override
public ResultSet<Resource> getResources(ResourceFilter filter, long startOffset, int maxResults) {
    QueryBuilder qb = qResource.from(IspnResource.class);
    FilterConditionContextQueryBuilder fccqb = null;
    if (filter.isRootOnly()) {
        fccqb = qb.having("parentId").isNull();
    }
    if (filter.getTypeId() != null) {
        fccqb = (fccqb == null ? qb : fccqb.and()).having("typeId").equal(filter.getTypeId());
    }
    if (filter.getFeedId() != null) {
        fccqb = (fccqb == null ? qb : fccqb.and()).having("feedId").equal(filter.getFeedId());
    }
    Query query = (fccqb == null ? qb : fccqb)
            .maxResults(maxResults)
            .startOffset(startOffset).build();
    List<IspnResource> ispnResources = query.list();
    List<Resource> result = ispnResources
            .stream()
            .map(r -> r.toResource(this::getResourceType))
            .collect(Collectors.toList());
    return new ResultSet<>(result, (long) query.getResultSize(), startOffset);
}
 
开发者ID:hawkular,项目名称:hawkular-commons,代码行数:24,代码来源:InventoryServiceIspn.java


示例6: buildMetricsEndpoints

import org.infinispan.query.dsl.Query; //导入依赖的package包/类
@Override
public void buildMetricsEndpoints() {
    for (Map.Entry<String, String> filter : scrapeConfig.getFilter().entrySet()) {
        int nResults, offSet = 0;
        do {
            Query qb = qResource.from(IspnResource.class)
                    .having("typeId")
                    .equal(filter.getKey())
                    .startOffset(offSet)
                    .maxResults(MAX_RESULTS)
                    .build();
            nResults = qb.getResultSize();
            List<IspnResource> results = qb.list();
            offSet = results.size();
            results.forEach(r -> writeMetricsEndpoint(r.getRawResource()));
        } while (offSet < nResults);
    }
}
 
开发者ID:hawkular,项目名称:hawkular-commons,代码行数:19,代码来源:InventoryServiceIspn.java


示例7: getRules

import org.infinispan.query.dsl.Query; //导入依赖的package包/类
@Override
public List<?> getRules(final String clientIPAddress) {
    try {
        final RemoteCache<String, Rule> ruleCache = cacheManagerForIndexableCaches.getCache(SinkitCacheName.infinispan_rules.toString());
        final ImmutablePair<String, String> startEndAddresses = CIDRUtils.getStartEndAddresses(clientIPAddress);
        final String clientIPAddressPaddedBigInt = startEndAddresses.getLeft();
        log.log(Level.FINE, "Getting key [" + clientIPAddress + "] which actually translates to BigInteger zero padded representation " + "[" + clientIPAddressPaddedBigInt + "]");
        // Let's try to hit it
        Rule rule = ruleCache.withFlags(Flag.SKIP_CACHE_LOAD).get(clientIPAddressPaddedBigInt);
        if (rule != null) {
            return Collections.singletonList(rule);
        }
        QueryFactory qf = Search.getQueryFactory(ruleCache);
        Query query = qf.from(Rule.class)
                .having("startAddress").lte(clientIPAddressPaddedBigInt)
                .and()
                .having("endAddress").gte(clientIPAddressPaddedBigInt)
                .toBuilder().build();
        return query.list();
    } catch (Exception e) {
        log.log(Level.SEVERE, "getRules client address troubles", e);
        // TODO: Proper Error codes.
        return null;
    }
}
 
开发者ID:whalebone,项目名称:sinkit-core,代码行数:26,代码来源:WebApiEJB.java


示例8: getAllRules

import org.infinispan.query.dsl.Query; //导入依赖的package包/类
@Override
public List<?> getAllRules() {
    try {
        final RemoteCache<String, Rule> ruleCache = cacheManagerForIndexableCaches.getCache(SinkitCacheName.infinispan_rules.toString());
        log.log(Level.SEVERE, "getAllRules: This is a very expensive operation.");
        final QueryFactory qf = Search.getQueryFactory(ruleCache);
        final Query query = qf.from(Rule.class).build();
        // Hundreds of records...
        List<Rule> results = query.list();
        return results;
    } catch (Exception e) {
        log.log(Level.SEVERE, "getRules client address troubles", e);
        // TODO: Proper Error codes.
        return null;
    }
}
 
开发者ID:whalebone,项目名称:sinkit-core,代码行数:17,代码来源:WebApiEJB.java


示例9: deleteRulesByCustomer

import org.infinispan.query.dsl.Query; //导入依赖的package包/类
@Override
public String deleteRulesByCustomer(Integer customerId) {
    int counter = 0;
    //TODO: Shouldn't this be done by a one Infinispan DSL removal call?
    try {
        final RemoteCache<String, Rule> ruleCache = cacheManagerForIndexableCaches.getCache(SinkitCacheName.infinispan_rules.toString());
        final QueryFactory qf = Search.getQueryFactory(ruleCache);
        Query query = qf.from(Rule.class)
                .having("customerId").eq(customerId)
                .toBuilder().build();
        // TODO: Use CloseableIterator
        Iterator iterator = query.list().iterator();
        while (iterator.hasNext()) {
            ruleCache.remove(((Rule) iterator.next()).getStartAddress());
            counter++;
        }
        return counter + " RULES DELETED FOR CUSTOMER ID: " + customerId;
    } catch (Exception e) {
        log.log(Level.SEVERE, "deleteRulesByCustomer", e);
        // TODO: Proper Error codes.
        return null;
    }
}
 
开发者ID:whalebone,项目名称:sinkit-core,代码行数:24,代码来源:WebApiEJB.java


示例10: performKeySearch

import org.infinispan.query.dsl.Query; //导入依赖的package包/类
@Override
public Object performKeySearch(String cacheName, String columnNameInSource, Object value, ObjectConnection conn) throws TranslatorException {
    
	
	@SuppressWarnings("rawtypes")
	QueryBuilder qb = getQueryBuilder(cacheName, conn);
    
	value = escapeReservedChars(value);
	
    FilterConditionContext fcc = qb.having(columnNameInSource).eq(value);
	
	Query query = fcc.toBuilder().build();
	List<Object> results = query.list();
	if (results.size() == 1) {
		return results.get(0);
	} else if (results.size() > 1) {
		throw new TranslatorException(InfinispanPlugin.Util.gs(InfinispanPlugin.Event.TEIID25053, value.toString()));
	}
	
	return null;
}
 
开发者ID:kenweezy,项目名称:teiid,代码行数:22,代码来源:DSLSearch.java


示例11: initialize

import org.infinispan.query.dsl.Query; //导入依赖的package包/类
@Override
protected void initialize(me.snowdrop.data.core.spi.Query<T> query) {
    queryBuilder = queryFactory.from(query.getEntityClass());

    String[] fields = toFields(getProjections(query));
    if (fields != null) {
        Expression[] projection = new Expression[fields.length];
        for (int i = 0; i < fields.length; i++) {
            projection[i] = Expression.property(fields[i]);
        }
        queryBuilder = queryBuilder.select(projection);
    }

    super.initialize(query);
}
 
开发者ID:snowdrop,项目名称:spring-data-snowdrop,代码行数:16,代码来源:InfinispanRemoteQueryAdapter.java


示例12: applyQuery

import org.infinispan.query.dsl.Query; //导入依赖的package包/类
@Override
protected void applyQuery(me.snowdrop.data.core.spi.Query<T> query) {
    // we need to sort before creating query
    Sort sort = query.getSort();
    if (sort == null || sort.isUnsorted()) {
        Pageable pageable = query.getPageable();
        if (pageable != null && pageable.isPaged()) {
            sort = pageable.getSort();
        }
    }
    if (sort != null && sort.isSorted()) {
        queryHelper.convert(sort);
    }
}
 
开发者ID:snowdrop,项目名称:spring-data-snowdrop,代码行数:15,代码来源:InfinispanRemoteQueryAdapter.java


示例13: execute

import org.infinispan.query.dsl.Query; //导入依赖的package包/类
@Override
void execute(InfinispanConfiguration configuration, BasicCache<Object, Object> cache, Message message) {
    Query query = getQuery(configuration, cache, message);
    if (query == null) {
        return;
    }
    setResult(query.list(), message);
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:9,代码来源:InfinispanOperation.java


示例14: getQuery

import org.infinispan.query.dsl.Query; //导入依赖的package包/类
Query getQuery(InfinispanConfiguration configuration, BasicCache<Object, Object> cache, Message message) {
    if (InfinispanUtil.isRemote(cache)) {
        return InfinispanRemoteOperation.buildQuery(configuration, cache, message);
    } else {
        return null;
    }

}
 
开发者ID:HydAu,项目名称:Camel,代码行数:9,代码来源:InfinispanOperation.java


示例15: doStart

import org.infinispan.query.dsl.Query; //导入依赖的package包/类
@Override
protected void doStart() throws Exception {
    super.doStart();
    manager.start();

    cache = manager.getCache();
    if (configuration.hasQueryBuilder()) {
        if (InfinispanUtil.isRemote(cache)) {
            RemoteCache<Object, Object> remoteCache = InfinispanUtil.asRemote(cache);
            Query query = InfinispanRemoteOperation.buildQuery(configuration.getQueryBuilder(), remoteCache);

            continuousQuery = Search.getContinuousQuery(remoteCache);
            continuousQuery.addContinuousQueryListener(query, new ContinuousQueryEventListener(cache.getName()));
        } else {
            throw new IllegalArgumentException(
                "Can't run continuous queries against embedded cache (" + cache.getName() + ")");
        }
    } else {
        if (manager.isCacheContainerEmbedded()) {
            consumerHandler = InfinispanConsumerEmbeddedHandler.INSTANCE;
        } else if (manager.isCacheContainerRemote()) {
            consumerHandler = InfinispanConsumerRemoteHandler.INSTANCE;
        } else {
            throw new UnsupportedOperationException(
                "Unsupported CacheContainer type " + manager.getCacheContainer().getClass().getName());
        }

        listener = consumerHandler.start(this);
    }
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:31,代码来源:InfinispanConsumer.java


示例16: buildQuery

import org.infinispan.query.dsl.Query; //导入依赖的package包/类
public static Query buildQuery(InfinispanConfiguration configuration, BasicCache<Object, Object> cache, Message message) {
    InfinispanQueryBuilder queryBuilder = message.getHeader(InfinispanConstants.QUERY_BUILDER, InfinispanQueryBuilder.class);
    if (queryBuilder == null) {
        queryBuilder = configuration.getQueryBuilder();
    }

    return buildQuery(queryBuilder, cache);
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:9,代码来源:InfinispanRemoteOperation.java


示例17: getResourceTypes

import org.infinispan.query.dsl.Query; //导入依赖的package包/类
@Override
public ResultSet<ResourceType> getResourceTypes(long startOffset, int maxResults) {
    Query query = qResourceType.from(IspnResourceType.class)
            .maxResults(maxResults)
            .startOffset(startOffset)
            .build();
    return new ResultSet<>(query.list()
            .stream()
            .map(r -> ((IspnResourceType) r).getResourceType())
            .collect(Collectors.toList()),
            (long) query.getResultSize(),
            startOffset);
}
 
开发者ID:hawkular,项目名称:hawkular-commons,代码行数:14,代码来源:InventoryServiceIspn.java


示例18: getChildren

import org.infinispan.query.dsl.Query; //导入依赖的package包/类
@Override
public ResultSet<Resource> getChildren(String parentId, long startOffset, int maxResults) {
    Query query = qResource.from(IspnResource.class)
            .having("parentId").equal(parentId)
            .maxResults(maxResults)
            .startOffset(startOffset).build();
    List<IspnResource> ispnResources = query.list();
    List<Resource> result = ispnResources
            .stream()
            .map(r -> r.toResource(this::getResourceType))
            .collect(Collectors.toList());
    return new ResultSet<>(result, (long) query.getResultSize(), startOffset);
}
 
开发者ID:hawkular,项目名称:hawkular-commons,代码行数:14,代码来源:InventoryServiceIspn.java


示例19: rulesLookup

import org.infinispan.query.dsl.Query; //导入依赖的package包/类
/**
 * There are 3 ways to find the result, in ascending order by their cost:
 * 1. local cache of already found results based on clientIPAddressPaddedBigInt
 * 2. getting key clientIPAddressPaddedBigInt from the cache of Rules
 * 3. lookup in the cache of Rules based on subnets
 * <p>
 * TODO: List? Array? Map with additional data? Let's think this over.
 * TODO: Replace/factor out duplicated code in .getRules out of webApiEJB
 *
 * @param clientIPAddressPaddedBigInt
 * @return list of rules
 */
private List<Rule> rulesLookup(final String clientIPAddressPaddedBigInt, final RemoteCache<String, Rule> ruleCache) {
    try {
        log.log(Level.FINE, "Getting key BigInteger zero padded representation " + clientIPAddressPaddedBigInt);
        // Let's search subnets
        final String keyInCache = DigestUtils.md5Hex(clientIPAddressPaddedBigInt + clientIPAddressPaddedBigInt);
        log.log(Level.FINE, "keyInCache: " + keyInCache + ", from: " + (clientIPAddressPaddedBigInt + clientIPAddressPaddedBigInt));

        final List<Rule> cached = ruleLocalCache.get(keyInCache);
        if (cached != null) {
            return cached;
        } else {
            // Let's try to hit it
            final Rule rule = ruleCache.withFlags(Flag.SKIP_CACHE_LOAD).get(clientIPAddressPaddedBigInt);
            if (rule != null) {
                return Collections.singletonList(rule);
            }
            final QueryFactory qf = Search.getQueryFactory(ruleCache);
            final Query query = qf.from(Rule.class)
                    .having("startAddress").lte(clientIPAddressPaddedBigInt)
                    .and()
                    .having("endAddress").gte(clientIPAddressPaddedBigInt)
                    .toBuilder().build();
            if (query != null) {
                final List<Rule> result = query.list();
                ruleLocalCache.put(keyInCache, result);
                return result;

            }
            return Collections.emptyList();
        }
    } catch (Exception e) {
        log.log(Level.SEVERE, "getRules client address troubles", e);
        return null;
    }
}
 
开发者ID:whalebone,项目名称:sinkit-core,代码行数:48,代码来源:DNSApiEJB.java


示例20: createQueryHelper

import org.infinispan.query.dsl.Query; //导入依赖的package包/类
@Override
protected QueryHelper<Query, Void> createQueryHelper() {
    return new InfinispanQueryHelper(queryBuilder);
}
 
开发者ID:snowdrop,项目名称:spring-data-snowdrop,代码行数:5,代码来源:InfinispanRemoteQueryAdapter.java



注:本文中的org.infinispan.query.dsl.Query类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java DataConnectionConfigurationFactory类代码示例发布时间:2022-05-22
下一篇:
Java ArrayCounter类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap