use of org.eclipse.persistence.platform.database.oracle.Oracle10Platform in project eclipselink by eclipse-ee4j.
the class VeearrayTestSuite method setUp.
@BeforeClass
public static void setUp() {
final String ddlCreateProp = System.getProperty(DATABASE_DDL_CREATE_KEY, DEFAULT_DATABASE_DDL_CREATE);
if ("true".equalsIgnoreCase(ddlCreateProp)) {
ddlCreate = true;
}
final String ddlDropProp = System.getProperty(DATABASE_DDL_DROP_KEY, DEFAULT_DATABASE_DDL_DROP);
if ("true".equalsIgnoreCase(ddlDropProp)) {
ddlDrop = true;
}
final String ddlDebugProp = System.getProperty(DATABASE_DDL_DEBUG_KEY, DEFAULT_DATABASE_DDL_DEBUG);
if ("true".equalsIgnoreCase(ddlDebugProp)) {
ddlDebug = true;
}
String username = System.getProperty(DATABASE_USERNAME_KEY);
if (username == null) {
fail("error retrieving database username");
}
String password = System.getProperty(DATABASE_PASSWORD_KEY);
if (password == null) {
fail("error retrieving database password");
}
String url = System.getProperty(DATABASE_URL_KEY);
if (url == null) {
fail("error retrieving database url");
}
String driver = System.getProperty(DATABASE_DRIVER_KEY);
if (driver == null) {
fail("error retrieving database driver");
}
Project orProject = new Project();
orProject.setName("or-veearray");
DatabaseLogin login = new DatabaseLogin();
login.setUserName(username);
login.setPassword(password);
login.setConnectionString(url);
login.setDriverClassName(driver);
login.setDatasourcePlatform(new Oracle10Platform());
login.bindAllParameters();
orProject.setDatasourceLogin(login);
ObjectRelationalDataTypeDescriptor phoneORDescriptor = new ObjectRelationalDataTypeDescriptor();
phoneORDescriptor.setAlias("phone");
phoneORDescriptor.useSoftCacheWeakIdentityMap();
phoneORDescriptor.setJavaClass(Phone.class);
phoneORDescriptor.descriptorIsAggregate();
phoneORDescriptor.setStructureName("XR_VEE_ARRAY_PHONE");
phoneORDescriptor.addFieldOrdering("AREACODE");
phoneORDescriptor.addFieldOrdering("PHONENUMBER");
phoneORDescriptor.addFieldOrdering("PHONETYPE");
phoneORDescriptor.addDirectMapping("areaCode", "AREACODE");
phoneORDescriptor.addDirectMapping("phonenumber", "PHONENUMBER");
phoneORDescriptor.addDirectMapping("type", "PHONETYPE");
orProject.addDescriptor(phoneORDescriptor);
ObjectRelationalDataTypeDescriptor employeeORDescriptor = new ObjectRelationalDataTypeDescriptor();
employeeORDescriptor.useSoftCacheWeakIdentityMap();
employeeORDescriptor.getQueryManager().checkCacheForDoesExist();
employeeORDescriptor.setAlias("employee");
employeeORDescriptor.setJavaClass(Employee.class);
employeeORDescriptor.addTableName("XR_VEE_ARRAY_EMP");
employeeORDescriptor.addPrimaryKeyFieldName("XR_VEE_ARRAY_EMP.EMPNO");
orProject.addDescriptor(employeeORDescriptor);
DirectToFieldMapping idMapping = new DirectToFieldMapping();
idMapping.setAttributeName("id");
idMapping.setFieldName("XR_VEE_ARRAY_EMP.EMPNO");
employeeORDescriptor.addMapping(idMapping);
DirectToFieldMapping firstNameMapping = new DirectToFieldMapping();
firstNameMapping.setAttributeName("firstName");
firstNameMapping.setFieldName("XR_VEE_ARRAY_EMP.FNAME");
employeeORDescriptor.addMapping(firstNameMapping);
DirectToFieldMapping lastNameMapping = new DirectToFieldMapping();
lastNameMapping.setAttributeName("lastName");
lastNameMapping.setFieldName("XR_VEE_ARRAY_EMP.LNAME");
employeeORDescriptor.addMapping(lastNameMapping);
ObjectArrayMapping phonesMapping = new ObjectArrayMapping();
phonesMapping.setAttributeName("phones");
phonesMapping.setStructureName("XR_VEE_ARRAY_PHONES");
phonesMapping.setReferenceClass(Phone.class);
phonesMapping.setFieldName("PHONES");
employeeORDescriptor.addMapping(phonesMapping);
ReadAllQuery raq = new ReadAllQuery(Employee.class);
raq.setName("getVeeArrayEmployees");
raq.refreshIdentityMapResult();
StoredProcedureCall spCall = new StoredProcedureCall();
spCall.setProcedureName("GET_VEE_ARRAY_EMPS");
spCall.useNamedCursorOutputAsResultSet("X");
raq.setCall(spCall);
employeeORDescriptor.getQueryManager().addQuery("getVeeArrayEmployees", raq);
ReadObjectQuery roq = new ReadObjectQuery(Employee.class);
roq.setName("getVeeArrayEmployee");
roq.refreshIdentityMapResult();
roq.addArgument("X");
spCall = new StoredProcedureCall();
spCall.setProcedureName("GET_VEE_ARRAY_EMP");
spCall.addNamedArgument("X", "X", Types.INTEGER);
spCall.useNamedCursorOutputAsResultSet("Y");
roq.setCall(spCall);
employeeORDescriptor.getQueryManager().addQuery("getVeeArrayEmployee", roq);
ObjectRelationalDatabaseField ordf = new ObjectRelationalDatabaseField("");
ordf.setSqlType(Types.STRUCT);
ordf.setSqlTypeName("XR_VEE_ARRAY_PHONE");
ordf.setType(Phone.class);
DataModifyQuery dataModifyQuery = new DataModifyQuery();
dataModifyQuery.setName("updateVeeArrayPhones");
dataModifyQuery.addArgument("X");
dataModifyQuery.addArgument("Y");
spCall = new StoredProcedureCall();
spCall.setProcedureName("UPDATE_VEE_ARRAY_PHS");
spCall.addNamedArgument("X", "X", Types.INTEGER);
spCall.addNamedArgument("Y", "Y", Types.ARRAY, "XR_VEE_ARRAY_PHONES", ordf);
dataModifyQuery.setCall(spCall);
employeeORDescriptor.getQueryManager().addQuery("updateVeeArrayPhones", dataModifyQuery);
NamespaceResolver ns = new NamespaceResolver();
ns.setDefaultNamespaceURI("urn:veearray");
Project oxProject = new Project();
oxProject.setName("ox-veearray");
XMLLogin xmlLogin = new XMLLogin();
xmlLogin.getProperties().remove("user");
xmlLogin.getProperties().remove("password");
oxProject.setLogin(xmlLogin);
XMLDescriptor employeeOXDescriptor = new XMLDescriptor();
employeeOXDescriptor.setAlias("employee");
employeeOXDescriptor.setJavaClass(Employee.class);
employeeOXDescriptor.setDefaultRootElement("employee");
employeeOXDescriptor.setNamespaceResolver(ns);
XMLSchemaURLReference schemaReference = new XMLSchemaURLReference();
schemaReference.setSchemaContext("/employeeType");
schemaReference.setType(XMLSchemaReference.COMPLEX_TYPE);
employeeOXDescriptor.setSchemaReference(schemaReference);
XMLDirectMapping xmlIdMapping = new XMLDirectMapping();
xmlIdMapping.setAttributeName("id");
XMLField idField = new XMLField();
idField.setName("@id/text()");
idField.setSchemaType(INT_QNAME);
xmlIdMapping.setField(idField);
employeeOXDescriptor.addMapping(xmlIdMapping);
XMLDirectMapping xmlFirstNameMapping = new XMLDirectMapping();
xmlFirstNameMapping.setAttributeName("firstName");
XMLField firstNameField = new XMLField();
firstNameField.setName("first-name/text()");
firstNameField.setSchemaType(STRING_QNAME);
xmlFirstNameMapping.setField(firstNameField);
employeeOXDescriptor.addMapping(xmlFirstNameMapping);
XMLDirectMapping xmlLastNameMapping = new XMLDirectMapping();
xmlLastNameMapping.setAttributeName("lastName");
XMLField lastNameField = new XMLField();
lastNameField.setName("last-name/text()");
lastNameField.setSchemaType(STRING_QNAME);
xmlLastNameMapping.setField(lastNameField);
employeeOXDescriptor.addMapping(xmlLastNameMapping);
XMLCompositeCollectionMapping xmlPhonesMapping = new XMLCompositeCollectionMapping();
xmlPhonesMapping.setAttributeName("phones");
xmlPhonesMapping.setReferenceClass(Phone.class);
xmlPhonesMapping.setXPath("phones/phone");
employeeOXDescriptor.addMapping(xmlPhonesMapping);
oxProject.addDescriptor(employeeOXDescriptor);
XMLDescriptor phoneOXDescriptor = new XMLDescriptor();
phoneOXDescriptor.setAlias("phone");
phoneOXDescriptor.setJavaClass(Phone.class);
phoneOXDescriptor.setDefaultRootElement("phone");
phoneOXDescriptor.setNamespaceResolver(ns);
schemaReference = new XMLSchemaURLReference();
schemaReference.setSchemaContext("/phoneType");
schemaReference.setType(XMLSchemaReference.COMPLEX_TYPE);
phoneOXDescriptor.setSchemaReference(schemaReference);
XMLDirectMapping areaCodeMapping = new XMLDirectMapping();
areaCodeMapping.setAttributeName("areaCode");
XMLField areaCodeField = new XMLField();
areaCodeField.setName("area-code/text()");
areaCodeField.setSchemaType(STRING_QNAME);
areaCodeMapping.setField(areaCodeField);
phoneOXDescriptor.addMapping(areaCodeMapping);
XMLDirectMapping phonenumberMapping = new XMLDirectMapping();
phonenumberMapping.setAttributeName("phonenumber");
XMLField phonenumberField = new XMLField();
phonenumberField.setName("phonenumber/text()");
phonenumberField.setSchemaType(STRING_QNAME);
phonenumberMapping.setField(phonenumberField);
phoneOXDescriptor.addMapping(phonenumberMapping);
XMLDirectMapping typeMapping = new XMLDirectMapping();
typeMapping.setAttributeName("type");
XMLField typeField = new XMLField();
typeField.setName("type/text()");
typeField.setSchemaType(STRING_QNAME);
typeMapping.setField(typeField);
phoneOXDescriptor.addMapping(typeMapping);
oxProject.addDescriptor(phoneOXDescriptor);
XRServiceFactory factory = new XRServiceFactory() {
Project orProject;
Project oxProject;
XRServiceFactory setProject(Project orProject, Project oxProject) {
this.orProject = orProject;
this.oxProject = oxProject;
parentClassLoader = ClassLoader.getSystemClassLoader();
xrSchemaStream = new ByteArrayInputStream(VEEARRAY_SCHEMA.getBytes());
return this;
}
@Override
public void buildSessions() {
DatabaseSession ds = orProject.createDatabaseSession();
ds.dontLogMessages();
xrService.setORSession(ds);
xrService.setXMLContext(new XMLContext(oxProject));
xrService.setOXSession(xrService.getXMLContext().getSession(0));
}
}.setProject(orProject, oxProject);
XMLContext context = new XMLContext(new DBWSModelProject());
XMLUnmarshaller unmarshaller = context.createUnmarshaller();
DBWSModel model = (DBWSModel) unmarshaller.unmarshal(new StringReader(VEEARRAY_XRMODEL));
xrService = factory.buildService(model);
if (ddlCreate) {
try {
AllTests.runDdl(CREATE_DDL, ddlDebug);
} catch (Exception e) {
// e.printStackTrace();
}
}
}
use of org.eclipse.persistence.platform.database.oracle.Oracle10Platform in project eclipselink by eclipse-ee4j.
the class NonJDBCTestHelper method buildTestProject.
public static Project buildTestProject(Properties p) {
String username = p.getProperty(DATABASE_USERNAME_KEY);
if (username == null) {
fail("error retrieving database username");
}
String password = p.getProperty(DATABASE_PASSWORD_KEY);
if (password == null) {
fail("error retrieving database password");
}
String url = p.getProperty(DATABASE_URL_KEY);
if (url == null) {
fail("error retrieving database url");
}
String driver = p.getProperty(DATABASE_DRIVER_KEY);
if (driver == null) {
fail("error retrieving database driver");
}
Project project = new Project();
project.setName("nonJDBCTestProject");
RelationalDescriptor emptyDescriptor = new RelationalDescriptor();
emptyDescriptor.setAlias("Empty");
emptyDescriptor.setJavaClass(Empty.class);
emptyDescriptor.addTableName("EMPTY");
emptyDescriptor.addPrimaryKeyFieldName("EMPTY.ID");
DirectToFieldMapping idMapping = new DirectToFieldMapping();
idMapping.setAttributeName("id");
idMapping.setFieldName("EMPTY.ID");
emptyDescriptor.addMapping(idMapping);
project.addDescriptor(emptyDescriptor);
DatabaseLogin login = new DatabaseLogin();
login.setUserName(username);
login.setPassword(password);
login.setConnectionString(url);
login.setDriverClassName(driver);
login.setDatasourcePlatform(new Oracle10Platform());
login.useBatchWriting();
project.setDatasourceLogin(login);
return project;
}
use of org.eclipse.persistence.platform.database.oracle.Oracle10Platform in project eclipselink by eclipse-ee4j.
the class PLSQLrecordTestHelper method buildTestProject.
public static Project buildTestProject(Properties p) {
String username = p.getProperty(DATABASE_USERNAME_KEY);
if (username == null) {
fail("error retrieving database username");
}
String password = p.getProperty(DATABASE_PASSWORD_KEY);
if (password == null) {
fail("error retrieving database password");
}
String url = p.getProperty(DATABASE_URL_KEY);
if (url == null) {
fail("error retrieving database url");
}
String driver = p.getProperty(DATABASE_DRIVER_KEY);
if (driver == null) {
fail("error retrieving database driver");
}
Project project = new Project();
project.setName("PLSQLrecordProject");
ObjectRelationalDataTypeDescriptor plsqlempORDescriptor = new ObjectRelationalDataTypeDescriptor();
plsqlempORDescriptor.setJavaClass(PLSQLEmployeeType.class);
plsqlempORDescriptor.setTableName("EMP");
plsqlempORDescriptor.setStructureName("EMP_TYPE");
plsqlempORDescriptor.addPrimaryKeyFieldName("EMPNO");
plsqlempORDescriptor.addFieldOrdering("EMPNO");
DirectToFieldMapping employeeNumberMapping = new DirectToFieldMapping();
employeeNumberMapping.setAttributeName("employeeNumber");
employeeNumberMapping.setFieldName("EMPNO");
employeeNumberMapping.setAttributeClassification(BigDecimal.class);
plsqlempORDescriptor.addMapping(employeeNumberMapping);
plsqlempORDescriptor.addFieldOrdering("ENAME");
DirectToFieldMapping nameMapping = new DirectToFieldMapping();
nameMapping.setAttributeName("name");
nameMapping.setFieldName("ENAME");
plsqlempORDescriptor.addMapping(nameMapping);
plsqlempORDescriptor.addFieldOrdering("JOB");
DirectToFieldMapping jobMapping = new DirectToFieldMapping();
jobMapping.setAttributeName("job");
jobMapping.setFieldName("JOB");
plsqlempORDescriptor.addMapping(jobMapping);
plsqlempORDescriptor.addFieldOrdering("MGR");
DirectToFieldMapping managerMapping = new DirectToFieldMapping();
managerMapping.setAttributeName("manager");
managerMapping.setFieldName("MGR");
managerMapping.setAttributeClassification(BigDecimal.class);
plsqlempORDescriptor.addMapping(managerMapping);
plsqlempORDescriptor.addFieldOrdering("HIREDATE");
DirectToFieldMapping hireDateMapping = new DirectToFieldMapping();
hireDateMapping.setAttributeName("hireDate");
hireDateMapping.setFieldName("HIREDATE");
plsqlempORDescriptor.addMapping(hireDateMapping);
plsqlempORDescriptor.addFieldOrdering("SAL");
DirectToFieldMapping salaryMapping = new DirectToFieldMapping();
salaryMapping.setAttributeName("salary");
salaryMapping.setFieldName("SAL");
salaryMapping.setAttributeClassification(Float.class);
plsqlempORDescriptor.addMapping(salaryMapping);
plsqlempORDescriptor.addFieldOrdering("COMM");
DirectToFieldMapping commissionMapping = new DirectToFieldMapping();
commissionMapping.setAttributeName("commission");
commissionMapping.setFieldName("COMM");
commissionMapping.setAttributeClassification(Float.class);
plsqlempORDescriptor.addMapping(commissionMapping);
plsqlempORDescriptor.addFieldOrdering("DEPTNO");
DirectToFieldMapping departmentMapping = new DirectToFieldMapping();
departmentMapping.setAttributeName("department");
departmentMapping.setFieldName("DEPTNO");
departmentMapping.setAttributeClassification(BigDecimal.class);
plsqlempORDescriptor.addMapping(departmentMapping);
project.addDescriptor(plsqlempORDescriptor);
DatabaseLogin login = new DatabaseLogin();
login.setUserName(username);
login.setPassword(password);
login.setConnectionString(url);
login.setDriverClassName(driver);
login.setDatasourcePlatform(new Oracle10Platform());
project.setDatasourceLogin(login);
return project;
}
use of org.eclipse.persistence.platform.database.oracle.Oracle10Platform in project eclipselink by eclipse-ee4j.
the class PLSQLcollectionTestSuite method fromProjectXML.
@Test
public void fromProjectXML() {
XRDynamicClassLoader xrdecl = new XRDynamicClassLoader(PLSQLcollectionTestSuite.class.getClassLoader());
Project projectFromXML = XMLProjectReader.read(new StringReader(TEST_PROJECT_CONTROL_DOC), xrdecl);
DatabaseLogin login = new DatabaseLogin();
login.setUserName(username);
login.setPassword(password);
login.setConnectionString(url);
login.setDriverClassName("oracle.jdbc.OracleDriver");
Platform platform = new Oracle10Platform();
ConversionManager cm = platform.getConversionManager();
cm.setLoader(xrdecl);
login.setDatasourcePlatform(platform);
login.bindAllParameters();
projectFromXML.setDatasourceLogin(login);
ProjectHelper.fixOROXAccessors(projectFromXML, null);
xrdecl.dontGenerateSubclasses();
ClassDescriptor t1Descriptor = projectFromXML.getDescriptorForAlias("T1");
DatabaseQuery query = t1Descriptor.getQueryManager().getQuery(QUERY_NAME);
assertTrue(QUERY_NAME + " is wrong type of query: " + query.getClass().getSimpleName(), query.isDataModifyQuery());
session = projectFromXML.createDatabaseSession();
session.dontLogMessages();
t1Descriptor = session.getDescriptorForAlias("T1");
Class<?> t1Clz = t1Descriptor.getJavaClass();
((DatabaseSession) session).login();
String[] elements = { "first string", "second string", "third string" };
NonSynchronizedVector<Object> queryArgs = new NonSynchronizedVector<>();
queryArgs.add(elements);
queryArgs.add("barf");
boolean worked = false;
String msg = null;
try {
session.executeQuery(QUERY_NAME, t1Clz, queryArgs);
worked = true;
} catch (Exception e) {
msg = e.getMessage();
}
assertTrue("invocation somePackage.p1 failed: " + msg, worked);
}
Aggregations