ORCentral

src/eu/coform/database/command/CheckLocationDBCommand.java

Go to the documentation of this file.
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 CheckLocationDBCommand implements ResultDatabaseCommand {
00015 
00016    private Location loc;
00017    private long result = 0;
00018    public CheckLocationDBCommand(Location loc){
00019       this.loc = loc;
00020    }
00021    
00027    @Override
00028    public void exec() throws DBException {
00029       Query query = Database.getInstance().getNewQuery();
00030       query.setQuery("SELECT uuidtable.ID from uuidtable, location WHERE uuidtable.ID = location.ID and Name = '" + loc.getName() + "'");
00031       
00032       ResultSet set = Database.getInstance().query(query);
00033 
00034       try {
00035          if (!(set.isBeforeFirst() && set.isAfterLast()))
00036             set.next();
00037          else
00038             assert(false);
00039          result = set.getInt("ID");
00040       } catch (IllegalArgumentException e) {
00041          throw new DBException(DBException.Error.QueryInvalid);
00042       } catch (SQLException e) {
00043          throw new DBException(DBException.Error.ObjectNotFound);
00044       }
00045 
00046    }
00047    @Override
00048    public Long getResult() {
00049       return new Long(result);
00050    }
00051 
00052 }
 All Classes Namespaces Files Functions Variables Enumerations