@Test
  public void testBasicOps() {
    Session session = openSession();
    session.beginTransaction();
    Country country = new Country("US", "United States of America");
    session.persist(country);
    Person person = new Person("Steve", new Address());
    person.getAddress().setLine1("123 Main");
    person.getAddress().setCity("Anywhere");
    person.getAddress().setCountry(country);
    person.getAddress().setPostalCode("123456789");
    session.persist(person);
    session.getTransaction().commit();
    session.close();

    session = openSession();
    session.beginTransaction();
    session.createQuery("from Person p where p.address.country.iso2 = 'US'").list();
    // same query!
    session.createQuery("from Person p where p.address.country.id = 'US'").list();
    person = (Person) session.load(Person.class, person.getId());
    session.delete(person);
    List countries = session.createQuery("from Country").list();
    assertEquals(1, countries.size());
    session.delete(countries.get(0));

    session.getTransaction().commit();
    session.close();
  }
Esempio n. 2
0
  public static void main(String[] args) {

    Address address = new Address("111-111", "서울시 종로구"); // Address 객체 생성
    Person p1 = new Person(); // Person 객체 생성
    System.out.println(p1.getAddress()); // 묵시적 초기화에 의해서 IV에 null값이 초기화

    p1.setAddress(address);
    System.out.println(
        p1.getAddress().getAddressDetails()); // p1.getAddress()의 리턴값이 Address 객체이므로 Address객체의 메소드를
    // 사용하여 값을 리턴한다.

  }
  @Test
  public void testLazyLoadedOneToOne() {
    Datastore ds = new RedisDatastore();
    ds.getMappingContext().addPersistentEntity(Person.class);
    Session conn = ds.connect();

    Person p = new Person();
    p.setName("Bob");
    Address a = new Address();
    a.setNumber("22");
    a.setPostCode("308420");
    p.setAddress(a);
    conn.persist(p);

    p = (Person) conn.retrieve(Person.class, p.getId());

    Address proxy = p.getAddress();

    assertTrue(proxy instanceof javassist.util.proxy.ProxyObject);
    assertTrue(proxy instanceof EntityProxy);

    EntityProxy ep = (EntityProxy) proxy;
    assertFalse(ep.isInitialized());
    assertEquals(a.getId(), proxy.getId());

    assertFalse(ep.isInitialized());
    assertEquals("22", a.getNumber());
  }
    @Override
    protected Boolean doInBackground(final String... args) {

      File dbFile = getDatabasePath("person.db");
      Log.v(TAG, "Db path is: " + dbFile); // get the path of db

      File exportDir = new File(Environment.getExternalStorageDirectory(), "");
      if (!exportDir.exists()) {
        exportDir.mkdirs();
      }

      file = new File(exportDir, "PersonCSV.csv");
      try {

        file.createNewFile();
        CSVWriter csvWrite = new CSVWriter(new FileWriter(file));

        // ormlite core method
        List<Person> listdata = dbhelper.GetDataPerson();
        Person person = null;

        // this is the Column of the table and same for Header of CSV
        // file
        String arrStr1[] = {"First Name", "Last Name", "Address", "Email"};
        csvWrite.writeNext(arrStr1);

        if (listdata.size() > 1) {
          for (int index = 0; index < listdata.size(); index++) {
            person = listdata.get(index);
            String arrStr[] = {
              person.getFirtname(), person.getLastname(), person.getAddress(), person.getEmail()
            };
            csvWrite.writeNext(arrStr);
          }
        }
        // sqlite core query

        /*
         * SQLiteDatabase db = DBob.getReadableDatabase(); //Cursor
         * curCSV=mydb.rawQuery("select * from " + TableName_ans,null);
         * Cursor curCSV =
         * db.rawQuery("SELECT * FROM table_ans12",null);
         * csvWrite.writeNext(curCSV.getColumnNames());
         *
         * while(curCSV.moveToNext()) {
         *
         * String arrStr[] ={curCSV.getString(0),curCSV.getString(1)};
         * curCSV.getString(2),curCSV.getString(3),curCSV.getString(4)
         * csvWrite.writeNext(arrStr);
         *
         * }
         */
        csvWrite.close();
        return true;
      } catch (IOException e) {
        Log.e("MainActivity", e.getMessage(), e);
        return false;
      }
    }
Esempio n. 5
0
 private void assertContainsOnlyNonEmptyPersons(Collection<Person> persons) {
   for (Person person : persons) {
     assertThat(person).isNotNull();
     assertThat(person.getAddress().getCity()).isNotEmpty();
     assertThat(person.getAddress().getZipCode()).isNotEmpty();
     assertThat(person.getName()).isNotEmpty();
   }
 }
Esempio n. 6
0
 protected void onNew(Event event) {
   Shell shell = (Shell) XWT.findElementByName(event.widget, "Root");
   Company company = (Company) XWT.getDataContext(shell);
   Person person = new Person();
   person.setName("New Manager1");
   person.getAddress().setCity("ShenZhen");
   company.setManager(person);
 }
