descriptor.getInheritancePolicy().setClassIndicatorField(new XMLField("@xsi:type"));
descriptor.getInheritancePolicy().addClassIndicator(DatabaseLogin.class, getPrimaryNamespaceXPath() + "database-login");
descriptor.getInheritancePolicy().addClassIndicator(EISLogin.class, getPrimaryNamespaceXPath() + "eis-login");
descriptor.getInheritancePolicy().addClassIndicator(XMLLogin.class, getPrimaryNamespaceXPath() + "xml-login");
XMLDirectMapping platformMapping = new XMLDirectMapping();
platformMapping.setAttributeName("platform");
platformMapping.setGetMethodName("getDatasourcePlatform");
platformMapping.setSetMethodName("usePlatform");
platformMapping.setConverter(new Converter() {
protected DatabaseMapping mapping;
private Map platformList;
private String oldPrefix = "oracle.toplink.";
private String newPrefix = "org.eclipse.persistence.";
public Object convertObjectValueToDataValue(Object objectValue, Session session) {
if (objectValue == null) {
return null;
}
return objectValue.getClass().getName();
}
public Object convertDataValueToObjectValue(Object fieldValue, Session session) {
if(fieldValue == null) {
return null;
}
if(((String)fieldValue).startsWith(oldPrefix)) {
fieldValue = ((String)fieldValue).replaceFirst(oldPrefix, newPrefix);
}
// convert deprecated platforms to new platforms
Object result = platformList.get(fieldValue);
if (result != null) {
fieldValue = result;
}
Object attributeValue;
Class attributeClass = (Class)((AbstractSession)session).getDatasourcePlatform().convertObject(fieldValue, ClassConstants.CLASS);
try {
if (PrivilegedAccessHelper.shouldUsePrivilegedAccess()) {
try {
attributeValue = AccessController.doPrivileged(new PrivilegedNewInstanceFromClass(attributeClass));
}
catch (PrivilegedActionException exception) {
throw ConversionException.couldNotBeConverted(fieldValue, attributeClass, exception.getException());
}
}
else {
attributeValue = PrivilegedAccessHelper.newInstanceFromClass(attributeClass);
}
}
catch (Exception exception) {
throw ConversionException.couldNotBeConverted(fieldValue, attributeClass, exception);
}
return attributeValue;
}
public boolean isMutable() {
return false;
}
public void initialize(DatabaseMapping mapping, Session session) {
this.platformList = new HashMap();
this.platformList.put("org.eclipse.persistence.internal.databaseaccess.AccessPlatform", "org.eclipse.persistence.platform.database.AccessPlatform");
this.platformList.put("org.eclipse.persistence.internal.databaseaccess.AttunityPlatform", "org.eclipse.persistence.platform.database.AttunityPlatform");
this.platformList.put("org.eclipse.persistence.internal.databaseaccess.CloudscapePlatform", "org.eclipse.persistence.platform.database.CloudscapePlatform");
this.platformList.put("org.eclipse.persistence.internal.databaseaccess.DatabasePlatform", "org.eclipse.persistence.platform.database.DatabasePlatform");
this.platformList.put("org.eclipse.persistence.internal.databaseaccess.DB2MainframePlatform", "org.eclipse.persistence.platform.database.DB2MainframePlatform");
this.platformList.put("org.eclipse.persistence.internal.databaseaccess.DB2Platform", "org.eclipse.persistence.platform.database.DB2Platform");
this.platformList.put("org.eclipse.persistence.internal.databaseaccess.DBasePlatform", "org.eclipse.persistence.platform.database.DBasePlatform");
this.platformList.put("org.eclipse.persistence.internal.databaseaccess.HSQLPlatform", "org.eclipse.persistence.platform.database.HSQLPlatform");
this.platformList.put("org.eclipse.persistence.internal.databaseaccess.InformixPlatform", "org.eclipse.persistence.platform.database.InformixPlatform");
this.platformList.put("org.eclipse.persistence.internal.databaseaccess.OraclePlatform", "org.eclipse.persistence.platform.database.OraclePlatform");
this.platformList.put("org.eclipse.persistence.internal.databaseaccess.PointBasePlatform", "org.eclipse.persistence.platform.database.PointBasePlatform");
this.platformList.put("org.eclipse.persistence.internal.databaseaccess.SQLAnyWherePlatform", "org.eclipse.persistence.platform.database.SQLAnywherePlatform");
this.platformList.put("org.eclipse.persistence.internal.databaseaccess.SQLServerPlatform", "org.eclipse.persistence.platform.database.SQLServerPlatform");
this.platformList.put("org.eclipse.persistence.internal.databaseaccess.SybasePlatform", "org.eclipse.persistence.platform.database.SybasePlatform");
this.platformList.put("org.eclipse.persistence.oraclespecific.Oracle8Platform", "org.eclipse.persistence.platform.database.oracle.Oracle8Platform");
this.platformList.put("org.eclipse.persistence.oraclespecific.Oracle9Platform", "org.eclipse.persistence.platform.database.oracle.Oracle9Platform");
this.platformList.put("org.eclipse.persistence.platform.database.SQLAnyWherePlatform", "org.eclipse.persistence.platform.database.SQLAnywherePlatform");
this.mapping = mapping;
// CR#... Mapping must also have the field classification.
if (this.mapping.isDirectToFieldMapping()) {
AbstractDirectMapping directMapping = (AbstractDirectMapping)this.mapping;
// Allow user to specify field type to override computed value. (i.e. blob, nchar)
if (directMapping.getFieldClassification() == null) {
directMapping.setFieldClassification(ClassConstants.STRING);
}
}
}
});
platformMapping.setXPath(getPrimaryNamespaceXPath() + "platform-class/text()");
descriptor.addMapping(platformMapping);
XMLDirectMapping userNameMapping = new XMLDirectMapping();
userNameMapping.setAttributeName("userName");
userNameMapping.setGetMethodName("getUserName");
userNameMapping.setSetMethodName("setUserName");
userNameMapping.setXPath(getPrimaryNamespaceXPath() + "user-name/text()");
descriptor.addMapping(userNameMapping);
XMLDirectMapping passwordMapping = new XMLDirectMapping();
passwordMapping.setAttributeName("password");
passwordMapping.setGetMethodName("getPassword");
passwordMapping.setSetMethodName("setEncryptedPassword");
passwordMapping.setXPath(getPrimaryNamespaceXPath() + "password/text()");
descriptor.addMapping(passwordMapping);
XMLDirectMapping usesExternalConnectionPoolingMapping = new XMLDirectMapping();
usesExternalConnectionPoolingMapping.setAttributeName("usesExternalConnectionPooling");
usesExternalConnectionPoolingMapping.setGetMethodName("shouldUseExternalConnectionPooling");
usesExternalConnectionPoolingMapping.setSetMethodName("setUsesExternalConnectionPooling");
usesExternalConnectionPoolingMapping.setXPath(getPrimaryNamespaceXPath() + "external-connection-pooling/text()");
usesExternalConnectionPoolingMapping.setNullValue(Boolean.FALSE);
descriptor.addMapping(usesExternalConnectionPoolingMapping);
XMLDirectMapping usesExternalTransactionControllerMapping = new XMLDirectMapping();
usesExternalTransactionControllerMapping.setAttributeName("usesExternalTransactionController");
usesExternalTransactionControllerMapping.setGetMethodName("shouldUseExternalTransactionController");
usesExternalTransactionControllerMapping.setSetMethodName("setUsesExternalTransactionController");
usesExternalTransactionControllerMapping.setXPath(getPrimaryNamespaceXPath() + "external-transaction-controller/text()");
usesExternalTransactionControllerMapping.setNullValue(Boolean.FALSE);
descriptor.addMapping(usesExternalTransactionControllerMapping);
XMLCompositeObjectMapping defaultSequenceMapping = new XMLCompositeObjectMapping();
defaultSequenceMapping.setAttributeName("defaultSequence");
defaultSequenceMapping.setSetMethodName("setDefaultSequence");