use of org.datanucleus.api.jdo.JDOPersistenceManagerFactory in project hive by apache.
the class TestHiveMetaStore method getJDOPersistanceManagerCacheSize.
private static int getJDOPersistanceManagerCacheSize() {
JDOPersistenceManagerFactory jdoPmf;
Set<JDOPersistenceManager> pmCacheObj;
Field pmCache;
Field pmf;
try {
pmf = ObjectStore.class.getDeclaredField("pmf");
if (pmf != null) {
pmf.setAccessible(true);
jdoPmf = (JDOPersistenceManagerFactory) pmf.get(null);
pmCache = JDOPersistenceManagerFactory.class.getDeclaredField("pmCache");
if (pmCache != null) {
pmCache.setAccessible(true);
pmCacheObj = (Set<JDOPersistenceManager>) pmCache.get(jdoPmf);
if (pmCacheObj != null) {
return pmCacheObj.size();
}
}
}
} catch (Exception ex) {
System.out.println(ex);
}
return -1;
}
use of org.datanucleus.api.jdo.JDOPersistenceManagerFactory in project tutorials by eugenp.
the class GuideToJDO method ListProducts.
@SuppressWarnings({ "rawtypes", "unchecked" })
public void ListProducts() {
PersistenceManagerFactory pmf = new JDOPersistenceManagerFactory(pumd, null);
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
Query q = pm.newQuery("SELECT FROM " + Product.class.getName() + " WHERE price > 10");
List<Product> products = (List<Product>) q.execute();
Iterator<Product> iter = products.iterator();
while (iter.hasNext()) {
Product p = iter.next();
LOGGER.log(Level.WARNING, "Product name: {0} - Price: {1}", new Object[] { p.name, p.price });
}
LOGGER.log(Level.INFO, "--------------------------------------------------------------");
tx.commit();
} finally {
if (tx.isActive()) {
tx.rollback();
}
pm.close();
}
}
use of org.datanucleus.api.jdo.JDOPersistenceManagerFactory in project tutorials by eugenp.
the class GuideToJDO method listXMLProducts.
@SuppressWarnings({ "rawtypes", "unchecked" })
public void listXMLProducts() {
PersistenceManagerFactory pmf = new JDOPersistenceManagerFactory(pumdXML, null);
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
Query q = pm.newQuery("SELECT FROM " + ProductXML.class.getName());
List<ProductXML> products = (List<ProductXML>) q.execute();
Iterator<ProductXML> iter = products.iterator();
while (iter.hasNext()) {
ProductXML p = iter.next();
LOGGER.log(Level.WARNING, "Product name: {0} - Price: {1}", new Object[] { p.getName(), p.getPrice() });
pm.deletePersistent(p);
}
LOGGER.log(Level.INFO, "--------------------------------------------------------------");
tx.commit();
} finally {
if (tx.isActive()) {
tx.rollback();
}
pm.close();
}
}
use of org.datanucleus.api.jdo.JDOPersistenceManagerFactory in project tutorials by eugenp.
the class GuideToJDO method persistXML.
public void persistXML() {
PersistenceManagerFactory pmf = new JDOPersistenceManagerFactory(pumdXML, null);
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
ProductXML productXML = new ProductXML(0, "Tablet", 80.0);
pm.makePersistent(productXML);
ProductXML productXML2 = new ProductXML(1, "Phone", 20.0);
pm.makePersistent(productXML2);
ProductXML productXML3 = new ProductXML(2, "Laptop", 200.0);
pm.makePersistent(productXML3);
tx.commit();
} finally {
if (tx.isActive()) {
tx.rollback();
}
pm.close();
}
}
use of org.datanucleus.api.jdo.JDOPersistenceManagerFactory in project tutorials by eugenp.
the class GuideToJDO method QuerySQL.
@SuppressWarnings({ "rawtypes", "unchecked" })
public void QuerySQL() {
PersistenceManagerFactory pmf = new JDOPersistenceManagerFactory(pumd, null);
PersistenceManager pm = pmf.getPersistenceManager();
Transaction tx = pm.currentTransaction();
try {
tx.begin();
// SQL :
LOGGER.log(Level.INFO, "SQL --------------------------------------------------------------");
Query query = pm.newQuery("javax.jdo.query.SQL", "SELECT * FROM PRODUCT");
query.setClass(Product.class);
List<Product> results = query.executeList();
Iterator<Product> iter = results.iterator();
while (iter.hasNext()) {
Product p = iter.next();
LOGGER.log(Level.WARNING, "Product name: {0} - Price: {1}", new Object[] { p.name, p.price });
}
LOGGER.log(Level.INFO, "--------------------------------------------------------------");
tx.commit();
} finally {
if (tx.isActive()) {
tx.rollback();
}
pm.close();
}
}
Aggregations