manifoldcf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kwri...@apache.org
Subject svn commit: r952617 - in /incubator/lcf/trunk/modules/framework/core/org/apache/lcf/core: database/DBInterfaceDerby.java database/DBInterfaceMySQL.java database/DBInterfacePostgreSQL.java interfaces/IDBInterface.java system/LCF.java
Date Tue, 08 Jun 2010 11:34:17 GMT
Author: kwright
Date: Tue Jun  8 11:34:16 2010
New Revision: 952617

URL: http://svn.apache.org/viewvc?rev=952617&view=rev
Log:
Revise database interface to combine user and database creation, since ordering seems pretty
database dependent for these two.

Modified:
    incubator/lcf/trunk/modules/framework/core/org/apache/lcf/core/database/DBInterfaceDerby.java
    incubator/lcf/trunk/modules/framework/core/org/apache/lcf/core/database/DBInterfaceMySQL.java
    incubator/lcf/trunk/modules/framework/core/org/apache/lcf/core/database/DBInterfacePostgreSQL.java
    incubator/lcf/trunk/modules/framework/core/org/apache/lcf/core/interfaces/IDBInterface.java
    incubator/lcf/trunk/modules/framework/core/org/apache/lcf/core/system/LCF.java

Modified: incubator/lcf/trunk/modules/framework/core/org/apache/lcf/core/database/DBInterfaceDerby.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/modules/framework/core/org/apache/lcf/core/database/DBInterfaceDerby.java?rev=952617&r1=952616&r2=952617&view=diff
==============================================================================
--- incubator/lcf/trunk/modules/framework/core/org/apache/lcf/core/database/DBInterfaceDerby.java
(original)
+++ incubator/lcf/trunk/modules/framework/core/org/apache/lcf/core/database/DBInterfaceDerby.java
Tue Jun  8 11:34:16 2010
@@ -470,11 +470,47 @@ public class DBInterfaceDerby extends Da
     performModification("DROP TABLE "+tableName,null,invalidateKeys);
   }
 
+  /** Create user and database.
+  *@param userName is the user name.
+  *@param password is the user's desired password.
+  *@param databaseName is the database name.
+  *@param invalidateKeys are the cache keys that should be invalidated, if any.
+  */
+  public void createUserAndDatabase(String userName, String password, String databaseName,
+    StringSet invalidateKeys)
+    throws LCFException
+  {
+    if (lookupUser(userName,null,null) == false)
+    {
+      performCreateUser(userName,password,invalidateKeys);
+    }
+
+    if (lookupDatabase(databaseName,null,null) == false)
+    {
+      performCreateDatabase(databaseName,userName,password,invalidateKeys);
+    }
+
+  }
+
+  /** Drop user and database.
+  *@param userName is the user name.
+  *@param databaseName is the database name.
+  *@param invalidateKeys are the cache keys that should be invalidated, if any.
+  */
+  public void dropUserAndDatabase(String userName, String databaseName, StringSet invalidateKeys)
+    throws LCFException
+  {
+    if (lookupDatabase(databaseName,null,null))
+    {
+      performDropDatabase(databaseName,invalidateKeys);
+    }
+  }
+
   /** Perform user lookup.
   *@param userName is the user name to lookup.
   *@return true if the user exists.
   */
