001package ca.uhn.fhir.jpa.model.config;
002
003/*-
004 * #%L
005 * HAPI FHIR JPA Model
006 * %%
007 * Copyright (C) 2014 - 2022 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
023/**
024 * @since 5.0.0
025 */
026public class PartitionSettings {
027
028        private boolean myPartitioningEnabled = false;
029        private CrossPartitionReferenceMode myAllowReferencesAcrossPartitions = CrossPartitionReferenceMode.NOT_ALLOWED;
030        private boolean myIncludePartitionInSearchHashes = false;
031        private boolean myUnnamedPartitionMode;
032        private Integer myDefaultPartitionId;
033
034        /**
035         * If set to <code>true</code> (default is <code>false</code>) the <code>PARTITION_ID</code> value will be factored into the
036         * hash values used in the <code>HFJ_SPIDX_xxx</code> tables, removing the need to explicitly add a selector
037         * on this column in queries. If set to <code>false</code>, an additional selector is used instead, which may perform
038         * better when using native database partitioning features.
039         * <p>
040         * This setting has no effect if partitioning is not enabled via {@link #isPartitioningEnabled()}.
041         * </p>
042         */
043        public boolean isIncludePartitionInSearchHashes() {
044                return myIncludePartitionInSearchHashes;
045        }
046
047        /**
048         * If set to <code>true</code> (default is <code>false</code>) the <code>PARTITION_ID</code> value will be factored into the
049         * hash values used in the <code>HFJ_SPIDX_xxx</code> tables, removing the need to explicitly add a selector
050         * on this column in queries. If set to <code>false</code>, an additional selector is used instead, which may perform
051         * better when using native database partitioning features.
052         * <p>
053         * This setting has no effect if partitioning is not enabled via {@link #isPartitioningEnabled()}.
054         * </p>
055         */
056        public PartitionSettings setIncludePartitionInSearchHashes(boolean theIncludePartitionInSearchHashes) {
057                myIncludePartitionInSearchHashes = theIncludePartitionInSearchHashes;
058                return this;
059        }
060
061        /**
062         * If enabled (default is <code>false</code>) the JPA server will support data partitioning
063         *
064         * @since 5.0.0
065         */
066        public boolean isPartitioningEnabled() {
067                return myPartitioningEnabled;
068        }
069
070        /**
071         * If enabled (default is <code>false</code>) the JPA server will support data partitioning
072         *
073         * @since 5.0.0
074         */
075        public void setPartitioningEnabled(boolean theMultiTenancyEnabled) {
076                myPartitioningEnabled = theMultiTenancyEnabled;
077        }
078
079        /**
080         * Should resources references be permitted to cross partition boundaries. Default is {@link CrossPartitionReferenceMode#NOT_ALLOWED}.
081         *
082         * @since 5.0.0
083         */
084        public CrossPartitionReferenceMode getAllowReferencesAcrossPartitions() {
085                return myAllowReferencesAcrossPartitions;
086        }
087
088        /**
089         * Should resources references be permitted to cross partition boundaries. Default is {@link CrossPartitionReferenceMode#NOT_ALLOWED}.
090         *
091         * @since 5.0.0
092         */
093        public void setAllowReferencesAcrossPartitions(CrossPartitionReferenceMode theAllowReferencesAcrossPartitions) {
094                myAllowReferencesAcrossPartitions = theAllowReferencesAcrossPartitions;
095        }
096
097        /**
098         * If set to <code>true</code> (default is <code>false</code>), partitions will be unnamed and all IDs from {@link Integer#MIN_VALUE} through
099         * {@link Integer#MAX_VALUE} will be allowed without needing to be created ahead of time.
100         *
101         * @since 5.5.0
102         */
103        public boolean isUnnamedPartitionMode() {
104                return myUnnamedPartitionMode;
105        }
106
107        /**
108         * If set to <code>true</code> (default is <code>false</code>), partitions will be unnamed and all IDs from {@link Integer#MIN_VALUE} through
109         * {@link Integer#MAX_VALUE} will be allowed without needing to be created ahead of time.
110         *
111         * @since 5.5.0
112         */
113        public void setUnnamedPartitionMode(boolean theUnnamedPartitionMode) {
114                myUnnamedPartitionMode = theUnnamedPartitionMode;
115        }
116
117        /**
118         * If set, the given ID will be used for the default partition. The default is
119         * <code>null</code> which will result in the use of a null value for default
120         * partition items.
121         *
122         * @since 5.5.0
123         */
124        public Integer getDefaultPartitionId() {
125                return myDefaultPartitionId;
126        }
127
128        /**
129         * If set, the given ID will be used for the default partition. The default is
130         * <code>null</code> which will result in the use of a null value for default
131         * partition items.
132         *
133         * @since 5.5.0
134         */
135        public void setDefaultPartitionId(Integer theDefaultPartitionId) {
136                myDefaultPartitionId = theDefaultPartitionId;
137        }
138
139
140        public enum CrossPartitionReferenceMode {
141
142                /**
143                 * References between resources are not allowed to cross partition boundaries
144                 */
145                NOT_ALLOWED,
146
147                /**
148                 * References can cross partition boundaries, in a way that hides the existence of partitions to the end user
149                 */
150                ALLOWED_UNQUALIFIED
151
152        }
153
154}