use of org.eclipse.persistence.internal.helper.DatabaseType in project eclipselink by eclipse-ee4j.
the class OracleObjectTypeMetadata method process.
/**
* INTERNAL:
* Build a runtime Oracle object type from the meta-data.
*/
@Override
public OracleObjectType process() {
OracleObjectType objectType = new OracleObjectType();
super.process(objectType);
Map<String, DatabaseType> typeFields = new HashMap<String, DatabaseType>();
for (PLSQLParameterMetadata field : this.fields) {
typeFields.put(field.getName(), getDatabaseTypeEnum(field.getDatabaseType()));
}
objectType.setFields(typeFields);
return objectType;
}
use of org.eclipse.persistence.internal.helper.DatabaseType in project eclipselink by eclipse-ee4j.
the class ObjectPersistenceRuntimeXMLProject_11_1_1 method buildOracleArrayTypeDescriptor.
protected ClassDescriptor buildOracleArrayTypeDescriptor() {
XMLDescriptor descriptor = new XMLDescriptor();
descriptor.setJavaClass(OracleArrayType.class);
XMLDirectMapping typeNameMapping = new XMLDirectMapping();
typeNameMapping.setAttributeName("typeName");
typeNameMapping.setXPath(getPrimaryNamespaceXPath() + "type-name/text()");
descriptor.addMapping(typeNameMapping);
XMLDirectMapping compatibleTypeMapping = new XMLDirectMapping();
compatibleTypeMapping.setAttributeName("compatibleType");
compatibleTypeMapping.setXPath(getPrimaryNamespaceXPath() + "compatible-type/text()");
descriptor.addMapping(compatibleTypeMapping);
XMLDirectMapping javaTypeMapping = new XMLDirectMapping();
javaTypeMapping.setAttributeName("javaType");
javaTypeMapping.setXPath(getPrimaryNamespaceXPath() + "java-type/text()");
descriptor.addMapping(javaTypeMapping);
XMLCompositeObjectMapping databaseTypeMapping = new XMLCompositeObjectMapping();
databaseTypeMapping.setAttributeName("databaseTypeWrapper");
databaseTypeMapping.setAttributeAccessor(new AttributeAccessor() {
@Override
public Object getAttributeValueFromObject(Object object) {
OracleArrayType array = (OracleArrayType) object;
DatabaseType type = array.getNestedType();
return wrapType(type);
}
@Override
public void setAttributeValueInObject(Object object, Object value) {
OracleArrayType array = (OracleArrayType) object;
DatabaseTypeWrapper type = (DatabaseTypeWrapper) value;
array.setNestedType(type.getWrappedType());
}
});
databaseTypeMapping.setReferenceClass(DatabaseTypeWrapper.class);
databaseTypeMapping.setXPath("nested-type");
descriptor.addMapping(databaseTypeMapping);
return descriptor;
}
use of org.eclipse.persistence.internal.helper.DatabaseType in project eclipselink by eclipse-ee4j.
the class ObjectPersistenceRuntimeXMLProject_11_1_1 method buildOracleObjectTypeDescriptor.
/**
* Builds a descriptor for the OracleObjectType class.
*/
protected ClassDescriptor buildOracleObjectTypeDescriptor() {
XMLDescriptor descriptor = new XMLDescriptor();
descriptor.setJavaClass(OracleObjectType.class);
XMLDirectMapping typeNameMapping = new XMLDirectMapping();
typeNameMapping.setAttributeName("typeName");
typeNameMapping.setXPath(getPrimaryNamespaceXPath() + "type-name/text()");
descriptor.addMapping(typeNameMapping);
XMLDirectMapping compatibleTypeMapping = new XMLDirectMapping();
compatibleTypeMapping.setAttributeName("compatibleType");
compatibleTypeMapping.setXPath(getPrimaryNamespaceXPath() + "compatible-type/text()");
descriptor.addMapping(compatibleTypeMapping);
XMLDirectMapping javaTypeMapping = new XMLDirectMapping();
javaTypeMapping.setAttributeName("javaType");
javaTypeMapping.setXPath(getPrimaryNamespaceXPath() + "java-type/text()");
descriptor.addMapping(javaTypeMapping);
XMLCompositeCollectionMapping fieldsMapping = new XMLCompositeCollectionMapping();
fieldsMapping.setAttributeName("fields");
fieldsMapping.setReferenceClass(ObjectTypeFieldAssociation.class);
// handle translation of 'field' LinkedHashMap
fieldsMapping.setAttributeAccessor(new AttributeAccessor() {
@Override
public Object getAttributeValueFromObject(Object object) {
Map<String, DatabaseType> fields = ((OracleObjectType) object).getFields();
List<ObjectTypeFieldAssociation> associations = new ArrayList<>(fields.size());
Iterator<Map.Entry<String, DatabaseType>> iterator = fields.entrySet().iterator();
while (iterator.hasNext()) {
Map.Entry<String, DatabaseType> entry = iterator.next();
associations.add(new ObjectTypeFieldAssociation(entry.getKey(), wrapType(entry.getValue())));
}
return associations;
}
@Override
public void setAttributeValueInObject(Object object, Object value) {
OracleObjectType objectType = (OracleObjectType) object;
List<ObjectTypeFieldAssociation> associations = (List<ObjectTypeFieldAssociation>) value;
Map<String, DatabaseType> fieldMap = new LinkedHashMap<>(associations.size() + 1);
Iterator<ObjectTypeFieldAssociation> iterator = associations.iterator();
while (iterator.hasNext()) {
ObjectTypeFieldAssociation association = iterator.next();
fieldMap.put(association.getKey(), unwrapType(association.getValue()));
}
objectType.setFields(fieldMap);
}
});
fieldsMapping.setXPath(getPrimaryNamespaceXPath() + "fields/" + getPrimaryNamespaceXPath() + "field");
descriptor.addMapping(fieldsMapping);
return descriptor;
}
use of org.eclipse.persistence.internal.helper.DatabaseType in project eclipselink by eclipse-ee4j.
the class ObjectPersistenceRuntimeXMLProject_11_1_1 method buildPLSQLargumentDescriptor.
protected ClassDescriptor buildPLSQLargumentDescriptor() {
XMLDescriptor descriptor = new XMLDescriptor();
descriptor.setJavaClass(PLSQLargument.class);
XMLDirectMapping nameMapping = new XMLDirectMapping();
nameMapping.setAttributeName("name");
nameMapping.setXPath(getPrimaryNamespaceXPath() + "name/text()");
descriptor.addMapping(nameMapping);
XMLDirectMapping indexMapping = new XMLDirectMapping();
indexMapping.setAttributeName("originalIndex");
indexMapping.setXPath(getPrimaryNamespaceXPath() + "index/text()");
indexMapping.setNullValue(-1);
descriptor.addMapping(indexMapping);
XMLDirectMapping directionMapping = new XMLDirectMapping();
directionMapping.setAttributeName("direction");
directionMapping.setXPath(getPrimaryNamespaceXPath() + "direction/text()");
ObjectTypeConverter directionConverter = new ObjectTypeConverter();
directionConverter.addConversionValue("IN", IN);
directionConverter.addConversionValue("INOUT", INOUT);
directionConverter.addConversionValue("OUT", OUT);
directionMapping.setConverter(directionConverter);
directionMapping.setNullValue(IN);
descriptor.addMapping(directionMapping);
XMLDirectMapping lengthMapping = new XMLDirectMapping();
lengthMapping.setAttributeName("length");
lengthMapping.setXPath(getPrimaryNamespaceXPath() + "length/text()");
lengthMapping.setNullValue(255);
descriptor.addMapping(lengthMapping);
XMLDirectMapping precisionMapping = new XMLDirectMapping();
precisionMapping.setAttributeName("precision");
precisionMapping.setXPath(getPrimaryNamespaceXPath() + "precision/text()");
precisionMapping.setNullValue(MIN_VALUE);
descriptor.addMapping(precisionMapping);
XMLDirectMapping scaleMapping = new XMLDirectMapping();
scaleMapping.setAttributeName("scale");
scaleMapping.setXPath(getPrimaryNamespaceXPath() + "scale/text()");
scaleMapping.setNullValue(MIN_VALUE);
descriptor.addMapping(scaleMapping);
XMLDirectMapping cursorOutputMapping = new XMLDirectMapping();
cursorOutputMapping.setAttributeName("cursorOutput");
cursorOutputMapping.setXPath("@cursorOutput");
cursorOutputMapping.setNullValue(Boolean.FALSE);
descriptor.addMapping(cursorOutputMapping);
XMLCompositeObjectMapping databaseTypeMapping = new XMLCompositeObjectMapping();
databaseTypeMapping.setAttributeName("databaseTypeWrapper");
databaseTypeMapping.setAttributeAccessor(new AttributeAccessor() {
@Override
public Object getAttributeValueFromObject(Object object) {
PLSQLargument argument = (PLSQLargument) object;
DatabaseType type = argument.databaseType;
return wrapType(type);
}
@Override
public void setAttributeValueInObject(Object object, Object value) {
PLSQLargument argument = (PLSQLargument) object;
DatabaseTypeWrapper type = (DatabaseTypeWrapper) value;
argument.databaseType = type.getWrappedType();
}
});
databaseTypeMapping.setReferenceClass(DatabaseTypeWrapper.class);
databaseTypeMapping.setXPath(".");
descriptor.addMapping(databaseTypeMapping);
return descriptor;
}
use of org.eclipse.persistence.internal.helper.DatabaseType in project eclipselink by eclipse-ee4j.
the class PLSQLTestSuite method testOracleTypeProcessing.
/**
* Test processing of OracleObject and OracleArray annotations.
*
* @see OracleArray
* @see org.eclipse.persistence.platform.database.oracle.annotations.OracleObject
*/
public void testOracleTypeProcessing() {
if (!getServerSession().getPlatform().isOracle()) {
return;
}
EntityManager em = createEntityManager();
beginTransaction(em);
try {
Query query = em.createNamedQuery("TEST_ORACLE_TYPES");
assertNotNull("EntityManager could not create query [TEST_ORACLE_TYPES]", query);
assertTrue("Expected EJBQueryImpl but was [" + query.getClass().getName() + "]", query instanceof EJBQueryImpl);
DatabaseCall call = ((EJBQueryImpl) query).getDatabaseQuery().getCall();
assertNotNull("The DatabaseCall was not set on the query", call);
assertTrue("Expected PLSQLStoredProcedureCall but was [" + call.getClass().getName() + "]", call instanceof PLSQLStoredProcedureCall);
PLSQLStoredProcedureCall plsqlCall = (PLSQLStoredProcedureCall) call;
List<PLSQLargument> args = plsqlCall.getArguments();
assertTrue("Expected 2 arguments, but was [" + args.size() + "]", args.size() == 2);
boolean foundINArg = false;
boolean foundOUTArg = false;
for (PLSQLargument arg : args) {
if (arg.name.equals("P_IN")) {
foundINArg = true;
assertNotNull("databaseType for arg P_IN is null", arg.databaseType);
assertTrue("Expected arg P_IN to be an OracleArrayType, but was [" + arg.databaseType.getClass().getName() + "]", arg.databaseType instanceof OracleArrayType);
OracleArrayType arrayType = (OracleArrayType) arg.databaseType;
assertTrue("Expected arg P_IN to have databaseType set with type name VARRAY_NUMERO_UNO, but was [" + arrayType.getTypeName() + "]", arrayType.getTypeName().equals("VARRAY_NUMERO_UNO"));
assertNotNull("Expected VARRAY_NUMERO_UNO to have nested type VARCHAR, but was null", arrayType.getNestedType());
assertTrue("Expected VARRAY_NUMERO_UNO to have nested type VARCHAR, but was [" + arrayType.getNestedType().getTypeName() + "]", arrayType.getNestedType().getTypeName().equals("VARCHAR"));
} else if (arg.name.equals("P_OUT")) {
foundOUTArg = true;
assertNotNull("databaseType for arg P_OUT is null", arg.databaseType);
assertTrue("Expected arg P_OUT to be an OracleObjectType, but was [" + arg.databaseType.getClass().getName() + "]", arg.databaseType instanceof OracleObjectType);
OracleObjectType objectType = (OracleObjectType) arg.databaseType;
assertTrue("Expected arg P_OUT to have databaseType set with type name OBJECT_NUMERO_DOS, but was [" + objectType.getTypeName() + "]", objectType.getTypeName().equals("OBJECT_NUMERO_DOS"));
assertTrue("Expected OBJECT_NUMERO_DOS to have 2 fields, but was [" + objectType.getFields().size() + "]", objectType.getFields().size() == 2);
for (String key : objectType.getFields().keySet()) {
DatabaseType dbType = objectType.getFields().get(key);
if (key.equals("OO_FLD1")) {
assertTrue("Expected field OO_FLD1 to have databaseType NUMERIC, but was [" + dbType.getTypeName() + "]", dbType.getTypeName().equals("NUMERIC"));
} else if (key.equals("OO_FLD2")) {
assertTrue("Expected field OO_FLD2 to have databaseType NUMERIC, but was [" + dbType.getTypeName() + "]", dbType.getTypeName().equals("NUMERIC"));
} else {
fail("Expected OBJECT_NUMERO_DOS to have fields OO_FLD1 and OO_FLD2 but encountered field [" + key + "]");
}
}
} else {
fail("Expected arg name to be one of P_IN or P_OUT, but was [" + arg.name + "]");
}
}
assertTrue("IN arg P_IN was not processed", foundINArg);
assertTrue("OUT arg P_OUT was not processed", foundOUTArg);
} finally {
closeEntityManagerAndTransaction(em);
}
}
Aggregations