Package mgui.datasources.util
Class DataSourceFunctions
java.lang.Object
mgui.datasources.util.DataSourceFunctions
public class DataSourceFunctions
extends java.lang.Object
-
Constructor Summary
Constructors Constructor Description DataSourceFunctions()
-
Method Summary
Modifier and Type Method Description static DataSource
createNewDataSource(java.lang.String driver, java.lang.String name, java.lang.String url, java.lang.String login, java.lang.String encrypted_password)
Attempts to creates a new data source, with the given parameters.static boolean
dropDataSource(DataSource source)
Drops the specified data source; i.e., deletes it entirely.static boolean
equalFields(DataField f1, DataField f2)
Compare fields for equalitystatic boolean
equalFields(DataField f1, DataField f2, boolean ignore_name)
Compare fields for equalitystatic java.lang.String
getAddFieldStatement(java.lang.String table, DataField field)
Returns an SQL statement for addingfield
totable
.static java.lang.String
getAddFieldStatement(java.lang.String table, DataField field, DataSourceDriver driver)
Returns an SQL statement for addingfield
totable
.static java.lang.String
getChangePrimaryKeyStatement(java.lang.String table, DataField new_field)
Returns an SQL statement to updatetable
by adding or dropping a primary key fornew_field
.static java.lang.String
getChangePrimaryKeyStatement(java.lang.String table, DataField new_field, DataSourceDriver driver)
Returns an SQL statement to updatetable
by adding or dropping a primary key fornew_field
.static java.util.ArrayList<java.lang.String>
getEditStatements(DataSource source, DataTable old_table, DataTable new_table, java.util.HashMap<java.lang.String,java.lang.String> changed_names)
Generates a set of SQL statements which transformold_table
intonew_table
.static java.lang.String
getRemoveFieldStatement(java.lang.String table, java.lang.String field)
Returns an SQL statement for removingfield
fromtable
.static java.lang.String
getRemoveFieldStatement(java.lang.String table, java.lang.String field, DataSourceDriver driver)
Returns an SQL statement for removingfield
fromtable
.static java.lang.String
getRenameFieldStatement(java.lang.String table, java.lang.String old_field, java.lang.String new_field)
Returns an SQL statement to renameold_field
tonew_field
.static java.lang.String
getRenameFieldStatement(java.lang.String table, java.lang.String old_name, java.lang.String new_name, DataSourceDriver driver)
Returns an SQL statement to renameold_field
tonew_field
.static java.lang.String
getRenameTableStatement(java.lang.String old_name, java.lang.String new_name)
Returns an SQL statement to renameold_table
tonew_table
.static java.lang.String
getRenameTableStatement(java.lang.String old_name, java.lang.String new_name, DataSourceDriver driver)
Returns an SQL statement to renameold_table
tonew_table
.static java.lang.String
getUpdateFieldStatement(java.lang.String table, DataField old_field, DataField new_field)
Returns an SQL statement to updateold_field
to matchnew_field
.static java.lang.String
getUpdateFieldStatement(java.lang.String table, DataField old_field, DataField new_field, DataSourceDriver driver)
Returns an SQL statement to updateold_field
to matchnew_field
.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Constructor Details
-
DataSourceFunctions
public DataSourceFunctions()
-
-
Method Details
-
createNewDataSource
public static DataSource createNewDataSource(java.lang.String driver, java.lang.String name, java.lang.String url, java.lang.String login, java.lang.String encrypted_password)Attempts to creates a new data source, with the given parameters. The password should already be encrypted usingSecureDataSourceFunctions.getEncryptedPassword()
.
- Parameters:
name
-url
-login
-encrypted_password
- System-encrypted version of the password- Returns:
- the new datasource, if successful;
null
otherwise. - See Also:
mgui.datasources.security.SecureDataSourceFunctions#getEncryptedPassword(String)
-
dropDataSource
Drops the specified data source; i.e., deletes it entirely.- Parameters:
source
-- Returns:
-
getEditStatements
public static java.util.ArrayList<java.lang.String> getEditStatements(DataSource source, DataTable old_table, DataTable new_table, java.util.HashMap<java.lang.String,java.lang.String> changed_names)Generates a set of SQL statements which transformold_table
intonew_table
. Statements must be run in sequence; order is critical for some operations.- Parameters:
source
-old_table
-new_table
-changed_names
-- Returns:
-
equalFields
Compare fields for equality- Parameters:
f1
-f2
-- Returns:
-
equalFields
Compare fields for equality- Parameters:
f1
-f2
-ignore_name
- If true, doesn't include the names in the comparison- Returns:
-
getAddFieldStatement
Returns an SQL statement for addingfield
totable
.- Parameters:
thisTable
-thisField
-- Returns:
-
getAddFieldStatement
public static java.lang.String getAddFieldStatement(java.lang.String table, DataField field, DataSourceDriver driver)Returns an SQL statement for addingfield
totable
.- Parameters:
thisTable
-thisField
-driver
-- Returns:
-
getRemoveFieldStatement
public static java.lang.String getRemoveFieldStatement(java.lang.String table, java.lang.String field)Returns an SQL statement for removingfield
fromtable
.- Parameters:
thisTable
-thisField
-- Returns:
-
getRemoveFieldStatement
public static java.lang.String getRemoveFieldStatement(java.lang.String table, java.lang.String field, DataSourceDriver driver)Returns an SQL statement for removingfield
fromtable
.- Parameters:
thisTable
-thisField
-driver
-- Returns:
-
getRenameTableStatement
public static java.lang.String getRenameTableStatement(java.lang.String old_name, java.lang.String new_name)Returns an SQL statement to renameold_table
tonew_table
.- Parameters:
thisTable
-thisField
-- Returns:
-
getRenameTableStatement
public static java.lang.String getRenameTableStatement(java.lang.String old_name, java.lang.String new_name, DataSourceDriver driver)Returns an SQL statement to renameold_table
tonew_table
.- Parameters:
thisTable
-thisField
-- Returns:
-
getRenameFieldStatement
public static java.lang.String getRenameFieldStatement(java.lang.String table, java.lang.String old_field, java.lang.String new_field)Returns an SQL statement to renameold_field
tonew_field
.- Parameters:
thisTable
-thisField
-- Returns:
-
getRenameFieldStatement
public static java.lang.String getRenameFieldStatement(java.lang.String table, java.lang.String old_name, java.lang.String new_name, DataSourceDriver driver)Returns an SQL statement to renameold_field
tonew_field
.- Parameters:
thisTable
-thisField
-- Returns:
-
getUpdateFieldStatement
public static java.lang.String getUpdateFieldStatement(java.lang.String table, DataField old_field, DataField new_field)Returns an SQL statement to updateold_field
to matchnew_field
.- Parameters:
thisTable
-thisField
-- Returns:
-
getUpdateFieldStatement
public static java.lang.String getUpdateFieldStatement(java.lang.String table, DataField old_field, DataField new_field, DataSourceDriver driver)Returns an SQL statement to updateold_field
to matchnew_field
.- Parameters:
thisTable
-thisField
-- Returns:
-
getChangePrimaryKeyStatement
public static java.lang.String getChangePrimaryKeyStatement(java.lang.String table, DataField new_field)Returns an SQL statement to updatetable
by adding or dropping a primary key fornew_field
. Dropping assumes the field is named "{field_name}_pkey"- Parameters:
thisTable
-thisField
-- Returns:
-
getChangePrimaryKeyStatement
public static java.lang.String getChangePrimaryKeyStatement(java.lang.String table, DataField new_field, DataSourceDriver driver)Returns an SQL statement to updatetable
by adding or dropping a primary key fornew_field
. Dropping assumes the field is named "{field_name}_pkey"- Parameters:
thisTable
-thisField
-- Returns:
-