public void testSerializeWithMultiValueProps() throws Exception {
    pm.setDetachAllOnCommit(true);
    beginTxn();
    DetachableWithMultiValuePropsJDO pojo = new DetachableWithMultiValuePropsJDO();
    pojo.setStrList(Utils.newArrayList("c", "d"));
    pm.makePersistent(pojo);
    commitTxn();
    assertEquals(ObjectState.DETACHED_CLEAN, JDOHelper.getObjectState(pojo));
    pm.close();
    assertEquals(ObjectState.DETACHED_CLEAN, JDOHelper.getObjectState(pojo));
    pm = pmf.getPersistenceManager();
    assertEquals(ObjectState.DETACHED_CLEAN, JDOHelper.getObjectState(pojo));

    pojo = toBytesAndBack(pojo);

    assertEquals(Utils.newArrayList("c", "d"), pojo.getStrList());
    assertEquals(ObjectState.DETACHED_CLEAN, JDOHelper.getObjectState(pojo));
    beginTxn();
    assertEquals(ObjectState.DETACHED_CLEAN, JDOHelper.getObjectState(pojo));
    // reattach to the pm - this turns our regular list field into a managed
    // list field
    pojo = pm.makePersistent(pojo);
    assertEquals(ObjectState.PERSISTENT_CLEAN, JDOHelper.getObjectState(pojo));
    pojo.getStrList().add("e");
    commitTxn();
    Entity e =
        ds.get(
            KeyFactory.createKey(
                DetachableWithMultiValuePropsJDO.class.getSimpleName(), pojo.getId()));
    assertEquals(3, ((List<String>) e.getProperty("strList")).size());
    assertEquals(Utils.newArrayList("c", "d", "e"), e.getProperty("strList"));
  }
  public void testUnencodedLongPk_BatchGet() throws EntityNotFoundException {
    switchDatasource(PersistenceManagerFactoryName.nontransactional);
    HasLongPkJDO pojo = new HasLongPkJDO();
    beginTxn();
    pojo.setId(1L);
    pm.makePersistent(pojo);
    commitTxn();

    HasLongPkJDO pojo2 = new HasLongPkJDO();
    beginTxn();
    pojo2.setId(2L);
    pm.makePersistent(pojo2);
    commitTxn();

    assertNotNull(pojo.getId());
    assertNotNull(pojo2.getId());

    beginTxn();
    Query q = pm.newQuery("select from " + HasLongPkJDO.class.getName() + " where id == :ids");
    List<HasLongPkJDO> pojos =
        (List<HasLongPkJDO>) q.execute(Utils.newArrayList(pojo.getId(), pojo2.getId()));
    assertEquals(2, pojos.size());
    // we should preserve order but right now we don't
    Set<Long> pks = Utils.newHashSet(pojos.get(0).getId(), pojos.get(1).getId());
    assertEquals(pks, Utils.newHashSet(1L, 2L));
    commitTxn();
  }
/** @author Max Ross <*****@*****.**> */
@PersistenceCapable(detachable = "true")
public class HasOneToManyKeyPkListJDO implements HasOneToManyKeyPkJDO {

  @PrimaryKey
  @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
  private Key key;

  @Element(dependent = "true")
  @Order(column = "flights_INTEGER_IDX_keypk")
  private List<Flight> flights = Utils.newArrayList();

  public void addFlight(Flight flight) {
    flights.add(flight);
  }

  public Collection<Flight> getFlights() {
    return flights;
  }

  public Key getId() {
    return key;
  }
}
  public void testEncodedStringPk_BatchGet() throws EntityNotFoundException {
    switchDatasource(PersistenceManagerFactoryName.nontransactional);
    HasEncodedStringPkJDO pojo = new HasEncodedStringPkJDO();
    beginTxn();
    String key1 =
        new KeyFactory.Builder("parent", 44)
            .addChild(HasEncodedStringPkJDO.class.getSimpleName(), "yar1")
            .getString();
    pojo.setId(key1);
    pm.makePersistent(pojo);
    commitTxn();

    HasEncodedStringPkJDO pojo2 = new HasEncodedStringPkJDO();
    beginTxn();
    String key2 =
        new KeyFactory.Builder("parent", 44)
            .addChild(HasEncodedStringPkJDO.class.getSimpleName(), "yar2")
            .getString();
    pojo2.setId(key2);
    pm.makePersistent(pojo2);
    commitTxn();

    assertNotNull(pojo.getId());
    assertNotNull(pojo2.getId());

    beginTxn();
    Query q =
        pm.newQuery("select from " + HasEncodedStringPkJDO.class.getName() + " where id == :ids");
    List<HasEncodedStringPkJDO> pojos =
        (List<HasEncodedStringPkJDO>) q.execute(Utils.newArrayList(pojo.getId(), pojo2.getId()));
    assertEquals(2, pojos.size());
    // we should preserve order but right now we don't
    Set<String> pks = Utils.newHashSet(pojos.get(0).getId(), pojos.get(1).getId());
    assertEquals(pks, Utils.newHashSet(key1, key2));
    commitTxn();
  }