javax.jdo.Query.getPersistenceManager()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(6.3k)|赞(0)|评价(0)|浏览(99)

本文整理了Java中javax.jdo.Query.getPersistenceManager方法的一些代码示例,展示了Query.getPersistenceManager的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Query.getPersistenceManager方法的具体详情如下:
包路径:javax.jdo.Query
类名称:Query
方法名:getPersistenceManager

Query.getPersistenceManager介绍

[英]Get the PersistenceManager associated with this Query.

If this Query was restored from a serialized form, it has no PersistenceManager, and this method returns null.
[中]获取与此Query关联的PersistenceManager
如果此Query是从序列化表单还原的,则它没有PersistenceManager,此方法返回null

代码示例

代码示例来源:origin: anjuke/hwi

@SuppressWarnings("unchecked")
public List<T> getItems() {
  if (items == null) {
    Query newQuery = query.getPersistenceManager().newQuery(query);
    int offset = (page - 1) * pageSize;
    newQuery.setRange(offset, offset + pageSize);
    items = (List<T>) newQuery.executeWithMap(map);
  }
  return items;
}

代码示例来源:origin: anjuke/hwi

public Long getTotal() {
  if (total == null) {
    Query newQuery = query.getPersistenceManager().newQuery(query);
    newQuery.setOrdering(null);
    newQuery.setResult("COUNT(id)");
    total = (Long) newQuery.executeWithMap(map);
  }
  return total;
}

代码示例来源:origin: tzaeschke/zoodb

private void checkOidWithParam(Object param1, Query q, Object ... matches) {
  Object o1 = param1 == null ? null : q.getPersistenceManager().getObjectById(param1);
  Collection<?> c = (Collection<?>) q.execute(o1); 
  for (int i = 0; i < matches.length; i++) {
    boolean match = false;
    for (Object o: c) {
      if (JDOHelper.getObjectId(o).equals(matches[i])) {
        match = true;
        break;
      }
    }
    assertTrue("p=" + i, match);
  }
  assertEquals(matches.length, c.size());
}

代码示例来源:origin: tzaeschke/zoodb

@SuppressWarnings("unchecked")
@Test
public void testIterator() {
  PersistenceManager pm = TestTools.openPM();
  pm.currentTransaction().begin();
  Query q = pm.newQuery(TestClass.class, "_int < 12345");
  assertEquals(pm, q.getPersistenceManager());
  assertFalse(q.isUnmodifiable());
  List<TestClass> r = (List<TestClass>) q.execute();
  assertEquals(4, r.size());
  Iterator<TestClass> iter = r.iterator();
  //avoid call to hasNext()
  for (int i = 0; i < 4; i++) {
    iter.next();
  }
  
  try {
    iter.next();
    fail();
  } catch (NoSuchElementException e) {
    //good
  }
  
  assertFalse(iter.hasNext());
  pm.currentTransaction().rollback();
  TestTools.closePM();
}

代码示例来源:origin: tzaeschke/zoodb

@Test
public void testQueryOfString() {
  PersistenceManager pm = TestTools.openPM();
  pm.currentTransaction().begin();
  Query q = pm.newQuery("SELECT FROM " + TestClass.class.getName());
  assertEquals(pm, q.getPersistenceManager());
  assertFalse(q.isUnmodifiable());
  
  testDeclarative(q);
  testString(q);
  
  TestTools.closePM(pm);
}

代码示例来源:origin: tzaeschke/zoodb

@SuppressWarnings("unchecked")
private void checkQuery(String queryStr, int nRes) {
  PersistenceManager pm = TestTools.openPM();
  pm.currentTransaction().begin();
  Query q = pm.newQuery("SELECT FROM " + TestClass.class.getName() + " WHERE " + queryStr);
  assertEquals(pm, q.getPersistenceManager());
  assertFalse(q.isUnmodifiable());
  List<TestClass> r = (List<TestClass>) q.execute();
  assertEquals(nRes, r.size());
  for (TestClass tc: r) {
    //just check existence
    assertTrue(tc.getInt() >= 1);
  }
  pm.currentTransaction().rollback();
  TestTools.closePM();
}

代码示例来源:origin: tzaeschke/zoodb

