View Javadoc

1   package org.sourceforge.jemm;
2   
3   import org.sourceforge.jemm.comm.connection.ConnectionException;
4   import org.sourceforge.jemm.comm.connection.socket.SocketClientConnectionFactory;
5   import org.sourceforge.jemm.database.Database;
6   import org.sourceforge.jemm.database.remote.client.RemoteDatabase;
7   
8   /**
9    * A PersistentStore uses a BDbDatabase to a local persistent database.
10   * 
11   * The following code shows how to register the PersistentStore such that it
12   * will store all objects that have been enhanced:
13   * <code>
14   * RemoteStore myStore = new RemoteStore();
15   * Session.setStore(myStore);
16   * </code>
17   * 
18   * One your program has finished running call the following:
19   * <code>
20   * Session.shutdown();
21   * </code>
22   * 
23   * @see Session
24   * @author Paul Keeble
25   * @author Rory Graves
26   *
27   */
28  public class RemoteStore extends AbstractStore {
29  
30  	protected final String hostname;
31  	protected final int port;
32  	protected RemoteDatabase remoteDB;
33  	
34  	public RemoteStore(String hostname,int port) {
35  		this(hostname,port,false);
36  	}
37  	
38  	public RemoteStore(String hostname,int port,boolean debug) {
39  		super(debug);		
40  		this.hostname = hostname;
41  		this.port = port;
42  		setup();
43  	}
44  	
45  	@Override
46  	protected Database createUnderlyingDatabase() {
47  		try {
48  			SocketClientConnectionFactory clientFactory = new SocketClientConnectionFactory(hostname,port);
49  			remoteDB = new RemoteDatabase(clientFactory);
50  			return remoteDB;
51  		}catch(ConnectionException ce) {
52  			throw new JEMMInternalException("Unable to initialise connection to remote server",ce);
53  		}		
54  	}
55  
56  	@Override
57  	protected void shutdownUnderlyingDatabase() {
58  		remoteDB.shutdown();
59  	}
60  }