ORCentral
|
00001 package eu.coform.database.command; 00002 00003 import java.sql.ResultSet; 00004 import java.sql.SQLException; 00005 00006 import eu.coform.database.DBException; 00007 import eu.coform.database.Database; 00008 import eu.coform.database.Query; 00009 00010 public class CheckLocationSessionExistsDBCommand implements ResultDatabaseCommand { 00011 00012 private boolean exists; 00013 private long userId; 00014 private long locationId; 00015 00016 public CheckLocationSessionExistsDBCommand(long userId, long locationId){ 00017 this.userId = userId; 00018 this.locationId = locationId; 00019 00020 } 00026 @Override 00027 public void exec() throws DBException { 00028 Query query = Database.getInstance().getNewQuery(); 00029 00030 ResultSet set; 00031 00032 00033 try { 00034 query.setQuery("SELECT UserID FROM session where UserID = "+ userId + " and LocationID = " + locationId); 00035 set = Database.getInstance().query(query); 00036 if (set.next()) { 00037 exists = true; 00038 } 00039 else 00040 { 00041 exists = false; 00042 } 00043 00044 00045 } catch (IllegalArgumentException e) { 00046 throw new DBException(DBException.Error.QueryInvalid); 00047 } catch (SQLException e) { 00048 throw new DBException(DBException.Error.ObjectNotFound); 00049 } 00050 00051 } 00052 @Override 00053 public Boolean getResult() { 00054 return new Boolean(exists); 00055 } 00056 00057 }