Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor store rest controller to optimize database access #494

Merged
merged 2 commits into from
Feb 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.springframework.content.rest.controllers;
package internal.org.springframework.content.rest.contentservice;

import java.io.IOException;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package internal.org.springframework.content.rest.contentservice;

import org.springframework.content.commons.repository.AssociativeStore;
import org.springframework.content.commons.repository.ContentStore;
import org.springframework.content.commons.storeservice.Stores;
import org.springframework.content.rest.config.RestConfiguration;
import org.springframework.data.repository.support.Repositories;
import org.springframework.data.repository.support.RepositoryInvokerFactory;

import internal.org.springframework.content.rest.io.AssociatedStoreResource;
import internal.org.springframework.content.rest.io.StoreResource;
import internal.org.springframework.content.rest.mappings.StoreByteRangeHttpRequestHandler;

public class ContentServiceFactory {

private final RestConfiguration config;
private final Repositories repositories;
private final RepositoryInvokerFactory repoInvokerFactory;
private final Stores stores;
private final StoreByteRangeHttpRequestHandler byteRangeRestRequestHandler;

public ContentServiceFactory(RestConfiguration config, Repositories repositories, RepositoryInvokerFactory repoInvokerFactory, Stores stores, StoreByteRangeHttpRequestHandler byteRangeRestRequestHandler) {
this.config = config;
this.repositories = repositories;
this.repoInvokerFactory = repoInvokerFactory;
this.stores = stores;
this.byteRangeRestRequestHandler = byteRangeRestRequestHandler;
}

public ContentService getContentService(StoreResource resource) {

if (ContentStore.class.isAssignableFrom(resource.getStoreInfo().getInterface())) {

Object entity = ((AssociatedStoreResource)resource).getAssociation();

return new ContentStoreContentService(config, null, repoInvokerFactory.getInvokerFor(entity.getClass()), entity, byteRangeRestRequestHandler);
} else if (AssociativeStore.class.isAssignableFrom(resource.getStoreInfo().getInterface())) {

throw new UnsupportedOperationException("AssociativeStore not supported");
} else {

return new StoreContentService(byteRangeRestRequestHandler);
}
}
}
Loading