Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/backbone.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何从`txn.getAll(";Entity";)`方法获取子集结果?_Java_Xodus - Fatal编程技术网

Java 如何从`txn.getAll(";Entity";)`方法获取子集结果?

Java 如何从`txn.getAll(";Entity";)`方法获取子集结果?,java,xodus,Java,Xodus,这是获取实体列表的示例代码,示例用户: 我的问题是,如果用户存储有数以百万计的记录,我们如何才能只获得结果的子集?就像有一个跳过和限制一样,这是通过Xodus API实现的,还是我们真的需要对它进行编程以迭代所有条目并手动进行分区?在XODU中获取实体子集最有效、最快的方法是什么 下面是我们试图解决的完整示例实现: @Override public List<User> listUsers(String instance, final String storeName, long s

这是获取实体列表的示例代码,示例用户:

我的问题是,如果用户存储有数以百万计的记录,我们如何才能只获得结果的子集?就像有一个跳过和限制一样,这是通过Xodus API实现的,还是我们真的需要对它进行编程以迭代所有条目并手动进行分区?在XODU中获取实体子集最有效、最快的方法是什么

下面是我们试图解决的完整示例实现:

@Override
public List<User> listUsers(String instance, final String storeName, long skip, long limit) {
    final List<User> users = new LinkedList<>();
    final PersistentEntityStore entityStore = PersistentEntityStores.newInstance(xodusRoot + instance);
    try {
        entityStore.executeInTransaction(new StoreTransactionalExecutable() {
            @Override
            public void execute(@NotNull final StoreTransaction txn) {
                final EntityIterable allUsers = txn.getAll(storeName);
                // TODO: How to skip/limit with 100k to millions of records, efficiently
                for (Entity userEntity : allUsers) {
                    User user = new User();
                    user.setEntityId((String) userEntity.getId().toString());
                    user.setUsername((String) userEntity.getProperty("username"));
                    users.add(user);
                }
            }
        });
    } finally {
        entityStore.close();
    }
    return users;
}
@覆盖
公共列表listUsers(字符串实例、最终字符串storeName、长跳过、长限制){
最终列表用户=新建LinkedList();
最终PersistentEntityStore entityStore=PersistentEntityStores.newInstance(xodusRoot+实例);
试一试{
entityStore.executeInTransaction(新的StoreTransactionalExecutable(){
@凌驾
public void execute(@NotNull final StoreTransaction txn){
最终EntityIterable allUsers=txn.getAll(店名);
//TODO:如何高效地跳过/限制10万到数百万条记录
对于(实体用户实体:allUsers){
用户=新用户();
user.setEntityId((字符串)userEntity.getId().toString());
user.setUsername((字符串)userEntity.getProperty(“用户名”);
用户。添加(用户);
}
}
});
}最后{
entityStore.close();
}
返回用户;
}

只需计算
txn.getAll(storeName).skip(skip).take(limit)
。您将得到一个
EntityIterable
Iterable
@Override
public List<User> listUsers(String instance, final String storeName, long skip, long limit) {
    final List<User> users = new LinkedList<>();
    final PersistentEntityStore entityStore = PersistentEntityStores.newInstance(xodusRoot + instance);
    try {
        entityStore.executeInTransaction(new StoreTransactionalExecutable() {
            @Override
            public void execute(@NotNull final StoreTransaction txn) {
                final EntityIterable allUsers = txn.getAll(storeName);
                // TODO: How to skip/limit with 100k to millions of records, efficiently
                for (Entity userEntity : allUsers) {
                    User user = new User();
                    user.setEntityId((String) userEntity.getId().toString());
                    user.setUsername((String) userEntity.getProperty("username"));
                    users.add(user);
                }
            }
        });
    } finally {
        entityStore.close();
    }
    return users;
}