Skip to content

Commit

Permalink
jakartaee/persistence#431 - add SchemaManager
Browse files Browse the repository at this point in the history
Final code cleanup.

Signed-off-by: Tomáš Kraus <[email protected]>
  • Loading branch information
Tomas-Kraus committed Dec 8, 2023
1 parent 6998d70 commit f4115c9
Show file tree
Hide file tree
Showing 22 changed files with 598 additions and 240 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@
// - 533148 : Add the eclipselink.jpa.sql-call-deferral property
// 12/06/2018 - Will Dazey
// - 542491: Add new 'eclipselink.jdbc.force-bind-parameters' property to force enable binding
// 12/05/2023: Tomas Kraus
// - New Jakarta Persistence 3.2 Features
package org.eclipse.persistence.config;

import jakarta.persistence.EntityManager;
Expand Down Expand Up @@ -3040,7 +3042,7 @@ public class PersistenceUnitProperties {
* should be automatically generated for foreign key constraints. It is normally recommended to have
* an index for a foreign key.
* <p>
* By default indexes are not generated, most database also do not auto generate indexes, although some do.
* By default, indexes are not generated, most database also do not auto generate indexes, although some do.
* <p>
* <b>Allowed Values:</b>
* <ul>
Expand All @@ -3052,6 +3054,39 @@ public class PersistenceUnitProperties {
*/
public static final String DDL_GENERATION_INDEX_FOREIGN_KEYS = "eclipselink.ddl-generation.index-foreign-keys";

/**
* The "<code>eclipselink.schema-validation.mode</code>" property specifies database schema validation mode.
* By default, the "<code>simple</code>" validation mode is selected.
* <b>Allowed Values:</b>
* <ul>
* <li>"<code>simple</code>" (DEFAULT)
* <li>"<code>full</code>" (experimental feature, may not work properly)
* </ul>
*
* @see #SCHEMA_VALIDATION_MODE_SIMPLE
* @see #SCHEMA_VALIDATION_MODE_FULL
*/
public static final String SCHEMA_VALIDATION_MODE = "eclipselink.schema-validation.mode";

/**
* The "<code>simple</code>" value of the "<code>eclipselink.schema-validation.mode</code>" property.
* Specifies, that simple schema validation shall be performed.
* Simple schema validation checks missing tables and missing or surplus columns in the existing tables.
*
* @see #SCHEMA_VALIDATION_MODE
*/
public static final String SCHEMA_VALIDATION_MODE_SIMPLE = "simple";

/**
* The "<code>full</code>" value of the "<code>eclipselink.schema-validation.mode</code>" property.
* Specifies, that full schema validation shall be performed.
* This feature is experimental and may not work properly on all supported databases.
* Full schema validation also checks differences in columns definitions.
*
* @see #SCHEMA_VALIDATION_MODE
*/
public static final String SCHEMA_VALIDATION_MODE_FULL = "full";

/**
* The parameter value "<code>sql-script</code>" specifies that DDL will be written to file(s).
* <p>For use with the "<code>eclipselink.ddl-generation.output-mode</code>" property.</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@
// - 542491: Add new 'eclipselink.jdbc.force-bind-parameters' property to force enable binding
// 13/01/2022-4.0.0 Tomas Kraus
// - 1391: JSON support in JPA
// 12/05/2023: Tomas Kraus
// - New Jakarta Persistence 3.2 Features
package org.eclipse.persistence.internal.databaseaccess;

// javase imports

import org.eclipse.persistence.descriptors.ClassDescriptor;
import org.eclipse.persistence.exceptions.DatabaseException;
import org.eclipse.persistence.exceptions.ValidationException;
Expand Down Expand Up @@ -3802,7 +3802,7 @@ public void initializeConnectionData(Connection connection) throws SQLException
*/
public void writeAddColumnClause(Writer writer, AbstractSession session, TableDefinition table, FieldDefinition field) throws IOException {
writer.write("ADD ");
field.appendDBString(writer, session, table);
field.appendDBCreateString(writer, session, table);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

// Contributors:
// Oracle - initial API and implementation from Oracle TopLink
// 12/05/2023: Tomas Kraus
// - New Jakarta Persistence 3.2 Features
package org.eclipse.persistence.internal.databaseaccess;

import java.io.Serializable;
Expand Down Expand Up @@ -58,21 +60,30 @@ private FieldTypeDefinition(Set<String> aliasesSet) {
aliases = aliasesSet;
}

/**
* Creates a new instance of {@link FieldTypeDefinition}
*/
public FieldTypeDefinition() {
this(Collections.emptySet());
}

/**
* Return a new field type.
* @see #setName(String)
*/
/**
* Creates a new instance of {@link FieldTypeDefinition} with database type name,
* see {@link #setName(String)}.
*
* @param databaseTypeName database type name
*/
public FieldTypeDefinition(String databaseTypeName) {
this();
name = databaseTypeName;
}

/**
* Return a new field type with a required size defaulting to the defaultSize.
* Creates a new instance of {@link FieldTypeDefinition} with database type name
* and default required size.
*
* @param databaseTypeName database type name
* @param defaultSize default required size
*/
public FieldTypeDefinition(String databaseTypeName, int defaultSize) {
this();
Expand All @@ -83,7 +94,12 @@ public FieldTypeDefinition(String databaseTypeName, int defaultSize) {
}

/**
* Return a new field type with a required size defaulting to the defaultSize.
* Creates a new instance of {@link FieldTypeDefinition} with database type name
* and default required size and sub-size.
*
* @param databaseTypeName database type name
* @param defaultSize default required size
* @param defaultSubSize default required sub-size
*/
public FieldTypeDefinition(String databaseTypeName, int defaultSize, int defaultSubSize) {
this();
Expand All @@ -95,14 +111,25 @@ public FieldTypeDefinition(String databaseTypeName, int defaultSize, int default
setMaxScale(defaultSubSize);
}

public FieldTypeDefinition(String databaseTypeName, int defaultSize, String aTypesuffix) {
/**
* Creates a new instance of {@link FieldTypeDefinition} with database type name,
* default required size and type suffix.
*
* @param databaseTypeName database type name
* @param defaultSize default required size
* @param typeSuffix type suffix
*/
public FieldTypeDefinition(String databaseTypeName, int defaultSize, String typeSuffix) {
this(databaseTypeName, defaultSize);
this.typesuffix = aTypesuffix;
this.typesuffix = typeSuffix;
this.isSizeAllowed = true;
}

/**
* Return a new field type with a required size defaulting to the defaultSize.
* Creates a new instance of {@link FieldTypeDefinition} with database type name.
*
* @param databaseTypeName database type name
* @param allowsSize whether database type allows size definition (e.g. {@code VARCHAR(8)}, {@code DECIMAL(15)})
*/
public FieldTypeDefinition(String databaseTypeName, boolean allowsSize) {
this();
Expand All @@ -111,7 +138,8 @@ public FieldTypeDefinition(String databaseTypeName, boolean allowsSize) {
}

/**
* Return a new field type with a required size defaulting to the defaultSize.
* Creates a new instance of {@link FieldTypeDefinition} with database type name
* and allowable size definition.
*
* @param databaseTypeName database type name
* @param allowsSize whether database type allows size definition (e.g. {@code VARCHAR(8)}, {@code DECIMAL(15)})
Expand All @@ -123,8 +151,13 @@ public FieldTypeDefinition(String databaseTypeName, boolean allowsSize, String..
this.isSizeAllowed = allowsSize;
}

/** Return a new field type with a required size defaulting to the defaultSize and
* shouldAllowNull set to allowsNull.
/**
* Creates a new instance of {@link FieldTypeDefinition} with database type name
* and allowable size definition and {@code NULL} values.
*
* @param databaseTypeName database type name
* @param allowsSize whether database type allows size definition (e.g. {@code VARCHAR(8)}, {@code DECIMAL(15)})
* @param allowsNull whether database type allows @code NULL} values.
*/
public FieldTypeDefinition(String databaseTypeName, boolean allowsSize, boolean allowsNull) {
this(databaseTypeName, allowsSize);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
// - 454189 : Misc message cleanup.#2
// 03/09/2016-2.6 Dalia Abo Sheasha
// - 489298: Wrap EclipseLink's Bean Validation calls in doPrivileged blocks when security is enabled
// 12/05/2023: Tomas Kraus
// - New Jakarta Persistence 3.2 Features
package org.eclipse.persistence.internal.localization.i18n;

import java.util.ListResourceBundle;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@
// - 526957 : Split the logging and trace messages
// 11/14/2017 - Dalia Abo Sheasha
// - 527273 : Minor message improvements
// 12/05/2023: Tomas Kraus
// - New Jakarta Persistence 3.2 Features
package org.eclipse.persistence.internal.localization.i18n;

import java.util.ListResourceBundle;
Expand Down Expand Up @@ -477,7 +479,13 @@ public class LoggingLocalizationResource extends ListResourceBundle {
// JPA 3.2
{ "unknown_property_type", "Unknown {0} type of {1} persistence property"},
{ "error_queryTimeoutParse", "Could not parse jakarta.persistence.query.timeout property value {0}: {1}"},
{ "schema_default_truncate_tables_failed", "Failed to truncate tables in the default table schema: {0}"},

{ "schema_default_create_tables_failed", "Failed to create tables in the default table schema: {0}"},
{ "schema_default_drop_tables_failed", "Failed to drop tables in the default table schema: {0}"},
{ "schema_default_replace_tables_failed", "Failed to replace tables in the default table schema: {0}"},
{ "schema_default_extend_tables_failed", "Failed to extend tables in the default table schema: {0}"},
{ "schema_drop_object_failed", "Failed to drop object in the default table schema: {0}"},
{ "validate_object_space", "validate object space." },
{ "stack_of_visited_objects_that_refer_to_the_corrupt_object", "stack of visited objects that refer to the corrupt object: {0}" },
{ "corrupt_object_referenced_through_mapping", "The following corrupt object is referenced through mapping: {0}" },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ protected void appendCalendar(Calendar calendar, Writer writer) throws IOExcepti
@Override
public void writeAddColumnClause(Writer writer, AbstractSession session, TableDefinition table, FieldDefinition field) throws IOException {
writer.write("ADD (");
field.appendDBString(writer, session, table);
field.appendDBCreateString(writer, session, table);
writer.write(")");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
// - 440278: Support fractional seconds in time values
// 02/19/2015 - Rick Curtis
// - 458877 : Add national character support
// 12/05/2023: Tomas Kraus
// - New Jakarta Persistence 3.2 Features
package org.eclipse.persistence.platform.database;

import org.eclipse.persistence.exceptions.ValidationException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
// Contributors:
// 01/19/2012-2.4 Chris Delahunt
// - 368490: Add support for Metadata to be refreshed through RCM
// 12/05/2023: Tomas Kraus
// - New Jakarta Persistence 3.2 Features
package org.eclipse.persistence.sessions.coordination;

import java.util.Map;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

// Contributors:
// Oracle - initial API and implementation from Oracle TopLink
// 12/05/2023: Tomas Kraus
// - New Jakarta Persistence 3.2 Features
package org.eclipse.persistence.tools.schemaframework;

import org.eclipse.persistence.exceptions.ValidationException;
Expand Down Expand Up @@ -119,8 +121,8 @@ public FieldDefinition(String name, String typeName) {
* @param table Database table being processed.
* @throws ValidationException When invalid or inconsistent data were found.
*/
public void appendDBString(final Writer writer, final AbstractSession session,
final TableDefinition table) {
public void appendDBCreateString(final Writer writer, final AbstractSession session,
final TableDefinition table) {
appendDBString(writer, session, table, null);
}

Expand All @@ -144,18 +146,19 @@ public boolean shouldPrintFieldNullClause(FieldTypeDefinition fieldType) {
* @param writer Target writer where to write field definition string.
* @param session Current session context.
* @param table Database table being processed.
* @param alterSeparator Field definition is part of ALTER/MODIFY COUMN statement when not {@code null}
* and {@code alterSeparator} is appended after column name
* @param alterKeyword Field definition is part of ALTER/MODIFY COLUMN statement
* and {@code alterKeyword} is appended after column name when not {@code null}
* @throws ValidationException When invalid or inconsistent data were found.
*/
public void appendDBString(final Writer writer, final AbstractSession session,
final TableDefinition table, String alterSeparator) throws ValidationException {
private void appendDBString(final Writer writer, final AbstractSession session,
final TableDefinition table, String alterKeyword) throws ValidationException {
try {
writer.write(name);
writer.write(" ");

if (alterSeparator != null) {
writer.write(alterSeparator);
// e.g. "ALTER TABLE assets ALTER COLUMN location TYPE VARCHAR" to add "TYPE" keyword
if (alterKeyword != null) {
writer.write(alterKeyword);
writer.write(" ");
}

Expand Down
Loading

0 comments on commit f4115c9

Please sign in to comment.