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