Skip to content

Commit

Permalink
Review notes applied.
Browse files Browse the repository at this point in the history
Signed-off-by: Tomáš Kraus <tomas.kraus@oracle.com>
  • Loading branch information
Tomas-Kraus authored and lukasj committed Dec 20, 2023
1 parent e9e8ae1 commit 1ef011f
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3060,7 +3060,7 @@ public class PersistenceUnitProperties {
* <b>Allowed Values:</b>
* <ul>
* <li>"<code>simple</code>" (DEFAULT)
* <li>"<code>full</code>" (experimental feature, may not work properly)
* <li>"<code>full</code>" (experimental feature)
* </ul>
*
* @see #SCHEMA_VALIDATION_MODE_SIMPLE
Expand All @@ -3079,9 +3079,8 @@ public class PersistenceUnitProperties {

/**
* 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.
* Specifies, that full schema validation shall be performed. Full schema validation also checks differences
* in columns definitions. This feature is experimental.
*
* @see #SCHEMA_VALIDATION_MODE
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ public boolean isStoredInObject() {
* INTERNAL:
* Retrieves the lock value from the object.
*/
public Object lockValueFromObject(Object domainObject) {
protected Object lockValueFromObject(Object domainObject) {
// PERF: If mapping with a direct mapping get from cached mapping.
if (this.lockMapping != null) {
return this.lockMapping.getAttributeValueFromObject(domainObject);
Expand All @@ -556,6 +556,18 @@ public Object lockValueFromObject(Object domainObject) {
}
}

/**
* Returns the version of provided entity instance.
*
* @param entity the entity instance
* @param <T> type of the version
* @return version of the entity instance
*/
@SuppressWarnings({"unchecked"})
public <T> T getVersion(Object entity) {
return (T) lockValueFromObject(entity);
}

/**
* INTERNAL:
* Returns the mapping that will be used to access the version value from an object.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3807,7 +3807,7 @@ public void writeAddColumnClause(Writer writer, AbstractSession session, TableDe

/**
* INTERNAL:
* May need to override this method if the platform supports ALTER TABLE DROP COLUMN &lt;column&gt;
* May need to override this method if the platform supports ALTER TABLE DROP COLUMN {@code column}
* and the generated sql doesn't work.
* Write the string that follows ALTER TABLE to create a sql statement for
* the platform in order to drop existing column from an existing table.
Expand All @@ -3819,7 +3819,7 @@ public void writeDropColumnClause(Writer writer, AbstractSession session, TableD

/**
* INTERNAL:
* May need to override this method if the platform supports TRUNCATE TABLE &lt;table&gt;
* May need to override this method if the platform supports TRUNCATE TABLE {@code column}
* and the generated sql doesn't work.
* Write the string that creates TRUNCATE TABLE sql statement for the platform in order
* to truncate an existing table.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1034,7 +1034,7 @@ public void createDefaultTables(boolean generateFKConstraints) {
TableCreator tableCreator = getDefaultTableCreator(generateFKConstraints);
tableCreator.createTables(this.session, this);
} catch (DatabaseException exception) {
session.log(SessionLog.WARNING, SessionLog.DDL, "schema_default_create_tables_failed", exception.getLocalizedMessage());
session.log(SessionLog.FINEST, SessionLog.DDL, "schema_default_create_tables_failed", exception.getLocalizedMessage());
} finally {
getSession().getSessionLog().setShouldLogExceptionStackTrace(shouldLogExceptionStackTrace);
}
Expand Down Expand Up @@ -1080,7 +1080,7 @@ public void dropDefaultTables() {
// called after all the constraints, tables etc. are dropped.
dropDatabaseSchemas();
} catch (DatabaseException exception) {
session.log(SessionLog.WARNING, SessionLog.DDL, "schema_default_drop_tables_failed", exception.getLocalizedMessage());
session.log(SessionLog.FINEST, SessionLog.DDL, "schema_default_drop_tables_failed", exception.getLocalizedMessage());
} finally {
getSession().getSessionLog().setShouldLogExceptionStackTrace(shouldLogExceptionStackTrace);
}
Expand Down Expand Up @@ -1120,7 +1120,7 @@ public void replaceDefaultTables(boolean createSequenceTables, boolean createSeq
// called after all the constraints, tables etc. are dropped.
dropDatabaseSchemas();
} catch (DatabaseException exception) {
session.log(SessionLog.WARNING, SessionLog.DDL, "schema_default_replace_tables_failed", exception.getLocalizedMessage());
session.log(SessionLog.FINEST, SessionLog.DDL, "schema_default_replace_tables_failed", exception.getLocalizedMessage());
} finally {
this.session.getSessionLog().setShouldLogExceptionStackTrace(shouldLogExceptionStackTrace);
}
Expand All @@ -1144,7 +1144,7 @@ public void truncateDefaultTables(boolean generateFKConstraints) {
TableCreator tableCreator = getDefaultTableCreator(generateFKConstraints);
tableCreator.truncateTables(session, this, generateFKConstraints);
} catch (DatabaseException exception) {
session.log(SessionLog.WARNING, SessionLog.DDL, "schema_default_truncate_tables_failed", exception.getLocalizedMessage());
session.log(SessionLog.FINEST, SessionLog.DDL, "schema_default_truncate_tables_failed", exception.getLocalizedMessage());
} finally {
session.getSessionLog().setShouldLogExceptionStackTrace(shouldLogExceptionStackTrace);
}
Expand Down Expand Up @@ -1224,7 +1224,7 @@ public void extendDefaultTables(boolean generateFKConstraints) throws EclipseLin
TableCreator tableCreator = getDefaultTableCreator(generateFKConstraints);
tableCreator.extendTables(this.session, this);
} catch (DatabaseException exception) {
session.log(SessionLog.WARNING, SessionLog.DDL, "schema_default_extend_tables_failed", exception.getLocalizedMessage());
session.log(SessionLog.FINEST, SessionLog.DDL, "schema_default_extend_tables_failed", exception.getLocalizedMessage());
} finally {
this.session.getSessionLog().setShouldLogExceptionStackTrace(shouldLogExceptionStackTrace);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,23 @@ public static Object getIdentifier(Object entity, AbstractSession session) {
}
}

public static Object getVersion(Object entity, AbstractSession session) {
/**
* Returns the version of provided entity instance.
*
* @param entity the entity instance
* @param session database session
* @param <T> type of the version
* @return version of the entity instance
*/
static <T> T getVersion(Object entity, AbstractSession session) {
ClassDescriptor descriptor = session.getDescriptor(entity);
if (descriptor == null) {
throw new IllegalArgumentException(ExceptionLocalization.buildMessage(
"jpa_persistence_util_get_version_non_persistent_class", new Object[] { entity }));
}
OptimisticLockingPolicy lockingPolicy = descriptor.getOptimisticLockingPolicy();
if (lockingPolicy instanceof VersionLockingPolicy versionLockingPolicy) {
return versionLockingPolicy.lockValueFromObject(entity);
return versionLockingPolicy.getVersion(entity);
}
throw new IllegalArgumentException(ExceptionLocalization.buildMessage(
"jpa_persistence_util_get_version_no_version_in_class", new Object[] { entity }));
Expand Down

0 comments on commit 1ef011f

Please sign in to comment.