Esempio n. 7
0
 /** Denne metode bruges til at ændre i variablerne knyttet til en person i personContainer */
 private void updatePerson() {
   int ID = inputManager.inputInteger("Indtast ID for person: ");
   if (personCtr.findPerson(ID) != null) {
     Person person = personCtr.findPerson(ID);
     // Print nuv�rerende info om person
     System.out.println(
         "\n"
             + "Der er fundet en person: "
             + person.getName()
             + "\n"
             + "Telefon: "
             + person.getPhone()
             + "\n"
             + "Adresse: "
             + person.getAddress()
             + "\n"
             + "By: "
             + person.getCity());
     // Modtag input for nye info om person
     String name = inputManager.inputString("Navn ændres til: ", false);
     int tlf = inputManager.inputInteger("Telefon nr ændres til: ");
     String adresse = inputManager.inputString("Adresse ændres til:", false);
     String by = inputManager.inputString("By ændres til: ", false);
     // Opdater person info
     Person updatePerson = personCtr.updatePerson(name, tlf, adresse, by, person, ID);
     // Skriv i konsollen
     inputManager.setLastAction(
         "Der er opdateret en kunde: "
             + updatePerson.getName()
             + "\n"
             + "Telefon: "
             + updatePerson.getPhone()
             + "\n"
             + "Adresse: "
             + updatePerson.getAddress()
             + "\n"
             + "By: "
             + updatePerson.getCity());
   } else {
     inputManager.setLastAction("Det lykkedes ikke at opdater info om en kunde!");
   }
 }
Esempio n. 8
0
  public static void main(String[] args) {
    Person p = new Person();
    p.setName("Bob");
    p.setAddress("33 Youreinmy Lane");

    Organization o = new Organization();
    o.setName("PCS");
    o.setAddress("1300 Outtamy Way");

    System.out.print(p.getName() + "'s address:  ");
    System.out.println(p.getAddress());
    System.out.print(o.getName() + "'s address:  ");
    System.out.println(o.getAddress());
  }
Esempio n. 9
0
  public static void main(String[] args) throws JAXBException, IOException {
    JAXBContext context = JAXBContext.newInstance(Person.class);
    // 下面代码演示将对象转变为xml
    Marshaller m = context.createMarshaller();
    Address address = new Address("China", "Beijing", "Beijing", "ShangDi West", "100080");
    Person p = new Person(Calendar.getInstance(), "JAXB2", address, Gender.MALE, "SW");
    FileWriter fw = new FileWriter("person.xml");
    m.marshal(p, fw);

    // 下面代码演示将上面生成的xml转换为对象
    FileReader fr = new FileReader("person.xml");
    Unmarshaller um = context.createUnmarshaller();
    Person p2 = (Person) um.unmarshal(fr);
    System.out.println("Country:" + p2.getAddress().getCountry());
  }
Esempio n. 10
0
 @Override
 public void addPersonToDb(Person newPerson) throws AddPersonException {
   try (Connection cn = DatabaseUtil.getConnection()) {
     String queryString = "INSERT INTO PHONEBOOK (NAME, PHONENUMBER, ADDRESS) VALUES(?, ?, ?)";
     PreparedStatement stmt = cn.prepareStatement(queryString);
     stmt.setString(1, newPerson.getName());
     stmt.setString(2, newPerson.getPhoneNumber());
     stmt.setString(3, newPerson.getAddress());
     stmt.executeUpdate();
     cn.commit();
   } catch (SQLException e) {
     e.printStackTrace();
     throw new AddPersonException("sql Exception");
   } catch (ClassNotFoundException e1) {
     e1.printStackTrace();
     throw new AddPersonException("sql Exception");
   }
 }
Esempio n. 11
0
  public static void main(String[] args) {
    Map<String, Person> people = generateExample();

    String jayZcity = "";
    Person person = people.get("Shawn");

    if (person != null) {
      Address address = person.getAddress();
      if (address != null) {
        jayZcity = address.getCity();
      }
    }

    if (jayZcity == null || jayZcity.equals("") || jayZcity.length() == 0 || jayZcity.isEmpty()) {
      jayZcity = "No City Available";
    }

    System.out.println(jayZcity);
  }
  public View getView(int position, View convertView, ViewGroup parent) {
    View vi = convertView;
    if (convertView == null)
      vi = inflater.inflate(R.layout.activity_ingcercapersone_list_row, null);

    TextView name = (TextView) vi.findViewById(R.id.name);
    TextView qualifica = (TextView) vi.findViewById(R.id.qualifica);
    TextView address = (TextView) vi.findViewById(R.id.address);
    TextView pbx = (TextView) vi.findViewById(R.id.pbx);
    TextView fax = (TextView) vi.findViewById(R.id.fax);
    TextView homepage = (TextView) vi.findViewById(R.id.homepage);

    Person p = data.get(position);

    name.setText(p.getName());
    qualifica.setText(p.getQualifica());
    address.setText(p.getAddress());
    pbx.setText(p.getPbx());
    fax.setText(p.getFax());
    homepage.setText(p.getUrl());

    return vi;
  }
Esempio n. 13
0
 @AppliesTo(Person.class)
 public String toString(Callable<String> proceed, Person self) throws Exception {
   return proceed.call() + "; Address: " + self.getAddress();
 }