Beispiel #1
0
  PersonHasRole(
      RelationManager manager,
      boolean full,
      Person subject,
      Role object,
      java.sql.Timestamp _ctime,
      java.sql.Timestamp _mtime,
      Person _createdBy) {
    if (subject == null || object == null) {
      throw new IllegalArgumentException();
    }
    this.manager = manager;
    this.subject = subject;
    this.subject_refid = subject.id();
    this.object = object;
    this.object_refid = object.id();

    this._ctime = _ctime;
    this.fetched_ctime = true;
    this._mtime = _mtime;
    this.fetched_mtime = true;
    this._createdBy = _createdBy;
    this.ref_createdBy = _createdBy.id();
    this.fetched_createdBy = true;
  }
Beispiel #2
0
 @Override
 public void create() throws de.fu.weave.orm.DatabaseException {
   String query =
       "INSERT INTO "
           + "\"scetris\".\"personHasRole\""
           + " (Person, Role, , \"ctime\", \"mtime\", \"created_by\")"
           + " VALUES (?, ?, ?);";
   try {
     java.sql.PreparedStatement stmt =
         manager.connectionManager.getConnection().prepareStatement(query);
     stmt.setInt(1, subject.id());
     stmt.setInt(2, object.id());
     int i = 3;
     stmt.setTimestamp(i++, _ctime);
     stmt.setTimestamp(i++, _mtime);
     if (ref_createdBy != null) {
       stmt.setInt(i++, ref_createdBy);
     } else {
       stmt.setNull(i++, java.sql.Types.INTEGER);
     }
     stmt.execute();
   } catch (java.sql.SQLException e) {
     throw new de.fu.weave.orm.DatabaseException(query, e);
   }
 }
  /** tests the behavior of XML id/idref. */
  public void testXMLIDIDREF() throws Exception {
    Person person = new Person();
    person.id = "me";
    person.name = "me";
    person.father = new Person();
    person.father.id = "father";
    person.father.name = "father";
    person.mother = new Person();
    person.mother.id = "mother";
    person.mother.name = "mother";

    NonRefPerson nonRefperson = new NonRefPerson();
    nonRefperson.id = "me";
    nonRefperson.name = "me";
    nonRefperson.father = "father";
    nonRefperson.mother = "mother";

    Marshaller marshaller = JAXBContext.newInstance(NonRefPerson.class).createMarshaller();
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    marshaller.marshal(nonRefperson, out);
    Unmarshaller unmarshaller = JAXBContext.newInstance(Person.class).createUnmarshaller();
    byte[] bytes = out.toByteArray();
    //    System.out.println(new String(bytes, "utf-8"));
    Person deserializedPerson = (Person) unmarshaller.unmarshal(new ByteArrayInputStream(bytes));
    assertEquals("me", deserializedPerson.id);
    assertEquals("me", deserializedPerson.name);
    assertNull(
        "The XMLID/IDREF tests have failed, meaning JAXB's doing some inference, and you may need add back the ID/IDREF warnings.",
        deserializedPerson.father);
    assertNull(
        "The XMLID/IDREF tests have failed, meaning JAXB's doing some inference, and you may need add back the ID/IDREF warnings.",
        deserializedPerson.mother);
  }
 public void testOneToOneExplicitJoinColumn() throws Exception {
   assertTrue(SchemaUtil.isColumnPresent("MedicalHistory", "FK1", getCfg()));
   assertTrue(SchemaUtil.isColumnPresent("MedicalHistory", "FK2", getCfg()));
   assertTrue(!SchemaUtil.isColumnPresent("MedicalHistory", "firstname", getCfg()));
   Person e = new Person();
   e.id = new PersonId();
   e.id.firstName = "Emmanuel";
   e.id.lastName = "Bernard";
   Session s = openSession();
   s.getTransaction().begin();
   s.persist(e);
   MedicalHistory d = new MedicalHistory();
   d.patient = e;
   s.persist(d);
   s.flush();
   s.clear();
   PersonId pId = new PersonId();
   pId.firstName = e.id.firstName;
   pId.lastName = e.id.lastName;
   d = (MedicalHistory) s.get(MedicalHistory.class, pId);
   assertEquals(pId.firstName, d.patient.id.firstName);
   s.delete(d);
   s.delete(d.patient);
   s.getTransaction().commit();
   s.close();
 }
Beispiel #5
0
 PersonHasRole(RelationManager manager, Person subject, Role object) {
   if (subject == null || object == null) {
     throw new IllegalArgumentException();
   }
   this.manager = manager;
   this.subject = subject;
   this.subject_refid = subject.id();
   this.object = object;
   this.object_refid = object.id();
 }
 public List<Person> queryAll() {
   List<Person> persons = new ArrayList<>();
   Cursor cursor = db.rawQuery("SELECT id,name,age,phone FROM person", null);
   Person person;
   while (cursor != null && cursor.moveToNext()) {
     person = new Person();
     person.id = cursor.getInt(cursor.getColumnIndex("id"));
     person.name = cursor.getString(cursor.getColumnIndex("name"));
     person.age = cursor.getInt(cursor.getColumnIndex("age"));
     person.phone = cursor.getString(cursor.getColumnIndex("phone"));
     persons.add(person);
   }
   return persons;
 }
  PersonTakesPartInElementInstance(
      RelationManager manager, Person subject, CourseElementInstance object, Timeslot _timeslot) {
    if (subject == null || object == null) {
      throw new IllegalArgumentException();
    }
    this.manager = manager;
    this.subject = subject;
    this.subject_refid = subject.id();
    this.object = object;
    this.object_refid = object.id();

    this._timeslot = _timeslot;
    this.ref_timeslot = _timeslot.id();
    this.fetched_timeslot = true;
  }
 @Override
 public void create() throws de.fu.weave.orm.DatabaseException {
   String query =
       "INSERT INTO "
           + "\"scetris\".\"personTakesPartInElementInstance\""
           + " (Person, CourseElementInstance, , \"timeslot\")"
           + " VALUES (?);";
   try {
     java.sql.PreparedStatement stmt =
         manager.connectionManager.getConnection().prepareStatement(query);
     stmt.setInt(1, subject.id());
     stmt.setInt(2, object.id());
     int i = 3;
     stmt.setInt(i++, ref_timeslot);
     stmt.execute();
   } catch (java.sql.SQLException e) {
     throw new de.fu.weave.orm.DatabaseException(query, e);
   }
 }
 public void testOneToOneExplicitJoinColumn() throws Exception {
   assertTrue(SchemaUtil.isColumnPresent("MedicalHistory", "FK1", getCfg()));
   assertTrue(SchemaUtil.isColumnPresent("MedicalHistory", "FK2", getCfg()));
   assertTrue(!SchemaUtil.isColumnPresent("MedicalHistory", "firstname", getCfg()));
   Person e = new Person();
   e.id = new PersonId();
   e.id.firstName = "Emmanuel";
   e.id.lastName = "Bernard";
   Session s = openSession();
   s.getTransaction().begin();
   s.persist(e);
   MedicalHistory d = new MedicalHistory();
   //		d.id = new PersonId();
   //		d.id.firstName = "Emmanuel"; //FIXME not needed when foreign is enabled
   //		d.id.lastName = "Bernard"; //FIXME not needed when foreign is enabled
   d.patient = e;
   s.persist(d);
   s.flush();
   s.clear();
   d = (MedicalHistory) s.get(MedicalHistory.class, d.id);
   assertEquals(d.id.firstName, d.patient.id.firstName);
   s.getTransaction().rollback();
   s.close();
 }