ORCentral
|
00001 package eu.coform.database.command; 00002 00003 import java.sql.ResultSet; 00004 import java.sql.SQLException; 00005 import java.util.Vector; 00006 00007 import eu.coform.Location; 00008 import eu.coform.database.DBException; 00009 import eu.coform.database.Database; 00010 import eu.coform.database.Query; 00011 00015 public class AllLocationsFromDBCommand implements DatabaseCommand { 00016 00017 private Vector<Location> result; 00018 public AllLocationsFromDBCommand(){ 00019 result = new Vector<Location>(); 00020 } 00021 00027 @Override 00028 public void exec() throws DBException { 00029 ResultSet rs_locations = null; 00030 UniqueIDFromDBCommand uniqueidcom = null; 00031 Location temp_loc = null; 00032 int temp_id = 0; 00033 00034 Query newLocationNameQuery = Database.getInstance().getNewQuery(); 00035 newLocationNameQuery.setQuery("SELECT * FROM location"); 00036 rs_locations = Database.getInstance().query(newLocationNameQuery); 00037 try{ 00038 while(rs_locations.next()){ 00039 temp_loc = new Location(); 00040 temp_loc.setName(rs_locations.getString("Name")); 00041 temp_loc.setWebserviceURL(rs_locations.getString("WebserviceURL")); 00042 temp_id = rs_locations.getInt("ID"); 00043 uniqueidcom = new UniqueIDFromDBCommand(new Integer(temp_id).toString()); 00044 uniqueidcom.exec(); 00045 temp_loc.setLocationId(uniqueidcom.getResult()); 00046 result.add(temp_loc); 00047 } 00048 }catch(SQLException u) { 00049 throw new DBException(DBException.Error.ObjectNotFound); 00050 } 00051 00052 } 00053 00054 public Location[] getResult() { 00055 return result.toArray(new Location[result.size()]); 00056 } 00057 00058 }