小编m1h*_*1h4的帖子

在Spring Repository接口中使用sort()和limit()进行查询

我是使用MongoDB的Spring Data的新手,我希望在MongoRepository扩展接口中有一个自动生成的查询方法,需要过滤,排序和限制.

查询如下所示:

// 'created' is the field I need to sort against

find({state:'ACTIVE'}).sort({created:-1}).limit(1)
Run Code Online (Sandbox Code Playgroud)

存储库界面如下所示:

public interface JobRepository extends MongoRepository<Job, String> {
    @Query("{ state: 'ACTIVE', userId: ?0 }")
    List<Job> findActiveByUserId(String userId);

    // The next line is the problem, it wont work since
    // it's not in the format @Query expects
    @Query("find({state:'ACTIVE'}).sort({created:-1}).limit(1)")
    Job findOneActiveOldest();

    ...
}
Run Code Online (Sandbox Code Playgroud)

我知道可以将一个Sort参数添加到查询方法中以便进行排序,但问题是将结果限制为仅一个对象.这可以在不必编写自定义JobRepositoryImpl的情况下完成吗?

谢谢

编辑:

我正在寻找的例子:

@Query("{ state:'ACTIVE', $orderby: {created:-1}, $limit:1 }")
Job findOneActiveOldest();
Run Code Online (Sandbox Code Playgroud)

要么

@Query("{ state:'ACTIVE' }")
@Sort("{ created:-1 }")
@Limit(1)
Job findOneActiveOldest();
Run Code Online (Sandbox Code Playgroud)

