Package org.milowski.db

Examples of org.milowski.db.DBConnection


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


      permissionCache = new DBCache<UUID,Permission>(-1,EXPIRATION,true) {
         protected Permission fetch(final UUID id)
            throws SQLException
         {
            final Slot<Permission> p = new Slot<Permission>();
            DBConnection connection = getConnection();
            try {
               connection.query(PERMISSION_BY_UUID, new DBQueryHandler() {
                  public void prepare(PreparedStatement s)
                     throws SQLException
                  {
                     s.setString(1,id.toString());
                  }
                  public void onResults(ResultSet set)
                     throws SQLException
                  {
                     if (set.next()) {
                        p.set(new Permission(AuthDB.this,set.getInt(1),set.getString(2),id));
                     }
                  }
               });
            } finally {
               release(connection);
            }
            return p.get();
         }
         protected Permission fetchById(final Integer id)
            throws SQLException
         {
            final Slot<Permission> p = new Slot<Permission>();
            DBConnection connection = getConnection();
            try {
               connection.query(PERMISSION_BY_ID, new DBQueryHandler() {
                  public void prepare(PreparedStatement s)
                     throws SQLException
                  {
                     s.setInt(1,id);
                  }
                  public void onResults(ResultSet set)
                     throws SQLException
                  {
                     if (set.next()) {
                        p.set(new Permission(AuthDB.this,set.getInt(1),set.getString(2),UUID.fromString(set.getString(3))));
                     }
                  }
               });
            } finally {
               release(connection);
            }
            return p.get();
         }
         protected Permission fetchByName(final String name)
            throws SQLException
         {
            final Slot<Permission> p = new Slot<Permission>();
            DBConnection connection = getConnection();
            try {
               connection.query(PERMISSION_BY_NAME, new DBQueryHandler() {
                  public void prepare(PreparedStatement s)
                     throws SQLException
                  {
                     s.setString(1,name);
                  }
                  public void onResults(ResultSet set)
                     throws SQLException
                  {
                     if (set.next()) {
                        p.set(new Permission(AuthDB.this,set.getInt(1),set.getString(2),UUID.fromString(set.getString(3))));
                     }
                  }
               });
            } finally {
               release(connection);
            }
            return p.get();
         }
        
         protected int getId(Permission p) {
            return p.getId();
         }
        
         protected UUID getFacet(Permission p) {
            return p.getUUID();
         }
         protected String getName(Permission r) {
            return r.getName();
         }
      };
      roleCache = new DBCache<UUID,Role>(-1,EXPIRATION,true) {
         protected Role fetch(final UUID id)
            throws SQLException
         {
            final Slot<Role> r = new Slot<Role>();
            DBConnection connection = getConnection();
            try {
               connection.query(ROLE_BY_UUID, new DBQueryHandler() {
                  public void prepare(PreparedStatement s)
                     throws SQLException
                  {
                     s.setString(1,id.toString());
                  }
                  public void onResults(ResultSet set)
                     throws SQLException
                  {
                     if (set.next()) {
                        r.set(new Role(AuthDB.this,set.getInt(1),set.getString(2),id));
                     }
                  }
               });
            } finally {
               release(connection);
            }
            return r.get();
         }
         protected Role fetchById(final Integer id)
            throws SQLException
         {
            final Slot<Role> r = new Slot<Role>();
            DBConnection connection = getConnection();
            try {
               connection.query(ROLE_BY_ID, new DBQueryHandler() {
                  public void prepare(PreparedStatement s)
                     throws SQLException
                  {
                     s.setInt(1,id);
                  }
                  public void onResults(ResultSet set)
                     throws SQLException
                  {
                     if (set.next()) {
                        r.set(new Role(AuthDB.this,set.getInt(1),set.getString(2),UUID.fromString(set.getString(3))));
                     }
                  }
               });
            } finally {
               release(connection);
            }
            return r.get();
        }
         protected Role fetchByName(final String name)
            throws SQLException
         {
            final Slot<Role> r = new Slot<Role>();
            DBConnection connection = getConnection();
            try {
               connection.query(ROLE_BY_NAME, new DBQueryHandler() {
                  public void prepare(PreparedStatement s)
                     throws SQLException
                  {
                     s.setString(1,name);
                  }
                  public void onResults(ResultSet set)
                     throws SQLException
                  {
                     if (set.next()) {
                        r.set(new Role(AuthDB.this,set.getInt(1),set.getString(2),UUID.fromString(set.getString(3))));
                     }
                  }
               });
            } finally {
               release(connection);
            }
            return r.get();
         }
        
         protected int getId(Role r) {
            return r.getId();
         }
        
         protected UUID getFacet(Role r) {
            return r.getUUID();
         }
         protected String getName(Role r) {
            return r.getName();
         }
      };
      realmCache = new DBCache<UUID,Realm>(-1,EXPIRATION,true) {
         protected Realm fetch(final UUID id)
            throws SQLException
         {
            final Slot<Realm> r = new Slot<Realm>();
            DBConnection connection = getConnection();
            try {
               connection.query(REALM_BY_UUID, new DBQueryHandler() {
                  public void prepare(PreparedStatement s)
                     throws SQLException
                  {
                     s.setString(1,id.toString());
                  }
                  public void onResults(ResultSet set)
                     throws SQLException
                  {
                     if (set.next()) {
                        r.set(new Realm(AuthDB.this,set.getInt(1),set.getString(2),id));
                     }
                  }
               });
            } finally {
               release(connection);
            }
            return r.get();
         }
         protected Realm fetchById(final Integer id)
            throws SQLException
         {
            final Slot<Realm> r = new Slot<Realm>();
            DBConnection connection = getConnection();
            try {
               connection.query(REALM_BY_ID, new DBQueryHandler() {
                  public void prepare(PreparedStatement s)
                     throws SQLException
                  {
                     s.setInt(1,id);
                  }
                  public void onResults(ResultSet set)
                     throws SQLException
                  {
                     if (set.next()) {
                        r.set(new Realm(AuthDB.this,set.getInt(1),set.getString(2),UUID.fromString(set.getString(3))));
                     }
                  }
               });
            } finally {
               release(connection);
            }
            return r.get();
        }
         protected Realm fetchByName(final String name)
            throws SQLException
         {
            final Slot<Realm> r = new Slot<Realm>();
            DBConnection connection = getConnection();
            try {
               connection.query(REALM_BY_NAME, new DBQueryHandler() {
                  public void prepare(PreparedStatement s)
                     throws SQLException
                  {
                     s.setString(1,name);
                  }
                  public void onResults(ResultSet set)
                     throws SQLException
                  {
                     if (set.next()) {
                        r.set(new Realm(AuthDB.this,set.getInt(1),set.getString(2),UUID.fromString(set.getString(3))));
                     }
                  }
               });
            } finally {
               release(connection);
            }
            return r.get();
         }
        
         protected int getId(Realm r) {
            return r.getId();
         }
        
         protected UUID getFacet(Realm r) {
            return r.getUUID();
         }
        
         protected String getName(Realm r) {
            return r.getName();
         }
      };
     
      userCache = new DBCache<UUID,User>(100,EXPIRATION,true) {
         protected User fetch(final UUID id)
            throws SQLException
         {
            final Slot<User> u = new Slot<User>();
            DBConnection connection = getConnection();
            try {
               connection.query(USER_BY_UUID, new DBQueryHandler() {
                  public void prepare(PreparedStatement s)
                     throws SQLException
                  {
                     s.setString(1,id.toString());
                  }
                  public void onResults(ResultSet set)
                     throws SQLException
                  {
                     if (set.next()) {
                        int uid = set.getInt(1);
                        String alias = getUserAlias(uid);
                        u.set(new User(AuthDB.this,uid,id,alias,set.getString(2),set.getString(3)));
                     }
                  }
               });
            } finally {
               release(connection);
            }
            return u.get();
         }
         protected User fetchById(final Integer id)
            throws SQLException
         {
            final Slot<User> u = new Slot<User>();
            DBConnection connection = getConnection();
            try {
               connection.query(USER_BY_ID, new DBQueryHandler() {
                  public void prepare(PreparedStatement s)
                     throws SQLException
                  {
                     s.setInt(1,id.intValue());
                  }
                  public void onResults(ResultSet set)
                     throws SQLException
                  {
                     if (set.next()) {
                        int uid = set.getInt(1);
                        String alias = getUserAlias(uid);
                        u.set(new User(AuthDB.this,uid,UUID.fromString(set.getString(4)),alias,set.getString(2),set.getString(3)));
                     }
                  }
               });
            } finally {
               release(connection);
            }
            return u.get();
        }
         protected User fetchByName(final String name)
            throws SQLException
         {
            final Slot<User> u = new Slot<User>();
            DBConnection connection = getConnection();
            try {
               connection.query(USER_BY_ALIAS, new DBQueryHandler() {
                  public void prepare(PreparedStatement s)
                     throws SQLException
                  {
                     s.setString(1,name);
                  }
View Full Code Here

  
   public Permission createPermission(final String name,final UUID uuid)
      throws SQLException
   {
     
      DBConnection connection = getConnection();
      try {
         int id = connection.create(CREATE_PERMISSION,LAST_ID_FROM_PERMISSIONS, new DBUpdateHandler() {
            public void prepare(PreparedStatement s)
               throws SQLException
            {
               s.setString(1,name);
               s.setString(2,uuid.toString());
View Full Code Here

  
   public Iterator<Permission> getPermissions()
      throws SQLException
   {
      final Slot<Iterator<Permission>> result = new Slot<Iterator<Permission>>();
      final DBConnection connection = getConnection();
      try {
         connection.query(PERMISSIONS, new DBQueryHandler() {
            public boolean shouldClose() { return false; }
            public void onResults(ResultSet set)
               throws SQLException
            {
               result.set(new DBIterator<Permission>(set,new DBResultConstructor<Permission>() {
View Full Code Here

   }
  
   public Role createRole(final String name,final UUID uuid)
      throws SQLException
   {
      DBConnection connection = getConnection();
      try {
         int id = connection.create(CREATE_ROLE,LAST_ID_FROM_ROLES, new DBUpdateHandler() {
            public void prepare(PreparedStatement s)
               throws SQLException
            {
               s.setString(1,name);
               s.setString(2,uuid.toString());
View Full Code Here

  
   public Iterator<Role> getRoles()
      throws SQLException
   {
      final Slot<Iterator<Role>> result = new Slot<Iterator<Role>>();
      final DBConnection connection = getConnection();
      try {
         connection.query(ROLES, new DBQueryHandler() {
            public boolean shouldClose() { return false; }
            public void onResults(ResultSet set)
               throws SQLException
            {
               result.set(new DBIterator<Role>(set,new DBResultConstructor<Role>() {
View Full Code Here

   }
  
   public Realm createRealm(final String name,final UUID uuid)
      throws SQLException
   {
      DBConnection connection = getConnection();
      try {
         int id = connection.create(CREATE_REALM,LAST_ID_FROM_REALMS, new DBUpdateHandler() {
            public void prepare(PreparedStatement s)
               throws SQLException
            {
               s.setString(1,name);
               s.setString(2,uuid.toString());
View Full Code Here

  
   public Iterator<Realm> getRealms()
      throws SQLException
   {
      final Slot<Iterator<Realm>> result = new Slot<Iterator<Realm>>();
      final DBConnection connection = getConnection();
      try {
         connection.query(REALMS, new DBQueryHandler() {
            public boolean shouldClose() { return false; }
            public void onResults(ResultSet set)
               throws SQLException
            {
               result.set(new DBIterator<Realm>(set,new DBResultConstructor<Realm>() {
View Full Code Here

   public boolean isUserAliasAvailable(final String alias)
      throws SQLException
   {
      final Slot<Boolean> found = new Slot<Boolean>(false);
      if (alias!=null) {
         DBConnection connection = getConnection();
         try {
            connection.query(USER_ALIAS_EXISTS, new DBQueryHandler() {
               public void prepare(PreparedStatement s)
                  throws SQLException
               {
                  s.setString(1,alias);
               }
View Full Code Here

      if (!isUserAliasAvailable(alias)) {
         LOG.info("Alias "+alias+" is not available");
         return null;
      }
      final Timestamp tstamp = new Timestamp((new Date()).getTime());
      DBConnection connection = getConnection();
      try {
         int id = connection.create(CREATE_USER,LAST_ID_FROM_USERS, new DBUpdateHandler() {
            public void prepare(PreparedStatement s)
               throws SQLException
            {
               s.setString(1,uuid.toString());
               if (name==null) {
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.