cmu.survey.data.mysql
Class DatabaseStorageMySQL

java.lang.Object
  extended by cmu.survey.data.mysql.DatabaseStorageMySQL
All Implemented Interfaces:
DatabaseStorage

public class DatabaseStorageMySQL
extends java.lang.Object
implements DatabaseStorage


Nested Class Summary
 
Nested classes/interfaces inherited from interface cmu.survey.data.DatabaseStorage
DatabaseStorage.UserDatabase
 
Field Summary
static java.lang.String MySQL_ALTER_PRIV
           
static java.lang.String MySQL_CREATE_PRIV
           
static java.lang.String MySQL_DELETE_PRIV
           
static java.lang.String MySQL_DROP_PRIV
           
static java.lang.String MySQL_INSERT_PRIV
           
static java.lang.String MySQL_LOCK_TABLES_PRIV
           
static java.lang.String MySQL_SELECT_PRIV
          MySQL privs granted to admins for survey databases.
static java.lang.String MySQL_UPDATE_PRIV
           
 
Fields inherited from interface cmu.survey.data.DatabaseStorage
READ, WRITE
 
Constructor Summary
DatabaseStorageMySQL(java.lang.String connectionString)
           
 
Method Summary
 void close()
           
 void connect()
          Connect to the database.
static boolean copyPropertiesTo(HasKeyValues copyFromProperties, KeyValuesModifiable copyToProperties)
           
 boolean createDatabase(java.lang.String databaseName)
           
 void createDatabaseUser(java.lang.String userName, java.lang.String password)
           
 boolean deleteDatabase(java.lang.String databaseName)
           
 void deleteDatabaseUser(java.lang.String username)
           
 boolean doesDatabaseExist(java.lang.String databaseName)
           
 void finalize()
           
 java.util.Vector<java.lang.String> getAccessibleDatabases()
           
 java.util.List<DatabaseStorage.UserDatabase> getCurrentUsers()
          Get the current users connected to databases.
static java.lang.String getDatabaseConnectionStringFrom(HasKeyValues properties, Dialogs dialogs)
           
static java.lang.String getDatabaseConnectionStringFrom(HasKeyValues properties, java.lang.String databaseUser, java.lang.String password)
           
 java.lang.String getDatabaseHelpURL()
          Optionally, return a URL as a string that the user can go to for help installing and running this database, especially when it doesn't work, etc.
 HasKeyValues getDatabaseKeyValuesForDatabase(java.lang.String hostName, java.lang.String databaseName, java.lang.String userID, java.lang.String password)
           
static HasKeyValues getDatabaseKeyValuesForDatabaseStatic(java.lang.String hostName, java.lang.String databaseName, java.lang.String userID, java.lang.String password)
           
 java.lang.String getDatabaseName()
          Optionally, return a database name for the user to se.
 java.lang.String getDatabaseStringForDatabase(java.lang.String hostName, java.lang.String databaseName, java.lang.String userID, java.lang.String password)
           
static java.lang.String getDatabaseStringForDatabaseStatic(java.lang.String hostName, java.lang.String databaseName, java.lang.String userID, java.lang.String password)
           
static java.lang.String getPassword(HasKeyValues properties)
           
static java.lang.String getUser(HasKeyValues properties)
           
 boolean grantDatabasePrivs(java.lang.String dbname, java.lang.String userName, java.lang.String priv)
          Attempts to grant the given privilege for a given user on a given database.
static boolean isPossibleDataSource(HasKeyValues propA)
          Ignores requriment of userid/password, because those can be asked for.
static boolean isPropertiesSameDataSource(HasKeyValues propA, HasKeyValues propB)
           
static boolean propertiesAreEqual(HasKeyValues propA, HasKeyValues propB)
           
 void renameDatabaseUser(java.lang.String username, java.lang.String newUsername)
           
 boolean revokeDatabasePrivs(java.lang.String dbname, java.lang.String userName, java.lang.String priv)
          Attempts to revoke the given privilege for a given user on a given database.
 void updateDatabaseUser(java.lang.String username, java.lang.String password)
           
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MySQL_SELECT_PRIV

public static final java.lang.String MySQL_SELECT_PRIV
MySQL privs granted to admins for survey databases.

See Also:
Constant Field Values

MySQL_INSERT_PRIV

public static final java.lang.String MySQL_INSERT_PRIV
See Also:
Constant Field Values

MySQL_DELETE_PRIV

public static final java.lang.String MySQL_DELETE_PRIV
See Also:
Constant Field Values

MySQL_LOCK_TABLES_PRIV

public static final java.lang.String MySQL_LOCK_TABLES_PRIV
See Also:
Constant Field Values

MySQL_UPDATE_PRIV

public static final java.lang.String MySQL_UPDATE_PRIV
See Also:
Constant Field Values

MySQL_ALTER_PRIV

public static final java.lang.String MySQL_ALTER_PRIV
See Also:
Constant Field Values

MySQL_CREATE_PRIV

public static final java.lang.String MySQL_CREATE_PRIV
See Also:
Constant Field Values

MySQL_DROP_PRIV

public static final java.lang.String MySQL_DROP_PRIV
See Also:
Constant Field Values
Constructor Detail

DatabaseStorageMySQL

public DatabaseStorageMySQL(java.lang.String connectionString)
                     throws java.lang.Throwable
Throws:
java.lang.Throwable
Method Detail

connect

public void connect()
             throws java.lang.Throwable
Description copied from interface: DatabaseStorage
Connect to the database. It is required that you call this before using it. This can be called multiple times -- if it is called after it's already connected, it will do nothing new.

Specified by:
connect in interface DatabaseStorage
Throws:
java.lang.Throwable

