NucleusContext nc = jdoPmf.getNucleusContext(); try { Field pmCache = pmf.getClass().getDeclaredField("pmCache"); jdoPmf.getNucleusContext().getPluginManager(); Field registryField = pluginManager.getClass().getDeclaredField("registry"); registryField.setAccessible(true);
/** * For JRebel plugin */ public static MetaDataManager getMetaDataManager() { return instance != null ? ((JDOPersistenceManagerFactory)instance.persistenceManagerFactory).getNucleusContext().getMetaDataManager() : null; }
/** * Accessor for the names of the classes that have MetaData for this PMF. * @param pmf The PMF * @return The class names */ public static String[] getClassesWithMetaData(PersistenceManagerFactory pmf) { if (pmf == null || !(pmf instanceof JDOPersistenceManagerFactory)) { return null; } JDOPersistenceManagerFactory myPMF = (JDOPersistenceManagerFactory)pmf; Collection classes = myPMF.getNucleusContext().getMetaDataManager().getClassesWithMetaData(); return (String[])classes.toArray(new String[classes.size()]); }
/** * Accessor for the MetaData for the specified class * @param pmf PersistenceManager factory * @param cls The class * @return The MetaData for the class */ public static ClassMetaData getMetaDataForClass(PersistenceManagerFactory pmf, Class cls) { if (pmf == null || cls == null) { return null; } if (!(pmf instanceof JDOPersistenceManagerFactory)) { return null; } JDOPersistenceManagerFactory myPMF = (JDOPersistenceManagerFactory)pmf; MetaDataManager mdmgr = myPMF.getNucleusContext().getMetaDataManager(); return (ClassMetaData)mdmgr.getMetaDataForClass(cls, myPMF.getNucleusContext().getClassLoaderResolver(null)); }
private static boolean isSchemaAwareStoreManager(Map<String,String> datanucleusProps) { // we create a throw-away instance of PMF so that we can probe whether DN has // been configured with a schema-aware store manager or not. final JDOPersistenceManagerFactory probePmf = (JDOPersistenceManagerFactory)JDOHelper.getPersistenceManagerFactory(datanucleusProps); try { final PersistenceNucleusContext nucleusContext = probePmf.getNucleusContext(); final StoreManager storeManager = nucleusContext.getStoreManager(); return storeManager instanceof SchemaAwareStoreManager; } finally { probePmf.close(); } }
NucleusContext nc = jdoPmf.getNucleusContext(); try { Field pmCache = pmf.getClass().getDeclaredField("pmCache"); org.datanucleus.plugin.PluginManager pluginManager = jdoPmf.getNucleusContext().getPluginManager(); Field registryField = pluginManager.getClass().getDeclaredField("registry"); registryField.setAccessible(true);
/** * Constructor. * @param pmf Persistence Manager Factory * @param userName Username for the datastore. Note that this is currently ignored * @param password Password for the datastore. Note that this is currently ignored */ public JDOPersistenceManager(JDOPersistenceManagerFactory pmf, String userName, String password) { Map<String, Object> options = new HashMap(); options.put(ExecutionContext.OPTION_USERNAME, userName); options.put(ExecutionContext.OPTION_PASSWORD, password); this.ec = pmf.getNucleusContext().getExecutionContext(this, options); this.pmf = pmf; this.fetchPlan = new JDOFetchPlan(ec.getFetchPlan()); this.jdotx = new JDOTransaction(this, ec.getTransaction()); BeanValidationHandler beanValidator = pmf.getNucleusContext().getBeanValidationHandler(ec); if (beanValidator != null) { ec.getCallbackHandler().setBeanValidationHandler(beanValidator); } }
/** * Method to remove a lifecycle listener. Removes the listener from all PM's as well. * @param listener The Listener */ public void removeInstanceLifecycleListener(InstanceLifecycleListener listener) { boolean allowListeners = getNucleusContext().getConfiguration().getBooleanProperty("datanucleus.allowListenerUpdateAfterInit", false); if (!allowListeners && active) { throw new JDOUserException(Localiser.msg("012023")); } if (listener == null || lifecycleListeners == null) { return; } // Remove from the PMF lifecycleListeners.remove(listener); }
/** * Method to perform the replication for all objects registered in the pmf source. */ public void replicateRegisteredClasses() { ClassLoaderResolver clr = ((JDOPersistenceManager)pmfSource.getPersistenceManager()).getExecutionContext().getClassLoaderResolver(); MetaDataManager mmgr = ((JDOPersistenceManagerFactory)pmfSource).getNucleusContext().getMetaDataManager(); Collection classNames = mmgr.getClassesWithMetaData(); ArrayList arrayTypes = new ArrayList(); Iterator iterator = classNames.iterator(); while (iterator.hasNext()) { String className = (String) iterator.next(); AbstractClassMetaData cmd = mmgr.getMetaDataForClass(className, clr); if (!cmd.isEmbeddedOnly()) // Omit embedded-only classes since can't replicate those { arrayTypes.add(clr.classForName(className)); } } replicate((Class[])arrayTypes.toArray(new Class[arrayTypes.size()])); }
private void createSchema( final PersistenceManagerFactory persistenceManagerFactory, final Set<String> persistableClassNameSet, final Map<String, String> datanucleusProps) { JDOPersistenceManagerFactory jdopmf = (JDOPersistenceManagerFactory) persistenceManagerFactory; final PersistenceNucleusContext nucleusContext = jdopmf.getNucleusContext(); final SchemaAwareStoreManager schemaAwareStoreManager = (SchemaAwareStoreManager)nucleusContext.getStoreManager(); final MetaDataManager metaDataManager = nucleusContext.getMetaDataManager(); registerMetadataListener(metaDataManager, datanucleusProps); schemaAwareStoreManager.createSchemaForClasses(persistableClassNameSet, asProperties(datanucleusProps)); }
boolean allowListeners = getNucleusContext().getConfiguration().getBooleanProperty("datanucleus.allowListenerUpdateAfterInit", false); if (!allowListeners && active)
NucleusContext nucleusCtxSource = ((JDOPersistenceManagerFactory)pmfSource).getNucleusContext(); MetaDataManager mmgr = nucleusCtxSource.getMetaDataManager(); ClassLoaderResolver clr = nucleusCtxSource.getClassLoaderResolver(null);
NucleusContext nucleusCtxSource = ((JDOPersistenceManagerFactory)pmfSource).getNucleusContext(); MetaDataManager mmgr = nucleusCtxSource.getMetaDataManager(); ClassLoaderResolver clr = nucleusCtxSource.getClassLoaderResolver(null);