/** * PUBLIC: * Create and return a new session. * By giving the login information on creation this allows the session to initialize itself * to the platform given in the login. This constructor does not return a connected session. * To connect the session to the database login() must be sent to it. The login(userName, password) * method may also be used to connect the session, this allows for the user name and password * to be given at login but for the other database information to be provided when the session is created. */ public AbstractSession(Login login) { this(new org.eclipse.persistence.sessions.Project(login)); }
public void addDescriptorToProject(Project project) { Iterator<XMLDescriptor> it = descriptorsMap.values().iterator(); while (it.hasNext()) { project.addDescriptor(it.next()); } }
/** * PUBLIC: * Return the descriptor specified for the class. * If the passed Class parameter is null, null will be returned. */ public ClassDescriptor getClassDescriptor(Class theClass) { return getDescriptor(theClass); }
/** * INTERNAL: * Return the correct session type from the sessionConfig */ protected void prepareProjectLogin(Project project, Login login) { if (login != null) { project.setLogin(login); } else if (project.getDatasourceLogin() == null) { // dummy login that needs to be set, otherwise session creation will fail project.setLogin(new DatabaseLogin()); } else { // we read a login from the deployment xml of java, don't overwrite } }
/** * PUBLIC: * Add the descriptor to the project. */ public void addDescriptor(ClassDescriptor descriptor) { getOrderedDescriptors().add(descriptor); String alias = descriptor.getAlias(); if (alias != null) { addAlias(alias, descriptor); } // Avoid loading class definition at this point if we haven't done so yet. if ((descriptors != null) && !descriptors.isEmpty()) { getDescriptors().put(descriptor.getJavaClass(), descriptor); } }
/** * INTERNAL: Used by the BuilderInterface when reading a Project from INI files. * @param descriptor The descriptor to be added to the session and the project. * @param session The current database session. */ public void addDescriptor(final ClassDescriptor descriptor, final DatabaseSessionImpl session) { synchronized (this.descriptorsLock) { if (session.isConnected()) { final String alias = descriptor.getAlias(); // Descriptor aliases may be concurrently accessed by other threads. // Make a clone, add new descriptor to the clone, override original with the clone. if (alias != null) { final Map aliasDescriptorsClone = getAliasDescriptors() != null ? (Map)((HashMap)getAliasDescriptors()).clone() : new HashMap(); aliasDescriptorsClone.put(alias, descriptor); setAliasDescriptors(aliasDescriptorsClone); } // Descriptors may be concurrently accessed by other threads. // Make a clone, add new descriptor to the clone, override original with the clone. final Map<Class, ClassDescriptor> descriptorsClone = (Map)((HashMap)getDescriptors()).clone(); descriptorsClone.put(descriptor.getJavaClass(), descriptor); setDescriptors(descriptorsClone); session.copyDescriptorsFromProject(); session.initializeDescriptorIfSessionAlive(descriptor); getOrderedDescriptors().add(descriptor); } else { addDescriptor(descriptor); } } }
final Map aliasDescriptorsClone = getAliasDescriptors() != null ? (Map)((HashMap)getAliasDescriptors()).clone() : new HashMap(); final Map<Class, ClassDescriptor> descriptorsClone = (Map)((HashMap)getDescriptors()).clone(); for (ClassDescriptor descriptor : (Collection<ClassDescriptor>) descriptors) { descriptorsClone.put(descriptor.getJavaClass(), descriptor); setAliasDescriptors(aliasDescriptorsClone); setDescriptors(descriptorsClone); session.copyDescriptorsFromProject(); session.initializeDescriptors(descriptors); } else { final Map<Class, ClassDescriptor> projectDescriptors = getDescriptors(); for (ClassDescriptor descriptor : (Collection<ClassDescriptor>) descriptors) { final String alias = descriptor.getAlias(); projectDescriptors.put(descriptor.getJavaClass(), descriptor); if (alias != null) { addAlias(alias, descriptor); getOrderedDescriptors().addAll(descriptors);
public Project getTopLinkProject() { if (topLinkProject == null) { topLinkProject = new Project(); XMLLogin xmlLogin = new XMLLogin(); xmlLogin.setEqualNamespaceResolvers(false); topLinkProject.setDatasourceLogin(xmlLogin); SDOType changeSummaryType = (SDOType) sdoTypeHelper.getType(SDOConstants.SDO_URL, SDOConstants.CHANGESUMMARY); changeSummaryType.getXmlDescriptor().setNamespaceResolver(nr); topLinkProject.addDescriptor(changeSummaryType.getXmlDescriptor()); SDOType openSequencedType = (SDOType) aHelperContext.getTypeHelper().getType(SDOConstants.ORACLE_SDO_URL, "OpenSequencedType"); topLinkProject.addDescriptor(openSequencedType.getXmlDescriptor()); SDOTypeType typeType = (SDOTypeType)aHelperContext.getTypeHelper().getType(SDOConstants.SDO_URL, SDOConstants.TYPE); typeType.getXmlDescriptor().setNamespaceResolver(nr); typeType.initializeMappings(); topLinkProject.addDescriptor(typeType.getXmlDescriptor()); SDOPropertyType propertyType = (SDOPropertyType)aHelperContext.getTypeHelper().getType(SDOConstants.SDO_URL, SDOConstants.PROPERTY); if(!propertyType.isInitialized()) { propertyType.initializeMappings(); topLinkProject.addDescriptor(propertyType.getXmlDescriptor());
/** * INTERNAL: */ protected static XMLContext createXMLContext(String namespaceURI) { Project project = new Project(); NamespaceResolver resolver = new NamespaceResolver(); resolver.setDefaultNamespaceURI(namespaceURI); project.addDescriptor(buildPersistenceXMLDescriptor(resolver)); project.addDescriptor(buildPUInfoDescriptor(resolver)); project.addDescriptor(buildPUPropertyDescriptor(resolver)); return new XMLContext(project); } }
public static Project loadDynamicProject(Project project, DatabaseLogin login, DynamicClassLoader dynamicClassLoader) { if (project != null) { if (login == null) { if (project.getLogin() == null) { project.setLogin(new DatabaseLogin()); } } else { project.setLogin(login); } if (project.getLogin().getPlatform() == null) { project.getLogin().setPlatform(new DatabasePlatform()); } project.getLogin().getPlatform().getConversionManager().setLoader(dynamicClassLoader); for (Iterator<?> i = project.getAliasDescriptors().values().iterator(); i.hasNext();) { ClassDescriptor descriptor = (ClassDescriptor) i.next(); if (descriptor.getJavaClass() == null) { createType(dynamicClassLoader, descriptor, project); } } project.convertClassNamesToClasses(dynamicClassLoader); } return project; }
/** * Read a project in the format of an ObjectPersistenceRuntimeXMLProject. * This could include a TopLink 11.1.1 project or a TopLink 10.1.3 project * @param document * @param classLoader * @param opmProject * @return */ public static Project readObjectPersistenceRuntimeFormat(Document document, ClassLoader classLoader, Project opmProject){ XMLLogin xmlLogin = new XMLLogin(); xmlLogin.setDatasourcePlatform(new org.eclipse.persistence.oxm.platform.DOMPlatform()); opmProject.setDatasourceLogin(xmlLogin); // Create the OPM project. if (classLoader != null) { xmlLogin.getDatasourcePlatform().getConversionManager().setLoader(classLoader); } // Marshal OPM format. XMLContext context = new XMLContext(opmProject); context.getSession(Project.class).getEventManager().addListener(new MissingDescriptorListener()); XMLUnmarshaller unmarshaller = context.createUnmarshaller(); Project project = (Project)unmarshaller.unmarshal(document); // Set the project's class loader. if ((classLoader != null) && (project.getDatasourceLogin() != null)) { project.getDatasourceLogin().getDatasourcePlatform().getConversionManager().setLoader(classLoader); } return project; }
import org.eclipse.persistence.descriptors.ClassDescriptor; import org.eclipse.persistence.mappings.DatabaseMapping; import org.eclipse.persistence.oxm.mappings.XMLDirectMapping; import org.eclipse.persistence.oxm.mappings.nullpolicy.XMLNullRepresentationType; import org.eclipse.persistence.sessions.*; public class NullPolicySessionEventListener extends SessionEventAdapter { @Override public void preLogin(SessionEvent event) { Project project = event.getSession().getProject(); for(ClassDescriptor descriptor : project.getOrderedDescriptors()) { for(DatabaseMapping mapping : descriptor.getMappings()) { if(mapping.isAbstractDirectMapping()) { XMLDirectMapping xmlDirectMapping = (XMLDirectMapping) mapping; xmlDirectMapping.getNullPolicy().setMarshalNullRepresentation(XMLNullRepresentationType.EMPTY_NODE); xmlDirectMapping.getNullPolicy().setNullRepresentedByEmptyNode(true); } } } } }
for (int i = 0; i < namespaces.size(); i++) { Namespace next = (Namespace)namespaces.get(i); ((XMLDescriptor)p.getDescriptor(Schema.class)).getNamespaceResolver().put(next.getPrefix(), next.getNamespaceURI()); p.setDatasourceLogin(login); XMLContext context = new XMLContext(p); XMLMarshaller marshaller = context.createMarshaller();
/** * PUBLIC: * Add the descriptor to the session. * All persistent classes must have a descriptor registered for them with the session. * It is best to add the descriptors before login, if added after login the order in which * descriptors are added is dependent on inheritance and references unless the addDescriptors * method is used. * * @see #addDescriptors(Vector) * @see #addDescriptors(org.eclipse.persistence.sessions.Project) */ @Override public void addDescriptor(final ClassDescriptor descriptor) { // Reset cached data, as may be invalid later on. this.lastDescriptorAccessed = null; // Bug# 429760: Add descriptor to the session when session Map exists and is not the same as in the project. if (this.descriptors != null && this.descriptors != getProject().getDescriptors()) { this.descriptors.put(descriptor.getJavaClass(), descriptor); } getProject().addDescriptor(descriptor, this); }
/** * PUBLIC: * Set all this project's descriptors to conform all read queries within the context of the unit of work. */ public void conformAllDescriptors() { Iterator descriptors = getDescriptors().values().iterator(); while (descriptors.hasNext()) { ClassDescriptor descriptor = (ClassDescriptor)descriptors.next(); descriptor.setShouldAlwaysConformResultsInUnitOfWork(true); } }
@Override public void validate(XRServiceAdapter xrService) { super.validate(xrService); if (descriptorName == null) { throw DBWSException.couldNotLocateDescriptorForOperation(descriptorName, getName()); } if (!xrService.getORSession().getProject().getAliasDescriptors().containsKey(descriptorName)) { throw DBWSException.couldNotLocateDescriptorForOperation(descriptorName, getName()); } classDescriptor = xrService.getORSession().getProject().getDescriptorForAlias(descriptorName); }
/** * PUBLIC: * Return the descriptor for the alias. * UnitOfWork delegates this to the parent */ @Override public ClassDescriptor getClassDescriptorForAlias(String alias) { return project.getDescriptorForAlias(alias); }
/** * PUBLIC: * Add an alias for the descriptor */ public void addAlias(String alias, ClassDescriptor descriptor) { project.addAlias(alias, descriptor); }
/** * PUBLIC: * Return the login, the login holds any database connection information given. * This return the Login interface and may need to be cast to the datasource specific implementation. */ @Override public Login getDatasourceLogin() { if (this.project == null) { return null; } return this.project.getDatasourceLogin(); }
/** * INTERNAL: */ public void addAlias(String alias, MetadataDescriptor descriptor) { ClassDescriptor existingDescriptor = m_session.getProject().getDescriptorForAlias(alias); if (existingDescriptor == null) { descriptor.setAlias(alias); m_session.getProject().addAlias(alias, descriptor.getClassDescriptor()); } else { throw ValidationException.nonUniqueEntityName(existingDescriptor.getJavaClassName(), descriptor.getJavaClassName(), alias); } }