use of org.eclipse.persistence.internal.sessions.factories.EclipseLinkObjectPersistenceRuntimeXMLProject in project eclipselink by eclipse-ee4j.
the class XMLProjectReader method read.
/**
* PUBLIC:
* Read the EclipseLink project deployment XML from the reader on the file.
* Note the class loader must be able to resolve the domain classes.
* Note the file must be the deployment XML, not the Mapping Workbench project file.
* This API supports 10g (10.0.3), 11g (11.1.1) formats.
*/
public static Project read(Reader reader, ClassLoader classLoader) {
// Since a reader is pass and it can only be streamed once (mark does not work)
// It must be first read into a buffer so multiple readers can be used to
// determine the format. This does not effect performance severely.
StringWriter writer;
Document document;
try {
writer = new StringWriter(4096);
char[] c = new char[4096];
int r = 0;
while ((r = reader.read(c)) != -1) {
writer.write(c, 0, r);
}
String schema = null;
if (shouldUseSchemaValidation()) {
schema = SCHEMA_DIR + ECLIPSELINK_SCHEMA;
}
// Assume the format is OPM parse the document with OPM validation on.
XMLPlatform xmlPlatform = XMLPlatformFactory.getInstance().getXMLPlatform();
XMLParser parser = createXMLParser(xmlPlatform, true, false, schema);
try {
document = parser.parse(new StringReader(writer.toString()));
} catch (Exception parseException) {
// If the parse fails, it may be because the format was EclipseLink 1.0
try {
if (shouldUseSchemaValidation()) {
schema = SCHEMA_DIR + ECLIPSELINK_1_0_SCHEMA;
}
parser = createXMLParser(xmlPlatform, true, false, schema);
document = parser.parse(new StringReader(writer.toString()));
} catch (Exception parseException2) {
// If the parse fails, it may be because the format was 11.1.1
try {
if (shouldUseSchemaValidation()) {
schema = SCHEMA_DIR + TOPLINK_11_SCHEMA;
}
parser = createXMLParser(xmlPlatform, true, false, schema);
document = parser.parse(new StringReader(writer.toString()));
} catch (Exception parseException3) {
// not support in eclipselink, just not valid, through original exception.
throw parseException;
}
String version = document.getDocumentElement().getAttribute("version");
// If 10.1.3 format use old format read.
if ((version == null) || (version.indexOf("1.0") == -1)) {
throw parseException;
}
}
}
} catch (Exception exception) {
throw XMLMarshalException.unmarshalException(exception);
}
String version = document.getDocumentElement().getAttribute("version");
// If 10.1.3 format use old format read.
if (version != null) {
if (version.indexOf("10.1.3") != -1) {
return read1013Format(document, classLoader);
} else if (version.indexOf("11.1.1") != -1) {
return read1111Format(document, classLoader);
}
if (version.indexOf("TopLink") != -1) {
// default to read 11.1.1
return read1111Format(document, classLoader);
}
}
if (project == null) {
project = new EclipseLinkObjectPersistenceRuntimeXMLProject();
}
// bug261072: clone the project since readObjectPersistenceRuntimeFormat will change its datasourceLogin and Classloader
return readObjectPersistenceRuntimeFormat(document, classLoader, project.clone());
}
use of org.eclipse.persistence.internal.sessions.factories.EclipseLinkObjectPersistenceRuntimeXMLProject in project eclipselink by eclipse-ee4j.
the class XRSessionsFactory method loadProjectConfig.
@Override
protected Project loadProjectConfig(ProjectConfig projectConfig) {
Project project = null;
String projectString = projectConfig.getProjectString();
if (projectConfig.isProjectClassConfig()) {
try {
if (PrivilegedAccessHelper.shouldUsePrivilegedAccess()) {
project = (Project) AccessController.doPrivileged(new PrivilegedNewInstanceFromClass<>(m_classLoader.loadClass(projectString)));
} else {
project = (Project) PrivilegedAccessHelper.newInstanceFromClass(m_classLoader.loadClass(projectString));
}
} catch (Throwable exception) {
throw SessionLoaderException.failedToLoadProjectClass(projectString, exception);
}
} else {
try {
URL url = null;
Matcher matcher = matchDBWSOrProject.matcher(projectString);
if (matcher.find()) {
// need to try a variety of URLs to find DBWS OR/OX Project
String orXml = matcher.group();
for (String prefix : META_INF_PATHS) {
String searchPath = prefix + orXml;
url = m_classLoader.getResource(searchPath);
if (url != null) {
break;
}
}
} else {
matcher = matchDBWSOxProject.matcher(projectString);
if (matcher.find()) {
String oxXml = matcher.group();
for (String prefix : META_INF_PATHS) {
String searchPath = prefix + oxXml;
url = m_classLoader.getResource(searchPath);
if (url != null) {
break;
}
}
}
}
if (url != null) {
Project p = new EclipseLinkObjectPersistenceRuntimeXMLProject();
XMLLogin xmlLogin = new XMLLogin();
xmlLogin.setDatasourcePlatform(new DOMPlatform());
p.setDatasourceLogin(xmlLogin);
if (m_classLoader != null) {
p.getDatasourceLogin().getDatasourcePlatform().getConversionManager().setLoader(m_classLoader);
}
XMLPlatform xmlPlatform = XMLPlatformFactory.getInstance().getXMLPlatform();
XMLParser parser = xmlPlatform.newXMLParser();
parser.setNamespaceAware(true);
parser.setWhitespacePreserving(false);
XMLContext context = new XMLContext(p);
context.getSession(Project.class).getEventManager().addListener(new MissingDescriptorListener());
XMLUnmarshaller unmarshaller = context.createUnmarshaller();
project = (Project) unmarshaller.unmarshal(url);
}
} catch (ValidationException validationException) {
if (validationException.getErrorCode() == ValidationException.PROJECT_XML_NOT_FOUND) {
throw SessionLoaderException.failedToLoadProjectXml(projectString, validationException);
} else {
throw SessionLoaderException.failedToParseXML(projectString, validationException);
}
}
}
return project;
}
use of org.eclipse.persistence.internal.sessions.factories.EclipseLinkObjectPersistenceRuntimeXMLProject in project eclipselink by eclipse-ee4j.
the class KeyMappingsTestSuite 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;
}
final String username = System.getProperty(DATABASE_USERNAME_KEY);
if (username == null) {
fail("error retrieving database username");
}
final String password = System.getProperty(DATABASE_PASSWORD_KEY);
if (password == null) {
fail("error retrieving database password");
}
final String url = System.getProperty(DATABASE_URL_KEY);
if (url == null) {
fail("error retrieving database url");
}
final String driver = System.getProperty(DATABASE_DRIVER_KEY);
if (driver == null) {
fail("error retrieving database driver");
}
XRServiceFactory factory = new XRServiceFactory() {
@Override
public XRServiceAdapter buildService(XRServiceModel xrServiceModel) {
parentClassLoader = this.getClass().getClassLoader();
xrSchemaStream = new ByteArrayInputStream(KEYMAPPINGS_SCHEMA.getBytes());
return super.buildService(xrServiceModel);
}
@Override
public void buildSessions() {
XRDynamicClassLoader xrdecl = new XRDynamicClassLoader(parentClassLoader);
XMLContext context = new XMLContext(new EclipseLinkObjectPersistenceRuntimeXMLProject(), xrdecl);
XMLUnmarshaller unmarshaller = context.createUnmarshaller();
Project orProject = (Project) unmarshaller.unmarshal(new StringReader(KEYMAPPINGS_OR_PROJECT));
DatasourceLogin login = new DatabaseLogin();
login.setUserName(username);
login.setPassword(password);
((DatabaseLogin) login).setConnectionString(url);
((DatabaseLogin) login).setDriverClassName(driver);
Platform platform = new MySQLPlatform();
ConversionManager conversionManager = platform.getConversionManager();
if (conversionManager != null) {
conversionManager.setLoader(xrdecl);
}
login.setDatasourcePlatform(platform);
((DatabaseLogin) login).bindAllParameters();
orProject.setDatasourceLogin(login);
Project oxProject = (Project) unmarshaller.unmarshal(new StringReader(KEYMAPPINGS_OX_PROJECT));
login = (DatasourceLogin) oxProject.getDatasourceLogin();
if (login != null) {
platform = login.getDatasourcePlatform();
if (platform != null) {
conversionManager = platform.getConversionManager();
if (conversionManager != null) {
conversionManager.setLoader(xrdecl);
}
}
}
ProjectHelper.fixOROXAccessors(orProject, oxProject);
xrService.setORSession(orProject.createDatabaseSession());
xrService.getORSession().dontLogMessages();
xrService.setXMLContext(new XMLContext(oxProject));
xrService.setOXSession(xrService.getXMLContext().getSession(0));
}
};
XMLContext context = new XMLContext(new DBWSModelProject());
XMLUnmarshaller unmarshaller = context.createUnmarshaller();
DBWSModel model = (DBWSModel) unmarshaller.unmarshal(new StringReader(KEYMAPPINGS_DBWS));
xrService = factory.buildService(model);
if (ddlCreate) {
try {
AllTests.runDdl(CREATE_DDL, ddlDebug);
} catch (Exception e) {
// e.printStackTrace();
}
}
}
use of org.eclipse.persistence.internal.sessions.factories.EclipseLinkObjectPersistenceRuntimeXMLProject in project eclipselink by eclipse-ee4j.
the class RelationshipsTestSuite 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;
}
final String username = System.getProperty(DATABASE_USERNAME_KEY);
if (username == null) {
fail("error retrieving database username");
}
final String password = System.getProperty(DATABASE_PASSWORD_KEY);
if (password == null) {
fail("error retrieving database password");
}
final String url = System.getProperty(DATABASE_URL_KEY);
if (url == null) {
fail("error retrieving database url");
}
final String driver = System.getProperty(DATABASE_DRIVER_KEY);
if (driver == null) {
fail("error retrieving database driver");
}
XRServiceFactory factory = new XRServiceFactory() {
@Override
public XRServiceAdapter buildService(XRServiceModel xrServiceModel) {
parentClassLoader = this.getClass().getClassLoader();
xrSchemaStream = new ByteArrayInputStream(RELATIONSHIPS_SCHEMA.getBytes());
return super.buildService(xrServiceModel);
}
@Override
public void buildSessions() {
XMLContext context = new XMLContext(new EclipseLinkObjectPersistenceRuntimeXMLProject());
XMLUnmarshaller unmarshaller = context.createUnmarshaller();
Project orProject = (Project) unmarshaller.unmarshal(new StringReader(RELATIONSHIPS_OR_PROJECT));
DatabaseLogin login = new DatabaseLogin();
login.setUserName(username);
login.setPassword(password);
login.setConnectionString(url);
login.setDriverClassName(driver);
Platform platform = new MySQLPlatform();
login.setDatasourcePlatform(platform);
login.bindAllParameters();
orProject.setDatasourceLogin(login);
Project oxProject = (Project) unmarshaller.unmarshal(new StringReader(RELATIONSHIPS_OX_PROJECT));
ProjectHelper.fixOROXAccessors(orProject, oxProject);
xrService.setORSession(orProject.createDatabaseSession());
xrService.getORSession().dontLogMessages();
xrService.setXMLContext(new XMLContext(oxProject));
xrService.setOXSession(xrService.getXMLContext().getSession(0));
}
};
XMLContext context = new XMLContext(new DBWSModelProject());
XMLUnmarshaller unmarshaller = context.createUnmarshaller();
DBWSModel model = (DBWSModel) unmarshaller.unmarshal(new StringReader(RELATIONSHIPS_DBWS));
xrService = factory.buildService(model);
if (ddlCreate) {
try {
AllTests.runDdl(CREATE_DDL, ddlDebug);
} catch (Exception e) {
// e.printStackTrace();
}
}
}
Aggregations