1 package phoneList.business; 2 3 import java.util.Vector ; 4 import java.sql.SQLException ; 5 import phoneList.data.*; 6 import org.enhydra.dods.DODS; 7 import com.lutris.appserver.server.Enhydra; 8 import com.lutris.appserver.server.sql.DatabaseManager; 9 import com.lutris.appserver.server.sql.DBConnection; 10 import com.lutris.appserver.server.sql.DBQuery; 11 import com.lutris.appserver.server.sql.DBTransaction; 12 import com.lutris.appserver.server.sql.ObjectId; 13 14 import phoneList.spec.*; 15 19 public class PhoneListImpl implements PhoneList { 20 21 31 public Vector [] getLists() throws Exception { 32 Vector [] results = new Vector [4]; 33 results[0] = new Vector (); 34 results[1] = new Vector (); 35 results[2] = new Vector (); 36 results[3] = new Vector (); 37 38 PersonQuery personQuery = new PersonQuery(); 39 PersonDO[] personDOs = personQuery.getDOArray(); 40 PersonDO personX =null; 41 if (personDOs.length>0){ 42 for (int i=0 ; i<personDOs.length; i++){ 43 results[0].addElement(personDOs[i].getFirstName()); 44 results[1].addElement(personDOs[i].getLastName()); 45 results[2].addElement(personDOs[i].getPhoneNumber()); 46 results[3].addElement("" + personDOs[i].get_Handle()); 47 } 48 } 49 return results; 50 } 51 52 64 public void addPerson(String firstName, 65 String lastName, 66 String phoneNumber) 67 throws Exception { 68 PersonDO newGuy = PersonDO.createVirgin(); 69 newGuy.setFirstName(firstName); 70 newGuy.setLastName(lastName); 71 newGuy.setPhoneNumber(phoneNumber); 72 newGuy.save(); 73 newGuy.commit(); 74 } 75 76 85 public void deletePerson(String id) throws Exception { 86 PersonDO personDO = getPersonDOById(id); 87 if (personDO == null) { 88 return; 89 } 90 personDO.delete(); 93 94 } 95 96 108 public void modifyPerson(String id, 109 String newFirstName, 110 String newLastName, 111 String newPhoneNumber) 112 throws Exception { 113 PersonDO personDO = getPersonDOById(id); 114 if (personDO == null) return; 115 personDO.setFirstName(newFirstName); 116 personDO.setLastName(newLastName); 117 personDO.setPhoneNumber(newPhoneNumber); 118 personDO.save(); 121 personDO.commit(); 122 123 } 124 125 132 public Person getById(String id) throws Exception { 133 PersonDO personDO = getPersonDOById(id); 134 if (personDO == null) { 135 return null; 136 } 137 return new PersonImpl(personDO); 138 } 139 140 147 148 public static String [] getPersonData(String id) throws Exception { 149 PersonDO personDO = getPersonDOById(id); 150 if (personDO == null) { 151 return null; 152 } 153 String personData[]=new String [3]; 154 personData[0]=personDO.getFirstName(); 155 personData[1]=personDO.getLastName(); 156 personData[2]=personDO.getPhoneNumber(); 157 return personData; 158 } 159 160 167 private static PersonDO getPersonDOById(String id) throws Exception { 168 ObjectId oid = new ObjectId(id); 169 PersonQuery personQuery = new PersonQuery(); 170 personQuery.setQueryOId(oid); 171 PersonDO personX = personQuery.getNextDO(); 172 return personX ; 173 } 174 175 } 176 177 | Popular Tags |