Package org.milowski.db

Examples of org.milowski.db.DBUpdateHandler


         throw new NoSuchAlgorithmException("Algorithm "+algorithm+" is not supported.");
      }
      DBConnection connection = db.getConnection();
      try {
         connection.deleteById(AuthDB.DELETE_AUTHENTICATION_BY_USER, id);
         connection.create(AuthDB.CREATE_AUTHENTICATION, -1,new DBUpdateHandler() {
            public void prepare(PreparedStatement s)
               throws SQLException
            {
               s.setInt(1,id);
               s.setString(2,value);
View Full Code Here


   public void addRole(final Role role)
      throws SQLException
   {
      DBConnection connection = db.getConnection();
      try {
         connection.update(AuthDB.DELETE_USER_ROLE, new DBUpdateHandler() {
            public void prepare(PreparedStatement s)
               throws SQLException
            {
               s.setInt(1,id);
               s.setInt(2,role.getId());
            }
         });
         connection.update(AuthDB.ADD_USER_ROLE, new DBUpdateHandler() {
            public void prepare(PreparedStatement s)
               throws SQLException
            {
               s.setInt(1,id);
               s.setInt(2,role.getId());
View Full Code Here

   public boolean removeRole(final Role role)
      throws SQLException
   {
      DBConnection connection = db.getConnection();
      try {
         return connection.update(AuthDB.USER_HAS_ROLE, new DBUpdateHandler() {
            public void prepare(PreparedStatement s)
               throws SQLException
            {
               s.setInt(1,id);
               s.setInt(2,role.getId());
View Full Code Here

      throws SQLException
   {
      if (alias==null && this.alias!=null) {
         DBConnection connection = db.getConnection();
         try {
            connection.update(AuthDB.DELETE_USER_ALIAS, new DBUpdateHandler() {
               public void prepare(PreparedStatement s)
                  throws SQLException
               {
                  s.setInt(1,id);
               }
            });
         } finally {
            db.release(connection);
         }
         this.alias = null;
         db.userCache.removeByName(this.alias);
         return true;
      }
      if (alias.equals(this.alias)) {
         return true;
      }
      if (!db.isUserAliasAvailable(alias)) {
         return false;
      }
      if (this.alias!=null) {
         db.userCache.removeByName(this.alias);
         DBConnection connection = db.getConnection();
         try {
            connection.update(AuthDB.CHANGE_USER_ALIAS, new DBUpdateHandler() {
               public void prepare(PreparedStatement s)
                  throws SQLException
               {
                  s.setString(1,alias);
                  s.setString(2,id+"-"+alias);
                  s.setInt(3,id);
               }
            });
         } finally {
            db.release(connection);
         }
      } else {
         DBConnection connection = db.getConnection();
         try {
            connection.update(AuthDB.CREATE_USER_ALIAS, new DBUpdateHandler() {
               public void prepare(PreparedStatement s)
                  throws SQLException
               {
                  s.setInt(1,id);
                  s.setString(2,alias);
View Full Code Here

   public void setName(final String name)
      throws SQLException
   {
      DBConnection connection = db.getConnection();
      try {
         connection.update(AuthDB.CHANGE_USER_NAME, new DBUpdateHandler() {
            public void prepare(PreparedStatement s)
               throws SQLException
            {
               if (name==null) {
                  s.setNull(1,Types.VARCHAR);
View Full Code Here

   public void setEmail(final String email)
      throws SQLException
   {
      DBConnection connection = db.getConnection();
      try {
         connection.update(AuthDB.CHANGE_USER_NAME, new DBUpdateHandler() {
            public void prepare(PreparedStatement s)
               throws SQLException
            {
               if (email==null) {
                  s.setNull(1,Types.VARCHAR);
View Full Code Here

      if (session!=null) {
         // delete any session authentication information first
         if (realm==null) {
            DBConnection connection = db.getConnection();
            try {
               connection.update(AuthDB.DELETE_USER_AUTHENTICATION, new DBUpdateHandler() {
                  public void prepare(PreparedStatement s)
                     throws SQLException
                  {
                     s.setInt(1,id);
                     s.setString(2,session.toString());
                  }
               });
            } finally {
               db.release(connection);
            }
         } else {
            DBConnection connection = db.getConnection();
            try {
               connection.update(AuthDB.DELETE_REALM_USER_AUTHENTICATION, new DBUpdateHandler() {
                  public void prepare(PreparedStatement s)
                     throws SQLException
                  {
                     s.setInt(1,id);
                     s.setInt(2,realm.getId());
                     s.setString(3,session.toString());
                  }
               });
            } finally {
               db.release(connection);
            }
         }
      }

      // delete any expired sessions for the user
      final Timestamp created = new Timestamp(System.currentTimeMillis());
      DBConnection connection = db.getConnection();
      try {
         connection.update(AuthDB.DELETE_EXPIRED_SESSIONS, new DBUpdateHandler() {
            public void prepare(PreparedStatement s)
               throws SQLException
            {
               s.setInt(1,id);
               s.setTimestamp(2,created);
            }
         });
      } finally {
         db.release(connection);
      }
     
      // check the internal password
      if (checkPassword(password)) {
         // We have the correct password
         int dbid = -1;
         if (expires>0) {
            //construct an auth record with a session id
            final UUID theSession = session==null ? UUID.randomUUID() : session;
            final Timestamp expiration = new Timestamp(created.getTime()+expires);
            connection = db.getConnection();
            try {
               connection.update(AuthDB.CREATE_AUTHENTICATED, new DBUpdateHandler() {
                  public void prepare(PreparedStatement s)
                     throws SQLException
                  {
                     s.setInt(1,id);
                     if (realm==null) {
View Full Code Here

      // delete any expired sessions for the user
      final Timestamp created = new Timestamp(System.currentTimeMillis());
      DBConnection connection = db.getConnection();
      try {
         connection.update(AuthDB.DELETE_EXPIRED_SESSIONS, new DBUpdateHandler() {
            public void prepare(PreparedStatement s)
               throws SQLException
            {
               s.setInt(1,id);
               s.setTimestamp(2,created);
            }
         });
      } finally {
         db.release(connection);
      }
     
      int dbid = -1;
      if (expires>0) {
         //construct an auth record with a session id
         final UUID session = UUID.randomUUID();
         final Timestamp expiration = new Timestamp(created.getTime()+expires);
         connection = db.getConnection();
         try {
            connection.update(AuthDB.CREATE_AUTHENTICATED, new DBUpdateHandler() {
               public void prepare(PreparedStatement s)
                  throws SQLException
               {
                  s.setInt(1,id);
                  if (realm==null) {
View Full Code Here

      if (permissions.contains(p)) {
         return true;
      }
      DBConnection connection = db.getConnection();
      try {
         connection.update(AuthDB.CREATE_ROLE_PERMISSION, new DBUpdateHandler() {
            public void prepare(PreparedStatement s)
               throws SQLException
            {
               s.setInt(1, id);
               s.setInt(2, p.getId());
View Full Code Here

   public boolean removePermission(final Permission p)
      throws SQLException
   {
      DBConnection connection = db.getConnection();
      try {
         connection.update(AuthDB.DELETE_ROLE_PERMISSION, new DBUpdateHandler() {
            public void prepare(PreparedStatement s)
               throws SQLException
            {
               s.setInt(1, id);
               s.setInt(2, p.getId());
View Full Code Here

TOP

Related Classes of org.milowski.db.DBUpdateHandler

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.