Skip to content

Commit

Permalink
dynamic, history pkg cleanup
Browse files Browse the repository at this point in the history
Signed-off-by: Lukas Jungmann <lukas.jungmann@oracle.com>
  • Loading branch information
lukasj committed Feb 22, 2024
1 parent 5a8479f commit c5827e7
Show file tree
Hide file tree
Showing 13 changed files with 174 additions and 198 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public class DynamicClassLoader extends ClassLoader {
/**
* Map of {@link DynamicClassWriter} used to dynamically create a class in
* the {@link #findClass(String)} call. The application must register
* classes using addClass or createDynameClass prior to the
* classes using addClass or createDynamicClass prior to the
* {@link #findClass(String)} being invoked.
* <p>
* The map of writers is maintained for the life of this DynamicClassLoader
Expand Down Expand Up @@ -164,14 +164,11 @@ public void addClass(String className, EclipseLinkClassWriter writer) throws Dyn
*/
public Class<?> createDynamicClass(String className, DynamicClassWriter writer) {
addClass(className, writer);
Class<?> newDynamicClass = null;
try {
newDynamicClass = loadClass(className);
return checkAssignable(loadClass(className));
} catch (ClassNotFoundException cnfe) {
throw new IllegalArgumentException("DynamicClassLoader: could not create class " + className);
}
catch (ClassNotFoundException cnfe) {
throw new IllegalArgumentException("DyanmicClassLoader: could not create class " + className);
}
return checkAssignable(newDynamicClass);
}

protected Class<?> checkAssignable(Class<?> clz) {
Expand Down Expand Up @@ -256,8 +253,8 @@ protected Class<?> findClass(String className) throws ClassNotFoundException {
}

/**
* Converts an array of bytes into an instance of class <code>Class</code>.
* Before the <code>Class</code> can be used it must be resolved.
* Converts an array of bytes into an instance of class {@code Class}.
* Before the {@code Class} can be used it must be resolved.
*
*/
protected Class<?> defineDynamicClass(String name, byte[] b) {
Expand All @@ -279,8 +276,8 @@ public static DynamicClassLoader lookup(Session session) {
cm = session.getPlatform().getConversionManager();
}

if (cm.getLoader() instanceof DynamicClassLoader) {
return (DynamicClassLoader) cm.getLoader();
if (cm.getLoader() instanceof DynamicClassLoader cl) {
return cl;
}

DynamicClassLoader dcl = new DynamicClassLoader(cm.getLoader());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
* Instances of this class and any subclasses are maintained within the
* {@link DynamicClassLoader#getClassWriters()} and
* {@link DynamicClassLoader#defaultWriter} for the life of the class loader so
* it is important that no unnecessary state be maintained that may effect
* it is important that no unnecessary state be maintained that may affect
* memory usage.
*
* @author dclarke, mnorman
Expand Down Expand Up @@ -158,7 +158,7 @@ public byte[] writeClass(DynamicClassLoader loader, String className) throws Cla
ClassWriter cw = new EclipseLinkASMClassWriter();

// public class Foo extends DynamicEntityImpl {
cw.visit(Opcodes.ACC_PUBLIC + Opcodes.ACC_SUPER, classNameAsSlashes, null, parentClassNameAsSlashes, interfaces != null ? interfaces.toArray(new String[interfaces.size()]) : null);
cw.visit(Opcodes.ACC_PUBLIC + Opcodes.ACC_SUPER, classNameAsSlashes, null, parentClassNameAsSlashes, interfaces != null ? interfaces.toArray(new String[0]) : null);

// public static DynamicPropertiesManager DPM = new
// DynamicPropertiesManager();
Expand Down Expand Up @@ -258,16 +258,16 @@ protected byte[] createEnum(EnumInfo enumInfo) {

// Add constructors
// SignatureAttribute methodAttrs1 = new SignatureAttribute("()V");
mv = cw.visitMethod(Opcodes.ACC_PRIVATE, "<init>", "(Ljava/lang/String;I)V", null, null);
mv = cw.visitMethod(Opcodes.ACC_PRIVATE, INIT, "(Ljava/lang/String;I)V", null, null);
mv.visitVarInsn(Opcodes.ALOAD, 0);
mv.visitVarInsn(Opcodes.ALOAD, 1);
mv.visitVarInsn(Opcodes.ILOAD, 2);
mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/lang/Enum", "<init>", "(Ljava/lang/String;I)V", false);
mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/lang/Enum", INIT, "(Ljava/lang/String;I)V", false);
mv.visitInsn(Opcodes.RETURN);
mv.visitMaxs(3, 3);

// Add enum constants
mv = cw.visitMethod(Opcodes.ACC_STATIC, "<clinit>", "()V", null, null);
mv = cw.visitMethod(Opcodes.ACC_STATIC, CLINIT, "()V", null, null);

int lastCount = 0;
for (int i = 0; i < enumValues.length; i++) {
Expand All @@ -282,7 +282,7 @@ protected byte[] createEnum(EnumInfo enumInfo) {
} else {
mv.visitIntInsn(Opcodes.SIPUSH, i);
}
mv.visitMethodInsn(Opcodes.INVOKESPECIAL, internalClassName, "<init>", "(Ljava/lang/String;I)V", false);
mv.visitMethodInsn(Opcodes.INVOKESPECIAL, internalClassName, INIT, "(Ljava/lang/String;I)V", false);
mv.visitFieldInsn(Opcodes.PUTSTATIC, internalClassName, enumValue, "L" + internalClassName + ";");
lastCount = i;
}
Expand Down Expand Up @@ -319,7 +319,7 @@ protected byte[] createEnum(EnumInfo enumInfo) {

/**
* Verify that the provided class meets the requirements of the writer. In
* the case of {@link DynamicClassWriter} this will ensure that the class is
* the case of {@code DynamicClassWriter} this will ensure that the class is
* a subclass of the {@link #parentClass}
*
*/
Expand All @@ -329,7 +329,7 @@ protected boolean verify(Class<?> dynamicClass, ClassLoader loader) throws Class
}

/**
* Interfaces the dynamic entity class implements. By default this is none
* Interfaces the dynamic entity class implements. By default, this is none
* but in the case of SDO a concrete interface must be implemented.
* Subclasses should override this as required.
*
Expand All @@ -340,7 +340,7 @@ protected String[] getInterfaces() {
}

/**
* Create a copy of this {@link DynamicClassWriter} but with a different
* Create a copy of this {@code DynamicClassWriter} but with a different
* parent class.
*
* @see DynamicClassLoader#addClass(String, Class)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2021 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2024 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
Expand All @@ -21,26 +21,25 @@
import org.eclipse.persistence.exceptions.DynamicException;

/**
* <code>DynamicEntity</code> is the public interface for dealing with dynamic persistent objects.
* {@code DynamicEntity} is the public interface for dealing with dynamic persistent objects.
* <p>
* The purpose of dynamic persistent objects is to enable (simple) data access when only mapping
* information is available <br>
* and no concrete Java model is present (specifically, no <code>.class</code> files .)
* and no concrete Java model is present (specifically, no {@code .class} files.)
* <p>
* Applications using <code>DynamicEntity</code>'s can access the persistent state using property names
* Applications using {@code DynamicEntity}'s can access the persistent state using property names
* which correspond <br>
* to the mapped attributes in the underlying EclipseLink descriptors.
* For properties mapped to containers ({@link java.util.Collection Collection},<br>
* {@link java.util.Map Map}, etc.), the property is retrieved then the resulting container can
* be manipulated.
* <pre>
* ...
* DynamicEntity de = ...; // retrieve from database
* Collection&lt;String&gt; myListOfGroups = de.&lt;Collection&lt;String&gt;&gt;get("myListOfGroups");
* if (!myListOfGroups.isEmpty()) {
* myListOfGroups.add("FabFour");
* }
* </pre>
* {@snippet :
* DynamicEntity de = ...; // retrieve from database
* Collection<String> myListOfGroups = de.<Collection<String>>get("myListOfGroups");
* if (!myListOfGroups.isEmpty()) {
* myListOfGroups.add("FabFour");
* }
* }
* To discover meta-data about a DynamicEntity's properties, see the {@link DynamicHelper} class
*
* @author dclarke, mnorman
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public DatabaseSession getSession() {
/**
* Lookup the dynamic type for an alias. This is required to get the type
* for factory creation but can also be used to provide the application with
* access to the meta model (type and properties) allowing for dynamic use
* access to the metamodel (type and properties) allowing for dynamic use
* as well as optimized data value retrieval from an entity.
*/
public DynamicType getType(String typeName) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,22 +79,23 @@ public class DynamicTypeBuilder {
* its wrapped descriptor are not automatically added to any session. This
* must be done by the application after the type's is fully configured.
* <p>
* <b>Creating new type Example</b>: <code>
* <b>Creating new type Example</b>:
* {@snippet :
* DynamicHelper helper = new DynamicHelper(session);
* DynamicClassLoader dcl = helper.getDynamicClassLoader();<br>
* <br>
* Class{@literal <?>} javaType = dcl.creatDynamicClass("model.Simple");<br>
* <br>
* DynamicTypeBuilder typeBuilder = new JPADynamicTypeBuilder(javaType, null, "SIMPLE_TYPE");<br>
* typeBuilder.setPrimaryKeyFields("SID");<br>
* typeBuilder.addDirectMapping("id", int.class, "SID");<br>
* typeBuilder.addDirectMapping("value1", String.class, "VAL_1");<br>
* typeBuilder.addDirectMapping("value2", boolean.class, "VAL_2");<br>
* typeBuilder.addDirectMapping("value3", Calendar.class, "VAL_3");<br>
* typeBuilder.addDirectMapping("value4", Character.class, "VAL_4");<br>
* <br>
* helper.addTypes(true, true, typeBuilder.getType());<br>
* </code>
* DynamicClassLoader dcl = helper.getDynamicClassLoader();
*
* Class<?> javaType = dcl.creatDynamicClass("model.Simple");
*
* DynamicTypeBuilder typeBuilder = new JPADynamicTypeBuilder(javaType, null, "SIMPLE_TYPE");
* typeBuilder.setPrimaryKeyFields("SID");
* typeBuilder.addDirectMapping("id", int.class, "SID");
* typeBuilder.addDirectMapping("value1", String.class, "VAL_1");
* typeBuilder.addDirectMapping("value2", boolean.class, "VAL_2");
* typeBuilder.addDirectMapping("value3", Calendar.class, "VAL_3");
* typeBuilder.addDirectMapping("value4", Character.class, "VAL_4");
*
* helper.addTypes(true, true, typeBuilder.getType());
* }
*
*/
public DynamicTypeBuilder(Class<?> dynamicClass, DynamicType parentType, String... tableNames) {
Expand Down Expand Up @@ -308,13 +309,13 @@ public OneToOneMapping addOneToOneMapping(String name, DynamicType refType, Stri
* {@link IndirectList}).
*
* @param name
* attribute name to use in the dynamic entity. Also the property
* attribute name to use in the dynamic entity. Also, the property
* name used to access the state of the entity
* @param fkFieldNames
* the FK field names specified in the same order to match the PK
* field names of the target class
*
* @return the newly created, configured mappin. It will be initialized if
* @return the newly created, configured mapping. It will be initialized if
* the descriptor is already initialized.
*/
public OneToManyMapping addOneToManyMapping(String name, DynamicType refType, String... fkFieldNames) {
Expand Down Expand Up @@ -346,7 +347,7 @@ public OneToManyMapping addOneToManyMapping(String name, DynamicType refType, St
* indirection ( {@link IndirectList}).
*
* @param name
* attribute name to use in the dynamic entity. Also the property
* attribute name to use in the dynamic entity. Also, the property
* name used to access the state of the entity
* @param targetTable
* name of table holding the direct values
Expand All @@ -359,7 +360,7 @@ public OneToManyMapping addOneToManyMapping(String name, DynamicType refType, St
* the FK field names on the source table specified in order to
* match the PK field names on the source.
* @return the new mapping configured and initialized (if the descriptor is
* already initialized.
* already initialized).
*/
public DirectCollectionMapping addDirectCollectionMapping(String name, String targetTable, String valueColumn, Class<?> valueType, String... fkFieldNames) throws IllegalArgumentException {
if (fkFieldNames == null) {
Expand Down Expand Up @@ -390,7 +391,7 @@ public DirectCollectionMapping addDirectCollectionMapping(String name, String ta
* {@link #entityType} being built or extended.
*
* @param name
* attribute name to use in the dynamic entity. Also the property
* attribute name to use in the dynamic entity. Also, the property
* name used to access the state of the entity
* @param refType
* dynamic type re[presenting the {@code Embeddable}/{@code AggregateObject}
Expand All @@ -417,7 +418,7 @@ public AggregateObjectMapping addAggregateObjectMapping(String name, DynamicType
* column names if they collide with the names from the source table.
*
* @param name
* attribute name to use in the dynamic entity. Also the property
* attribute name to use in the dynamic entity. Also, the property
* name used to access the state of the entity
* @param refType
* target dynamic entity
Expand Down Expand Up @@ -532,7 +533,7 @@ protected AbstractDirectMapping addDirectMappingForEnum(String fieldName, String
* Login/Platform is being configured that the
* {@link ConversionManager#getLoader()} is maintained.
* <p>
* <code>null</code> is returned if the resourcePath cannot locate a
* {@code null} is returned if the resourcePath cannot locate a
* deployment XML
*/
public static Project loadDynamicProject(String resourcePath, DatabaseLogin login, DynamicClassLoader dynamicClassLoader) throws IOException {
Expand All @@ -557,7 +558,7 @@ public static Project loadDynamicProject(String resourcePath, DatabaseLogin logi
* Login/Platform is being configured that the
* {@link ConversionManager#getLoader()} is maintained.
* <p>
* <code>null</code> is returned if the resourcePath cannot locate a
* {@code null} is returned if the resourcePath cannot locate a
* deployment XML
*/
public static Project loadDynamicProject(InputStream resourceStream, DatabaseLogin login, DynamicClassLoader dynamicClassLoader) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2023 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2024 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2022 IBM Corporation. All rights reserved.
*
* This program and the accompanying materials are made available under the
Expand Down Expand Up @@ -28,9 +28,9 @@
* <b>Purpose:</b>Wraps an immutable value for a past time.
* A session, query, or expression can be as of a past time.
* <p>
* For Oracle 9R2 Flasback corresponds to the sub clause which appears between
* For Oracle 9R2 Flashback corresponds to the sub clause which appears between
* the table and alias name in the FROM clause:
* <code>SELECT ... FROM EMPLOYEE AS OF TIMESTAMP (value) t0, ...</code>
* {@code SELECT ... FROM EMPLOYEE AS OF TIMESTAMP (value) t0, ...}
* </p><p>For generic historical schema support, a special criteria can be added to
* the where clause for each table in a select:
* <code>((t0.ROW_START {@literal <=} value) AND ((t0.END IS NULL) OR (t1.END {@literal >} value)))</code>
Expand Down Expand Up @@ -104,13 +104,13 @@ public boolean equals(Object object) {
public void printSQL(ExpressionSQLPrinter printer) {
printer.printString("AS OF TIMESTAMP (");
Object value = getValue();
if (value instanceof Expression) {
if (value instanceof Expression expression) {
// Sort of an implementation of native sql.
// Print AS OF TIMESTAMP (SYSDATE - 1000*60*10) not AS OF ('SYSDATE - 1000*60*10').
if ((value instanceof ConstantExpression) && (((ConstantExpression)value).getValue() instanceof String)) {
printer.printString((String)((ConstantExpression)value).getValue());
if ((value instanceof ConstantExpression ce) && (ce.getValue() instanceof String s)) {
printer.printString(s);
} else {
printer.printExpression((Expression)value);
printer.printExpression(expression);
}
} else {
ConversionManager converter = ConversionManager.getDefaultManager();
Expand All @@ -131,10 +131,10 @@ public Object getValue() {

/**
* PUBLIC:
* Indicates that <code>value</code> is a system change number or an expression
* Indicates that {@code value} is a system change number or an expression
* evaluating to one.
* <p>In Oracle the value will have to be printed using the syntax <code>AS OF SCN(value)</code>
* instead of <code>AS OF TIMESTAMP(value)</code>.
* <p>In Oracle the value will have to be printed using the syntax {@code AS OF SCN(value)}
* instead of {@code AS OF TIMESTAMP(value)}.
* @see AsOfSCNClause
*/
public boolean isAsOfSCNClause() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1998, 2023 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1998, 2024 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2022 IBM Corporation. All rights reserved.
*
* This program and the accompanying materials are made available under the
Expand Down Expand Up @@ -59,13 +59,13 @@ public AsOfSCNClause(Expression expression) {
public void printSQL(ExpressionSQLPrinter printer) {
printer.printString("AS OF SCN (");
Object value = getValue();
if (value instanceof Expression) {
if (value instanceof Expression expression) {
// Sort of an implementation of native sql.
// Print AS OF SCN (1000L - 45L) not AS OF ('1000L - 45L').
if ((value instanceof ConstantExpression) && (((ConstantExpression)value).getValue() instanceof String)) {
printer.printString((String)((ConstantExpression)value).getValue());
if ((value instanceof ConstantExpression ce) && (ce.getValue() instanceof String s)) {
printer.printString(s);
} else {
printer.printExpression((Expression)value);
printer.printExpression(expression);
}
} else {
ConversionManager converter = ConversionManager.getDefaultManager();
Expand Down

0 comments on commit c5827e7

Please sign in to comment.