001package ca.uhn.fhir.jpa.search;
002
003/*
004 * #%L
005 * HAPI FHIR JPA Server
006 * %%
007 * Copyright (C) 2014 - 2021 Smile CDR, Inc.
008 * %%
009 * Licensed under the Apache License, Version 2.0 (the "License");
010 * you may not use this file except in compliance with the License.
011 * You may obtain a copy of the License at
012 *
013 *      http://www.apache.org/licenses/LICENSE-2.0
014 *
015 * Unless required by applicable law or agreed to in writing, software
016 * distributed under the License is distributed on an "AS IS" BASIS,
017 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
018 * See the License for the specific language governing permissions and
019 * limitations under the License.
020 * #L%
021 */
022
023import ca.uhn.fhir.jpa.api.dao.DaoRegistry;
024import ca.uhn.fhir.jpa.dao.SearchBuilderFactory;
025import ca.uhn.fhir.rest.api.server.IBundleProvider;
026import ca.uhn.fhir.rest.api.server.RequestDetails;
027import ca.uhn.fhir.rest.server.BasePagingProvider;
028import org.springframework.beans.factory.annotation.Autowired;
029
030// Note: this class is not annotated with @Service because we want to
031// explicitly define it in BaseConfig.java. This is done so that
032// implementors can override if they want to.
033public class DatabaseBackedPagingProvider extends BasePagingProvider {
034
035        @Autowired
036        private DaoRegistry myDaoRegistry;
037        @Autowired
038        private SearchBuilderFactory mySearchBuilderFactory;
039        @Autowired
040        private PersistedJpaBundleProviderFactory myPersistedJpaBundleProviderFactory;
041
042        /**
043         * Constructor
044         */
045        public DatabaseBackedPagingProvider() {
046                super();
047        }
048
049        /**
050         * Constructor
051         * @deprecated Use {@link DatabaseBackedPagingProvider} as this constructor has no purpose
052         */
053        @Deprecated
054        public DatabaseBackedPagingProvider(int theSize) {
055                this();
056        }
057
058        @Override
059        public synchronized IBundleProvider retrieveResultList(RequestDetails theRequestDetails, String theId) {
060                PersistedJpaBundleProvider provider = myPersistedJpaBundleProviderFactory.newInstance(theRequestDetails, theId);
061                if (!provider.ensureSearchEntityLoaded()) {
062                        return null;
063                }
064                return provider;
065        }
066
067        @Override
068        public synchronized String storeResultList(RequestDetails theRequestDetails, IBundleProvider theList) {
069                String uuid = theList.getUuid();
070                return uuid;
071        }
072
073}