Skip to content

Commit 2dd631c

Browse files
committed
Understand new (eclipselink-)orm xsd
Signed-off-by: Lukas Jungmann <[email protected]>
1 parent 3d1e6b4 commit 2dd631c

File tree

38 files changed

+1452
-321
lines changed

38 files changed

+1452
-321
lines changed

foundation/org.eclipse.persistence.core/src/main/java/org/eclipse/persistence/annotations/CacheIsolationType.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,10 @@
1717
/**
1818
* Options for how Entity instances should be shared within an EclipseLink Persistence Unit / ServerSession
1919
* @see org.eclipse.persistence.descriptors.ClassDescriptor#setCacheIsolation(CacheIsolationType)
20-
* @see org.eclipse.persistence.annotations.Cache
20+
* @see Cache
2121
* @author Gordon Yorke
2222
* @since EclipseLink 2.2
2323
*/
24-
2524
public enum CacheIsolationType {
2625
// These enums are ordered with ascending protective requirements
2726
// This is intentional and any additions/alterations should take that into account

foundation/org.eclipse.persistence.core/src/main/java/org/eclipse/persistence/internal/helper/DatabaseField.java

+54-1
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,16 @@ public class DatabaseField implements Cloneable, Serializable, CoreField {
4747
protected int scale;
4848
protected int length;
4949
protected int precision;
50+
protected int secondPrecision;
5051
protected boolean isUnique;
5152
protected boolean isNullable;
5253
protected boolean isUpdatable;
5354
protected boolean isInsertable;
5455
protected boolean isCreatable;
5556
protected boolean isPrimaryKey;
5657
protected String columnDefinition;
58+
protected String comment;
59+
protected String optionalSuffix;
5760

5861
/** Column name of the field. */
5962
protected String name;
@@ -131,7 +134,7 @@ public DatabaseField(String qualifiedName, String startDelimiter, String endDeli
131134
setName(qualifiedName, startDelimiter, endDelimiter);
132135
this.table = new DatabaseTable();
133136
} else {
134-
setName(qualifiedName.substring(index + 1, qualifiedName.length()), startDelimiter, endDelimiter);
137+
setName(qualifiedName.substring(index + 1), startDelimiter, endDelimiter);
135138
this.table = new DatabaseTable(qualifiedName.substring(0, index), startDelimiter, endDelimiter);
136139
}
137140
initDDLFields();
@@ -164,13 +167,16 @@ public void initDDLFields() {
164167
scale = 0;
165168
length = 0;
166169
precision = 0;
170+
secondPrecision = -1;
167171
isUnique = false;
168172
isNullable = true;
169173
isUpdatable = true;
170174
isInsertable = true;
171175
isCreatable = true;
172176
isPrimaryKey = false;
173177
columnDefinition = "";
178+
comment = "";
179+
optionalSuffix = "";
174180
}
175181

176182
/**
@@ -274,6 +280,13 @@ public String getColumnDefinition() {
274280
return this.columnDefinition;
275281
}
276282

283+
/**
284+
* Get the SQL fragment that is used when generating the DDL for the column.
285+
*/
286+
public String getComment() {
287+
return this.comment;
288+
}
289+
277290
/**
278291
* Return the expected index that this field will occur in the result set
279292
* row. This is used to optimize performance of database row field lookups.
@@ -308,6 +321,13 @@ public String getNameDelimited(DatasourcePlatform platform) {
308321
return this.name;
309322
}
310323

324+
/**
325+
* Get the SQL fragment appended to the generated DDL.
326+
*/
327+
public String getOptionalSuffix() {
328+
return this.optionalSuffix;
329+
}
330+
311331
/**
312332
* Returns the precision for a decimal column when generating DDL.
313333
*/
@@ -337,13 +357,22 @@ public String getQualifiedNameDelimited(DatasourcePlatform platform) {
337357
return getNameDelimited(platform);
338358
}
339359
}
360+
340361
/**
341362
* Returns the scale for a decimal column when generating DDL.
342363
*/
343364
public int getScale() {
344365
return this.scale;
345366
}
346367

368+
/**
369+
* Get the number of decimal digits to use for storing fractional
370+
* seconds in a SQL time or timestamp column when generating DDL.
371+
*/
372+
public int getSecondPrecision() {
373+
return this.secondPrecision;
374+
}
375+
347376
public DatabaseTable getTable() {
348377
return table;
349378
}
@@ -490,6 +519,13 @@ public void setColumnDefinition(String columnDefinition) {
490519
this.columnDefinition = columnDefinition;
491520
}
492521

522+
/**
523+
* Set the SQL fragment that is used when generating the DDL for the column.
524+
*/
525+
public void setComment(String comment) {
526+
this.comment = comment;
527+
}
528+
493529
/**
494530
* Set the expected index that this field will occur in the result set row.
495531
* This is used to optimize performance of database row field lookups.
@@ -567,13 +603,30 @@ public void setNullable(boolean isNullable) {
567603
this.isNullable = isNullable;
568604
}
569605

606+
/**
607+
* Used to specify the SQL fragment appended to the generated DDL.
608+
*/
609+
public void setOptionalSuffix(String optionalSuffix) {
610+
this.optionalSuffix = optionalSuffix;
611+
}
612+
570613
/**
571614
* Used to specify the precision for a decimal column when generating DDL.
572615
*/
573616
public void setPrecision(int precision) {
574617
this.precision = precision;
575618
}
576619

620+
/**
621+
* Used to specify the number of decimal digits to use for storing fractional
622+
* seconds in a SQL time or timestamp column when generating DDL.
623+
* <p>
624+
* Applies only to columns of time or timestamp type.
625+
*/
626+
public void setSecondPrecision(int secondPrecision) {
627+
this.secondPrecision = secondPrecision;
628+
}
629+
577630
/**
578631
* Used to specify whether the column should be included in primary key
579632
* on the database table.

foundation/org.eclipse.persistence.core/src/main/java/org/eclipse/persistence/internal/helper/DatabaseTable.java

+30-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import org.eclipse.persistence.internal.databaseaccess.DatabasePlatform;
2626
import org.eclipse.persistence.internal.databaseaccess.DatasourcePlatform;
2727
import org.eclipse.persistence.internal.expressions.ExpressionSQLPrinter;
28+
import org.eclipse.persistence.tools.schemaframework.CheckConstraint;
2829
import org.eclipse.persistence.tools.schemaframework.ForeignKeyConstraint;
2930
import org.eclipse.persistence.tools.schemaframework.IndexDefinition;
3031

@@ -63,6 +64,8 @@ public class DatabaseTable implements CoreTable, Cloneable, Serializable {
6364
*/
6465
protected Map<String, List<List<String>>> uniqueConstraints;
6566

67+
protected Map<String, CheckConstraint> checkConstraints;
68+
6669
/**
6770
* Store the set of indexes defined through meta-data for the table.
6871
*/
@@ -72,6 +75,8 @@ public class DatabaseTable implements CoreTable, Cloneable, Serializable {
7275

7376
protected String creationSuffix;
7477

78+
protected String comment;
79+
7580
/**
7681
* Initialize the newly allocated instance of this class.
7782
* By default their is no qualifier.
@@ -99,6 +104,13 @@ public DatabaseTable(String tableName, String qualifier, boolean useDelimiters,
99104
this.useDelimiters = useDelimiters;
100105
}
101106

107+
public void addCheckConstraint(CheckConstraint checkConstraint) {
108+
if (checkConstraints == null) {
109+
checkConstraints = new HashMap<>();
110+
}
111+
checkConstraints.put(checkConstraint.getName(), checkConstraint);
112+
}
113+
102114
public void addForeignKeyConstraint(ForeignKeyConstraint foreignKeyConstraint) {
103115
if (foreignKeyConstraints == null) {
104116
foreignKeyConstraints = new HashMap<>();
@@ -183,6 +195,14 @@ public boolean equals(DatabaseTable table) {
183195
return false;
184196
}
185197

198+
public CheckConstraint getCheckConstraint(String name) {
199+
return checkConstraints.get(name);
200+
}
201+
202+
public Map<String, CheckConstraint> getCheckConstraints() {
203+
return checkConstraints;
204+
}
205+
186206
/**
187207
* returns the suffix applied to the CREATE table statement on this field for DDL generation.
188208
*/
@@ -379,7 +399,7 @@ public void setPossiblyQualifiedName(String possiblyQualifiedName, String startD
379399
setName(possiblyQualifiedName, startDelimiter, endDelimiter);
380400
this.tableQualifier = "";
381401
} else {
382-
setName(possiblyQualifiedName.substring(index + 1, possiblyQualifiedName.length()), startDelimiter, endDelimiter);
402+
setName(possiblyQualifiedName.substring(index + 1), startDelimiter, endDelimiter);
383403
setTableQualifier(possiblyQualifiedName.substring(0, index), startDelimiter, endDelimiter);
384404

385405
if((startDelimiter != null) && possiblyQualifiedName.startsWith(startDelimiter) && (endDelimiter != null) && possiblyQualifiedName.endsWith(endDelimiter)) {
@@ -419,4 +439,13 @@ public void setUseDelimiters(boolean useDelimiters) {
419439
public boolean shouldUseDelimiters() {
420440
return useDelimiters;
421441
}
442+
443+
public void setComment(String comment) {
444+
this.comment = comment;
445+
}
446+
447+
public String getComment() {
448+
return comment;
449+
}
450+
422451
}

foundation/org.eclipse.persistence.core/src/main/java/org/eclipse/persistence/internal/oxm/record/namespaces/PrefixMapperNamespaceResolver.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,7 @@ public PrefixMapperNamespaceResolver(NamespacePrefixMapper mapper, org.eclipse.p
4545
}
4646
String defaultUri= null;
4747
if(nestedResolver != null){
48-
for(Object next:nestedResolver.getNamespaces()) {
49-
Namespace ns = (Namespace)next;
48+
for (Namespace ns: nestedResolver.getNamespaces()) {
5049
String uri = ns.getNamespaceURI();
5150
String existingPrefix = null;
5251
if(contextualNamespaces != null) {

foundation/org.eclipse.persistence.core/src/main/java/org/eclipse/persistence/mappings/AggregateObjectMapping.java

+5-2
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@ public Object buildAggregateFromRow(AbstractRecord databaseRow, Object targetObj
468468
}
469469

470470
// Build a new aggregate if the target object does not reference an existing aggregate.
471-
// EL Bug 474956 - build a new aggregate if the the target object references an existing aggregate, and
471+
// EL Bug 474956 - build a new aggregate if the the target object references an existing aggregate, and
472472
// the passed cacheKey is null from the invalidation of the target object in the IdentityMap.
473473
if (aggregate == null || (aggregate != null && cacheKey == null)) {
474474
aggregate = descriptor.getObjectBuilder().buildNewInstance();
@@ -1926,7 +1926,7 @@ public void setAggregateToSourceFields(Map<String, DatabaseField> aggregateToSou
19261926

19271927
/**
19281928
* INTERNAL:
1929-
* Set the hashtable that stores a field in the source table
1929+
* Set the hashtable that stores a field in the source table
19301930
* to a field name in a nested aggregate descriptor.
19311931
*/
19321932
public void setNestedFieldTranslations(Map<String, Object[]> fieldTranslations) {
@@ -1978,7 +1978,10 @@ protected void translateField(DatabaseField sourceField, DatabaseField mappingFi
19781978
mappingField.setScale(sourceField.getScale());
19791979
mappingField.setLength(sourceField.getLength());
19801980
mappingField.setPrecision(sourceField.getPrecision());
1981+
mappingField.setSecondPrecision(sourceField.getSecondPrecision());
1982+
mappingField.setOptionalSuffix(sourceField.getOptionalSuffix());
19811983
mappingField.setColumnDefinition(sourceField.getColumnDefinition());
1984+
mappingField.setComment(sourceField.getComment());
19821985

19831986
// Check if the translated field specified a table qualifier.
19841987
if (sourceField.hasTableName()) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
/*
2+
* Copyright (c) 2024 Oracle and/or its affiliates. All rights reserved.
3+
*
4+
* This program and the accompanying materials are made available under the
5+
* terms of the Eclipse Public License v. 2.0 which is available at
6+
* http://www.eclipse.org/legal/epl-2.0,
7+
* or the Eclipse Distribution License v. 1.0 which is available at
8+
* http://www.eclipse.org/org/documents/edl-v10.php.
9+
*
10+
* SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
11+
*/
12+
13+
package org.eclipse.persistence.tools.schemaframework;
14+
15+
import org.eclipse.persistence.exceptions.ValidationException;
16+
import org.eclipse.persistence.internal.sessions.AbstractSession;
17+
18+
import java.io.IOException;
19+
import java.io.Serializable;
20+
import java.io.Writer;
21+
import java.util.ArrayList;
22+
import java.util.Arrays;
23+
import java.util.Iterator;
24+
25+
/**
26+
* <b>Purpose</b>: Define a check constraint.
27+
*/
28+
public class CheckConstraint implements Serializable {
29+
protected String name;
30+
protected String constraint;
31+
protected String options;
32+
33+
public CheckConstraint() {
34+
this.name = "";
35+
this.constraint = "";
36+
}
37+
38+
public CheckConstraint(String name, String constraint) {
39+
this();
40+
this.name = name;
41+
this.constraint = constraint;
42+
}
43+
44+
/**
45+
* INTERNAL:
46+
* Append the database field definition string to the table creation statement.
47+
*/
48+
public void appendDBString(Writer writer, AbstractSession session) {
49+
try {
50+
writer.write("CONSTRAINT " + getName() + " CHECK (");
51+
writer.write(getConstraint());
52+
if (getOptions() != null && !getOptions().isEmpty()) {
53+
writer.write(" ");
54+
writer.write(getOptions());
55+
writer.write(" ");
56+
}
57+
writer.write(")");
58+
} catch (IOException ioException) {
59+
throw ValidationException.fileError(ioException);
60+
}
61+
}
62+
63+
/**
64+
* PUBLIC:
65+
*/
66+
public String getName() {
67+
return name;
68+
}
69+
70+
/**
71+
* PUBLIC:
72+
*/
73+
public String getConstraint() {
74+
return constraint;
75+
}
76+
77+
public String getOptions() {
78+
return options;
79+
}
80+
81+
/**
82+
* PUBLIC:
83+
*/
84+
public void setName(String name) {
85+
this.name = name;
86+
}
87+
88+
/**
89+
* PUBLIC:
90+
*/
91+
public void setConstraint(String constraint) {
92+
this.constraint = constraint;
93+
}
94+
95+
public void setOptions(String options) {
96+
this.options = options;
97+
}
98+
}
99+

foundation/org.eclipse.persistence.core/src/main/java/org/eclipse/persistence/tools/schemaframework/DefaultTableGenerator.java

+10
Original file line numberDiff line numberDiff line change
@@ -737,6 +737,10 @@ protected TableDefinition getTableDefFromDBTable(DatabaseTable databaseTable) {
737737
tableDefinition.setCreationSuffix(databaseTable.getCreationSuffix());
738738
}
739739

740+
if (databaseTable.getComment() !=null){
741+
tableDefinition.setComment(databaseTable.getComment());
742+
}
743+
740744
// Add the foreign key constraints that were set on the table.
741745
if (databaseTable.hasForeignKeyConstraints()) {
742746
tableDefinition.setUserDefinedForeignKeyConstraints(databaseTable.getForeignKeyConstraints());
@@ -842,6 +846,12 @@ protected FieldDefinition getFieldDefFromDBField(DatabaseField dbField) {
842846

843847
fieldDef.setShouldAllowNull(dbField.isNullable());
844848
fieldDef.setUnique(dbField.isUnique());
849+
if (dbField.getOptionalSuffix() != null) {
850+
fieldDef.setAdditional(dbField.getOptionalSuffix());
851+
}
852+
}
853+
if (dbField.getComment() != null) {
854+
fieldDef.setComment(dbField.getComment());
845855
}
846856
this.fieldMap.put(dbField, fieldDef);
847857
this.databaseFields.put(dbField, dbField);

0 commit comments

Comments
 (0)