Skip to content

Commit 50db219

Browse files
committed
HHH-15899 Add @PartitionColumn annotation
1 parent fb840ef commit 50db219

File tree

46 files changed

+494
-7
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+494
-7
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* Hibernate, Relational Persistence for Idiomatic Java
3+
*
4+
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
5+
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
6+
*/
7+
package org.hibernate.annotations;
8+
9+
import java.lang.annotation.Retention;
10+
import java.lang.annotation.Target;
11+
12+
import static java.lang.annotation.ElementType.FIELD;
13+
import static java.lang.annotation.ElementType.METHOD;
14+
import static java.lang.annotation.RetentionPolicy.RUNTIME;
15+
16+
/**
17+
* Identifies a field of an entity that holds the partition key of a table.
18+
*
19+
* @since 6.2
20+
*/
21+
@Target({METHOD, FIELD})
22+
@Retention(RUNTIME)
23+
public @interface PartitionKey {
24+
25+
}

hibernate-core/src/main/java/org/hibernate/boot/model/internal/BasicValueBinder.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import org.hibernate.annotations.CollectionIdJdbcType;
2929
import org.hibernate.annotations.CollectionIdJdbcTypeCode;
3030
import org.hibernate.annotations.CollectionIdMutability;
31+
import org.hibernate.annotations.PartitionKey;
3132
import org.hibernate.annotations.CollectionIdType;
3233
import org.hibernate.annotations.Immutable;
3334
import org.hibernate.annotations.JdbcTypeCode;
@@ -148,6 +149,7 @@ public enum Kind {
148149
private EnumType enumType;
149150
private TemporalType temporalPrecision;
150151
private TimeZoneStorageType timeZoneStorageType;
152+
private boolean partitionKey;
151153

152154
private Table table;
153155
private AnnotatedColumns columns;
@@ -983,6 +985,10 @@ private void normalSupplementalDetails(XProperty attributeXProperty) {
983985
}
984986
}
985987
}
988+
final PartitionKey partitionKey = attributeXProperty.getAnnotation( PartitionKey.class );
989+
if ( partitionKey != null ) {
990+
this.partitionKey = true;
991+
}
986992
}
987993

988994
private static Class<? extends UserType<?>> normalizeUserType(Class<? extends UserType<?>> userType) {
@@ -1103,6 +1109,8 @@ public BasicValue make() {
11031109
basicValue.setTimeZoneStorageType( timeZoneStorageType );
11041110
}
11051111

1112+
basicValue.setPartitionKey( partitionKey );
1113+
11061114
if ( temporalPrecision != null ) {
11071115
basicValue.setTemporalPrecision( temporalPrecision );
11081116
}

hibernate-core/src/main/java/org/hibernate/mapping/PersistentClass.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1115,6 +1115,19 @@ public void setSubselectLoadableCollections(boolean hasSubselectCollections) {
11151115
this.hasSubselectLoadableCollections = hasSubselectCollections;
11161116
}
11171117

1118+
public boolean hasPartitionedSelectionMapping() {
1119+
if ( getSuperclass() != null && getSuperclass().hasPartitionedSelectionMapping() ) {
1120+
return true;
1121+
}
1122+
for ( Property property : getProperties() ) {
1123+
final Value value = property.getValue();
1124+
if ( value instanceof BasicValue && ( (BasicValue) value ).isPartitionKey() ) {
1125+
return true;
1126+
}
1127+
}
1128+
return false;
1129+
}
1130+
11181131
public Component getIdentifierMapper() {
11191132
return identifierMapper;
11201133
}

hibernate-core/src/main/java/org/hibernate/mapping/SimpleValue.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ public abstract class SimpleValue implements KeyValue {
8080
private final List<Selectable> columns = new ArrayList<>();
8181
private final List<Boolean> insertability = new ArrayList<>();
8282
private final List<Boolean> updatability = new ArrayList<>();
83+
private boolean partitionKey;
8384

8485
private String typeName;
8586
private Properties typeParameters;
@@ -120,6 +121,7 @@ protected SimpleValue(SimpleValue original) {
120121
this.columns.addAll( original.columns );
121122
this.insertability.addAll( original.insertability );
122123
this.updatability.addAll( original.updatability );
124+
this.partitionKey = original.partitionKey;
123125
this.typeName = original.typeName;
124126
this.typeParameters = original.typeParameters == null ? null : new Properties( original.typeParameters );
125127
this.isVersion = original.isVersion;
@@ -866,6 +868,14 @@ public boolean isColumnUpdateable(int index) {
866868
return false;
867869
}
868870

871+
public boolean isPartitionKey() {
872+
return partitionKey;
873+
}
874+
875+
public void setPartitionKey(boolean partitionColumn) {
876+
this.partitionKey = partitionColumn;
877+
}
878+
869879
private static boolean[] extractBooleansFromList(List<Boolean> list) {
870880
final boolean[] array = new boolean[ list.size() ];
871881
int i = 0;

hibernate-core/src/main/java/org/hibernate/metamodel/internal/AbstractCompositeIdentifierMapping.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,4 +288,9 @@ protected EntityMappingType getEntityMapping() {
288288
return entityMapping;
289289
}
290290

291+
@Override
292+
public boolean hasPartitionedSelectionMapping() {
293+
return false;
294+
}
295+
291296
}

hibernate-core/src/main/java/org/hibernate/metamodel/mapping/BasicValuedModelPart.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,9 @@ default int forEachSelectable(SelectableConsumer consumer) {
5151
consumer.accept( 0, this );
5252
return getJdbcTypeCount();
5353
}
54+
55+
@Override
56+
default boolean hasPartitionedSelectionMapping() {
57+
return isPartitioned();
58+
}
5459
}

hibernate-core/src/main/java/org/hibernate/metamodel/mapping/ManagedMappingType.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,4 +101,14 @@ default boolean anyRequiresAggregateColumnWriter() {
101101
}
102102
return false;
103103
}
104+
105+
@Override
106+
default boolean hasPartitionedSelectionMapping() {
107+
for ( AttributeMapping attributeMapping : getAttributeMappings() ) {
108+
if ( attributeMapping.hasPartitionedSelectionMapping() ) {
109+
return true;
110+
}
111+
}
112+
return false;
113+
}
104114
}

