ORCentral

src/eu/coform/database/command/IntIDDBCommand.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 IntIDDBCommand implements DatabaseCommand {
00015 
00016    private UniqueID id;
00017    private int result = 0;
00018    public IntIDDBCommand(UniqueID id){
00019       this.id = id;
00020    }
00026    @Override
00027    public void exec() throws DBException {
00028       Query query = Database.getInstance().getNewQuery();
00029       query.setQuery("SELECT ID from `uuidtable` WHERE UUID = UNHEX('" + id.toBin16() + "')");
00030       
00031       ResultSet set = Database.getInstance().query(query);
00032 
00033       try {
00034          if (!(set.isBeforeFirst() && set.isAfterLast()))
00035             set.next();
00036          else
00037             assert(false);
00038          result = set.getInt("ID");
00039       } catch (IllegalArgumentException e) {
00040          throw new DBException(DBException.Error.QueryInvalid);
00041       } catch (SQLException e) {
00042          throw new DBException(DBException.Error.ObjectNotFound);
00043       }
00044 
00045    }
00046    public int getResult() {
00047       return result;
00048    }
00049 
00050 }
 All Classes Namespaces Files Functions Variables Enumerations