-  public boolean lookupUser(String userName, StringSet cacheKeys, String queryClass)
+  protected boolean lookupUser(String userName, StringSet cacheKeys, String queryClass)
     throws LCFException
   {
     Database rootDatabase = new Database(context,_url+databaseName+";create=true",_driver,databaseName,"","");
@@ -488,23 +524,23 @@ public class DBInterfaceDerby extends Da
   *@param userName is the user name.
   *@param password is the user's password.
   */
-  public void performCreateUser(String userName, String password)
+  protected void performCreateUser(String userName, String password, StringSet invalidateKeys)
     throws LCFException
   {
     Database rootDatabase = new Database(context,_url+databaseName+";create=true",_driver,databaseName,"","");
-    rootDatabase.executeQuery("CALL SYSCS_UTIL.SYSCS_SET_DATABASE_PROPERTY('derby.user."+userName+"',
'"+password+"')",null,null,null,null,false,0,null,null);
-    rootDatabase.executeQuery("CREATE SCHEMA "+userName+" AUTHORIZATION "+userName,null,null,null,null,false,0,null,null);
+    rootDatabase.executeQuery("CALL SYSCS_UTIL.SYSCS_SET_DATABASE_PROPERTY('derby.user."+userName+"',
'"+password+"')",null,invalidateKeys,null,null,false,0,null,null);
+    rootDatabase.executeQuery("CREATE SCHEMA "+userName+" AUTHORIZATION "+userName,null,invalidateKeys,null,null,false,0,null,null);
   }
 
   /** Perform user delete.
   *@param userName is the user name.
   */
-  public void performDropUser(String userName)
+  public void performDropUser(String userName, StringSet invalidateKeys)
     throws LCFException
   {
     Database rootDatabase = new Database(context,_url+databaseName+";create=true",_driver,databaseName,"","");
-    rootDatabase.executeQuery("DROP SCHEMA "+userName+" RESTRICT",null,null,null,null,false,0,null,null);
-    rootDatabase.executeQuery("CALL SYSCS_UTIL.SYSCS_SET_DATABASE_PROPERTY('derby.user."+userName+"',
null)",null,null,null,null,false,0,null,null);
+    rootDatabase.executeQuery("DROP SCHEMA "+userName+" RESTRICT",null,invalidateKeys,null,null,false,0,null,null);
+    rootDatabase.executeQuery("CALL SYSCS_UTIL.SYSCS_SET_DATABASE_PROPERTY('derby.user."+userName+"',
null)",null,invalidateKeys,null,null,false,0,null,null);
   }
 
   /** Perform database lookup.
@@ -512,7 +548,7 @@ public class DBInterfaceDerby extends Da
   *@param cacheKeys are the cache keys, if any.
   *@return true if the database exists.
   */
-  public boolean lookupDatabase(String databaseName, StringSet cacheKeys, String queryClass)
+  protected boolean lookupDatabase(String databaseName, StringSet cacheKeys, String queryClass)
     throws LCFException
   {
     File f = new File(databaseName);
@@ -525,7 +561,7 @@ public class DBInterfaceDerby extends Da
   *@param databasePassword is the password of the user to grant access to the database.
   *@param invalidateKeys are the cache keys that should be invalidated, if any.
   */
-  public void performCreateDatabase(String databaseName, String databaseUser, String databasePassword,
+  protected void performCreateDatabase(String databaseName, String databaseUser, String databasePassword,
     StringSet invalidateKeys)
     throws LCFException
   {
@@ -538,7 +574,7 @@ public class DBInterfaceDerby extends Da
   *@param databaseName is the database name.
   *@param invalidateKeys are the cache keys that should be invalidated, if any.
   */
-  public void performDropDatabase(String databaseName, StringSet invalidateKeys)
+  protected void performDropDatabase(String databaseName, StringSet invalidateKeys)
     throws LCFException
   {
     // rm -rf <databasename>

Modified: incubator/lcf/trunk/modules/framework/core/org/apache/lcf/core/database/DBInterfaceMySQL.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/modules/framework/core/org/apache/lcf/core/database/DBInterfaceMySQL.java?rev=952617&r1=952616&r2=952617&view=diff
==============================================================================
--- incubator/lcf/trunk/modules/framework/core/org/apache/lcf/core/database/DBInterfaceMySQL.java
(original)
+++ incubator/lcf/trunk/modules/framework/core/org/apache/lcf/core/database/DBInterfaceMySQL.java
Tue Jun  8 11:34:16 2010
@@ -359,54 +359,13 @@ public class DBInterfaceMySQL extends Da
     performModification("DROP TABLE "+tableName,null,invalidateKeys);
   }
 
-  /** Perform user lookup.
-  *@param userName is the user name to lookup.
-  *@return true if the user exists.
-  */
-  public boolean lookupUser(String userName, StringSet cacheKeys, String queryClass)
-    throws LCFException
-  {
-    throw new LCFException("Not Supported");
-  }
-
-  /** Perform user create.
-  *@param userName is the user name.
-  *@param password is the user's password.
-  */
-  public void performCreateUser(String userName, String password)
-    throws LCFException
-  {
-    // Does nothing for MySQL
-  }
-
-  /** Perform user delete.
+  /** Create user and database.
   *@param userName is the user name.
-  */
-  public void performDropUser(String userName)
-    throws LCFException
-  {
-    // Does nothing
-  }
-
-  /** Perform database lookup.
-  *@param databaseName is the database name.
-  *@param cacheKeys are the cache keys, if any.
-  *@return true if the database exists.
-  */
-  public boolean lookupDatabase(String databaseName, StringSet cacheKeys, String queryClass)
-    throws LCFException
-  {
-    throw new LCFException("Not Supported");
-  }
-
-
-  /** Perform database create.
+  *@param password is the user's desired password.
   *@param databaseName is the database name.
-  *@param databaseUser is the user to grant access to the database.
-  *@param databasePassword is the password of the user to grant access to the database.
   *@param invalidateKeys are the cache keys that should be invalidated, if any.
   */
-  public void performCreateDatabase(String databaseName, String databaseUser, String databasePassword,
+  public void createUserAndDatabase(String userName, String password, String databaseName,
     StringSet invalidateKeys)
     throws LCFException
   {
@@ -415,12 +374,12 @@ public class DBInterfaceMySQL extends Da
     {
       performModification("CREATE DATABASE "+databaseName+" CHARACTER SET "+
         quoteSQLString("utf8"),null,invalidateKeys);
-      if (databaseUser != null)
+      if (userName != null)
       {
         performModification("GRANT ALL ON "+databaseName+".* TO "+
-          quoteSQLString(databaseUser)+"@"+
+          quoteSQLString(userName)+"@"+
           quoteSQLString("localhost")+" IDENTIFIED BY "+
-          quoteSQLString(databasePassword),null,invalidateKeys);
+          quoteSQLString(password),null,invalidateKeys);
       }
     }
     catch (LCFException e)
@@ -439,11 +398,12 @@ public class DBInterfaceMySQL extends Da
     }
   }
 
-  /** Perform database drop.
+  /** Drop user and database.
+  *@param userName is the user name.
   *@param databaseName is the database name.
   *@param invalidateKeys are the cache keys that should be invalidated, if any.
   */
-  public void performDropDatabase(String databaseName, StringSet invalidateKeys)
+  public void dropUserAndDatabase(String userName, String databaseName, StringSet invalidateKeys)
     throws LCFException
   {
     performModification("DROP DATABASE "+databaseName,null,invalidateKeys);

Modified: incubator/lcf/trunk/modules/framework/core/org/apache/lcf/core/database/DBInterfacePostgreSQL.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/modules/framework/core/org/apache/lcf/core/database/DBInterfacePostgreSQL.java?rev=952617&r1=952616&r2=952617&view=diff
==============================================================================
--- incubator/lcf/trunk/modules/framework/core/org/apache/lcf/core/database/DBInterfacePostgreSQL.java
(original)
+++ incubator/lcf/trunk/modules/framework/core/org/apache/lcf/core/database/DBInterfacePostgreSQL.java
Tue Jun  8 11:34:16 2010
@@ -459,11 +459,45 @@ public class DBInterfacePostgreSQL exten
     performModification("DROP TABLE "+tableName,null,invalidateKeys);
   }
 
+  /** Create user and database.
+  *@param userName is the user name.
+  *@param password is the user's desired password.
+  *@param databaseName is the database name.
+  *@param invalidateKeys are the cache keys that should be invalidated, if any.
+  */
+  public void createUserAndDatabase(String userName, String password, String databaseName,
+    StringSet invalidateKeys)
+    throws LCFException
+  {
+    if (lookupUser(userName,null,null) == false)
+    {
+      performCreateUser(userName,password,invalidateKeys);
+    }
+
+    if (lookupDatabase(databaseName,null,null) == false)
+    {
+      performCreateDatabase(databaseName,userName,password,invalidateKeys);
+    }
+
+  }
+
+  /** Drop user and database.
+  *@param userName is the user name.
+  *@param databaseName is the database name.
+  *@param invalidateKeys are the cache keys that should be invalidated, if any.
+  */
+  public void dropUserAndDatabase(String userName, String databaseName, StringSet invalidateKeys)
+    throws LCFException
+  {
+    performDropDatabase(databaseName,invalidateKeys);
+    performDropUser(userName,invalidateKeys);
+  }
+
   /** Perform user lookup.
   *@param userName is the user name to lookup.
   *@return true if the user exists.
   */
-  public boolean lookupUser(String userName, StringSet cacheKeys, String queryClass)
+  protected boolean lookupUser(String userName, StringSet cacheKeys, String queryClass)
     throws LCFException
   {
     ArrayList params = new ArrayList();
@@ -478,20 +512,20 @@ public class DBInterfacePostgreSQL exten
   *@param userName is the user name.
   *@param password is the user's password.
   */
-  public void performCreateUser(String userName, String password)
+  protected void performCreateUser(String userName, String password, StringSet invalidateKeys)
     throws LCFException
   {
     performModification("CREATE USER "+userName+" PASSWORD "+
-      quoteSQLString(password),null,null);
+      quoteSQLString(password),null,invalidateKeys);
   }
 
   /** Perform user delete.
   *@param userName is the user name.
   */
-  public void performDropUser(String userName)
+  protected void performDropUser(String userName, StringSet invalidateKeys)
     throws LCFException
   {
-    performModification("DROP USER "+userName,null,null);
+    performModification("DROP USER "+userName,null,invalidateKeys);
   }
 
   /** Perform database lookup.
@@ -499,7 +533,7 @@ public class DBInterfacePostgreSQL exten
   *@param cacheKeys are the cache keys, if any.
   *@return true if the database exists.
   */
-  public boolean lookupDatabase(String databaseName, StringSet cacheKeys, String queryClass)
+  protected boolean lookupDatabase(String databaseName, StringSet cacheKeys, String queryClass)
     throws LCFException
   {
     ArrayList params = new ArrayList();
@@ -516,7 +550,7 @@ public class DBInterfacePostgreSQL exten
   *@param databasePassword is the password of the user to grant access to the database.
   *@param invalidateKeys are the cache keys that should be invalidated, if any.
   */
-  public void performCreateDatabase(String databaseName, String databaseUser, String databasePassword,
+  protected void performCreateDatabase(String databaseName, String databaseUser, String databasePassword,
     StringSet invalidateKeys)
     throws LCFException
   {
@@ -529,7 +563,7 @@ public class DBInterfacePostgreSQL exten
   *@param databaseName is the database name.
   *@param invalidateKeys are the cache keys that should be invalidated, if any.
   */
-  public void performDropDatabase(String databaseName, StringSet invalidateKeys)
+  protected void performDropDatabase(String databaseName, StringSet invalidateKeys)
     throws LCFException
   {
     performModification("DROP DATABASE "+databaseName,null,invalidateKeys);

Modified: incubator/lcf/trunk/modules/framework/core/org/apache/lcf/core/interfaces/IDBInterface.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/modules/framework/core/org/apache/lcf/core/interfaces/IDBInterface.java?rev=952617&r1=952616&r2=952617&view=diff
==============================================================================
--- incubator/lcf/trunk/modules/framework/core/org/apache/lcf/core/interfaces/IDBInterface.java
(original)
+++ incubator/lcf/trunk/modules/framework/core/org/apache/lcf/core/interfaces/IDBInterface.java
Tue Jun  8 11:34:16 2010
@@ -154,51 +154,24 @@ public interface IDBInterface
   public void performDrop(String tableName, StringSet invalidateKeys)
     throws LCFException;
 
-  /** Perform user lookup.
-  *@param userName is the user name to lookup.
-  *@return true if the user exists.
-  */
-  public boolean lookupUser(String userName, StringSet cacheKeys, String queryClass)
-    throws LCFException;
-
-  /** Perform user create.
-  *@param userName is the user name.
-  *@param password is the user's password.
-  */
-  public void performCreateUser(String userName, String password)
-    throws LCFException;
-
-  /** Perform user delete.
+  /** Create user and database.
   *@param userName is the user name.
-  */
-  public void performDropUser(String userName)
-    throws LCFException;
-
-  /** Perform database lookup.
-  *@param databaseName is the database name.
-  *@param cacheKeys are the cache keys, if any.
-  *@return true if the database exists.
-  */
-  public boolean lookupDatabase(String databaseName, StringSet cacheKeys, String queryClass)
-    throws LCFException;
-
-  /** Perform database create.
+  *@param password is the user's desired password.
   *@param databaseName is the database name.
-  *@param databaseUser is the user to grant access to the database.
-  *@param databasePassword is the password of the user to grant access to the database.
   *@param invalidateKeys are the cache keys that should be invalidated, if any.
   */
-  public void performCreateDatabase(String databaseName, String databaseUser, String databasePassword,
+  public void createUserAndDatabase(String userName, String password, String databaseName,
     StringSet invalidateKeys)
     throws LCFException;
 
-  /** Perform database drop.
+  /** Drop user and database.
+  *@param userName is the user name.
   *@param databaseName is the database name.
   *@param invalidateKeys are the cache keys that should be invalidated, if any.
   */
-  public void performDropDatabase(String databaseName, StringSet invalidateKeys)
+  public void dropUserAndDatabase(String userName, String databaseName, StringSet invalidateKeys)
     throws LCFException;
-
+    
   /** Get a table's schema.
   *@param tableName is the name of the table.
   *@param cacheKeys are the keys against which to cache the query, or null.

Modified: incubator/lcf/trunk/modules/framework/core/org/apache/lcf/core/system/LCF.java
URL: http://svn.apache.org/viewvc/incubator/lcf/trunk/modules/framework/core/org/apache/lcf/core/system/LCF.java?rev=952617&r1=952616&r2=952617&view=diff
==============================================================================
--- incubator/lcf/trunk/modules/framework/core/org/apache/lcf/core/system/LCF.java (original)
+++ incubator/lcf/trunk/modules/framework/core/org/apache/lcf/core/system/LCF.java Tue Jun
 8 11:34:16 2010
@@ -547,18 +547,7 @@ public class LCF
     String databasePassword = getMasterDatabasePassword();
 
     IDBInterface master = DBInterfaceFactory.make(threadcontext,masterName,masterUsername,masterPassword);
-    // Ideally, check for existence of lcf user.  In fact, we don't
-    // have a hook for this.  So, attempt the create, and interpret failure as
-    // meaning "user already exists".
-    if (master.lookupUser(databaseUsername,null,null) == false)
-    {
-      master.performCreateUser(databaseUsername,databasePassword);
-    }
-
-    if (master.lookupDatabase(databaseName,null,null) == false)
-    {
-      master.performCreateDatabase(databaseName,databaseUsername,databasePassword,null);
-    }
+    master.createUserAndDatabase(databaseUsername,databasePassword,databaseName,null);
   }
 
   /** Drop system database.
@@ -572,8 +561,7 @@ public class LCF
     throws LCFException
   {
     IDBInterface master = DBInterfaceFactory.make(threadcontext,masterName,masterUsername,masterPassword);
-    master.performDropDatabase(getMasterDatabaseName(),null);
-    master.performDropUser(getMasterDatabaseUsername());
+    master.dropUserAndDatabase(getMasterDatabaseUsername(),getMasterDatabaseName(),null);
   }
 
   /** Add a file to the tracking system. */



Mime
View raw message