avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From co...@apache.org
Subject cvs commit: jakarta-avalon-apps/ftpserver/src/java/org/apache/avalon/ftpserver/usermanager DbUserManager.java
Date Tue, 30 Jul 2002 10:23:12 GMT
colus       2002/07/30 03:23:12

  Modified:    ftpserver/src/java/org/apache/avalon/ftpserver/usermanager
                        DbUserManager.java
  Log:
  Make sqls constant string.
  
  Revision  Changes    Path
  1.9       +25 -27    jakarta-avalon-apps/ftpserver/src/java/org/apache/avalon/ftpserver/usermanager/DbUserManager.java
  
  Index: DbUserManager.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-apps/ftpserver/src/java/org/apache/avalon/ftpserver/usermanager/DbUserManager.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- DbUserManager.java	22 May 2002 20:41:36 -0000	1.8
  +++ DbUserManager.java	30 Jul 2002 10:23:11 -0000	1.9
  @@ -47,8 +47,24 @@
    */
   public
   class DbUserManager extends AbstractUserManager {
  +    private static final String CREATE_USER_TABLE_SQL = "CREATE TABLE FTP_USER (" +
  +	"LOGIN_ID VARCHAR(64) NOT NULL PRIMARY KEY," +
  +	"PASSWORD VARCHAR(64)," +
  +	"HOME_DIR VARCHAR(128) NOT NULL," +
  +	"ENABLED VARCHAR(8) NOT NULL," +
  +	"WRITE_PERM VARCHAR(8) NOT NULL," +
  +	"IDLE_TIME INT NOT NULL," +
  +	"UPLOAD_RATE INT NOT NULL," +
  +	"DOWNLOAD_RATE INT NOT NULL" +
  +	")";
  +    private static final String COUNT_USERS_SQL = "SELECT COUNT(*) FROM FTP_USER";
  +    private static final String GET_ALL_USERS_SQL = "SELECT LOGIN_ID FROM FTP_USER";
  +    private static final String GET_USER_SQL = "SELECT * FROM FTP_USER WHERE LOGIN_ID =
?";
  +    private static final String NEW_USER_SQL = "INSERT INTO FTP_USER VALUES (?, ?, ?, ?,
?, ?, ?, ?)";
  +    private static final String UPDATE_USER_SQL = "UPDATE FTP_USER SET PASSWORD = ?, HOME_DIR
= ?, ENABLED = ?, WRITE_PERM = ?, IDLE_TIME = ?, UPLOAD_RATE = ?, DOWNLOAD_RATE = ? WHERE
LOGIN_ID = ?";
  +    private static final String DELETE_USER_SQL = "DELETE FROM FTP_USER WHERE LOGIN_ID
= ?";
   
  -    private Connection mDbConnection       = null;
  +    private Connection mDbConnection = null;
   
       private PreparedStatement mNewUserStmt = null;
       private PreparedStatement mDelUserStmt = null;
  @@ -85,11 +101,11 @@
               createTable();        
                   
               // prepare statements
  -            mDelUserStmt = mDbConnection.prepareStatement("DELETE FROM FTP_USER WHERE LOGIN_ID
= ?");
  -            mGetAllStmt  = mDbConnection.prepareStatement("SELECT LOGIN_ID FROM FTP_USER");
  -            mNewUserStmt = mDbConnection.prepareStatement("INSERT INTO FTP_USER VALUES
(?, ?, ?, ?, ?, ?, ?, ?)");
  -            mUpdUserStmt = mDbConnection.prepareStatement("UPDATE FTP_USER SET PASSWORD
= ?, HOME_DIR = ?, ENABLED = ?, WRITE_PERM = ?, IDLE_TIME = ?, UPLOAD_RATE = ?, DOWNLOAD_RATE
= ? WHERE LOGIN_ID = ?");
  -            mGetUserStmt = mDbConnection.prepareStatement("SELECT * FROM FTP_USER WHERE
LOGIN_ID = ?");
  +            mGetAllStmt = mDbConnection.prepareStatement( GET_ALL_USERS_SQL );
  +            mGetUserStmt = mDbConnection.prepareStatement( GET_USER_SQL );
  +            mNewUserStmt = mDbConnection.prepareStatement( NEW_USER_SQL );
  +            mUpdUserStmt = mDbConnection.prepareStatement( UPDATE_USER_SQL );
  +            mDelUserStmt = mDbConnection.prepareStatement( DELETE_USER_SQL );
               getLogger().info("Database user manager opened.");
           }
           catch(Exception ex) {
  @@ -106,9 +122,8 @@
           // check existance
           boolean bExist = false;
           try {
  -            String usrCnt = "SELECT COUNT(*) FROM FTP_USER";
               Statement stmt = mDbConnection.createStatement();
  -            ResultSet rs = stmt.executeQuery(usrCnt);
  +            ResultSet rs = stmt.executeQuery( COUNT_USERS_SQL );
               rs.close();
               stmt.close();
               bExist = true;
  @@ -122,21 +137,9 @@
           
           // table does not exist - trying to create
           getLogger().info("Table FTP_USER does non exist - creating table.");
  -        StringBuffer sb = new StringBuffer();
  -        sb.append("CREATE TABLE FTP_USER (\n"); 
  -        sb.append("  LOGIN_ID VARCHAR(64) NOT NULL PRIMARY KEY,\n");
  -        sb.append("  PASSWORD VARCHAR(64),\n");
  -        sb.append("  HOME_DIR VARCHAR(128) NOT NULL,\n");
  -        sb.append("  ENABLED VARCHAR(8) NOT NULL,\n");
  -        sb.append("  WRITE_PERM VARCHAR(8) NOT NULL,\n");
  -        sb.append("  IDLE_TIME INT NOT NULL,\n");             
  -        sb.append("  UPLOAD_RATE INT NOT NULL,\n");
  -        sb.append("  DOWNLOAD_RATE INT NOT NULL\n");
  -        sb.append(")\n");
  -        
  -        String sql = sb.toString();
  +
           Statement stmt = mDbConnection.createStatement();
  -        stmt.execute(sql);
  +        stmt.execute( CREATE_USER_TABLE_SQL );
           stmt.close();
       }
       
  @@ -344,8 +347,3 @@
       }
           
   }
  -
  -
  -
  -
  -
  
  
  

--
To unsubscribe, e-mail:   <mailto:avalon-cvs-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:avalon-cvs-help@jakarta.apache.org>


Mime
View raw message