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(); }
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(); }
/** @author Max Ross <*****@*****.**> */ @PersistenceCapable(detachable = "true") public class HasOneToManyUnencodedStringPkSetJDO implements HasOneToManyUnencodedStringPkJDO { @PrimaryKey private String key; @Element(dependent = "true") private Set<Flight> flights = Utils.newHashSet(); @Persistent(mappedBy = "parent") @Element(dependent = "true") private Set<BidirectionalChildUnencodedStringPkSetJDO> bidirChildren = new HashSet<BidirectionalChildUnencodedStringPkSetJDO>(); public void addFlight(Flight flight) { flights.add(flight); } public Collection<Flight> getFlights() { return flights; } public String getId() { return key; } public void setId(String key) { this.key = key; } public void addBidirChild(BidirectionalChildUnencodedStringPkJDO child) { bidirChildren.add((BidirectionalChildUnencodedStringPkSetJDO) child); } public Collection<BidirectionalChildUnencodedStringPkJDO> getBidirChildren() { return (Set) bidirChildren; } public boolean removeFlights(Collection<Flight> flights) { return this.flights.removeAll(flights); } public boolean removeBidirChildren( Collection<BidirectionalChildUnencodedStringPkJDO> bidirChildren) { return this.bidirChildren.removeAll(bidirChildren); } }