hibernate-core/src/main/java/org/hibernate/metamodel/mapping/ModelPart.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ default boolean isVirtual() {
9191
return false;
9292
}
9393

94+
boolean hasPartitionedSelectionMapping();
95+
9496
/**
9597
* Create a DomainResult for a specific reference to this ModelPart.
9698
*/

hibernate-core/src/main/java/org/hibernate/metamodel/mapping/SelectableConsumer.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,11 @@ public boolean isUpdateable() {
104104
return false;
105105
}
106106

107+
@Override
108+
public boolean isPartitioned() {
109+
return false;
110+
}
111+
107112
@Override
108113
public String getColumnDefinition() {
109114
// we could probably use the details from `base`, but
@@ -217,6 +222,11 @@ public boolean isUpdateable() {
217222
return true;
218223
}
219224

225+
@Override
226+
public boolean isPartitioned() {
227+
return false;
228+
}
229+
220230
@Override
221231
public JdbcMapping getJdbcMapping() {
222232
return null;

hibernate-core/src/main/java/org/hibernate/metamodel/mapping/SelectableMapping.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,6 @@ default String getWriteExpression() {
6565
boolean isInsertable();
6666

6767
boolean isUpdateable();
68+
69+
boolean isPartitioned();
6870
}

hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/AnyDiscriminatorPart.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ public class AnyDiscriminatorPart implements BasicValuedModelPart, FetchOptions,
6161

6262
private final boolean insertable;
6363
private final boolean updateable;
64+
private final boolean partitioned;
6465
private final MetaType metaType;
6566

6667
public AnyDiscriminatorPart(
@@ -74,6 +75,7 @@ public AnyDiscriminatorPart(
7475
Integer scale,
7576
boolean insertable,
7677
boolean updateable,
78+
boolean partitioned,
7779
MetaType metaType) {
7880
this.navigableRole = partRole;
7981
this.declaringType = declaringType;
@@ -85,6 +87,7 @@ public AnyDiscriminatorPart(
8587
this.scale = scale;
8688
this.insertable = insertable;
8789
this.updateable = updateable;
90+
this.partitioned = partitioned;
8891
this.metaType = metaType;
8992
}
9093

@@ -126,6 +129,11 @@ public boolean isUpdateable() {
126129
return updateable;
127130
}
128131

132+
@Override
133+
public boolean isPartitioned() {
134+
return partitioned;
135+
}
136+
129137
@Override
130138
public String getCustomReadExpression() {
131139
return null;

hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/AnyKeyPart.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ public class AnyKeyPart implements BasicValuedModelPart, FetchOptions {
5656
private final boolean nullable;
5757
private final boolean insertable;
5858
private final boolean updateable;
59+
private final boolean partitioned;
5960
private final JdbcMapping jdbcMapping;
6061

6162
public AnyKeyPart(
@@ -70,6 +71,7 @@ public AnyKeyPart(
7071
boolean nullable,
7172
boolean insertable,
7273
boolean updateable,
74+
boolean partitioned,
7375
JdbcMapping jdbcMapping) {
7476
this.navigableRole = navigableRole;
7577
this.table = table;
@@ -82,6 +84,7 @@ public AnyKeyPart(
8284
this.nullable = nullable;
8385
this.insertable = insertable;
8486
this.updateable = updateable;
87+
this.partitioned = partitioned;
8588
this.jdbcMapping = jdbcMapping;
8689
}
8790

@@ -115,6 +118,11 @@ public boolean isUpdateable() {
115118
return updateable;
116119
}
117120

121+
@Override
122+
public boolean isPartitioned() {
123+
return partitioned;
124+
}
125+
118126
@Override
119127
public String getCustomReadExpression() {
120128
return null;

hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/BasicAttributeMapping.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ public class BasicAttributeMapping
6363
private final boolean nullable;
6464
private final boolean insertable;
6565
private final boolean updateable;
66+
private final boolean partitioned;
6667

6768
private final JavaType domainTypeDescriptor;
6869

@@ -87,6 +88,7 @@ public BasicAttributeMapping(
8788
boolean nullable,
8889
boolean insertable,
8990
boolean updateable,
91+
boolean partitioned,
9092
JdbcMapping jdbcMapping,
9193
ManagedMappingType declaringType,
9294
PropertyAccess propertyAccess) {
@@ -117,6 +119,7 @@ public BasicAttributeMapping(
117119
this.nullable = nullable;
118120
this.insertable = insertable;
119121
this.updateable = updateable;
122+
this.partitioned = partitioned;
120123
this.jdbcMapping = jdbcMapping;
121124
this.domainTypeDescriptor = jdbcMapping.getJavaTypeDescriptor();
122125

@@ -175,6 +178,7 @@ else if ( original instanceof SingularAttributeMapping ) {
175178
selectableMapping.isNullable(),
176179
insertable,
177180
updateable,
181+
selectableMapping.isPartitioned(),
178182
original.getJdbcMapping(),
179183
declaringType,
180184
propertyAccess
@@ -231,6 +235,11 @@ public boolean isUpdateable() {
231235
return updateable;
232236
}
233237

238+
@Override
239+
public boolean isPartitioned() {
240+
return partitioned;
241+
}
242+
234243
@Override
235244
public String getCustomReadExpression() {
236245
return customReadExpression;

hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/BasicEntityIdentifierMappingImpl.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,16 @@ public boolean isUpdateable() {
314314
return insertable;
315315
}
316316

317+
@Override
318+
public boolean isPartitioned() {
319+
return false;
320+
}
321+
322+
@Override
323+
public boolean hasPartitionedSelectionMapping() {
324+
return false;
325+
}
326+
317327
@Override
318328
public String getCustomReadExpression() {
319329
return null;

hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/BasicValuedCollectionPart.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,11 @@ public boolean isInsertable() {
9898
return selectableMapping.isInsertable();
9999
}
100100

101+
@Override
102+
public boolean isPartitioned() {
103+
return selectableMapping.isPartitioned();
104+
}
105+
101106
@Override
102107
public boolean isUpdateable() {
103108
return selectableMapping.isUpdateable();

hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/CaseStatementDiscriminatorMappingImpl.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,16 @@ public boolean isUpdateable() {
220220
return false;
221221
}
222222

223+
@Override
224+
public boolean isPartitioned() {
225+
return false;
226+
}
227+
228+
@Override
229+
public boolean hasPartitionedSelectionMapping() {
230+
return false;
231+
}
232+
223233
@Override
224234
public String getContainingTableExpression() {
225235
throw new UnsupportedOperationException();

hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/CollectionIdentifierDescriptorImpl.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,16 @@ public boolean isUpdateable() {
8989
return false;
9090
}
9191

92+
@Override
93+
public boolean isPartitioned() {
94+
return false;
95+
}
96+
97+
@Override
98+
public boolean hasPartitionedSelectionMapping() {
99+
return false;
100+
}
101+
92102
@Override
93103
public boolean isNullable() {
94104
return false;

hibernate-core/src/main/java/org/hibernate/metamodel/mapping/internal/CompoundNaturalIdMapping.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import org.hibernate.loader.ast.spi.NaturalIdLoader;
2525
import org.hibernate.mapping.IndexedConsumer;
2626
import org.hibernate.metamodel.UnsupportedMappingException;
27+
import org.hibernate.metamodel.mapping.AttributeMapping;
2728
import org.hibernate.metamodel.mapping.AttributeMetadata;
2829
import org.hibernate.metamodel.mapping.EntityMappingType;
2930
import org.hibernate.metamodel.mapping.JdbcMapping;
@@ -265,6 +266,16 @@ public JavaType<?> getMappedJavaType() {
265266
return getJavaType();
266267
}
267268

269+
@Override
270+
public boolean hasPartitionedSelectionMapping() {
271+
for ( AttributeMapping attributeMapping : attributes ) {
272+
if ( attributeMapping.hasPartitionedSelectionMapping() ) {
273+
return true;
274+
}
275+
}
276+
return false;
277+
}
278+
268279

269280
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
270281
// ModelPart

0 commit comments

Comments
 (0)