Package org.milowski.db

Examples of org.milowski.db.DBConnection


         return false;
      }
      if (this.alias==null) {
         // Only set the realm user's alias if the alias is not null
         if (alias!=null) {
            DBConnection connection = db.getConnection();
            try {
               connection.update(AuthDB.CREATE_REALM_USER_ALIAS, new DBUpdateHandler() {
                  public void prepare(PreparedStatement s)
                     throws SQLException
                  {
                     s.setInt(1,id);
                     s.setString(2,alias);
                     s.setString(3,id+"-"+alias);
                  }
               });
            } finally {
               db.release(connection);
            }
         }
      } else {
         if (alias!=null) {
            // just update
            DBConnection connection = db.getConnection();
            try {
               connection.update(AuthDB.UPDATE_REALM_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 {
            // alias is null, delete so we inherit
            DBConnection connection = db.getConnection();
            try {
               connection.deleteById(AuthDB.DELETE_REALM_USER_ALIAS, id);
            } finally {
               db.release(connection);
            }
         }
      }
View Full Code Here


   {
      boolean result = user.hasRole(role);
      if (!result) {
         final Slot<Boolean> found = new Slot<Boolean>(Boolean.FALSE);
         final DBCache<UUID,Group> cache = db.realmGroupCaches.get(realm);
         DBConnection connection = db.getConnection();
         try {
            connection.query(AuthDB.GROUP_BY_REALM_USER, new DBQueryHandler() {
               public void prepare(PreparedStatement s)
                  throws SQLException
               {
                  s.setInt(1,realm.getId());
                  s.setInt(2,id);
View Full Code Here

   public Iterator<Group> getGroups()
      throws SQLException
   {
      final Slot<Iterator<Group>> result = new Slot<Iterator<Group>>();
      final DBCache<UUID,Group> cache = db.realmGroupCaches.get(realm);
      final DBConnection connection = db.getConnection();
      try {
         connection.query(AuthDB.GROUP_BY_REALM_USER, new DBQueryHandler() {
            public boolean shouldClose() {
               return false;
            }
            public void prepare(PreparedStatement s)
               throws SQLException
View Full Code Here

   {
      if (name!=null && name.equals(user.getName())) {
         name = null;
      }
      final String theName = name;
      DBConnection connection = db.getConnection();
      try {
         connection.update(AuthDB.CHANGE_REALM_USER_NAME, new DBUpdateHandler() {
            public void prepare(PreparedStatement s)
               throws SQLException
            {
               if (theName==null) {
                  s.setNull(1,Types.VARCHAR);
View Full Code Here

   {
      if (email!=null && email.equals(user.getEmail())) {
         email = null;
      }
      final String theEmail = email;
      DBConnection connection = db.getConnection();
      try {
         connection.update(AuthDB.CHANGE_REALM_USER_EMAIL, new DBUpdateHandler() {
            public void prepare(PreparedStatement s)
               throws SQLException
            {
               if (theEmail==null) {
                  s.setNull(1,Types.VARCHAR);
View Full Code Here

         throws SQLException
      {
         final User user = userCache.get(id);
         if (user!=null) {
            final Slot<RealmUser> u = new Slot<RealmUser>();
            final DBConnection connection = getConnection();
            try {
               connection.query(REALM_USER_BY_USER, new DBQueryHandler() {
                  public void prepare(PreparedStatement s)
                     throws SQLException
                  {
                     s.setInt(1,realm.getId());
                     s.setInt(2,user.getId());
                  }
                  public void onResults(ResultSet set)
                     throws SQLException
                  {
                     if (set.next()) {
                        final int rid = set.getInt(1);
                        final Slot<String> alias = new Slot<String>();
                        connection.query(REALM_USER_ALIAS, new DBQueryHandler() {
                           public void prepare(PreparedStatement s)
                              throws SQLException
                           {
                              s.setInt(1,rid);
                           }
View Full Code Here

      }
      protected RealmUser fetchById(final Integer id)
         throws SQLException
      {
         final Slot<RealmUser> u = new Slot<RealmUser>();
         final DBConnection connection = getConnection();
         try {
            connection.query(REALM_USER, new DBQueryHandler() {
               public void prepare(PreparedStatement s)
                  throws SQLException
               {
                  s.setInt(1,id.intValue());
               }
               public void onResults(ResultSet set)
                  throws SQLException
               {
                  if (set.next()) {
                     final Slot<String> alias = new Slot<String>();
                     connection.query(REALM_USER_ALIAS, new DBQueryHandler() {
                        public void prepare(PreparedStatement s)
                           throws SQLException
                        {
                           s.setInt(1,id);
                        }
View Full Code Here

      protected RealmUser fetchByName(final String name)
         throws SQLException
      {
         final Slot<RealmUser> u = new Slot<RealmUser>();

         final DBConnection connection = getConnection();
         try {
            connection.query(REALM_USER_BY_ALIAS, new DBQueryHandler() {
               public void prepare(PreparedStatement s)
                  throws SQLException
               {
                  s.setInt(1,realm.getId());
                  s.setString(2,name);
               }
               public void onResults(ResultSet set)
                  throws SQLException
               {
                  if (set.next()) {
                     User user = userCache.get(set.getInt(2));
                     u.set(new RealmUser(AuthDB.this,set.getInt(1),realm,user,name,set.getString(3),set.getString(4)));
                  }
               }
            });
         } finally {
            release(connection);
         }
        
         if (u.get()==null) {
            final User user = userCache.getNamed(name);
            if (user!=null) {
               final DBConnection connection2 = getConnection();
               try {
                  connection2.query(REALM_USER_BY_INHERITED_ALIAS, new DBQueryHandler() {
                     public void prepare(PreparedStatement s)
                        throws SQLException
                     {
                        s.setInt(1,realm.getId());
                        s.setInt(2,user.getId());
View Full Code Here

      }
      protected Group fetch(final UUID id)
         throws SQLException
      {
         final Slot<Group> g = new Slot<Group>();
         DBConnection connection = getConnection();
         try {
            connection.query(GROUP_BY_UUID, new DBQueryHandler() {
               public void prepare(PreparedStatement s)
                  throws SQLException
               {
                  s.setInt(1,realm.getId());
                  s.setString(2,id.toString());
View Full Code Here

      }
      protected Group fetchById(final Integer id)
         throws SQLException
      {
         final Slot<Group> g = new Slot<Group>();
         DBConnection connection = getConnection();
         try {
            connection.query(GROUP_BY_ID, new DBQueryHandler() {
               public void prepare(PreparedStatement s)
                  throws SQLException
               {
                  s.setInt(1,realm.getId());
                  s.setInt(2,id);
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.