ORCentral

src/eu/coform/database/command/UserIdForSessDBCommand.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.Session;
00007 import eu.coform.database.DBException;
00008 import eu.coform.database.Database;
00009 import eu.coform.database.Query;
00010 
00014 public class UserIdForSessDBCommand implements DatabaseCommand {
00015 
00016    private Session session;
00017    private int result;
00018    public UserIdForSessDBCommand(Session session){
00019       this.session = session;
00020    }
00026    @Override
00027    public void exec() throws DBException {
00028       // TODO testing
00029       ResultSet set = null;
00030       Query query = Database.getInstance().getNewQuery();
00031       query.setQuery("SELECT UserID FROM session WHERE UUID = " +
00032                 "UNHEX('"+session.getSessionID().toBin16()+"')");
00033       set = Database.getInstance().query(query);
00034 
00035       try {
00036          if (!(set.isBeforeFirst() && set.isAfterLast()))
00037             set.next();
00038          else
00039             assert(false);
00040          result = set.getInt("UserID"); // only one row, so select first
00041       } catch (IllegalArgumentException e) {
00042          throw new DBException(DBException.Error.QueryInvalid);
00043       } catch (SQLException e) {
00044          throw new DBException(DBException.Error.ObjectNotFound);
00045       }
00046    }
00047    
00048    public int getResult() {
00049       return result;
00050    }
00051 
00052 }
 All Classes Namespaces Files Functions Variables Enumerations