Skip to Main Content

Java HotSpot Virtual Machine

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How should I deploy my java application

1010537May 23 2013 — edited May 23 2013
Let's say I have a package with a main class, and the main class uses some class in the package

I export it all in the package in a jar file using Eclipse

Then, I put the jar file in the lib
and run using

java -cp "A1.jar";"lib/*" package/Mainclass

Is this the correct way of running java application?

Comments

Shaun Smith-Oracle
Hi Patrick,

We don't have specific support for Java 5 enums in 10.1.3.0.0. One way to handle them is with a transformation mapping. You can use the Enum api to convert to/from the text name of the enum to an instance and back again pretty easily and don't have to hard wire any values. Below's an example of the classes you can use to complete a transformation mapping for an enum BookCategory type which is an attribute of a Book.

--Shaun

The Enum class:
public enum BookCategory {MYSTERY, SCIENCE_FICTION, BIOGRAPHY}
-------------------------------
The Field Transformer for the CATEGORY field:
public class BookCategoryFieldTransformer extends FieldTransformerAdapter {

	@Override
	public Object buildFieldValue(Object object, String fieldName, Session session) {
		Book book = (Book)object;
		BookCategory category = book.getCategory();
		if (category !=  null) {
			return category.name();
		} else {
			return null;
		}
	}

}
-----------------------------

The category AttributeTransformer:
// the database field CATEGORY contains a string obtained from an Enum using the name() method
public class BookCategoryAttributeTransformer extends AttributeTransformerAdapter {

	@Override
	public Object buildAttributeValue(Record record, Object object, Session session) {
		return BookCategory.valueOf((String)record.get("CATEGORY"));
	}
}
476702
Shaun,

Thank you, that was exactly what I was looking for.

-Patrick
Shaun Smith-Oracle
Hi Patrick,

One more thing. If you're using the TopLink Workbench be sure to run it on JDK 5 or you'll get errors trying to load your Java 5 compiled classes in to a pre-5 VM. You can set this up by setting the JAVA_HOME variable in the setenv.cmd/sh script in the toplink/bin folder of your TopLink installation directory.

Shaun
476702
In general this transformation mechanism is working fine. However, I have a class that has two fields that are of the same enum type. Each field maps to its own column in the database.

The problem is that I don't see a way of defining an AttributeTransformer for this attribute, because it is ambiguous which of the fields is being mapped in a given call to buildAttributeValue. I.e. which column name do I look at to get the data for generating the enum. Any ideas?

Thanks,
Patrick
625894
I use oracle.toplink.mappings.converters.Converter in our project. It works the same as TransformMapping and can meet your need.


First you create an implementation of Converter with exactly the same code in a TransformMapping

public class EnumConverter implements Converter {

public Object convertDataValueToObjectValue(Object arg0, Session arg1) {
....
}

public Object convertObjectValueToDataValue(Object arg0, Session arg1) {
.....
}

........
}

Then use DirectToFieldMapping and set the converter to the Mapping.

mapping.setConverter(new EnumConverter());



Regards,
Harper
1 - 5
Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Jun 20 2013
Added on May 23 2013
1 comment
1,168 views