use of org.eclipse.persistence.platform.database.oracle.jdbc.OracleArrayType in project eclipselink by eclipse-ee4j.
the class OracleArrayTypeMetadata method process.
/**
* INTERNAL:
* Build a runtime OracleArrayType from the meta-data.
*/
@Override
public OracleArrayType process() {
OracleArrayType array = new OracleArrayType();
super.process(array);
array.setNestedType(getDatabaseTypeEnum(getNestedType()));
return array;
}
use of org.eclipse.persistence.platform.database.oracle.jdbc.OracleArrayType 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.platform.database.oracle.jdbc.OracleArrayType 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);
}
}
use of org.eclipse.persistence.platform.database.oracle.jdbc.OracleArrayType in project eclipselink by eclipse-ee4j.
the class BaseDBWSBuilderHelper method buildDatabaseTypeFromMetadataType.
/**
* Build a org.eclipse.persistence.internal.helper.DatabaseType instance from an
* org.eclipse.persistence.tools.oracleddl.metadata.DatabaseType instance. In the
* the case of PLSQL Packages, the catalog (package) name can be passed in as well.
*/
@SuppressWarnings("rawtypes")
protected org.eclipse.persistence.internal.helper.DatabaseType buildDatabaseTypeFromMetadataType(DatabaseType dType, String catalog) {
// argument could be from a different package
if (dType.isPLSQLType()) {
PLSQLType pType = (PLSQLType) dType;
catalog = pType.getParentType().getPackageName();
}
// handle cursors
if (dType.isPLSQLCursorType()) {
if (dType.isArgumentType()) {
dType = ((ArgumentType) dType).getEnclosedType();
}
PLSQLCursorType pType = (PLSQLCursorType) dType;
return new PLSQLCursor(pType.getParentType().getPackageName() + DOT + pType.getCursorName());
}
if (dType.isArgumentType()) {
dType = ((ArgumentType) dType).getEnclosedType();
} else if (dType.isTYPEType()) {
dType = ((TYPEType) dType).getEnclosedType();
}
// composite types
if (dType.isComposite()) {
String typeName = dType.getTypeName();
// for %ROWTYPE, the compatible JDBC type name cannot contain '%'
String compatibleType = typeName.contains(PERCENT) ? typeName.replace(PERCENT, UNDERSCORE) : typeName;
String javaTypeName = compatibleType.toLowerCase();
// handle PL/SQL types
if (dType.isPLSQLType()) {
// for %ROWTYPE we don't want the catalog name prepended even if non-null
if (catalog != null && !typeName.contains(ROWTYPE_STR)) {
typeName = (catalog + DOT).concat(typeName);
compatibleType = (catalog + UNDERSCORE).concat(compatibleType);
javaTypeName = (catalog.toLowerCase() + DOT).concat(javaTypeName);
}
// handle PL/SQL record
if (dType.isPLSQLRecordType()) {
PLSQLrecord plsqlRec = new PLSQLrecord();
plsqlRec.setTypeName(typeName);
plsqlRec.setCompatibleType(compatibleType);
plsqlRec.setJavaTypeName(javaTypeName);
// process fields
for (FieldType fld : ((PLSQLRecordType) dType).getFields()) {
if (fld.getEnclosedType().isPrecisionType()) {
PrecisionType precisionType = (PrecisionType) fld.getEnclosedType();
plsqlRec.addField(fld.getFieldName(), buildDatabaseTypeFromMetadataType(precisionType), (int) precisionType.getPrecision(), (int) precisionType.getScale());
} else if (fld.getEnclosedType().isSizedType()) {
SizedType sizedType = (SizedType) fld.getEnclosedType();
plsqlRec.addField(fld.getFieldName(), buildDatabaseTypeFromMetadataType(sizedType), (int) sizedType.getSize());
} else {
plsqlRec.addField(fld.getFieldName(), buildDatabaseTypeFromMetadataType(fld.getEnclosedType(), catalog));
}
}
return plsqlRec;
}
// assumes PL/SQL collection
PLSQLCollection plsqlCollection = new PLSQLCollection();
plsqlCollection.setTypeName(typeName);
plsqlCollection.setCompatibleType(compatibleType);
plsqlCollection.setJavaTypeName(javaTypeName + COLLECTION_WRAPPER_SUFFIX);
plsqlCollection.setNestedType(buildDatabaseTypeFromMetadataType(((PLSQLCollectionType) dType).getEnclosedType(), catalog));
return plsqlCollection;
}
// handle advanced Oracle types
if (dType.isVArrayType()) {
OracleArrayType varray = new OracleArrayType();
varray.setTypeName(typeName);
varray.setCompatibleType(compatibleType);
varray.setJavaTypeName(getGeneratedWrapperClassName(javaTypeName, dbwsBuilder.getProjectName()));
varray.setNestedType(buildDatabaseTypeFromMetadataType(((VArrayType) dType).getEnclosedType(), null));
return varray;
}
if (dType.isObjectType()) {
OracleObjectType objType = new OracleObjectType();
objType.setTypeName(typeName);
objType.setCompatibleType(compatibleType);
objType.setJavaTypeName(getGeneratedJavaClassName(javaTypeName, dbwsBuilder.getProjectName()));
objType.setJavaType(getWrapperClass(objType.getJavaTypeName()));
Map<String, org.eclipse.persistence.internal.helper.DatabaseType> fields = objType.getFields();
ObjectType oType = (ObjectType) dType;
for (FieldType field : oType.getFields()) {
fields.put(field.getFieldName(), buildDatabaseTypeFromMetadataType(field.getEnclosedType()));
}
return objType;
}
if (dType.isObjectTableType()) {
OracleArrayType tableType = new OracleArrayType();
tableType.setTypeName(typeName);
tableType.setCompatibleType(compatibleType);
tableType.setJavaTypeName(getGeneratedWrapperClassName(javaTypeName, dbwsBuilder.getProjectName()));
org.eclipse.persistence.internal.helper.DatabaseType nestedType = buildDatabaseTypeFromMetadataType(((ObjectTableType) dType).getEnclosedType(), null);
// need to set the Java Type on the nested type
Class wrapper = getWrapperClass(nestedType);
if (wrapper != null) {
((ComplexDatabaseType) nestedType).setJavaType(wrapper);
}
tableType.setNestedType(nestedType);
return tableType;
}
return null;
} else if (dType.isScalar()) {
org.eclipse.persistence.internal.helper.DatabaseType theType = OraclePLSQLTypes.getDatabaseTypeForCode(dType.getTypeName());
if (theType != null) {
return theType;
}
}
// scalar types
return JDBCTypes.getDatabaseTypeForCode(org.eclipse.persistence.tools.dbws.Util.getJDBCTypeFromTypeName(dType.getTypeName()));
}
Aggregations