use of jgnash.engine.attachment.DistributedAttachmentManager in project jgnash by ccavanaugh.
the class JpaNetworkServer method createEngine.
private Engine createEngine(final DataStoreType dataStoreType, final String fileName, final int port, final char[] password) {
final Properties properties = JpaConfiguration.getClientProperties(dataStoreType, fileName, EngineFactory.LOCALHOST, port, password);
logger.log(Level.INFO, "Local connection url is: {0}", properties.getProperty(JpaConfiguration.JAVAX_PERSISTENCE_JDBC_URL));
Engine engine = null;
try {
// An exception will be thrown if the password is not correct, or the database did not have a password
if (SqlUtils.isConnectionValid(properties.getProperty(JpaConfiguration.JAVAX_PERSISTENCE_JDBC_URL))) {
if (SqlUtils.useOldPersistenceUnit(fileName, password)) {
System.out.println("Using old persistence unit");
factory = Persistence.createEntityManagerFactory(JpaConfiguration.OLD_UNIT_NAME, properties);
} else {
factory = Persistence.createEntityManagerFactory(JpaConfiguration.UNIT_NAME, properties);
}
em = factory.createEntityManager();
distributedLockManager = new DistributedLockManager(EngineFactory.LOCALHOST, port + LOCK_SERVER_INCREMENT);
distributedLockManager.connectToServer(password);
distributedAttachmentManager = new DistributedAttachmentManager(EngineFactory.LOCALHOST, port + TRANSFER_SERVER_INCREMENT);
distributedAttachmentManager.connectToServer(password);
logger.info("Created local JPA container and engine");
engine = new Engine(new JpaEngineDAO(em, true), distributedLockManager, distributedAttachmentManager, // treat as a remote engine
SERVER_ENGINE);
}
} catch (final Exception e) {
logger.log(Level.SEVERE, e.toString(), e);
}
return engine;
}
use of jgnash.engine.attachment.DistributedAttachmentManager in project jgnash by ccavanaugh.
the class AbstractJpaDataStore method getClientEngine.
@Override
public Engine getClientEngine(final String host, final int port, final char[] password, final String dataBasePath) {
final Properties properties = JpaConfiguration.getClientProperties(getType(), dataBasePath, host, port, password);
Engine engine = null;
try {
if (SqlUtils.isConnectionValid(properties.getProperty(JpaConfiguration.JAVAX_PERSISTENCE_JDBC_URL))) {
factory = Persistence.createEntityManagerFactory(JpaConfiguration.UNIT_NAME, properties);
em = factory.createEntityManager();
if (em != null) {
distributedLockManager = new DistributedLockManager(host, port + JpaNetworkServer.LOCK_SERVER_INCREMENT);
boolean lockManagerResult = distributedLockManager.connectToServer(password);
distributedAttachmentManager = new DistributedAttachmentManager(host, port + JpaNetworkServer.TRANSFER_SERVER_INCREMENT);
boolean attachmentManagerResult = distributedAttachmentManager.connectToServer(password);
if (attachmentManagerResult && lockManagerResult) {
engine = new Engine(new JpaEngineDAO(em, true), distributedLockManager, distributedAttachmentManager, EngineFactory.DEFAULT);
logger.info("Created local JPA container and engine");
fileName = null;
remote = true;
} else {
distributedLockManager.disconnectFromServer();
distributedAttachmentManager.disconnectFromServer();
em.close();
factory.close();
em = null;
factory = null;
}
}
}
} catch (final Exception e) {
logger.log(Level.SEVERE, e.toString(), e);
}
return engine;
}
Aggregations