ORCentral

src/eu/coform/database/command/UniqueIDFromDBCommand.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.UniqueID;
00007 import eu.coform.database.DBException;
00008 import eu.coform.database.Database;
00009 import eu.coform.database.Query;
00010 
00014 public class UniqueIDFromDBCommand implements DatabaseCommand  {
00015 
00016    UniqueID result = null;
00017    String id;
00018    
00019    public UniqueID getResult() {
00020       return result;
00021    }
00022    
00023    public UniqueIDFromDBCommand(String id){
00024       this.id = id;
00025    }
00031    @Override
00032    public void exec() throws DBException {
00033       Query query = Database.getInstance().getNewQuery();
00034       query.setQuery("SELECT hex(UUID) from `uuidtable` WHERE ID = '" + id + "'");
00035       
00036       ResultSet set = Database.getInstance().query(query);
00037 
00038       try {
00039          if (!(set.isBeforeFirst() && set.isAfterLast()))
00040             set.next();
00041          else
00042             assert(false);
00043          result = UniqueID.fromBin16(set.getString("hex(UUID)"));
00044       } catch (IllegalArgumentException e) {
00045          throw new DBException(DBException.Error.QueryInvalid);
00046       } catch (SQLException e) {
00047          throw new DBException(DBException.Error.ObjectNotFound);
00048       }
00049    }
00050 
00051 }
 All Classes Namespaces Files Functions Variables Enumerations