ORCentral

src/eu/coform/database/command/CheckPrimarySessionDBCommand.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 
00007 import eu.coform.database.DBException;
00008 import eu.coform.database.Database;
00009 import eu.coform.database.Query;
00010 
00011 public class CheckPrimarySessionDBCommand implements ResultDatabaseCommand {
00012 
00013    private boolean primary;     
00014    private long userId;
00015    
00016    public CheckPrimarySessionDBCommand(long userId){
00017       this.userId = userId;
00018    }
00019    @Override
00020    public void exec() throws DBException {
00021       Query query = Database.getInstance().getNewQuery();
00022        
00023       ResultSet set;
00024 
00025       
00026       try {
00027                   query.setQuery("SELECT UserID FROM session where Userid = "+ userId);
00028                   set = Database.getInstance().query(query);
00029                  if (set.next()) {
00030                          primary = false;
00031                  }
00032                  else
00033                  {
00034                          primary = true;
00035                  }
00036                     
00037 
00038       } catch (IllegalArgumentException e) {
00039          throw new DBException(DBException.Error.QueryInvalid);
00040       } catch (SQLException e) {
00041          throw new DBException(DBException.Error.ObjectNotFound);
00042       }
00043 
00044    }
00045    @Override
00046    public Boolean getResult() {
00047       return new Boolean(primary);      
00048    }
00049 
00050 }
00051 
 All Classes Namespaces Files Functions Variables Enumerations