</s:params>\r
</s:initHandler>\r
*\r
- * $LastChangedRevision: $\r
- * $LastChangedDate: $\r
+ * $LastChangedRevision$\r
+ * $LastChangedDate$\r
*/\r
public class AddIndices extends InitHandler implements IInitHandler {\r
\r
\r
private boolean indexExists(DatabaseProductType databaseProductType,\r
String tableName, String indexName) {\r
+ \r
+ // FIXME: May need to qualify table name by database/catalog,\r
+ // as table names likely will not be globally unique across same\r
+ // (although index names *may* be unique within scope).\r
+ // - Pass in database name as parameter, retrieved via\r
+ // getDatabaseName(field) in onRepositoryInitialized, above.\r
+ // - Add 'IN databaseName' after tableName in MySQL variant, below.\r
+ // (PostgreSQL variant, below, uses a view that doesn't include\r
+ // a foreign key for associating a database/catalog to the index.)\r
+ \r
+ // FIXME: Consider instead substituting a database-agnostic\r
+ // JDBC mechanism for retrieving indexes; e.g.\r
+ // java.sql.DatabaseMetaData.getIndexInfo()\r
+ \r
boolean indexExists = false;\r
int rows = 0;\r
String sql = "";\r
if (databaseProductType == DatabaseProductType.MYSQL) {\r
sql = "SHOW INDEX FROM " + tableName + " WHERE key_name='" + indexName + "'";\r
} else if (databaseProductType == DatabaseProductType.POSTGRESQL) {\r
- // FIXME: Add comparable SQL statement for PostgreSQL.\r
+ sql = "SELECT indexname FROM pg_catalog.pg_indexes "\r
+ + "WHERE indexname = '" + indexName + "'"\r
+ + " AND tablename = '" + tableName + "'";\r
}\r
\r
try {\r
* some action on the event onRepositoryInitialized(), such as sending JDBC\r
* calls to the repository to add indices, etc.\r
* @author Laramie\r
- * $LastChangedRevision: $\r
- * $LastChangedDate: $\r
+ * $LastChangedRevision$\r
+ * $LastChangedDate$\r
*/\r
public class InitHandler implements IInitHandler {\r
\r
* ModifyFieldDatatypes, post-init action to configure the database
* datatypes of individual fields.
*
- * $LastChangedRevision: $
- * $LastChangedDate: $
+ * $LastChangedRevision$
+ * $LastChangedDate$
*/
public class ModifyFieldDatatypes extends InitHandler implements IInitHandler {
private boolean fieldHasDesiredDatatype(DatabaseProductType databaseProductType,
Field field, String datatype) {
+
+ // FIXME: Consider instead using the database-agnostic
+ // JDBC DatabaseMetaData class to extract metadata, as per
+ // http://www.java2s.com/Code/Java/Database-SQL-JDBC/GetColumnType.htm
boolean fieldHasDesiredDatatype = false;
int rows = 0;
+ " AND TABLE_NAME = '" + getTableName(field) + "'"
+ " AND COLUMN_NAME = '" + field.getCol() + "'";
} else if (databaseProductType == DatabaseProductType.POSTGRESQL) {
- // FIXME: Add comparable SQL statement for PostgreSQL.
+ sql = "SELECT data_type FROM information_schema.columns "
+ + "WHERE table_catalog = '" + getDatabaseName(field) + "'"
+ + " AND table_name = '" + getTableName(field) + "'"
+ + " AND column_name = '" + field.getCol() + "'";
}
try {