但这显然不起作用:(

mongodb-java spring-data

17
推荐指数
2
解决办法
3万
查看次数

在Android ContentProvider中从网络同步时防止网络同步循环

我正在编写自己的ContentProvider,它将使用SyncAdapter同步到Web服务.

当同步适配器正在修改内容提供程序的数据时,问题发生在内部调用getContentResolver().notifyChange导致同步循环时,提供程序触发网络同步.

客户端应用程序执行修改时需要带有网络同步标志的notifyChange,但在同步适配器修改时应避免使用.

如何在内容提供者内部轻松判断客户端应用程序(应该在修改时触发网络同步)或同步适配器(不应触发网络同步)使用它.

目前我正在使用不同的CONTENT_URI(同步适配器使用CONTENT_URI_NO_SYNC访问数据,使用CONTENT_URI访问客户端应用程序)以便能够区分这两种类型的访问并相应地设置网络同步标志.

java android android-contentprovider android-syncadapter

14
推荐指数
1
解决办法
2826
查看次数

Apache multipart POST"传递请求体失败"

我们的Web服务器(配置为ssl - > apache - > jetty)随机拒绝带有400 Bad Request错误代码的多部分上传POST请求.apache错误日志(在信息级别)显示以下两个错误:

[info] [client x1.y1.z1.w1] (70007)The timeout specified has expired: SSL input filter read failed.
[error] proxy: pass request body failed to x.y.z.w:8087 from x1.y1.z1.w1
[info] [client x1.y1.z1.w1] Connection closed to child 74 with standard shutdown
Run Code Online (Sandbox Code Playgroud)

要么

[info] [client x2.y2.z2.w2] (70014)End of file found: SSL input filter read failed.
[error] proxy: pass request body failed to x.y.z.w:8087 from x2.y2.z2.w2
[info] [client x2.y2.z2.w2] Connection closed to child 209 with standard shutdown
Run Code Online (Sandbox Code Playgroud)

这两种情况都是客户端在400 Bad Request中产生的.有时我们的jetty服务器甚至没有看到请求意味着它在apaches端被拒绝,有时它开始处理它只是被拒绝(这在我们的UploadFilter中表现为MultipartException) …

apache https jetty multipart mod-proxy

8
推荐指数
1
解决办法
2万
查看次数

在iOS上使用激活事件时,Firebase A/B测试不计算用户

我们正在使用当前版本的Firebase iOS框架(5.9.0),当我们尝试运行具有激活事件的A/B测试实验时,我们发现了一个奇怪的问题.

由于我们希望在首次启动时运行实验,因此我们在启动远程配置时显示的app start上有一个自定义启动画面.提取完成后,我们立即激活提取的配置,然后检查我们是否收到了有关实验参与的信息,以便适当地重新配置下一个UI.在我们确定当前实例实际上应该是测试的一部分,因此激活事件之前,还有其他检查已完成.基本上,代码看起来像:

<code that shows splash>

…

[[FIRRemoteConfig remoteConfig] fetchWithExpirationDuration:7 completionHandler:^(FIRRemoteConfigFetchStatus status, NSError * _Nullable error) {

    [[FIRRemoteConfig remoteConfig] activateFetched];

    if (<checks that see if we received info about being selected to participate in the experiment and if local conditions are met for experiment participation>) {

        [FIRAnalytics logEventWithName:@"RegistrationEntryExperimentActivation" parameters:nil];

        <dismiss splash screen and show next UI screen based on experiment variation received in remote config>
    } else {
        <dismiss splash screen and show next UI screen> …
Run Code Online (Sandbox Code Playgroud)

ios firebase firebase-analytics firebase-ab-testing

8
推荐指数
0
解决办法
516
查看次数

手动触发@Scheduled方法

我需要以下建议:

我有一个@Scheduled服务方法,它有一个几秒钟的fixedDelay,它可以扫描一个工作队列并在找到任何工作队列时处理合适的工作.在同一个服务中,我有一个方法将工作放入工作队列,我希望这个方法在完成后立即触发队列扫描(因为我确信现在有一些工作要做扫描器)为了避免计划踢的延迟(因为这可能是秒,时间有点关键).

任务执行和Scheaduling子系统的"现在触发"功能将是理想的,也可以在手动启动执行后重置fixedDelay(因为我不希望我的手动执行与计划的冲突).注意:队列中的工作可以来自外部源,因此需要定期扫描.

欢迎任何建议

编辑:队列存储在基于文档的数据库中,因此本地基于队列的解决方案不合适.

我不太满意的解决方案(不喜欢使用原始线程)会是这样的:

@Service
public class MyProcessingService implements ProcessingService {

    Thread worker;

    @PostCreate
    public void init() {
        worker = new Thread() {
            boolean ready = false;

            private boolean sleep() {
                synchronized(this) {
                    if (ready) {
                        ready = false;
                    } else {
                        try {
                            wait(2000);
                        } catch(InterruptedException) {
                            return false;
                        }
                    }
                }

                return true;
            }

            public void tickle() {
                synchronized(this) {
                    ready = true;
                    notify();
                }
            }

            public void run() {
                while(!interrupted()) {
                    if(!sleep()) continue;

                    scan();
                } …
Run Code Online (Sandbox Code Playgroud)

java queue spring multithreading synchronization

6
推荐指数
1
解决办法
4564
查看次数

iOS 8上的AVCaptureVideoDataOutput不会在指定的调度队列上发布样本缓冲区

当使用AVCaptureVideoDataOutput并使用调度队列(setSampleBufferDelegate:queue)定义样本缓冲区委托时,我们在iOS 8上遇到AVFoundation不会在指定的调度队列上发布样本缓冲区,而是始终使用"com.apple.avfoundation.videodataoutput" .bufferqueue".

这在iOS7上按预期工作.

还有其他人经历过这个吗?

一个明显的解决方法是在回调中手动调用dispatch_sync以将处理同步到自定义调度队列,但奇怪的是,这会导致死锁......

产生此问题的示例代码:

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.

    AVCaptureSession *session = [[AVCaptureSession alloc] init];
    session.sessionPreset = AVCaptureSessionPresetMedium;

    AVCaptureVideoPreviewLayer *captureVideoPreviewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:session];
    captureVideoPreviewLayer.frame = self.view.bounds;
    [self.view.layer addSublayer:captureVideoPreviewLayer];

    [session addInput:[AVCaptureDeviceInput deviceInputWithDevice:[AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo] error:nil]];

    AVCaptureVideoDataOutput *output = [[AVCaptureVideoDataOutput alloc] init];

    queue = dispatch_queue_create("our.dispatch.queue", DISPATCH_QUEUE_SERIAL);

    [output setSampleBufferDelegate:self queue:queue];

    [session addOutput:output];

    [session startRunning];
}

- (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputSampleBuffer:(CMSampleBufferRef)sampleBuffer fromConnection:(AVCaptureConnection *)connection {
    NSLog(@"Running on queue %@, queue …
Run Code Online (Sandbox Code Playgroud)

avfoundation grand-central-dispatch ios avcapturesession ios8

6
推荐指数
1
解决办法
2202
查看次数