1 4 package jspPhoneBook.business; 5 6 import java.util.Vector ; 7 import java.sql.SQLException ; 8 import jspPhoneBook.data.*; 9 import org.enhydra.dods.DODS; 10 import com.lutris.appserver.server.sql.*; 11 12 16 public class PersonList { 17 18 28 public static Vector [] getLists() throws Exception { 29 Vector [] results = new Vector [4]; 30 results[0] = new Vector (); 31 results[1] = new Vector (); 32 results[2] = new Vector (); 33 results[3] = new Vector (); 34 35 PersonQuery personQuery = new PersonQuery(); 36 PersonDO[] personDOs = personQuery.getDOArray(); 37 PersonDO personX =null; 38 if (personDOs.length>0){ 39 for (int i=0 ; i<personDOs.length; i++){ 40 results[0].addElement(personDOs[i].getFirstName()); 41 results[1].addElement(personDOs[i].getLastName()); 42 results[2].addElement(personDOs[i].getPhoneNumber()); 43 results[3].addElement("" + personDOs[i].get_Handle()); 44 } 45 } 46 return results; 47 } 48 49 61 public static void addPerson(String firstName, 62 String lastName, 63 String phoneNumber) 64 throws Exception { 65 PersonDO newGuy = PersonDO.createVirgin(); 68 newGuy.setFirstName(firstName); 69 newGuy.setLastName(lastName); 70 newGuy.setPhoneNumber(phoneNumber); 71 newGuy.save(); 72 newGuy.commit(); 73 } 83 84 93 public static void deletePerson(String id) throws Exception { 94 PersonDO personDO = getPersonDOById(id); 96 if (personDO == null) { 97 return; 98 } 99 personDO.delete(); 103 113 } 114 115 127 public static void modifyPerson(String id, 128 String newFirstName, 129 String newLastName, 130 String newPhoneNumber) 131 throws Exception { 132 PersonDO personDO = getPersonDOById(id); 134 if (personDO == null) return; 135 personDO.setFirstName(newFirstName); 136 personDO.setLastName(newLastName); 137 personDO.setPhoneNumber(newPhoneNumber); 138 personDO.save(); 142 personDO.commit(); 143 153 } 154 155 162 public static Person getById(String id) throws Exception { 163 PersonDO personDO = getPersonDOById(id); 164 if (personDO == null) { 165 return null; 166 } 167 return new Person(personDO); 168 } 169 170 177 private static PersonDO getPersonDOById(String id) throws Exception { 178 ObjectId oid = new ObjectId(id); 179 PersonQuery personQuery = new PersonQuery(); 180 personQuery.setQueryOId(oid); 181 PersonDO personX = personQuery.getNextDO(); 182 return personX ; 183 } 184 185 } 186 187 | Popular Tags |