ORCentral
|
00001 package eu.coform.command.location; 00002 00003 import java.sql.ResultSet; 00004 import java.sql.SQLException; 00005 00006 import eu.coform.Location; 00007 import eu.coform.ORException; 00008 import eu.coform.UniqueID; 00009 import eu.coform.Error; 00010 import eu.coform.command.QueryUniqueIDCommand; 00011 import eu.coform.command.proto.Abstract; 00012 import eu.coform.database.Database; 00013 import eu.coform.database.Query; 00014 00018 public class QueryLocationCommand implements AbstractSectionLocation { 00019 00020 private String locationName; 00021 private UniqueID locatioUUID; 00022 00023 @Override 00024 public Location execute() throws ORException { 00025 Query query = Database.getInstance().getNewQuery(); 00026 assert(query != null); 00027 if (!locationName.isEmpty()) 00028 query.setQuery("SELECT * from `location` WHERE Name = '" + locationName + "'"); 00029 else 00030 // TODO 00031 assert(false); 00032 assert(query != null); 00033 ResultSet set = Database.getInstance().query(query); 00034 00035 boolean empty = true; 00036 try { 00037 if (set.next()) 00038 empty = false; 00039 } catch (SQLException e) { 00040 // TODO Auto-generated catch block 00041 e.printStackTrace(); 00042 assert(false); 00043 } 00044 if (empty) 00045 throw new ORException(Error.LocationInvalid); 00046 00047 QueryUniqueIDCommand c = new QueryUniqueIDCommand(); 00048 00049 try { 00050 c.setId(set.getString("ID")); 00051 UniqueID u = c.execute(); 00052 00053 Location l = new Location(u, set.getString("Name"), set.getString("WebserviceURL")); 00054 return l; 00055 } catch (SQLException e) { 00056 // TODO Auto-generated catch block 00057 e.printStackTrace(); 00058 } 00059 00060 assert(false); 00061 return null; 00062 } 00063 00064 public String getLocationName() { 00065 return locationName; 00066 } 00067 00068 public void setLocationName(String locationName) { 00069 this.locationName = locationName; 00070 } 00071 00072 public void setLocatioUUID(UniqueID locatioUUID) { 00073 this.locatioUUID = locatioUUID; 00074 } 00075 00076 public UniqueID getLocatioUUID() { 00077 return locatioUUID; 00078 } 00079 00080 }