/** * Replaces the factory with this JVMs pooled version if it exists. Also * freezes the factory. */ protected Object readResolve() throws ObjectStreamException { AbstractBrokerFactory factory = getPooledFactoryForKey(_poolKey); if (factory != null) return factory; // reset these transient fields to empty values _transactional = new ConcurrentHashMap(); _brokers = newBrokerSet(); makeReadOnly(); return this; }
public Map<String,Object> getProperties() { Map<String,Object> props = super.getProperties(); props.put("Platform", _platform); return props; }
public Broker newBroker(String user, String pass, boolean managed, int connRetainMode, boolean findExisting) { try { assertOpen(); makeReadOnly(); BrokerImpl broker = null; if (findExisting) broker = findBroker(user, pass, managed); if (broker == null) { broker = newBrokerImpl(user, pass); initializeBroker(managed, connRetainMode, broker, false); } return broker; } catch (OpenJPAException ke) { throw ke; } catch (RuntimeException re) { throw new GeneralException(re); } }
public void removeTransactionListener(Object listener) { lock(); try { assertOpen(); if (_transactionListeners != null) _transactionListeners.remove(listener); } finally { unlock(); } }
private void readObject(ObjectInputStream in) throws ClassNotFoundException, IOException { Object factoryKey = in.readObject(); AbstractBrokerFactory factory = AbstractBrokerFactory.getPooledFactoryForKey(factoryKey); // this needs to happen before defaultReadObject so that it's // available for calls to broker.getConfiguration() during // StateManager deserialization _conf = factory.getConfiguration(); in.defaultReadObject(); factory.initializeBroker(_managed, _connRetainMode, this, true); // re-initialize the lock if needed. setMultithreaded(_multithreaded); if (isActive() && _runtime instanceof LocalManagedRuntime) ((LocalManagedRuntime) _runtime).begin(); }
public void close() { lock(); try { assertOpen(); assertNoActiveTransaction(); _closedException = new IllegalStateException(); } finally { unlock();
J2DoPrivHelper.getContextClassLoaderAction()); if (!fromDeserialization){ _conf = factory.getConfiguration(); _repo = _conf.getMetaDataRepositoryInstance(); _factory.configureBroker(this); _factory.addListeners(this); if (_factory.syncWithManagedTransaction(this, false)) beginInternal();
void initializeBroker(boolean managed, int connRetainMode, Broker broker, boolean fromDeserialization) { assertOpen(); makeReadOnly(); DelegatingStoreManager dsm = createDelegatingStoreManager(); ((BrokerImpl) broker).initialize(this, dsm, managed, connRetainMode, fromDeserialization); // if we're using remote events, register the event manager so // that it can broadcast commit notifications from the broker RemoteCommitEventManager remote = _conf.getRemoteCommitEventManager(); if (remote.areRemoteEventsEnabled()) broker.addTransactionListener(remote); loadPersistentTypes(broker.getClassLoader()); _brokers.add(broker); _conf.setReadOnly(Configuration.INIT_STATE_FROZEN); }
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { try { _ret = PersistenceExceptions.getRollbackTranslator(this); // this assumes that serialized Brokers are from something // that extends AbstractBrokerFactory. Object factoryKey = in.readObject(); AbstractBrokerFactory factory = AbstractBrokerFactory.getPooledFactoryForKey(factoryKey); byte[] brokerBytes = (byte[]) in.readObject(); ObjectInputStream innerIn = new BrokerBytesInputStream(brokerBytes, factory.getConfiguration()); Broker broker = (Broker) innerIn.readObject(); EntityManagerFactoryImpl emf = (EntityManagerFactoryImpl) JPAFacadeHelper.toEntityManagerFactory( broker.getBrokerFactory()); broker.putUserObject(JPAFacadeHelper.EM_KEY, this); initialize(emf, broker); } catch (RuntimeException re) { try { re = _ret.translate(re); } catch (Exception e) { // ignore } throw re; } }
void initializeBroker(boolean managed, int connRetainMode, BrokerImpl broker, boolean fromDeserialization) { assertOpen(); makeReadOnly(); // decorate the store manager for data caching and custom // result object providers; always make sure it's a delegating // store manager, because it's easier for users to deal with // that way StoreManager sm = newStoreManager(); DelegatingStoreManager dsm = null; if (_conf.getDataCacheManagerInstance().getSystemDataCache() != null) dsm = new DataCacheStoreManager(sm); dsm = new ROPStoreManager((dsm == null) ? sm : dsm); broker.initialize(this, dsm, managed, connRetainMode, fromDeserialization); if (!fromDeserialization) addListeners(broker); // if we're using remote events, register the event manager so // that it can broadcast commit notifications from the broker RemoteCommitEventManager remote = _conf. getRemoteCommitEventManager(); if (remote.areRemoteEventsEnabled()) broker.addTransactionListener(remote); loadPersistentTypes(broker.getClassLoader()); _brokers.add(broker); _conf.setReadOnly(Configuration.INIT_STATE_FROZEN); }
public void writeExternal(ObjectOutput out) throws IOException { try { // this requires that only AbstractBrokerFactory-sourced // brokers can be serialized Object factoryKey = ((AbstractBrokerFactory) _broker .getBrokerFactory()).getPoolKey(); out.writeObject(factoryKey); ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream innerOut = new ObjectOutputStream(baos); innerOut.writeObject(_broker.getDelegate()); innerOut.flush(); out.writeObject(baos.toByteArray()); } catch (RuntimeException re) { try { re = ret.translate(re); } catch (Exception e) { // ignore } throw re; } }
J2DoPrivHelper.getContextClassLoaderAction()); if (!fromDeserialization) _conf = factory.getConfiguration(); _compat = _conf.getCompatibilityInstance(); _factory = factory; _factory.configureBroker(this); if (_factory.syncWithManagedTransaction(this, false)) beginInternal();
protected BrokerImpl newBrokerImpl(String user, String pass) { BrokerImpl broker = super.newBrokerImpl(user, pass); lock(); try { // synchronize mappings; we wait until now to do this so that // we can use the first broker user/pass for connection if no // global login is given if (!_synchronizedMappings) { _synchronizedMappings = true; synchronizeMappings(broker.getClassLoader()); } return broker; } finally { unlock(); } }
protected boolean findPersistenceUnit() { // START - ALLOW PRINT STATEMENTS if (_emf == null) { System.err.println("Discovering auxiliary Persistent Unit " + _unit); BrokerFactory bf = AbstractBrokerFactory.getPooledFactoryForKey(_unit); if (bf != null) { _emf = (OpenJPAEntityManagerFactory)bf.getUserObject(JPAFacadeHelper.EMF_KEY); } System.err.println("Discovered auxiliary Persistent Unit " + _unit + ":" + _emf); } // STOP - ALLOW PRINT STATEMENTS return _emf != null; }
public Object getUserObject(Object key) { lock(); try { assertOpen(); return (_userObjects == null) ? null : _userObjects.get(key); } finally { unlock(); } }
private void readObject(ObjectInputStream in) throws ClassNotFoundException, IOException { Object factoryKey = in.readObject(); AbstractBrokerFactory factory = AbstractBrokerFactory.getPooledFactoryForKey(factoryKey); // this needs to happen before defaultReadObject so that it's // available for calls to broker.getConfiguration() during // StateManager deserialization _conf = factory.getConfiguration(); _repo = _conf.getMetaDataRepositoryInstance(); in.defaultReadObject(); factory.initializeBroker(_managed, _connRetainMode, this, true); // re-initialize the lock if needed. setMultithreaded(_multithreaded); // force recreation of set _operatingDirty = true; initializeOperatingSet(); if (isActive() && _runtime instanceof LocalManagedRuntime) ((LocalManagedRuntime) _runtime).begin(); }
public void close() { lock(); try { assertOpen(); assertNoActiveTransaction(); // remove from factory pool synchronized (_pool) { if (_pool.get(_poolKey) == this) _pool.remove(_poolKey); } // close all brokers for (Broker broker : _brokers) { // Check for null because _brokers may contain weak references if ((broker != null) && (!broker.isClosed())) broker.close(); } if(_conf.metaDataRepositoryAvailable()) { // remove metadata repository from listener list PCRegistry.removeRegisterClassListener (_conf.getMetaDataRepositoryInstance()); } _conf.close(); _closed = true; Log log = _conf.getLog(OpenJPAConfiguration.LOG_RUNTIME); if (log.isTraceEnabled()) _closedException = new IllegalStateException(); } finally { unlock(); } }
J2DoPrivHelper.getContextClassLoaderAction()); if (!fromDeserialization){ _conf = factory.getConfiguration(); _repo = _conf.getMetaDataRepositoryInstance(); _factory.configureBroker(this); _factory.addListeners(this); if (_factory.syncWithManagedTransaction(this, false)) beginInternal();
void initializeBroker(boolean managed, int connRetainMode, Broker broker, boolean fromDeserialization) { assertOpen(); makeReadOnly(); DelegatingStoreManager dsm = createDelegatingStoreManager(); ((BrokerImpl) broker).initialize(this, dsm, managed, connRetainMode, fromDeserialization); // if we're using remote events, register the event manager so // that it can broadcast commit notifications from the broker RemoteCommitEventManager remote = _conf.getRemoteCommitEventManager(); if (remote.areRemoteEventsEnabled()) broker.addTransactionListener(remote); loadPersistentTypes(broker.getClassLoader()); _brokers.add(broker); _conf.setReadOnly(Configuration.INIT_STATE_FROZEN); }
public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { try { _ret = PersistenceExceptions.getRollbackTranslator(this); // this assumes that serialized Brokers are from something // that extends AbstractBrokerFactory. Object factoryKey = in.readObject(); AbstractBrokerFactory factory = AbstractBrokerFactory.getPooledFactoryForKey(factoryKey); byte[] brokerBytes = (byte[]) in.readObject(); ObjectInputStream innerIn = new BrokerBytesInputStream(brokerBytes, factory.getConfiguration()); Broker broker = (Broker) innerIn.readObject(); EntityManagerFactoryImpl emf = (EntityManagerFactoryImpl) JPAFacadeHelper.toEntityManagerFactory( broker.getBrokerFactory()); broker.putUserObject(JPAFacadeHelper.EM_KEY, this); initialize(emf, broker); } catch (RuntimeException re) { try { re = _ret.translate(re); } catch (Exception e) { // ignore } throw re; } }