Package org.milowski.db

Examples of org.milowski.db.DBConnection


   }
  
   public void delete()
      throws SQLException
   {
      DBConnection connection = db.getConnection();
      try {
         connection.deleteById(AuthDB.DELETE_ROLE_PERMISSIONS_BY_PERMISSION, id);
         connection.deleteById(AuthDB.DELETE_PERMISSION, id);
         db.realmGroupCaches.clear();
         db.roleCache.clear();
         db.permissionCache.remove(id);
      } finally {
         db.release(connection);
View Full Code Here


   public void delete()
      throws SQLException
   {
      final DBCache<UUID,Group> groupCache = db.realmGroupCaches.get(this);
      final DBCache<UUID,RealmUser> userCache = db.realmUserCaches.get(this);
      DBConnection connection = db.getConnection();
      try {
         connection.query(AuthDB.GROUP_BY_REALM,new DBQueryHandler() {
            public void prepare(PreparedStatement s)
               throws SQLException
            {
               s.setInt(1,id);
            }
            public void onResults(ResultSet set)
               throws SQLException
            {
               while (set.next()) {
                  Group group = groupCache.get(set.getInt(1));
                  group.delete();
               }
            }
         });
         connection.query(AuthDB.REALM_USER_BY_REALM,new DBQueryHandler() {
            public void prepare(PreparedStatement s)
               throws SQLException
            {
               s.setInt(1,id);
            }
            public void onResults(ResultSet set)
               throws SQLException
            {
               while (set.next()) {
                  RealmUser user = userCache.get(set.getInt(1));
                  user.delete();
               }
            }
         });
         connection.deleteById(AuthDB.DELETE_AUTHENTICATED_BY_REALM, id);
         connection.deleteById(AuthDB.DELETE_REALM, id);
         db.realmCache.remove(id);
         db.realmUserCaches.remove(this);
         db.realmGroupCaches.remove(this);
      } finally {
         db.release(connection);
View Full Code Here

   }
  
   public void delete()
      throws SQLException
   {
      DBConnection connection = db.getConnection();
      try {
         connection.deleteById(AuthDB.DELETE_USER_ROLES_BY_USER, id);
         connection.deleteById(AuthDB.DELETE_AUTHENTICATION_BY_USER, id);
         connection.deleteById(AuthDB.DELETE_USER_ALIAS_BY_USER, id);
         connection.query(AuthDB.REALM_USERS_BY_USER, new DBQueryHandler() {
            public void prepare(PreparedStatement s)
               throws SQLException
            {
               s.setInt(1, id);
            }
            public void onResults(ResultSet set)
               throws SQLException
            {
               while (set.next()) {
                  Realm realm = db.realmCache.get(set.getInt(2));
                  RealmUser user = db.realmUserCaches.get(realm).get(set.getInt(1));
                  user.delete();
                  db.realmUserCaches.get(realm).remove(user.getId());
               }
            }
         });
         connection.deleteById(AuthDB.DELETE_USER, id);
         db.userCache.remove(id);
      } finally {
         db.release(connection);
      }
   }
View Full Code Here

      throws SQLException,NoSuchAlgorithmException
   {
      if (!algorithm.equals("md5")) {
         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 hasRole(final Role role)
      throws SQLException
   {
     
      final Slot<Boolean> hasRole = new Slot<Boolean>(false);
      DBConnection connection = db.getConnection();
      try {
         connection.query(AuthDB.USER_HAS_ROLE, new DBQueryHandler() {
            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

   public Iterator<Role> getRoles()
      throws SQLException
   {
      final Slot<Iterator<Role>> result = new Slot<Iterator<Role>>();
      final DBConnection connection = db.getConnection();
      try {
         connection.query(AuthDB.USER_ROLES, new DBQueryHandler() {
         public boolean shouldClose() { return false; }
            public void prepare(PreparedStatement s)
               throws SQLException
            {
               s.setInt(1,id);
View Full Code Here

  
   public boolean changeAlias(final String alias)
      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

TOP

Related Classes of org.milowski.db.DBConnection

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.