Package org.objectweb.speedo.pobjects.collection.serialization

Examples of org.objectweb.speedo.pobjects.collection.serialization.Student


    }
   
    public void testSerializeWithCollection() {
        PersistenceManager pm = pmf.getPersistenceManager();
        Professor prof = new Professor("prof");
        Student s1 = new Student(1);
        Student s2 = new Student(2);
        Student s3 = new Student(3);
        Collection col = new ArrayList();
        col.add(s1);
        col.add(s2);
        col.add(s3);
        Course c = new Course("Course1");
        c.setProf(prof);
        c.setStudents(col);
        pm.currentTransaction().begin();
        pm.makePersistent(c);
        Object oid = pm.getObjectId(c);
        Course copyOfC = (Course) pm.detachCopy(c);
        pm.currentTransaction().commit();
        pm.close();
    File f = new File(new File(new File("output"),"test"), "testSerializeWithCollection");
    if (f.exists()) {
      f.delete();
    }
    try {
      ObjectOutputStream oos = new ObjectOutputStream(
          new FileOutputStream(f));
      oos.writeObject(copyOfC);
      oos.close();

      c = null;
      ObjectInputStream ois = new ObjectInputStream(
          new FileInputStream(f));
      c = (Course) ois.readObject();
      ois.close();
      assertEquals("Not the same professor", c.getProf().getName(), copyOfC.getProf().getName());
      assertEquals("Not the same list of students", col.size(), copyOfC.getStudents().size());
      int sid = 0;
      int copySid = 0;
      pm = pmf.getPersistenceManager();
      Iterator itCol = col.iterator();
      Iterator itCopy = copyOfC.getStudents().iterator();
      while (itCol.hasNext()) {
        Student s = (Student) itCol.next();
        sid += s.getSid();
        s = (Student) itCopy.next();
        copySid += s.getSid();
      }
      assertEquals(sid, copySid);
      pm.close();
    } catch (Exception e) {
      logger.log(BasicLevel.ERROR, "testSerializeWithCollection fails: ", e);
View Full Code Here

TOP

Related Classes of org.objectweb.speedo.pobjects.collection.serialization.Student

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.