public static void main(String args[]) { Person p1 = new Person(); p1.name = "zhongshan"; Person p2 = new Person(); p2.name = "lisi"; System.out.println(p1.getName()); System.out.println(p2.getName()); }
public static void main(String[] args) { Person person1 = new Person(); person1.name = "John F****t"; person1.age = 37; Person person2 = new Person(); person2.name = "Sarah Sucks Dick"; person2.age = 20; System.out.println(person1.name); }
/** 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); }
@Test public void testMapElementProperties() { MapperFactory factory = MappingUtil.getMapperFactory(); factory .classMap(Person.class, PersonDto.class) .field("name.first", "names['first']") .field("name.last", "names[\"last\"]") .register(); MapperFacade mapper = factory.getMapperFacade(); Person person = new Person(); person.name = new Name(); person.name.first = "Chuck"; person.name.last = "Testa"; PersonDto result = mapper.map(person, PersonDto.class); Assert.assertNotNull(result.names); Assert.assertEquals(person.name.first, result.names.get("first")); Assert.assertEquals(person.name.last, result.names.get("last")); Person mapBack = mapper.map(result, Person.class); Assert.assertNotNull(mapBack.name.first); Assert.assertEquals(person.name.first, mapBack.name.first); Assert.assertEquals(person.name.last, mapBack.name.last); }
public static void main(String[] args) { // Create a Person object using the Person class Person person1 = new Person(); person1.name = "Joe Bloggs"; person1.age = 37; person1.speak(); person1.sayHello(); // Create a second Person object Person person2 = new Person(); person2.name = "Sarah Smith"; person2.age = 20; person2.speak(); person1.sayHello(); System.out.println(person1.name); }
public static void main(String[] args) { Person person1 = new Person(); person1.name = "Joe Bloggs"; person1.age = 37; Person person2 = new Person(); person2.name = "Sarah Smith"; person2.age = 20; System.out.println(person1.name); Bicycle speedy = new Bicycle(); speedy.gears = 24; speedy.owner = "Peter"; speedy.speed = 454334; System.out.println(speedy.owner); }
public static void main(String[] args) { MM.setMM("morphia0"); MM.map(Person.class); MM.map(Address.class); PersonDAO pD = new PersonDAO(MM.getMorphia(), MM.getMongo()); Person p1 = pD.getPersonByName("Pepp"); p1.name = "Tester"; // updating automatically when using DAO (not fully efficient) pD.save(p1); }
public static void main(String args[]) { Person firstPerson = new Person(); firstPerson.name = "Gabe"; firstPerson.age = 27; System.out.println(firstPerson); System.out.println("Done"); }
public static void main(String[] args) { // TODO Auto-generated method stub Person person = new Person(); person.name = "张三"; person.age = 20; person.address = "USA"; person.introduce(); Person person1 = new Person("李白", 35); person1.introduce(); }
Object createPerson(int id, String name) { if (!isBinaryMarshaller()) { Person p = new Person(id); p.name = name; return p; } else { BinaryObjectBuilder o = grid(0).binary().builder("Person"); o.setField("id", id); o.setField("name", name); return o.build(); } }
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; }
@Test public void testPerson() { final Person p = new Person(); p.name = "John Doe"; p.age = 33; p.smoker = false; p.job = new Job(); p.job.title = "Manager"; final String pBaseStr = p.getClass().getName() + "@" + Integer.toHexString(System.identityHashCode(p)); final String pJobStr = p.job.getClass().getName() + "@" + Integer.toHexString(System.identityHashCode(p.job)); assertEquals( pBaseStr + "[name=John Doe,age=33,smoker=false,job=" + pJobStr + "[title=Manager]]", new ReflectionToStringBuilder(p, new RecursiveToStringStyle()).toString()); }
@Test public void testNestedMapElement() { MapperFactory factory = MappingUtil.getMapperFactory(); factory .classMap(Person.class, PersonDto2.class) .field("name.first", "names['self'].first") .field("name.last", "names['self'].last") .field("father.first", "names['father'].first") .field("father.last", "names['father'].last") .register(); MapperFacade mapper = factory.getMapperFacade(); Person person = new Person(); person.name = new Name(); person.name.first = "Chuck"; person.name.last = "Testa"; person.father = new Name(); person.father.first = "Buck"; person.father.last = "Testa"; PersonDto2 result = mapper.map(person, PersonDto2.class); Assert.assertNotNull(result.names); Assert.assertEquals(person.name.first, result.names.get("self").first); Assert.assertEquals(person.name.last, result.names.get("self").last); Assert.assertEquals(person.father.first, result.names.get("father").first); Assert.assertEquals(person.father.last, result.names.get("father").last); Person mapBack = mapper.map(result, Person.class); Assert.assertNotNull(mapBack.name.first); Assert.assertEquals(person.name.first, mapBack.name.first); Assert.assertEquals(person.name.last, mapBack.name.last); Assert.assertEquals(person.father.first, mapBack.father.first); Assert.assertEquals(person.father.last, mapBack.father.last); }
@Test public void testOneToOneOnSubclass() { Person p = new Person(); p.name = "Gavin"; Address a = new Address(); a.entityName = "Gavin"; a.zip = "3181"; a.state = "VIC"; a.street = "Karbarook Ave"; p.address = a; Session s = openSession(); Transaction t = s.beginTransaction(); s.persist(p); t.commit(); s.close(); s = openSession(); t = s.beginTransaction(); EntityStatistics addressStats = sessionFactory().getStatistics().getEntityStatistics(Address.class.getName()); EntityStatistics mailingAddressStats = sessionFactory().getStatistics().getEntityStatistics("MailingAddress"); p = (Person) s.createQuery("from Person p join fetch p.address left join fetch p.mailingAddress") .uniqueResult(); assertNotNull(p.address); assertNull(p.mailingAddress); s.clear(); assertEquals(addressStats.getFetchCount(), 0); assertEquals(mailingAddressStats.getFetchCount(), 0); p = (Person) s.createQuery("from Person p join fetch p.address").uniqueResult(); assertNotNull(p.address); assertNull(p.mailingAddress); s.clear(); assertEquals(addressStats.getFetchCount(), 0); assertEquals(mailingAddressStats.getFetchCount(), 1); p = (Person) s.createQuery("from Person").uniqueResult(); assertNotNull(p.address); assertNull(p.mailingAddress); s.clear(); assertEquals(addressStats.getFetchCount(), 1); assertEquals(mailingAddressStats.getFetchCount(), 2); p = (Person) s.createQuery("from Entity").uniqueResult(); assertNotNull(p.address); assertNull(p.mailingAddress); s.clear(); assertEquals(addressStats.getFetchCount(), 2); assertEquals(mailingAddressStats.getFetchCount(), 3); // note that in here join fetch is used for the nullable // one-to-one, due to a very special case of default p = (Person) s.get(Person.class, "Gavin"); assertNotNull(p.address); assertNull(p.mailingAddress); s.clear(); assertEquals(addressStats.getFetchCount(), 2); assertEquals(mailingAddressStats.getFetchCount(), 3); p = (Person) s.get(Entity.class, "Gavin"); assertNotNull(p.address); assertNull(p.mailingAddress); s.clear(); assertEquals(addressStats.getFetchCount(), 2); assertEquals(mailingAddressStats.getFetchCount(), 3); t.commit(); s.close(); s = openSession(); t = s.beginTransaction(); Org org = new Org(); org.name = "IFA"; Address a2 = new Address(); a2.entityName = "IFA"; a2.zip = "3181"; a2.state = "VIC"; a2.street = "Orrong Rd"; org.addresses.add(a2); s.persist(org); t.commit(); s.close(); s = openSession(); t = s.beginTransaction(); org = (Org) s.get(Entity.class, "IFA"); s.clear(); List list = s.createQuery("from Entity e order by e.name").list(); p = (Person) list.get(0); assertNotNull(p.address); assertNull(p.mailingAddress); org = (Org) list.get(1); assertEquals(org.addresses.size(), 1); s.clear(); list = s.createQuery( "from Entity e left join fetch e.address left join fetch e.mailingAddress order by e.name") .list(); p = (Person) list.get(0); org = (Org) list.get(1); assertNotNull(p.address); assertNull(p.mailingAddress); assertEquals(org.addresses.size(), 1); s.delete(p); s.delete(org); t.commit(); s.close(); }