getDatabaseConnectionStringFrom

public static java.lang.String getDatabaseConnectionStringFrom(HasKeyValues properties,
                                                               java.lang.String databaseUser,
                                                               java.lang.String password)

getDatabaseStringForDatabaseStatic

public static final java.lang.String getDatabaseStringForDatabaseStatic(java.lang.String hostName,
                                                                        java.lang.String databaseName,
                                                                        java.lang.String userID,
                                                                        java.lang.String password)

getDatabaseKeyValuesForDatabaseStatic

public static final HasKeyValues getDatabaseKeyValuesForDatabaseStatic(java.lang.String hostName,
                                                                       java.lang.String databaseName,
                                                                       java.lang.String userID,
                                                                       java.lang.String password)

getDatabaseConnectionStringFrom

public static java.lang.String getDatabaseConnectionStringFrom(HasKeyValues properties,
                                                               Dialogs dialogs)

getDatabaseStringForDatabase

public java.lang.String getDatabaseStringForDatabase(java.lang.String hostName,
                                                     java.lang.String databaseName,
                                                     java.lang.String userID,
                                                     java.lang.String password)
Specified by:
getDatabaseStringForDatabase in interface DatabaseStorage

getDatabaseKeyValuesForDatabase

public HasKeyValues getDatabaseKeyValuesForDatabase(java.lang.String hostName,
                                                    java.lang.String databaseName,
                                                    java.lang.String userID,
                                                    java.lang.String password)
Specified by:
getDatabaseKeyValuesForDatabase in interface DatabaseStorage

getUser

public static final java.lang.String getUser(HasKeyValues properties)

getPassword

public static final java.lang.String getPassword(HasKeyValues properties)

copyPropertiesTo

public static boolean copyPropertiesTo(HasKeyValues copyFromProperties,
                                       KeyValuesModifiable copyToProperties)

propertiesAreEqual

public static boolean propertiesAreEqual(HasKeyValues propA,
                                         HasKeyValues propB)

isPropertiesSameDataSource

public static boolean isPropertiesSameDataSource(HasKeyValues propA,
                                                 HasKeyValues propB)

isPossibleDataSource

public static boolean isPossibleDataSource(HasKeyValues propA)
Ignores requriment of userid/password, because those can be asked for.

Parameters:
propA -
Returns:

getAccessibleDatabases

public java.util.Vector<java.lang.String> getAccessibleDatabases()
Specified by:
getAccessibleDatabases in interface DatabaseStorage

doesDatabaseExist

public boolean doesDatabaseExist(java.lang.String databaseName)
Specified by:
doesDatabaseExist in interface DatabaseStorage

createDatabase

public boolean createDatabase(java.lang.String databaseName)
Specified by:
createDatabase in interface DatabaseStorage

deleteDatabase

public boolean deleteDatabase(java.lang.String databaseName)
Specified by:
deleteDatabase in interface DatabaseStorage

close

public void close()
Specified by:
close in interface DatabaseStorage

finalize

public void finalize()
Overrides:
finalize in class java.lang.Object

revokeDatabasePrivs

public boolean revokeDatabasePrivs(java.lang.String dbname,
                                   java.lang.String userName,
                                   java.lang.String priv)
Attempts to revoke the given privilege for a given user on a given database.

Specified by:
revokeDatabasePrivs in interface DatabaseStorage
Parameters:
dbname - The database to operate on.
userName - The user to operate on.
priv - The privledge to operate on. Should be one of the constants defined in DatabaseStorageMySQL.
grant - Whether to grant or revoke this privilege.
Returns:

grantDatabasePrivs

public boolean grantDatabasePrivs(java.lang.String dbname,
                                  java.lang.String userName,
                                  java.lang.String priv)
Attempts to grant the given privilege for a given user on a given database.

Specified by:
grantDatabasePrivs in interface DatabaseStorage
Parameters:
dbname - The database to operate on.
userName - The user to operate on.
userPassword - The password of the user to operate on.
priv - The privledge to operate on. Should be one of the constants defined in DatabaseStorageMySQL.
grant - Whether to grant or revoke this privilege.
Returns:

createDatabaseUser

public void createDatabaseUser(java.lang.String userName,
                               java.lang.String password)
Specified by:
createDatabaseUser in interface DatabaseStorage

updateDatabaseUser

public void updateDatabaseUser(java.lang.String username,
                               java.lang.String password)
Specified by:
updateDatabaseUser in interface DatabaseStorage

renameDatabaseUser

public void renameDatabaseUser(java.lang.String username,
                               java.lang.String newUsername)
Specified by:
renameDatabaseUser in interface DatabaseStorage

deleteDatabaseUser

public void deleteDatabaseUser(java.lang.String username)
Specified by:
deleteDatabaseUser in interface DatabaseStorage

getCurrentUsers

public java.util.List<DatabaseStorage.UserDatabase> getCurrentUsers()
Description copied from interface: DatabaseStorage
Get the current users connected to databases. This is not required to be implemented -- if it's not implemented, it should return null.

Specified by:
getCurrentUsers in interface DatabaseStorage
Returns:
array of UserDatabase[number of connections]

getDatabaseName

public java.lang.String getDatabaseName()
Description copied from interface: DatabaseStorage
Optionally, return a database name for the user to se.

Specified by:
getDatabaseName in interface DatabaseStorage
Returns:

getDatabaseHelpURL

public java.lang.String getDatabaseHelpURL()
Description copied from interface: DatabaseStorage
Optionally, return a URL as a string that the user can go to for help installing and running this database, especially when it doesn't work, etc.

Specified by:
getDatabaseHelpURL in interface DatabaseStorage
Returns: