public static synchronized void update(String array[]) { int index, count; Date date; Person person; SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy", Locale.ENGLISH); for (int i = 1; i < array.length; i++) { if (array[i].equals("м")) { count = i - 2; index = Integer.parseInt(array[count]); if (index < allPeople.size()) { person = allPeople.get(index); } else return; count = i - 1; person.setName(array[count]); person.setSex(Sex.MALE); try { count = i + 1; date = format.parse(array[count]); person.setBirthDay(date); } catch (Exception e) { } } if (array[i].equals("ж")) { count = i - 2; index = Integer.parseInt(array[count]); if (index < allPeople.size()) { person = allPeople.get(index); } else return; count = i - 1; person.setName(array[count]); person.setSex(Sex.FEMALE); try { count = i + 1; date = format.parse(array[count]); person.setBirthDay(date); } catch (Exception e) { } } } }
public static Person getObject() { Person person = new Person(); person.setNamespaces(new Namespace("tns", "http://www.pinae.com")); person.setNamespaces(new Namespace("tns2", "http://www.pinae.org")); person.setId(1); Person.Sex sex = person.new Sex(); sex.setValue("1"); Website website1 = new Website(); website1.setValue("http://www.google.com"); Website website2 = new Website(); website2.setValue("http://www.baidu.com"); Website website3 = new Website(); website3.setValue("http://www.163.com"); Website website4 = new Website(); website4.setValue("http://www.21cn.com"); person.setWebsite(website1); person.setWebsite(website2); person.setWebsite(website3); person.setWebsite(website4); Name name = new Name(); Name.Firstname firstname = name.new Firstname(); Name.Lastname lastname = name.new Lastname(); firstname.setValue("Tom"); lastname.setValue("Jim"); name.setFirstname(firstname); name.setLastname(lastname); Telephone telephone = new Telephone(); Telephone.Mobile mobile = telephone.new Mobile(); mobile.setNet("gsm"); mobile.setValue("13343351822"); Telephone.Office office = telephone.new Office(); office.setValue("010-8556697"); Telephone.Home home = telephone.new Home(); home.setValue("0757-82988679"); telephone.setHome(home); telephone.setOffice(office); telephone.setMobile(mobile); person.setBirthday(new Date()); person.setName(name); person.setAge(23); person.setSex(sex); person.setTelephone(telephone); person.setOther(new CdataText("<XML>Tearcher</XML>")); person.setPc("<Model>Acer 4750G</Model>"); return person; }
public static synchronized void delete(String array[]) { int index; Person person; for (int i = 1; i < array.length; i++) { index = Integer.parseInt(array[i]); if (index < allPeople.size()) { person = allPeople.get(index); person.setName(null); person.setSex(null); person.setBirthDay(null); } } }
public void testSaveObject() { Person person = new Person(); person.setName("liuyong"); person.setSex("male"); this.db4oTemplate.save(person); List<Person> persons = this.db4oTemplate.query( new Predicate<Person>() { public boolean match(Person person) { return person.getName().equals("liuyong"); } }); assertEquals(1, persons.size()); }
@Test public void test1() { PhoneNumber phone = new PhoneNumber(); phone.setCode(123); phone.setNumber("1234-456"); PhoneNumber fax = new PhoneNumber(); fax.setCode(123); fax.setNumber("<aaaa>9999-999中文乱码</bbbb>"); Set dataSet = new TreeSet(); dataSet.add("aa"); dataSet.add("bb"); List dataList = new ArrayList(); dataList.add("aa"); dataList.add("bb"); dataList.add(1); Map dataMap = new HashMap(); dataMap.put("aa", "aavalue"); dataMap.put("bb", "bbvalue"); String[] dataArray = new String[] {"aa", "bb"}; String[][] datadoubleArray = new String[][] {{"aaa", "bbb"}, {"cccc", "dddd"}}; Person joe = new Person(); joe.setFirstname("Joe"); joe.setDataDoubleArray(datadoubleArray); // joe.setLastname("Walnes"); // 用来验证bboss和Xstream是否会按照null值传递,也就是说lastname有默认值"ssss" // 这样我们手动把lastname设置为null,理论上来说反序列化后joe中的lastname应该是null而不是默认值"ssss" joe.setBirthdate(new Date()); Date[] updates = new Date[] {new Date(), new Date()}; joe.setUpdatedate(updates); joe.setLastname(null); joe.setPhone(phone); joe.setFax(fax); joe.setDataArray(dataArray); joe.setDataList(dataList); joe.setDataMap(dataMap); joe.setDataSet(dataSet); EnumData sex = EnumData.M; joe.setSex(sex); try { // 预热bboss和xstream String xml = ObjectSerializable.toXML(joe); System.out.println(xml); Person person = ObjectSerializable.toBean(xml, Person.class); System.out.println(); // 测试用例结束 } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } }
@Test public void test() { PhoneNumber phone = new PhoneNumber(); phone.setCode(123); phone.setNumber("1234-456"); PhoneNumber fax = new PhoneNumber(); fax.setCode(123); fax.setNumber("<aaaa>9999-999</bbbb>"); Set dataSet = new TreeSet(); dataSet.add("aa"); dataSet.add("bb"); List dataList = new ArrayList(); dataList.add("中国人阿斯顿发水电费"); dataList.add("bb"); Map dataMap = new HashMap(); dataMap.put("aa", "aavalue"); dataMap.put("bb", "bbvalue"); String[] dataArray = new String[] {"aa", "bb"}; String[][] datadoubleArray = new String[][] {{"aaa", "bbb"}, {"cccc", "dddd"}}; Person joe = new Person(); joe.setFirstname("Joe"); joe.setDataDoubleArray(datadoubleArray); // joe.setLastname("Walnes"); // 用来验证bboss和Xstream是否会按照null值传递,也就是说lastname有默认值"ssss" // 这样我们手动把lastname设置为null,理论上来说反序列化后joe中的lastname应该是null而不是默认值"ssss" joe.setBirthdate(new Date()); Date[] updates = new Date[] {new Date(), new Date()}; joe.setUpdatedate(updates); joe.setLastname(null); joe.setPhone(phone); joe.setFax(fax); joe.setDataArray(dataArray); joe.setDataList(dataList); joe.setDataMap(dataMap); joe.setDataSet(dataSet); EnumData sex = EnumData.M; joe.setSex(sex); try { // 预热bboss和xstream String xml = ObjectSerializable.toXML(joe); System.out.println(xml); System.out.println("bboss:" + xml.getBytes().length); Person person = ObjectSerializable.toBean(xml, Person.class); String xmlXstream = xStream.toXML(joe); System.out.println("xmlXstream:" + xmlXstream.getBytes().length); Person p = (Person) xStream.fromXML(xmlXstream); System.out.println(xmlXstream); System.out.println(); System.out.println("bboss序列化测试用例开始"); System.out.println(); long start = System.currentTimeMillis(); ObjectSerializable.toXML(joe); long end = System.currentTimeMillis(); System.out.println("执行bboss beantoxml 1次,耗时:" + (end - start) + "毫秒"); convertBeanToXml(10, joe); convertBeanToXml(100, joe); convertBeanToXml(1000, joe); convertBeanToXml(10000, joe); System.out.println(); System.out.println("xstream序列化测试用例开始"); System.out.println(); start = System.currentTimeMillis(); xStream.toXML(joe); end = System.currentTimeMillis(); System.out.println("执行XStream beantoxml 1次,耗时:" + (end - start) + "毫秒"); convertBeanToXStreamXml(10, joe); convertBeanToXStreamXml(100, joe); convertBeanToXStreamXml(1000, joe); convertBeanToXStreamXml(10000, joe); System.out.println(); System.out.println("bboss反序列化测试用例开始"); System.out.println(); start = System.currentTimeMillis(); person = ObjectSerializable.toBean(xml, Person.class); end = System.currentTimeMillis(); System.out.println("执行bboss xmltobean 1次,耗时:" + (end - start) + "豪秒"); convertXMLToBean(10, xml); convertXMLToBean(100, xml); convertXMLToBean(1000, xml); convertXMLToBean(10000, xml); System.out.println(); System.out.println("xstream反序列化测试用例开始"); System.out.println(); start = System.currentTimeMillis(); xStream.fromXML(xmlXstream); end = System.currentTimeMillis(); System.out.println("执行XStream xmltobean 1次,耗时:" + (end - start) + "豪秒"); convertXStreamXMLToBean(10, xmlXstream); convertXStreamXMLToBean(100, xmlXstream); convertXStreamXMLToBean(1000, xmlXstream); convertXStreamXMLToBean(10000, xmlXstream); // 测试用例结束 } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } }
public void testDirtyButNotDirty() throws Exception { EntityManager manager = getOrCreateEntityManager(); manager.getTransaction().begin(); Employee mark = new Employee(); mark.setName("Mark"); mark.setTitle("internal sales"); mark.setSex('M'); mark.setAddress("buckhead"); mark.setZip("30305"); mark.setCountry("USA"); Customer joe = new Customer(); joe.setName("Joe"); joe.setSex('M'); joe.setAddress("San Francisco"); joe.setZip("XXXXX"); joe.setCountry("USA"); joe.setComments("Very demanding"); joe.setSalesperson(mark); Person yomomma = new Person(); yomomma.setName("mum"); yomomma.setSex('F'); manager.persist(mark); manager.persist(joe); manager.persist(yomomma); long[] ids = {mark.getId(), joe.getId(), yomomma.getId()}; manager.getTransaction().commit(); manager.getTransaction().begin(); assertEquals( manager .createQuery("select p.address, p.name from Person p order by p.name") .getResultList() .size(), 3); assertEquals( manager .createQuery("select p from Person p where p.class = Customer") .getResultList() .size(), 1); manager.getTransaction().commit(); manager.getTransaction().begin(); List customers = manager .createQuery("select c from Customer c left join fetch c.salesperson") .getResultList(); for (Iterator iter = customers.iterator(); iter.hasNext(); ) { Customer c = (Customer) iter.next(); assertEquals(c.getSalesperson().getName(), "Mark"); } assertEquals(customers.size(), 1); manager.getTransaction().commit(); manager.getTransaction().begin(); customers = manager.createQuery("select c from Customer c").getResultList(); for (Iterator iter = customers.iterator(); iter.hasNext(); ) { Customer c = (Customer) iter.next(); assertEquals(c.getSalesperson().getName(), "Mark"); } assertEquals(customers.size(), 1); manager.getTransaction().commit(); manager.getTransaction().begin(); mark = manager.find(Employee.class, new Long(ids[0])); joe = (Customer) manager.find(Customer.class, new Long(ids[1])); yomomma = manager.find(Person.class, new Long(ids[2])); mark.setZip("30306"); assertEquals( 1, manager.createQuery("select p from Person p where p.zip = '30306'").getResultList().size()); manager.remove(mark); manager.remove(joe); manager.remove(yomomma); assertTrue(manager.createQuery("select p from Person p").getResultList().isEmpty()); manager.getTransaction().commit(); manager.close(); }
public static synchronized void UpdatePerson(int id, Person person) { Person per = allPeople.get(id); per.setName(person.getName()); per.setSex(person.getSex()); per.setBirthDay(person.getBirthDay()); }