use of org.eclipse.persistence.sessions.remote.RemoteSession in project eclipselink by eclipse-ee4j.
the class EntityManagerSetupImpl method updateRemote.
/**
* Checks for partitioning properties.
*/
protected void updateRemote(Map m, ClassLoader loader) {
String protocol = getConfigPropertyAsStringLogDebug(PersistenceUnitProperties.REMOTE_PROTOCOL, m, this.session);
String serverName = getConfigPropertyAsStringLogDebug(PersistenceUnitProperties.REMOTE_SERVER_NAME, m, this.session);
if (serverName == null) {
// Configure as client.
if (protocol != null) {
RemoteConnection connection = null;
if (protocol.equalsIgnoreCase(RemoteProtocol.RMI)) {
String url = getConfigPropertyAsStringLogDebug(PersistenceUnitProperties.REMOTE_URL, m, this.session);
if (url == null) {
throw EntityManagerSetupException.missingProperty(PersistenceUnitProperties.REMOTE_URL);
}
try {
connection = new RMIConnection(((RMIServerSessionManager) Naming.lookup(url)).createRemoteSessionController());
} catch (Exception exception) {
throw ValidationException.invalidValueForProperty(url, PersistenceUnitProperties.REMOTE_URL, exception);
}
} else {
try {
Class<? extends RemoteConnection> cls = findClassForProperty(protocol, PersistenceUnitProperties.REMOTE_PROTOCOL, loader);
Constructor<? extends RemoteConnection> constructor = cls.getConstructor();
connection = constructor.newInstance();
} catch (Exception exception) {
throw ValidationException.invalidValueForProperty(protocol, PersistenceUnitProperties.REMOTE_PROTOCOL, exception);
}
}
RemoteSession remoteSession = new RemoteSession();
remoteSession.setIsMetadataRemote(false);
remoteSession.setProject(this.session.getProject());
remoteSession.setProfiler(this.session.getProfiler());
remoteSession.setSessionLog(this.session.getSessionLog());
remoteSession.setEventManager(this.session.getEventManager());
remoteSession.setQueries(this.session.getQueries());
remoteSession.setProperties(this.session.getProperties());
remoteSession.setName(this.session.getName());
remoteSession.setRemoteConnection(connection);
this.session = remoteSession;
}
} else {
// Configure as server.
if (protocol.equalsIgnoreCase(RemoteProtocol.RMI)) {
RMIServerSessionManager manager = null;
// Make sure RMI registry is started.
try {
java.rmi.registry.LocateRegistry.createRegistry(1099);
} catch (Exception exception) {
System.out.println("Security violation " + exception.toString());
}
// Create local instance of the factory
try {
manager = new RMIServerSessionManagerDispatcher(session);
} catch (RemoteException exception) {
throw ValidationException.invalidValueForProperty(serverName, PersistenceUnitProperties.REMOTE_SERVER_NAME, exception);
}
// Put the local instance into the Registry
try {
Naming.unbind(serverName);
} catch (Exception exception) {
// Ignore.
}
// Put the local instance into the Registry
try {
Naming.rebind(serverName, manager);
} catch (Exception exception) {
throw ValidationException.invalidValueForProperty(serverName, PersistenceUnitProperties.REMOTE_SERVER_NAME, exception);
}
}
}
}
use of org.eclipse.persistence.sessions.remote.RemoteSession in project eclipselink by eclipse-ee4j.
the class ComplexMultipleUnitOfWorkTest method verify.
@Override
public void verify() {
getSession().getIdentityMapAccessor().initializeIdentityMaps();
Session sessionToVerifyDelete;
if (getSession() instanceof RemoteSession) {
sessionToVerifyDelete = RemoteModel.getServerSession();
} else {
sessionToVerifyDelete = getSession();
}
// Verify if object deleted in the uow was deleted
if (!(((AbstractSession) sessionToVerifyDelete).verifyDelete(this.readInSession))) {
throw new TestErrorException("The object '" + this.readInSession + "'deleted in the uow was not completely deleted from the database.");
}
// Verify if object deleted in the uow was deleted
if (!(((AbstractSession) sessionToVerifyDelete).verifyDelete(this.readInUow))) {
throw new TestErrorException("The object '" + this.readInUow + "'deleted in the nested uow was not completely deleted from the database.");
}
ReadObjectQuery query = new ReadObjectQuery();
query.setSelectionObject(this.newEmployeeInUow);
Employee objectFromDatabase = (Employee) getSession().executeQuery(query);
if (!(((AbstractSession) getSession()).compareObjects(this.newEmployeeInUow, objectFromDatabase))) {
throw new TestErrorException("The object read from the database, '" + this.newEmployeeInUow + "' does not match the originial, '" + objectFromDatabase + ".");
}
}
use of org.eclipse.persistence.sessions.remote.RemoteSession in project eclipselink by eclipse-ee4j.
the class RemoteConnectionExceptionsTest method setRemoteConnection.
protected void setRemoteConnection(RemoteConnection remoteConnection) {
Class<? extends RemoteConnection> cls = remoteConnection.getClass();
if (!remoteConnectionClass.equals(cls)) {
throw new TestProblemException("remoteConnection's type is different from the type used to create the test");
}
this.remoteConnection = remoteConnection;
this.remoteConnection.setSession(new RemoteSession());
}
use of org.eclipse.persistence.sessions.remote.RemoteSession in project eclipselink by eclipse-ee4j.
the class CommitAfterExecuteModifyQueryDuringTransTest method setup.
/**
* Test makes modifications that is not wrapped in a transaction..
*/
@Override
public void setup() {
if (getSession() instanceof RemoteSession) {
throw new TestWarningException("test will not run on RemoteSession - it uses events");
}
// employee to be modified - needed for reset.
cachedEmployee = (Employee) getSession().readObject(Employee.class);
ClassDescriptor descriptor = getSession().getDescriptor(this.cachedEmployee);
if (descriptor.isProtectedIsolation() && descriptor.shouldIsolateProtectedObjectsInUnitOfWork() && getSession() instanceof IsolatedClientSession) {
// this will have read a version of the protected Entity into the Isolated Cache even though the test wants to isolated to UOW
// replace with actual shared cache version
this.cachedEmployee = (Employee) ((AbstractSession) getSession()).getParentIdentityMapSession(descriptor, false, true).getIdentityMapAccessor().getFromIdentityMap(this.cachedEmployee);
}
originalEmployee = (Employee) getSession().copy(cachedEmployee);
employeesNewFirstName = "formerlyKnownAs";
initialVersionField = getSession().getIdentityMapAccessor().getWriteLockValue(cachedEmployee);
// query to be executed more than once
dataModifyQuery = new DataModifyQuery("UPDATE EMPLOYEE SET F_NAME = #F_NAME, VERSION = #VERSION WHERE L_NAME = #L_NAME");
dataModifyQuery.addArgument("F_NAME");
dataModifyQuery.addArgument("VERSION");
dataModifyQuery.addArgument("L_NAME");
}
Aggregations