@Test
public void testQueryOfClass() {
  PersistenceManager pm = TestTools.openPM();
  pm.currentTransaction().begin();
  Query q = pm.newQuery(TestClass.class);
  assertEquals(pm, q.getPersistenceManager());
  assertFalse(q.isUnmodifiable());
  
  testDeclarative(q);
  testString(q);
  
  TestTools.closePM(pm);
}

代码示例来源:origin: tzaeschke/zoodb

@SuppressWarnings("unchecked")
@Test
public void testSyntaxBracesAndOperators() {
  PersistenceManager pm = TestTools.openPM();
  pm.currentTransaction().begin();
  Query q = pm.newQuery("SELECT FROM " + TestClass.class.getName());
  assertEquals(pm, q.getPersistenceManager());
  assertFalse(q.isUnmodifiable());
  List<TestClass> r;
  
  // OR
  q.setFilter("_int < 12345 && (_short == 32000 || _string == 'xyz') && _int >= 123");
  r = (List<TestClass>) q.execute();
  assertEquals(2, r.size());
  for (TestClass tc: r) {
    assertTrue("int="+tc.getInt(), tc.getInt() >= 123);
  }
  //again with ""
  q.setFilter("_int < 12345 && (_short == 32000 || _string == \"xyz\") && _int >= 123");
  r = (List<TestClass>) q.execute();
  assertEquals(2, r.size());
  for (TestClass tc: r) {
    assertTrue("int="+tc.getInt(), tc.getInt() >= 123);
  }
  TestTools.closePM(pm);
}

代码示例来源:origin: tzaeschke/zoodb

@Test
public void testQuery() {
  PersistenceManager pm = TestTools.openPM();
  pm.currentTransaction().begin();
  Query q = pm.newQuery();
  assertEquals(pm, q.getPersistenceManager());
  assertFalse(q.isUnmodifiable());
  
  q.setClass(TestClass.class);
  
  testDeclarative(q);
  testString(q);
  
  TestTools.closePM(pm);
}

代码示例来源:origin: tzaeschke/zoodb

@Test
public void testQueryOfExtent() {
  PersistenceManager pm = TestTools.openPM();
  pm.currentTransaction().begin();
  Extent<?> ext = pm.getExtent(TestClass.class);
  Query q = pm.newQuery(ext);
  assertEquals(pm, q.getPersistenceManager());
  assertFalse(q.isUnmodifiable());
  
  
  testDeclarative(q);
  testString(q);
  
  TestTools.closePM(pm);
}

代码示例来源:origin: tzaeschke/zoodb

assertEquals(pm, q.getPersistenceManager());
assertFalse(q.isUnmodifiable());

代码示例来源:origin: tzaeschke/zoodb

/**
   * Create two sub-queries with different indices.
   * The result should not contain duplicates.
   */
  @SuppressWarnings("unchecked")
  @Test
  public void testDualIndexingWithOrSplit() {
    PersistenceManager pm = TestTools.openPM();
    pm.currentTransaction().begin();

    Query q = pm.newQuery("SELECT FROM " + TestClass.class.getName());
    assertEquals(pm, q.getPersistenceManager());
    assertFalse(q.isUnmodifiable());

    Collection<TestClass> r;
    
    // OR
    q.setFilter("_int < 12345 && (_short == 32000 || _string == 'xyz') && _int >= 123");
    r = (Collection<TestClass>) q.execute();
    int n = 0;
    for (TestClass tc: r) {
      assertTrue("int=" + tc.getInt(), tc.getInt() >= 123);
      assertTrue(tc.getInt() >= 123);
      n++;
    }
    assertEquals(2, n);

    TestTools.closePM(pm);
  }
}

代码示例来源:origin: tzaeschke/zoodb

@Test
public void testQueryWithNullArgs() {
  PersistenceManager pm = TestTools.openPM();
  pm.currentTransaction().begin();
  try {
    pm.newQuery("");
    fail();
  } catch (NullPointerException e) {
    //good
  }
  try {
    pm.newQuery((String)null);
    fail();
  } catch (NullPointerException e) {
    //good
  }
  Query q = pm.newQuery(TestClass.class, (String)null);
  q = pm.newQuery(TestClass.class, "");
  
  assertEquals(pm, q.getPersistenceManager());
  assertFalse(q.isUnmodifiable());
  
  testDeclarative(q);
  testString(q);
  
  TestTools.closePM(pm);
}

相关文章