You can subscribe to this list here.
2006 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
(7) |
Aug
|
Sep
(46) |
Oct
(102) |
Nov
(10) |
Dec
(21) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2007 |
Jan
(1) |
Feb
(3) |
Mar
(14) |
Apr
(9) |
May
(12) |
Jun
(4) |
Jul
(40) |
Aug
(60) |
Sep
(38) |
Oct
(2) |
Nov
(1) |
Dec
(42) |
2008 |
Jan
(23) |
Feb
(29) |
Mar
(107) |
Apr
(27) |
May
(3) |
Jun
(1) |
Jul
(15) |
Aug
(7) |
Sep
(19) |
Oct
|
Nov
(2) |
Dec
|
2009 |
Jan
(36) |
Feb
(4) |
Mar
(2) |
Apr
(1) |
May
(1) |
Jun
(15) |
Jul
(30) |
Aug
(32) |
Sep
(11) |
Oct
(21) |
Nov
(12) |
Dec
(15) |
2010 |
Jan
(29) |
Feb
(9) |
Mar
(25) |
Apr
|
May
(7) |
Jun
(5) |
Jul
(21) |
Aug
(32) |
Sep
(10) |
Oct
(8) |
Nov
(29) |
Dec
(8) |
2011 |
Jan
(9) |
Feb
(35) |
Mar
(11) |
Apr
(4) |
May
|
Jun
(1) |
Jul
|
Aug
|
Sep
|
Oct
(2) |
Nov
(3) |
Dec
(30) |
2012 |
Jan
(5) |
Feb
(7) |
Mar
(10) |
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: <fu...@us...> - 2010-01-26 17:53:57
|
Revision: 1027 http://cishell.svn.sourceforge.net/cishell/?rev=1027&view=rev Author: fugu13 Date: 2010-01-26 17:53:43 +0000 (Tue, 26 Jan 2010) Log Message: ----------- Nearly forgot this, needed for database copy. Modified Paths: -------------- trunk/core/org.cishell.reference.service.database/META-INF/MANIFEST.MF Modified: trunk/core/org.cishell.reference.service.database/META-INF/MANIFEST.MF =================================================================== --- trunk/core/org.cishell.reference.service.database/META-INF/MANIFEST.MF 2010-01-26 17:46:36 UTC (rev 1026) +++ trunk/core/org.cishell.reference.service.database/META-INF/MANIFEST.MF 2010-01-26 17:53:43 UTC (rev 1027) @@ -12,6 +12,8 @@ org.apache.derby.jdbc, org.cishell.framework.algorithm;version="1.0.0", org.cishell.service.database, + org.cishell.utilities, + org.cishell.utilities.database, org.eclipse.core.internal.runtime, org.osgi.framework;version="1.4.0", org.osgi.service.cm;version="1.2.0", This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fu...@us...> - 2010-01-26 17:46:43
|
Revision: 1026 http://cishell.svn.sourceforge.net/cishell/?rev=1026&view=rev Author: fugu13 Date: 2010-01-26 17:46:36 +0000 (Tue, 26 Jan 2010) Log Message: ----------- Database Copy stuff. Reviewed by Patrick. Modified Paths: -------------- trunk/core/org.cishell.reference.service.database/src/org/cishell/reference/service/database/DerbyDatabaseService.java trunk/core/org.cishell.reference.service.database/src/org/cishell/reference/service/database/InternalDerbyDatabase.java trunk/core/org.cishell.service.database/src/org/cishell/service/database/DatabaseService.java Modified: trunk/core/org.cishell.reference.service.database/src/org/cishell/reference/service/database/DerbyDatabaseService.java =================================================================== --- trunk/core/org.cishell.reference.service.database/src/org/cishell/reference/service/database/DerbyDatabaseService.java 2010-01-26 16:51:30 UTC (rev 1025) +++ trunk/core/org.cishell.reference.service.database/src/org/cishell/reference/service/database/DerbyDatabaseService.java 2010-01-26 17:46:36 UTC (rev 1026) @@ -1,13 +1,13 @@ package org.cishell.reference.service.database; +import java.io.File; +import java.sql.CallableStatement; import java.sql.Connection; -import java.sql.DatabaseMetaData; -import java.sql.ResultSet; import java.sql.SQLException; -import java.sql.Statement; import java.util.ArrayList; import java.util.Hashtable; import java.util.List; +import java.util.UUID; import javax.sql.DataSource; @@ -20,179 +20,269 @@ import org.apache.commons.pool.impl.GenericObjectPool; import org.cishell.reference.service.database.utility.DatabaseCleaner; import org.cishell.service.database.Database; +import org.cishell.service.database.DatabaseCopyException; import org.cishell.service.database.DatabaseCreationException; import org.cishell.service.database.DatabaseService; +import org.cishell.utilities.DatabaseUtilities; import org.osgi.framework.BundleActivator; import org.osgi.framework.BundleContext; import org.osgi.framework.ServiceRegistration; +//TODO: rework exception handling everywhere to be failsafe. public class DerbyDatabaseService implements DatabaseService, BundleActivator { - + public static final String DERBY_DRIVER_NAME = "org.apache.derby.jdbc.EmbeddedDriver"; public static final String DERBY_PROTOCOL = "jdbc:derby:"; - + public static final String DEFAULT_CREATE_CONNECTION_STRING = ";create=true"; public static final String DEFAULT_SHUTDOWN_CONNECTION_STRING =";shutdown=true"; - + //where the database exists on the filesystem (relative to the application root directory) private static final String DATABASE_DIRECTORY = "database/"; - + //hold on to our service registration so we can unregister when this plugin stops. private ServiceRegistration databaseServiceRegistration; - + /* * internal databases are created when requested by outside services, * and are cleaned and shut down when this service is stopped. */ private List<InternalDerbyDatabase> internalDatabases = new ArrayList<InternalDerbyDatabase>(); - + public final void start(BundleContext context) throws Exception { - + /* * Tell Derby to look for an existing database or create a new database * in the default directory (within our application's directory) */ System.setProperty("derby.system.home", DATABASE_DIRECTORY); - + //Allow the database service to be found by other services/plugins databaseServiceRegistration = context.registerService( DatabaseService.class.getName(), this, new Hashtable()); } - + public final void stop(BundleContext context) { - //disallow the database service to be found by other services/plugins - this.databaseServiceRegistration.unregister(); - - //Clean out the internal databases and shut them down. - try { - for (InternalDerbyDatabase internalDatabase : internalDatabases) { - Connection internalDatabaseConnection = internalDatabase.getConnection(); - //DatabaseCleaner.cleanDatabase(internalDatabaseConnection, false); - internalDatabase.shutdown(); - } - } catch (Exception e) { - String message = - "An unexpected exception occurred while shutting down the internal database." - + "Aborting database shutdown process." - + "Database may not be left in a valid state, " - + "but we will try to make its state valid on next startup."; - throw new RuntimeException(message, e); + //disallow the database service to be found by other services/plugins + this.databaseServiceRegistration.unregister(); + + //Clean out the internal databases and shut them down. + try { + for (InternalDerbyDatabase internalDatabase : internalDatabases) { + Connection internalDatabaseConnection = internalDatabase.getConnection(); + //DatabaseCleaner.cleanDatabase(internalDatabaseConnection, false); + internalDatabase.shutdown(); } + } catch (Exception e) { + String message = + "An unexpected exception occurred while shutting down the internal database." + + "Aborting database shutdown process." + + "Database may not be left in a valid state, " + + "but we will try to make its state valid on next startup."; + throw new RuntimeException(message, e); + } } - + private static final String INTERNAL_DB_NAME_PREFIX = "cishell_database"; private static int id = 0; - - public synchronized Database createNewDatabase() throws DatabaseCreationException { - try { + + public Database createNewDatabase() throws DatabaseCreationException { //connect to and create a 'new' database - String databaseName = INTERNAL_DB_NAME_PREFIX + id; - InternalDerbyDatabase db = - new InternalDerbyDatabase(createNewInternalDataSource(databaseName)); - - - //if this database existed on disk from a previous session, clean it to be like new - DatabaseCleaner.cleanDatabase(db.getConnection(), false); - - //keep track of our new database for this CIShell session - internalDatabases.add(db); - - id++; - - return db; - } catch (Exception e) { - throw new DatabaseCreationException(e); - } + String databaseName = nextDatabaseIdentifier(); + DataSource internalDataSource = createNewInternalDataSource(databaseName); + //TODO: find a way to get the darn database name that isn't awful! + InternalDerbyDatabase internalDatabase = createNewInternalDatabase(internalDataSource); + internalDatabase.setName(databaseName); + return internalDatabase; } - + + + public Database connectToExistingDatabase(String driver, String url) - throws DatabaseCreationException { + throws DatabaseCreationException { return connectToExistingDatabase(driver, url, null, null); } - + public Database connectToExistingDatabase( String driver, String url, String username, String password) - throws DatabaseCreationException { + throws DatabaseCreationException { DataSource dataSource = createNewDataSource(driver, url, username, password); //TODO: See if we can get the default schema as a property somehow. Database db = new ExternalDatabase(dataSource, "APP"); return db; } + + + + public Database copyDatabase(Database originalDatabase) throws DatabaseCopyException { + /* Connection originalConnection = null; + Connection newConnection = null; + try { + Database newDatabase = createNewDatabase(); + originalConnection = originalDatabase.getConnection(); + try { + newConnection = newDatabase.getConnection(); + DatabaseTable[] tables = DatabaseTable.availableTables(originalConnection); + for(DatabaseTable table : tables) { + table.duplicateTable(originalConnection, newConnection); + } + for(DatabaseTable table : tables) { + table.transferPrimaryKey(originalConnection, newConnection); + table.pointForeignKeys(originalConnection, newConnection); + } + + + } catch(SQLException e) { + throw new DatabaseCopyException("There was a problem creating the new database: " + e.getMessage(), e); + } + } catch (DatabaseCreationException e) { + throw new DatabaseCopyException("Unable to create a new database to copy into: " + e.getMessage(), e); + } catch (SQLException e) { + throw new DatabaseCopyException("Unable to connect to the database being copied.", e); + } finally { + DatabaseUtilities.closeConnectionQuietly(originalConnection); + DatabaseUtilities.closeConnectionQuietly(newConnection); + } + + //TODO: copy views. Wait until we have the darn things. + /* + * TODO: make copy table work + * On the subject of copying tables . . . looks like that needs to be provided. Rough plan of attack: + * Make new database. For every table in the original (make sure system tables are excluded), make an identical table in the new one. + * For every table, copy all values into the new database. + * Put all constraints in place on the new database (especially: primary keys, foreign keys) + */ + + //Make a backup, then make a new database derived from the backup. + if(originalDatabase instanceof InternalDerbyDatabase) { + InternalDerbyDatabase database = (InternalDerbyDatabase) originalDatabase; + String originalName = database.getName(); + Connection connection = null; + try { + connection = database.getConnection(); + String backupLocation = createDatabaseBackup(connection, + originalName); + + InternalDerbyDatabase internalDatabase = createInternalDatabaseFromBackup(backupLocation); + return internalDatabase; + + + } catch (SQLException e) { + throw new DatabaseCopyException("A problem occurred while attempting to copy the database.", e); + } catch (DatabaseCreationException e) { + throw new DatabaseCopyException("A problem occurred while attempting to copy the database.", e); + } finally { + DatabaseUtilities.closeConnectionQuietly(connection); + } + + + + } else { + throw new DatabaseCopyException("Unable to copy external databases!"); + } + } + + private InternalDerbyDatabase createInternalDatabaseFromBackup( + String backupLocation) throws DatabaseCreationException { + String newName = nextDatabaseIdentifier(); + String newDatabaseConnectionURL = DERBY_PROTOCOL + newName + ";restoreFrom=" + backupLocation; + DataSource derivedDataSource = createNewDataSource(DERBY_DRIVER_NAME, + newDatabaseConnectionURL, null, null); + InternalDerbyDatabase internalDatabase = createNewInternalDatabase(derivedDataSource, false); + internalDatabase.setName(newName); + return internalDatabase; + } + + private String createDatabaseBackup(Connection connection, + String originalName) throws SQLException { + CallableStatement backupStatement = connection.prepareCall("CALL SYSCS_UTIL.SYSCS_BACKUP_DATABASE(?)"); + String tempDir = System.getProperty("java.io.tmpdir"); + backupStatement.setString(1, tempDir); + backupStatement.execute(); + String backupLocation = new File(new File(tempDir), originalName).getAbsolutePath(); + return backupLocation; + } + //***---UTILITIES---*** - + private DataSource createNewDataSource( String driver, String url, String username, String password) - throws DatabaseCreationException { + throws DatabaseCreationException { try { - //Load the database driver - Class.forName(driver); - - //create a new data source based on the database connection info provided. - ConnectionFactory connectionFactory = new DriverManagerConnectionFactory( - url, username, password); - GenericObjectPool connectionPool = new GenericObjectPool(); + //Load the database driver + Class.forName(driver); + + //create a new data source based on the database connection info provided. + ConnectionFactory connectionFactory = new DriverManagerConnectionFactory( + url, username, password); + GenericObjectPool connectionPool = new GenericObjectPool(); KeyedObjectPoolFactory stmtPool = new GenericKeyedObjectPoolFactory(null); new PoolableConnectionFactory( connectionFactory, connectionPool, stmtPool, null, false, true); DataSource dataSource = new PoolingDataSource(connectionPool); - + //test the connection (this will throw an exception if the connection is faulty) dataSource.getConnection(); - + //return that data source. - return dataSource; - } catch (ClassNotFoundException e) { - throw new DatabaseCreationException( - "Database driver '" + driver + "' could not be found", e); - } catch (SQLException e) { - throw new DatabaseCreationException(e.getMessage(), e); - } + return dataSource; + } catch (ClassNotFoundException e) { + throw new DatabaseCreationException( + "Database driver '" + driver + "' could not be found", e); + } catch (SQLException e) { + throw new DatabaseCreationException(e.getMessage(), e); + } } - + private DataSource createNewInternalDataSource(String dbName) - throws DatabaseCreationException { + throws DatabaseCreationException { String newDatabaseConnectionURL = DERBY_PROTOCOL - + dbName - + DEFAULT_CREATE_CONNECTION_STRING; + + dbName + + DEFAULT_CREATE_CONNECTION_STRING; return createNewDataSource(DERBY_DRIVER_NAME, newDatabaseConnectionURL, null, null); } - private static final int SCHEMA_NAME_INDEX = 2; - private static final int TABLE_NAME_INDEX = 3; - private static final String NONSYSTEM_SCHEMA_NAME = "APP"; -// //(removes all non-system tables from the provided databases) -// private void removeAllNonSystemDatabaseTables(Connection dbConnection) throws SQLException { -// DatabaseMetaData dbMetadata = dbConnection.getMetaData(); -// ResultSet allTableNames = dbMetadata.getTables(null, null, null, null); -// -// Statement removeTables = dbConnection.createStatement(); -// -// while (allTableNames.next()) { -// if (!hasSystemSchema(allTableNames.getString(SCHEMA_NAME_INDEX))) { -// String dropTableQuery = formDropTableQuery(allTableNames.getString(TABLE_NAME_INDEX)); -// removeTables.addBatch(dropTableQuery); -// } -// } -// -// removeTables.executeBatch(); -// } - - private boolean hasSystemSchema(String tableSchemaName) { - return tableSchemaName.indexOf(NONSYSTEM_SCHEMA_NAME) == -1; + private InternalDerbyDatabase createNewInternalDatabase(DataSource internalDataSource) throws DatabaseCreationException { + return createNewInternalDatabase(internalDataSource, true); } - - private String formDropTableQuery(String tableName) { - String removeTableSQL = - "DROP TABLE " - + NONSYSTEM_SCHEMA_NAME + "." + tableName; - return removeTableSQL; + + private InternalDerbyDatabase createNewInternalDatabase(DataSource internalDataSource, boolean clean) + throws DatabaseCreationException { + InternalDerbyDatabase db = + new InternalDerbyDatabase(internalDataSource); + Connection cleaningConnection = null; + try { + //if this database existed on disk from a previous session, clean it to be like new + if(clean) { + cleaningConnection = db.getConnection(); + DatabaseCleaner.cleanDatabase(cleaningConnection, false); + } + + //keep track of our new database for this CIShell session + internalDatabases.add(db); + + + return db; + } catch (Exception e) { + DatabaseUtilities.closeConnectionQuietly(cleaningConnection); + throw new DatabaseCreationException(e); + } } + //only thing that needs to be synchronized; all other ops are non-conflicting once they have differing names + private synchronized String nextDatabaseIdentifier() { + //Random to deal with the multiple running CIShell instance problem. Note: this means databases will build up. This is not a big deal, as even a "large" database will only be a few megabytes. + String randomPart = UUID.randomUUID().toString(); + String identifier = INTERNAL_DB_NAME_PREFIX + randomPart + "_" + id; + id++; + return identifier; + } + } Modified: trunk/core/org.cishell.reference.service.database/src/org/cishell/reference/service/database/InternalDerbyDatabase.java =================================================================== --- trunk/core/org.cishell.reference.service.database/src/org/cishell/reference/service/database/InternalDerbyDatabase.java 2010-01-26 16:51:30 UTC (rev 1025) +++ trunk/core/org.cishell.reference.service.database/src/org/cishell/reference/service/database/InternalDerbyDatabase.java 2010-01-26 17:46:36 UTC (rev 1026) @@ -11,7 +11,8 @@ public class InternalDerbyDatabase implements Database { private DataSource dataSource; - + private String databaseName; + // TODO: Should this be public? public InternalDerbyDatabase(DataSource dataSource) { this.dataSource = dataSource; } @@ -33,4 +34,13 @@ public String getApplicationSchemaName() { return "APP"; } + + + protected void setName(String databaseName) { + this.databaseName = databaseName; + } + + protected String getName() { + return databaseName; + } } Modified: trunk/core/org.cishell.service.database/src/org/cishell/service/database/DatabaseService.java =================================================================== --- trunk/core/org.cishell.service.database/src/org/cishell/service/database/DatabaseService.java 2010-01-26 16:51:30 UTC (rev 1025) +++ trunk/core/org.cishell.service.database/src/org/cishell/service/database/DatabaseService.java 2010-01-26 17:46:36 UTC (rev 1026) @@ -7,4 +7,5 @@ public Database connectToExistingDatabase( String driver, String url, String username, String password) throws DatabaseCreationException; + public Database copyDatabase(Database originalDatabase) throws DatabaseCopyException; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fu...@us...> - 2010-01-26 16:51:38
|
Revision: 1025 http://cishell.svn.sourceforge.net/cishell/?rev=1025&view=rev Author: fugu13 Date: 2010-01-26 16:51:30 +0000 (Tue, 26 Jan 2010) Log Message: ----------- Some minor changes. Modified Paths: -------------- trunk/core/org.cishell.utilities/src/org/cishell/utilities/DatabaseUtilities.java trunk/core/org.cishell.utilities/src/org/cishell/utilities/database/DatabaseTable.java trunk/core/org.cishell.utilities/src/org/cishell/utilities/database/ForeignKey.java Modified: trunk/core/org.cishell.utilities/src/org/cishell/utilities/DatabaseUtilities.java =================================================================== --- trunk/core/org.cishell.utilities/src/org/cishell/utilities/DatabaseUtilities.java 2010-01-26 16:34:27 UTC (rev 1024) +++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/DatabaseUtilities.java 2010-01-26 16:51:30 UTC (rev 1025) @@ -31,8 +31,8 @@ } return connection; } - - public static String getInExpression(List<String> columns, List<Map<String, Object>> valueMaps) { + // TODO: I'd prefer something like createSQLInExpression + public static String createSQLInExpression(List<String> columns, List<Map<String, Object>> valueMaps) { String columnNames = implodeAndWrap(columns); List<String> values = new ArrayList<String>(); @@ -62,6 +62,7 @@ } } + //TODO: Consider abstracting what you're wrapping with and making this a StringUtility. public static String implodeAndWrap(List<String> values) { return "(" + StringUtilities.implodeList(values, ", ") + ")"; } Modified: trunk/core/org.cishell.utilities/src/org/cishell/utilities/database/DatabaseTable.java =================================================================== --- trunk/core/org.cishell.utilities/src/org/cishell/utilities/database/DatabaseTable.java 2010-01-26 16:34:27 UTC (rev 1024) +++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/database/DatabaseTable.java 2010-01-26 16:51:30 UTC (rev 1025) @@ -145,7 +145,7 @@ private String constructDeleteStatement(List<String> columns, List<Map<String, Object>> otherEntities) { - return "DELETE FROM " + this.toString() + " WHERE " + DatabaseUtilities.getInExpression(columns, otherEntities); + return "DELETE FROM " + this.toString() + " WHERE " + DatabaseUtilities.createSQLInExpression(columns, otherEntities); } public void duplicateTable(Connection originalConnection, Modified: trunk/core/org.cishell.utilities/src/org/cishell/utilities/database/ForeignKey.java =================================================================== --- trunk/core/org.cishell.utilities/src/org/cishell/utilities/database/ForeignKey.java 2010-01-26 16:34:27 UTC (rev 1024) +++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/database/ForeignKey.java 2010-01-26 16:51:30 UTC (rev 1025) @@ -37,7 +37,7 @@ private String constructUpdateQuery(List<Map<String, Object>> from, Map<String, Object> to) { return "UPDATE " + otherTable.toString() + " SET "+ formatUpdates(to) + " WHERE " - + DatabaseUtilities.getInExpression(getForeignColumnNames(), translateToForeignNames(from)); + + DatabaseUtilities.createSQLInExpression(getForeignColumnNames(), translateToForeignNames(from)); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mwl...@us...> - 2010-01-26 16:34:33
|
Revision: 1024 http://cishell.svn.sourceforge.net/cishell/?rev=1024&view=rev Author: mwlinnem Date: 2010-01-26 16:34:27 +0000 (Tue, 26 Jan 2010) Log Message: ----------- An example jython CIShell algorithm (not tested to see if it still works). Added Paths: ----------- trunk/examples/test_jython_algorithm/.project trunk/examples/test_jython_algorithm/.pydevproject trunk/examples/test_jython_algorithm/META-INF/ trunk/examples/test_jython_algorithm/META-INF/MANIFEST.MF trunk/examples/test_jython_algorithm/OSGI-INF/ trunk/examples/test_jython_algorithm/OSGI-INF/algorithm.properties trunk/examples/test_jython_algorithm/OSGI-INF/component.xml trunk/examples/test_jython_algorithm/OSGI-INF/l10n/ trunk/examples/test_jython_algorithm/OSGI-INF/l10n/bundle_en.properties trunk/examples/test_jython_algorithm/OSGI-INF/metatype/ trunk/examples/test_jython_algorithm/OSGI-INF/metatype/METADATA.XML trunk/examples/test_jython_algorithm/README.txt trunk/examples/test_jython_algorithm/build.properties trunk/examples/test_jython_algorithm/donkey.py Added: trunk/examples/test_jython_algorithm/.project =================================================================== --- trunk/examples/test_jython_algorithm/.project (rev 0) +++ trunk/examples/test_jython_algorithm/.project 2010-01-26 16:34:27 UTC (rev 1024) @@ -0,0 +1,17 @@ +<?xml version="1.0" encoding="UTF-8"?> +<projectDescription> + <name>jbdd</name> + <comment></comment> + <projects> + </projects> + <buildSpec> + <buildCommand> + <name>org.python.pydev.PyDevBuilder</name> + <arguments> + </arguments> + </buildCommand> + </buildSpec> + <natures> + <nature>org.python.pydev.pythonNature</nature> + </natures> +</projectDescription> Added: trunk/examples/test_jython_algorithm/.pydevproject =================================================================== --- trunk/examples/test_jython_algorithm/.pydevproject (rev 0) +++ trunk/examples/test_jython_algorithm/.pydevproject 2010-01-26 16:34:27 UTC (rev 1024) @@ -0,0 +1,7 @@ +<?xml version="1.0" encoding="UTF-8" standalone="no"?> +<?eclipse-pydev version="1.0"?> + +<pydev_project> +<pydev_property name="org.python.pydev.PYTHON_PROJECT_VERSION">python 2.6</pydev_property> +<pydev_property name="org.python.pydev.PYTHON_PROJECT_INTERPRETER">Default</pydev_property> +</pydev_project> Added: trunk/examples/test_jython_algorithm/META-INF/MANIFEST.MF =================================================================== --- trunk/examples/test_jython_algorithm/META-INF/MANIFEST.MF (rev 0) +++ trunk/examples/test_jython_algorithm/META-INF/MANIFEST.MF 2010-01-26 16:34:27 UTC (rev 1024) @@ -0,0 +1,18 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: Sample Jython Algorithm +Bundle-SymbolicName: org.cishell.templates.wizards.samplejythonalgorithm +Bundle-Version: 0.0.1 +Bundle-ClassPath: . +Bundle-Localization: plugin +Import-Package: org.cishell.templates.jythonrunner, + org.cishell.framework, + org.cishell.framework.algorithm, + org.cishell.framework.data, + org.osgi.framework;version="1.3.0", + org.osgi.service.component;version="1.0.0", + org.osgi.service.log;version="1.3.0", + org.osgi.service.metatype;version="1.1.0", + org.osgi.service.prefs;version="1.1.0" +X-AutoStart: true +Service-Component: OSGI-INF/component.xml Added: trunk/examples/test_jython_algorithm/OSGI-INF/algorithm.properties =================================================================== --- trunk/examples/test_jython_algorithm/OSGI-INF/algorithm.properties (rev 0) +++ trunk/examples/test_jython_algorithm/OSGI-INF/algorithm.properties 2010-01-26 16:34:27 UTC (rev 1024) @@ -0,0 +1,14 @@ +menu_path=File/Test/additions +label=Sample Jython Algorithm +description=Demonstrates some basic Jython-based algorithm functionality. +in_data=prefuse.data.Graph +out_data=prefuse.data.Graph, file:text/plain +service.pid=org.cishell.templates.wizards.samplejythonalgorithm +remoteable=false +script_path=/donkey.py +result0.label=Exact same network that was passed in +result0.type=Network +result0.parent=arg0 +result1.label=Number of edges in provided network +result1.type=Text +result1.parent=arg0 Added: trunk/examples/test_jython_algorithm/OSGI-INF/component.xml =================================================================== --- trunk/examples/test_jython_algorithm/OSGI-INF/component.xml (rev 0) +++ trunk/examples/test_jython_algorithm/OSGI-INF/component.xml 2010-01-26 16:34:27 UTC (rev 1024) @@ -0,0 +1,12 @@ +<?xml version="1.0" encoding="UTF-8"?> +<component name="org.cishell.templates.wizards.samplejythonalgorithm" immediate="false"> + <implementation class="org.cishell.templates.jythonrunner.JythonAlgorithmFactory"/> + <properties entry="OSGI-INF/algorithm.properties"/> + <reference name="LOG" interface="org.osgi.service.log.LogService"/> + <reference name="MTS" interface="org.osgi.service.metatype.MetaTypeService"/> + + <service> + <provide interface= + "org.cishell.framework.algorithm.AlgorithmFactory"/> + </service> +</component> \ No newline at end of file Added: trunk/examples/test_jython_algorithm/OSGI-INF/l10n/bundle_en.properties =================================================================== --- trunk/examples/test_jython_algorithm/OSGI-INF/l10n/bundle_en.properties (rev 0) +++ trunk/examples/test_jython_algorithm/OSGI-INF/l10n/bundle_en.properties 2010-01-26 16:34:27 UTC (rev 1024) @@ -0,0 +1,7 @@ +#Localization variables for OSGI-INF/metatatype/METADATA.XML +# +#Samples: +#input=Input +#desc=Enter an integer (that will be converted to a string) +#name=Input->String +#name_desc=Converts inputted integer to string Added: trunk/examples/test_jython_algorithm/OSGI-INF/metatype/METADATA.XML =================================================================== --- trunk/examples/test_jython_algorithm/OSGI-INF/metatype/METADATA.XML (rev 0) +++ trunk/examples/test_jython_algorithm/OSGI-INF/metatype/METADATA.XML 2010-01-26 16:34:27 UTC (rev 1024) @@ -0,0 +1,10 @@ +<?xml version="1.0" encoding="UTF-8"?> +<metatype:MetaData xmlns:metatype="http://www.osgi.org/xmlns/metatype/v1.0.0"> + <OCD name="Sample Jython Algorithm" id="org.cishell.templates.wizards.samplejythonalgorithm.OCD" + description="A sample jython algorithm"> + <AD name="Sample Attribute" id="sample_attr" type="Integer" description="Enter a positive integer" default="1" min="1" /> + </OCD> + <Designate pid="org.cishell.templates.wizards.samplejythonalgorithm"> + <Object ocdref="org.cishell.templates.wizards.samplejythonalgorithm.OCD" /> + </Designate> +</metatype:MetaData> Added: trunk/examples/test_jython_algorithm/README.txt =================================================================== --- trunk/examples/test_jython_algorithm/README.txt (rev 0) +++ trunk/examples/test_jython_algorithm/README.txt 2010-01-26 16:34:27 UTC (rev 1024) @@ -0,0 +1,40 @@ +Here is the minimum you need to know to integrate a jython script with +CIShell, working from what is already provided by default in this project. + +Arguments passed in from the Network Workbench Data Manager are passed +into your script by default as variables with the prefix "arg" and a +numeric suffix. The first argument is arg0, the next is arg1, and so on. +You may specify how many, and what type of data you want these to be by +editing the in_data property in the algorithm.properties file. The + +Arguments passed in from the user at the time the algorithm is run (The +kind where a dialog box pops up and the user fills things in) can have +any valid python variable name. You can define what data you need, the +type of data, and the variable names of that data by editing the +METADATA.XML file. The id provided will be the name of the variable in +the python environment. + +To return results, assign values to variables with the prefix "result". +The first result is result0, the second is result1, and so on. You +must specify the format of the data you are returning by editing the +out_data property in the algorithm.properties file. You must also +define values for the metadata of each result you return. Look at the +algorithm.properties file to see how this is done. Each result must +specify a label and type, but parent part is optional. Label can be +any text, type must be one of the pre-define types ("Network", "Text", +"Matrix", or "Other" currently), and parent must be the variable +name of one of the provided data arguments (arg0, arg1, etc...). + +Change the menu path to something sensible too. + +NOTE: There are other things that should probably be changed if you +are doing anything more than playing around with the jython algorithm +capabilities in CIShell. The plugin name, symbolic-name, all references +to the package, the service.pid, the algorithm description, and +probably a few other things should be unique for each project. This +template is currently in a rough state. It should probably have +a wizard that asks the user to specify all the stuff that +should change between projects. This should do for now though, +especially for internal use. + + \ No newline at end of file Added: trunk/examples/test_jython_algorithm/build.properties =================================================================== --- trunk/examples/test_jython_algorithm/build.properties (rev 0) +++ trunk/examples/test_jython_algorithm/build.properties 2010-01-26 16:34:27 UTC (rev 1024) @@ -0,0 +1,5 @@ +bin.includes = META-INF/,\ + .,\ + OSGI-INF/,\ + samplealgorithm.py,\ + donkey.py Added: trunk/examples/test_jython_algorithm/donkey.py =================================================================== --- trunk/examples/test_jython_algorithm/donkey.py (rev 0) +++ trunk/examples/test_jython_algorithm/donkey.py 2010-01-26 16:34:27 UTC (rev 1024) @@ -0,0 +1,29 @@ +# To see the output printed to the console in Network Workbench, use the +# switch "-console" when opening Network Workbench from the command line. +from java import io + +print "Here is the value you gave me when you ran the algorithm..." +print sample_attr + +print "Here is what I got from CIShell (the graph you highlighted)" +print arg0 +graph = arg0 +edge_count = graph.getEdgeCount() + +print "Here is the number of edges in the graph you provided..." +print edge_count + +aFile = io.File("whatever.txt") +writer = io.BufferedWriter(io.FileWriter(aFile)) +writer.write(str(edge_count)) +writer.close() + +print "I will now return the original graph, and the edge count in a file" + +aFile = io.File("whatever.txt") +writer = io.BufferedWriter(io.FileWriter(aFile)) +writer.write(str(edge_count)) +writer.close() + +result0 = arg0 +result1 = aFile \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mwl...@us...> - 2010-01-26 16:33:08
|
Revision: 1023 http://cishell.svn.sourceforge.net/cishell/?rev=1023&view=rev Author: mwlinnem Date: 2010-01-26 16:33:01 +0000 (Tue, 26 Jan 2010) Log Message: ----------- Initial import. Added Paths: ----------- trunk/examples/test_jython_algorithm/ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mwl...@us...> - 2010-01-25 22:09:11
|
Revision: 1022 http://cishell.svn.sourceforge.net/cishell/?rev=1022&view=rev Author: mwlinnem Date: 2010-01-25 22:09:05 +0000 (Mon, 25 Jan 2010) Log Message: ----------- Added database stuff to cishell build. Modified Paths: -------------- trunk/deployment/org.cishell.reference.releng/build-files/fetchSvnAll.xml Modified: trunk/deployment/org.cishell.reference.releng/build-files/fetchSvnAll.xml =================================================================== --- trunk/deployment/org.cishell.reference.releng/build-files/fetchSvnAll.xml 2010-01-25 16:57:58 UTC (rev 1021) +++ trunk/deployment/org.cishell.reference.releng/build-files/fetchSvnAll.xml 2010-01-25 22:09:05 UTC (rev 1022) @@ -175,5 +175,26 @@ <param name="project.name" value="/core/org.cishell.utilities"/> <param name="url" value="https://cishell.svn.sourceforge.net/svnroot/cishell/trunk"/> </antcall> + + <antcall target="svn.co"> + <param name="target" value="plugins"/> + <param name="element.id" value="org.cishell.reference.service.database"/> + <param name="project.name" value="/core/org.cishell.reference.service.database"/> + <param name="url" value="https://cishell.svn.sourceforge.net/svnroot/cishell/trunk"/> + </antcall> + + <antcall target="svn.co"> + <param name="target" value="plugins"/> + <param name="element.id" value="org.cishell.service.database"/> + <param name="project.name" value="/core/org.cishell.service.database"/> + <param name="url" value="https://cishell.svn.sourceforge.net/svnroot/cishell/trunk"/> + </antcall> + + <antcall target="svn.co"> + <param name="target" value="plugins"/> + <param name="element.id" value="org.cishell.templates.database"/> + <param name="project.name" value="/templates/org.cishell.templates.database"/> + <param name="url" value="https://cishell.svn.sourceforge.net/svnroot/cishell/trunk"/> + </antcall> </target> </project> \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pat...@us...> - 2010-01-25 16:58:14
|
Revision: 1021 http://cishell.svn.sourceforge.net/cishell/?rev=1021&view=rev Author: pataphil Date: 2010-01-25 16:57:58 +0000 (Mon, 25 Jan 2010) Log Message: ----------- * Added TableUtilities.allAreNull() and TableUtilities.allAreNotNull(). * Added the package org.cishell.utilities.dictionary. * Did some refactoring in StringUtilities. * Added various utilities in StringUtilities. * Reviewed by Joseph. Modified Paths: -------------- trunk/core/org.cishell.utilities/META-INF/MANIFEST.MF trunk/core/org.cishell.utilities/src/org/cishell/utilities/ArrayUtilities.java trunk/core/org.cishell.utilities/src/org/cishell/utilities/IntegerParserWithDefault.java trunk/core/org.cishell.utilities/src/org/cishell/utilities/StringUtilities.java Added Paths: ----------- trunk/core/org.cishell.utilities/src/org/cishell/utilities/Pair.java trunk/core/org.cishell.utilities/src/org/cishell/utilities/dictionary/ trunk/core/org.cishell.utilities/src/org/cishell/utilities/dictionary/DictionaryEntry.java trunk/core/org.cishell.utilities/src/org/cishell/utilities/dictionary/DictionaryIterator.java trunk/core/org.cishell.utilities/src/org/cishell/utilities/dictionary/DictionaryUtilities.java Modified: trunk/core/org.cishell.utilities/META-INF/MANIFEST.MF =================================================================== --- trunk/core/org.cishell.utilities/META-INF/MANIFEST.MF 2010-01-21 20:31:28 UTC (rev 1020) +++ trunk/core/org.cishell.utilities/META-INF/MANIFEST.MF 2010-01-25 16:57:58 UTC (rev 1021) @@ -19,8 +19,9 @@ prefuse.data.util, prefuse.util, prefuse.util.collections -Export-Package: org.cishell.utilities, - org.cishell.utilities.database, +Export-Package: org.cishell.utilities, + org.cishell.utilities.dictionary, + org.cishell.utilities.database, org.cishell.utilities.mutateParameter, org.cishell.utilities.mutateParameter.defaultvalue, org.cishell.utilities.mutateParameter.dropdown, Modified: trunk/core/org.cishell.utilities/src/org/cishell/utilities/ArrayUtilities.java =================================================================== --- trunk/core/org.cishell.utilities/src/org/cishell/utilities/ArrayUtilities.java 2010-01-21 20:31:28 UTC (rev 1020) +++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/ArrayUtilities.java 2010-01-25 16:57:58 UTC (rev 1021) @@ -42,4 +42,26 @@ return clone; } + + // TODO: Find a better place to put this? + public static <T> boolean allAreNull(T... objects) { + for (T object : objects) { + if (object != null) { + return false; + } + } + + return true; + } + + // TODO: Find a better place to put this? + public static <T> boolean allAreNotNull(T... objects) { + for (T object : objects) { + if (object == null) { + return false; + } + } + + return true; + } } Modified: trunk/core/org.cishell.utilities/src/org/cishell/utilities/IntegerParserWithDefault.java =================================================================== --- trunk/core/org.cishell.utilities/src/org/cishell/utilities/IntegerParserWithDefault.java 2010-01-21 20:31:28 UTC (rev 1020) +++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/IntegerParserWithDefault.java 2010-01-25 16:57:58 UTC (rev 1021) @@ -1,9 +1,9 @@ package org.cishell.utilities; public class IntegerParserWithDefault { - public static final int DEFAULT = -1; + public static final Integer DEFAULT = null; - public static int parse(String target) { + public static Integer parse(String target) { try { return Integer.parseInt(target); } catch (Exception e) { Added: trunk/core/org.cishell.utilities/src/org/cishell/utilities/Pair.java =================================================================== --- trunk/core/org.cishell.utilities/src/org/cishell/utilities/Pair.java (rev 0) +++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/Pair.java 2010-01-25 16:57:58 UTC (rev 1021) @@ -0,0 +1,19 @@ +package org.cishell.utilities; + +public class Pair<S, T> { + S firstObject; + T secondObject; + + public Pair(S firstObject, T secondObject) { + this.firstObject = firstObject; + this.secondObject = secondObject; + } + + public S getFirstObject() { + return this.firstObject; + } + + public T getSecondObject() { + return this.secondObject; + } +} \ No newline at end of file Modified: trunk/core/org.cishell.utilities/src/org/cishell/utilities/StringUtilities.java =================================================================== --- trunk/core/org.cishell.utilities/src/org/cishell/utilities/StringUtilities.java 2010-01-21 20:31:28 UTC (rev 1020) +++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/StringUtilities.java 2010-01-25 16:57:58 UTC (rev 1021) @@ -93,21 +93,59 @@ } // TODO Think about instead using a Pattern, "\s*". Don't have to though. - public static boolean isEmptyOrWhiteSpace(String test) { - String trimmed = test.trim(); + public static boolean isEmptyOrWhitespace(String string) { + String trimmed = string.trim(); return (trimmed.length() == 0); } - public static boolean allAreEmptyOrWhiteSpace(String... tests) { - for (String test : tests) { - if (!isEmptyOrWhiteSpace(test)) { + public static boolean allAreEmptyOrWhitespace(String... strings) { + for (String string : strings) { + if (!isEmptyOrWhitespace(string)) { return false; } } return true; } + + public static boolean allAreNeitherEmptyNorWhitespace(String... strings) { + for (String string : strings) { + if (isEmptyOrWhitespace(string)) { + return false; + } + } + + return true; + } + + public static boolean isNull_Empty_OrWhitespace(String string) { + if (string == null) { + return true; + } + + return isEmptyOrWhitespace(string); + } + + public static boolean allAreNull_Empty_OrWhitespace(String... strings) { + for (String string : strings) { + if (!isNull_Empty_OrWhitespace(string)) { + return false; + } + } + + return true; + } + + public static boolean allAreNeitherNullNorEmptyNorWhitespace(String... strings) { + for (String string : strings) { + if (isNull_Empty_OrWhitespace(string)) { + return false; + } + } + + return true; + } public static int countOccurrencesOfChar( CharSequence characters, char target) { @@ -167,6 +205,14 @@ return (String[])cleanedStrings.toArray(new String[0]); } + public static String trimIfNotNull(String string) { + if (string == null) { + return null; + } + + return string.trim(); + } + public static String toSentenceCase(String word) { String cleanedWord = simpleClean(word); @@ -193,18 +239,25 @@ return -1; } - public static boolean validAndEquivalent(String string1, String string2) { - return (!isEmptyOrWhiteSpace(string1) && (string1.compareTo(string2) == 0)); + /* TODO Perhaps make a "hasContent" method in here and apply that terminology throughout. */ + public static boolean areValidAndEqual(String string1, String string2) { + return ( + !isNull_Empty_OrWhitespace(string1) && + !isNull_Empty_OrWhitespace(string2) && + (string1.equals(string2))); } - public static boolean validAndEquivalentIgnoreCase(String string1, String string2) { - return (!isEmptyOrWhiteSpace(string1) && (string1.compareToIgnoreCase(string2) == 0)); + public static boolean areValidAndEqualIgnoreCase(String string1, String string2) { + return ( + !isNull_Empty_OrWhitespace(string1) && + !isNull_Empty_OrWhitespace(string2) && + string1.equalsIgnoreCase(string2)); } // TODO: New Name. public static String simpleMerge(String string1, String string2) { - if (!isEmptyOrWhiteSpace(string1)) { - if (!isEmptyOrWhiteSpace(string2)) { + if (!isNull_Empty_OrWhitespace(string1)) { + if (!isNull_Empty_OrWhitespace(string2)) { if (string1.length() >= string2.length()) { return string1; } else { @@ -214,7 +267,7 @@ return string1; } } - else if (!isEmptyOrWhiteSpace(string2)) { + else if (!isNull_Empty_OrWhitespace(string2)) { return string2; } Added: trunk/core/org.cishell.utilities/src/org/cishell/utilities/dictionary/DictionaryEntry.java =================================================================== --- trunk/core/org.cishell.utilities/src/org/cishell/utilities/dictionary/DictionaryEntry.java (rev 0) +++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/dictionary/DictionaryEntry.java 2010-01-25 16:57:58 UTC (rev 1021) @@ -0,0 +1,19 @@ +package org.cishell.utilities.dictionary; + +public class DictionaryEntry<K, V> { + private K key; + private V value; + + public DictionaryEntry(K key, V value) { + this.key = key; + this.value = value; + } + + public K getKey() { + return this.key; + } + + public V getValue() { + return this.value; + } +} \ No newline at end of file Added: trunk/core/org.cishell.utilities/src/org/cishell/utilities/dictionary/DictionaryIterator.java =================================================================== --- trunk/core/org.cishell.utilities/src/org/cishell/utilities/dictionary/DictionaryIterator.java (rev 0) +++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/dictionary/DictionaryIterator.java 2010-01-25 16:57:58 UTC (rev 1021) @@ -0,0 +1,37 @@ +package org.cishell.utilities.dictionary; + +import java.util.Dictionary; +import java.util.Enumeration; +import java.util.Iterator; + +public class DictionaryIterator<K, V> + implements Iterator<DictionaryEntry<K, V>>, Iterable<DictionaryEntry<K, V>> { + private Dictionary<K, V> dictionary; + Enumeration<K> keys; + + public DictionaryIterator(Dictionary<K, V> dictionary) { + this.dictionary = dictionary; + this.keys = dictionary.keys(); + } + + public boolean hasNext() { + return this.keys.hasMoreElements(); + } + + public DictionaryEntry<K, V> next() { + K nextKey = this.keys.nextElement(); + V nextValue = this.dictionary.get(nextKey); + + return new DictionaryEntry<K, V>(nextKey, nextValue); + } + + public void remove() { + String exceptionMessage = "remove() cannot be called on a DictionaryIterator."; + + throw new UnsupportedOperationException(exceptionMessage); + } + + public Iterator<DictionaryEntry<K, V>> iterator() { + return this; + } +} \ No newline at end of file Added: trunk/core/org.cishell.utilities/src/org/cishell/utilities/dictionary/DictionaryUtilities.java =================================================================== --- trunk/core/org.cishell.utilities/src/org/cishell/utilities/dictionary/DictionaryUtilities.java (rev 0) +++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/dictionary/DictionaryUtilities.java 2010-01-25 16:57:58 UTC (rev 1021) @@ -0,0 +1,41 @@ +package org.cishell.utilities.dictionary; + +import java.util.Dictionary; +import java.util.Hashtable; + +public class DictionaryUtilities { + /// Side-effects the provided Dictionary. + public static <K, V> void addIfNotNull(Dictionary<K, V> dictionary, K key, V value) { + if ((key != null) && (value != null)) { + dictionary.put(key, value); + } + } + + /// Side-effects the provided Dictionary. + public static <K, V> void addIfNotNull( + Dictionary<K, V> dictionary, DictionaryEntry<K, V>... entries) { + for (DictionaryEntry<K, V> entry : entries) { + addIfNotNull(dictionary, entry.getKey(), entry.getValue()); + } + } + + public static <K, V> Dictionary<K, V> copyWithValuesThatAreNotNull( + Dictionary<K, V> originalDictionary, DictionaryEntry<K, V>... entries) { + Dictionary<K, V> newDictionary = copy(originalDictionary); + + addIfNotNull(newDictionary, entries); + + return newDictionary; + } + + public static <K, V> Dictionary<K, V> copy(Dictionary<K, V> originalDictionary) { + Dictionary<K, V> newDictionary = new Hashtable<K, V>(); + + for (DictionaryEntry<K, V> originalEntry : + new DictionaryIterator<K, V>(originalDictionary)) { + newDictionary.put(originalEntry.getKey(), originalEntry.getValue()); + } + + return newDictionary; + } +} \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fu...@us...> - 2010-01-21 20:31:35
|
Revision: 1020 http://cishell.svn.sourceforge.net/cishell/?rev=1020&view=rev Author: fugu13 Date: 2010-01-21 20:31:28 +0000 (Thu, 21 Jan 2010) Log Message: ----------- Add various database utilities. Modified Paths: -------------- trunk/core/org.cishell.utilities/META-INF/MANIFEST.MF trunk/core/org.cishell.utilities/src/org/cishell/utilities/DatabaseUtilities.java Added Paths: ----------- trunk/core/org.cishell.utilities/src/org/cishell/utilities/database/ trunk/core/org.cishell.utilities/src/org/cishell/utilities/database/Column.java trunk/core/org.cishell.utilities/src/org/cishell/utilities/database/ColumnPair.java trunk/core/org.cishell.utilities/src/org/cishell/utilities/database/DatabaseTable.java trunk/core/org.cishell.utilities/src/org/cishell/utilities/database/ForeignKey.java trunk/core/org.cishell.utilities/src/org/cishell/utilities/database/ForeignKeyNameWithTable.java trunk/core/org.cishell.utilities/src/org/cishell/utilities/database/InvalidRepresentationException.java Modified: trunk/core/org.cishell.utilities/META-INF/MANIFEST.MF =================================================================== --- trunk/core/org.cishell.utilities/META-INF/MANIFEST.MF 2010-01-14 21:02:06 UTC (rev 1019) +++ trunk/core/org.cishell.utilities/META-INF/MANIFEST.MF 2010-01-21 20:31:28 UTC (rev 1020) @@ -20,6 +20,7 @@ prefuse.util, prefuse.util.collections Export-Package: org.cishell.utilities, + org.cishell.utilities.database, org.cishell.utilities.mutateParameter, org.cishell.utilities.mutateParameter.defaultvalue, org.cishell.utilities.mutateParameter.dropdown, Modified: trunk/core/org.cishell.utilities/src/org/cishell/utilities/DatabaseUtilities.java =================================================================== --- trunk/core/org.cishell.utilities/src/org/cishell/utilities/DatabaseUtilities.java 2010-01-14 21:02:06 UTC (rev 1019) +++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/DatabaseUtilities.java 2010-01-21 20:31:28 UTC (rev 1020) @@ -2,12 +2,18 @@ import java.sql.Connection; import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; import org.cishell.framework.algorithm.AlgorithmExecutionException; import org.cishell.service.database.Database; public class DatabaseUtilities { public static void closeConnectionQuietly(Connection connection) { + if(connection == null) { + return; + } try { connection.close(); } catch (SQLException e) { @@ -25,4 +31,38 @@ } return connection; } + + public static String getInExpression(List<String> columns, List<Map<String, Object>> valueMaps) { + String columnNames = implodeAndWrap(columns); + + List<String> values = new ArrayList<String>(); + for(Map<String, Object> oldValues : valueMaps) { + List<String> rowValues = new ArrayList<String>(); + for(String column : columns) { + rowValues.add(formatValue(oldValues.get(column))); + } + values.add(implodeAndWrap(rowValues)); + } + String columnValues = implodeAndWrap(values); + + + //first make part with column names + //then make part with groups of column values + return columnNames + " IN " + columnValues; + } + + //TODO: expand this to other sorts of SQL datatypes (per their Prefuse table equivalents) + public static String formatValue(Object value) { + if(value == null) { + return "NULL"; + } else if(value instanceof Number) { + return value.toString(); + } else { + return "'" + value.toString() + "'"; + } + } + + public static String implodeAndWrap(List<String> values) { + return "(" + StringUtilities.implodeList(values, ", ") + ")"; + } } Added: trunk/core/org.cishell.utilities/src/org/cishell/utilities/database/Column.java =================================================================== --- trunk/core/org.cishell.utilities/src/org/cishell/utilities/database/Column.java (rev 0) +++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/database/Column.java 2010-01-21 20:31:28 UTC (rev 1020) @@ -0,0 +1,55 @@ +package org.cishell.utilities.database; + +import java.sql.Types; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +public class Column { + + public final String name; + public final int type; + public final int size; + + public static final Map<Integer, String> TYPE_MAP = constructTypeMap(); + public static final Set<Integer> SIZED_TYPES = constructSizedTypes(); + + private static Map<Integer, String> constructTypeMap() { //if this ever gets derby specific, it shouldn't go here + Map<Integer, String> typeMap = new HashMap<Integer, String>() {{ + put(Types.CHAR, "char"); + put(Types.DATE, "date"); + put(Types.DOUBLE, "double"); + put(Types.FLOAT, "float"); + put(Types.INTEGER, "integer"); + put(Types.SMALLINT, "smallint"); + put(Types.TIME, "time"); + put(Types.VARCHAR, "varchar"); + }}; + return Collections.unmodifiableMap(typeMap); + } + + private static Set<Integer> constructSizedTypes() { + Set<Integer> sizedTypes = new HashSet<Integer>() {{ + add(Types.CHAR); + add(Types.VARCHAR); + + }}; + return null; + } + + public Column(String name, int type, int size) { + this.name = name; + this.type = type; + this.size = size; + } + + + + public String getDefinition() { + // TODO Auto-generated method stub + return null; + } + +} Added: trunk/core/org.cishell.utilities/src/org/cishell/utilities/database/ColumnPair.java =================================================================== --- trunk/core/org.cishell.utilities/src/org/cishell/utilities/database/ColumnPair.java (rev 0) +++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/database/ColumnPair.java 2010-01-21 20:31:28 UTC (rev 1020) @@ -0,0 +1,23 @@ +package org.cishell.utilities.database; + +public final class ColumnPair { + public final String local; + public final String foreign; + + public ColumnPair(String local, String foreign) { + this.local = local; + this.foreign = foreign; + } + + public boolean equals(Object other) { + if(!(other instanceof ColumnPair)) { + return false; + } + ColumnPair o = (ColumnPair) other; + return o.local.equals(this.local) && o.foreign.equals(this.foreign); + } + + public int hashCode() { + return local.hashCode() * 31 + foreign.hashCode(); + } +} Added: trunk/core/org.cishell.utilities/src/org/cishell/utilities/database/DatabaseTable.java =================================================================== --- trunk/core/org.cishell.utilities/src/org/cishell/utilities/database/DatabaseTable.java (rev 0) +++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/database/DatabaseTable.java 2010-01-21 20:31:28 UTC (rev 1020) @@ -0,0 +1,193 @@ +package org.cishell.utilities.database; + +import java.sql.Connection; +import java.sql.ResultSet; +import java.sql.ResultSetMetaData; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import org.cishell.utilities.DatabaseUtilities; + +public final class DatabaseTable { + public final String catalog; + public final String schema; + public final String name; + + public DatabaseTable(String catalog, String schema, String name) { + this.catalog = catalog == null ? "" : catalog.intern(); + this.schema = schema == null ? "" : schema.intern(); + this.name = name == null ? "" : name.intern(); + } + + public static DatabaseTable fromRepresentation(String representation) throws InvalidRepresentationException { + String[] parts = representation.split("\\."); + switch(parts.length) { + case 1: + return new DatabaseTable(null, null, parts[0]); + case 2: + return new DatabaseTable(null, parts[0], parts[1]); + case 3: + return new DatabaseTable(parts[0], parts[1], parts[2]); + default: + throw new InvalidRepresentationException("The representation '" + representation + "' has the wrong number of parts!"); + } + } + + public static DatabaseTable[] availableTables(Connection connection) throws SQLException { + ResultSet results = connection.getMetaData().getTables(null, null, null, new String[]{"TABLE"}); + + List<DatabaseTable> tables = new ArrayList<DatabaseTable>(); + while(results.next()) { + tables.add(new DatabaseTable(results.getString(1), results.getString(2), results.getString(3))); + } + + results.close(); + + return tables.toArray(new DatabaseTable[]{}); + } + + public String toString() { + StringBuilder output = new StringBuilder(); + if(catalog != null && catalog != "") { + output.append(catalog); + output.append('.'); + } + if(schema != null && schema != "") { + output.append(schema); + output.append('.'); + } + + output.append(name); + + return output.toString(); + } + + public boolean equals(Object other) { + if(!(other instanceof DatabaseTable)) { + return false; + } + DatabaseTable o = (DatabaseTable) other; + return o.catalog == this.catalog && o.schema == this.schema && o.name == this.name; + } + + + public int hashCode() { + int hash = catalog.hashCode() * 7; + hash += schema.hashCode() * 5; + hash += name.hashCode() * 3; + return hash; + + } + + public boolean presentInDatabase(Connection connection) throws SQLException { + ResultSet results = connection.getMetaData().getTables(catalog, schema, name, new String[]{"TABLE"}); + boolean foundOne = results.next(); + results.close(); + return foundOne; + } + + public boolean hasPrimaryKey(Connection connection) throws SQLException { + return getPrimaryKeyColumns(connection).length != 0; + } + + public ForeignKey[] getRelations(Connection connection) throws SQLException { + ResultSet related = connection.getMetaData().getExportedKeys(catalog, schema, name); + Map<ForeignKeyNameWithTable, Set<ColumnPair>> correspondences = new HashMap<ForeignKeyNameWithTable, Set<ColumnPair>>(); + while(related.next()) { + String foreignKeyName = related.getString(12); + DatabaseTable relatedTable = new DatabaseTable(related.getString(5), related.getString(6), related.getString(7)); + ForeignKeyNameWithTable key = new ForeignKeyNameWithTable(foreignKeyName, relatedTable); + ColumnPair pair = new ColumnPair(related.getString(4), related.getString(8)); + if(!correspondences.containsKey(key)) { + correspondences.put(key, new HashSet<ColumnPair>()); + } + correspondences.get(key).add(pair); + } + + related.close(); + + return makeForeignKeys(correspondences); + } + + private ForeignKey[] makeForeignKeys( + Map<ForeignKeyNameWithTable, Set<ColumnPair>> correspondences) { + ForeignKey[] foreignKeys = new ForeignKey[correspondences.size()]; + int index = 0; + for(Map.Entry<ForeignKeyNameWithTable, Set<ColumnPair>> entry : correspondences.entrySet()) { + foreignKeys[index] = new ForeignKey(this, entry.getKey().table, entry.getValue()); + index++; + } + return foreignKeys; + } + + public String[] getPrimaryKeyColumns(Connection connection) throws SQLException { + ResultSet columns = connection.getMetaData().getPrimaryKeys(catalog, schema, name); + List<String> columnNames = new ArrayList<String>(); + while(columns.next()) { + columnNames.add(columns.getString(4)); + } + return columnNames.toArray(new String[]{}); + } + + public void deleteRowsByColumns(List<Map<String, Object>> otherEntities, Connection connection) throws SQLException { + if(otherEntities.size() == 0) { + return; + } + List<String> columns = new ArrayList<String>(otherEntities.get(0).keySet()); + String deleteStatement = constructDeleteStatement(columns, otherEntities); + connection.createStatement().executeUpdate(deleteStatement); + } + + private String constructDeleteStatement(List<String> columns, + List<Map<String, Object>> otherEntities) { + return "DELETE FROM " + this.toString() + " WHERE " + DatabaseUtilities.getInExpression(columns, otherEntities); + } + + public void duplicateTable(Connection originalConnection, + Connection newConnection) throws SQLException { + this.duplicateTableStructure(originalConnection, newConnection); + //TODO: finish + + } + + public void duplicateTableStructure(Connection originalConnection, + Connection newConnection) throws SQLException { + Column[] columns = getColumns(originalConnection); + String createStatement = createCreateStatement(columns); + newConnection.createStatement().executeUpdate(createStatement); + } + + private String createCreateStatement(Column[] columns) { + List<String> definitions = new ArrayList<String>(); + for(int ii = 0; ii < columns.length; ii++) { + definitions.add(columns[ii].getDefinition()); + } + return "CREATE TABLE " + this.toString() + DatabaseUtilities.implodeAndWrap(definitions); + } + + private Column[] getColumns(Connection connection) throws SQLException { + ResultSet results = connection.getMetaData().getColumns(this.catalog, this.schema, this.name, null); + List<Column> columns = new ArrayList<Column>(); + while(results.next()) { + columns.add(new Column(results.getString(4), results.getInt(5), results.getInt(7))); + } + return columns.toArray(new Column[]{}); + } + + public void transferPrimaryKey(Connection originalConnection, + Connection newConnection) { + // TODO Auto-generated method stub + + } + + public void pointForeignKeys(Connection originalConnection, + Connection newConnection) { + // TODO Auto-generated method stub + + } +} Added: trunk/core/org.cishell.utilities/src/org/cishell/utilities/database/ForeignKey.java =================================================================== --- trunk/core/org.cishell.utilities/src/org/cishell/utilities/database/ForeignKey.java (rev 0) +++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/database/ForeignKey.java 2010-01-21 20:31:28 UTC (rev 1020) @@ -0,0 +1,82 @@ +package org.cishell.utilities.database; + +import java.sql.Connection; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import org.cishell.utilities.DatabaseUtilities; +import org.cishell.utilities.StringUtilities; + +public final class ForeignKey { + + final public DatabaseTable localTable; + final public DatabaseTable otherTable; + final public Set<ColumnPair> pairs; + + public ForeignKey(DatabaseTable localTable, DatabaseTable otherTable, Set<ColumnPair> pairs) { + this.localTable = localTable; + this.otherTable = otherTable; + this.pairs = Collections.unmodifiableSet(pairs); + } + + public void repoint(List<Map<String, Object>> from, + Map<String, Object> to, Connection connection) throws SQLException { + + String updateQuery = constructUpdateQuery(from, to); + //TODO: remove + System.err.println("Issuing update: " + updateQuery); + connection.createStatement().executeUpdate(updateQuery); + + } + + private String constructUpdateQuery(List<Map<String, Object>> from, + Map<String, Object> to) { + return "UPDATE " + otherTable.toString() + " SET "+ formatUpdates(to) + " WHERE " + + DatabaseUtilities.getInExpression(getForeignColumnNames(), translateToForeignNames(from)); + } + + + + private List<Map<String, Object>> translateToForeignNames( + List<Map<String, Object>> from) { + List<Map<String, Object>> output = new ArrayList<Map<String, Object>>(); + for(Map<String, Object> fromValues : from) { + Map<String, Object> toValues = new HashMap<String, Object>(); + for(ColumnPair pair : pairs) { + toValues.put(pair.foreign, fromValues.get(pair.local)); + } + output.add(toValues); + } + + + return output; + } + + private List<String> getForeignColumnNames() { + List<String> foreignColumns = new ArrayList<String>(); + for(ColumnPair pair : pairs) { + foreignColumns.add(pair.foreign); + } + return foreignColumns; + } + + + + private String formatUpdates(Map<String, Object> to) { + List<String> updateStatements = new ArrayList<String>(); + for(ColumnPair pair : pairs) { + String foreignColumn = pair.foreign; + Object newValue = to.get(pair.local); + updateStatements.add(foreignColumn + " = " + DatabaseUtilities.formatValue(newValue)); + } + return StringUtilities.implodeList(updateStatements, ", "); + } + + + +} Added: trunk/core/org.cishell.utilities/src/org/cishell/utilities/database/ForeignKeyNameWithTable.java =================================================================== --- trunk/core/org.cishell.utilities/src/org/cishell/utilities/database/ForeignKeyNameWithTable.java (rev 0) +++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/database/ForeignKeyNameWithTable.java 2010-01-21 20:31:28 UTC (rev 1020) @@ -0,0 +1,23 @@ +package org.cishell.utilities.database; + +public final class ForeignKeyNameWithTable { + public final String name; + public final DatabaseTable table; + + public ForeignKeyNameWithTable(String name, DatabaseTable table) { + this.name = name; + this.table = table; + } + + public boolean equals(Object other) { + if(!(other instanceof ForeignKeyNameWithTable)) { + return false; + } + ForeignKeyNameWithTable o = (ForeignKeyNameWithTable) other; + return o.name.equals(this.name) && o.table.equals(this.table); + } + + public int hashCode() { + return name.hashCode() * 31 + table.hashCode(); + } +} Added: trunk/core/org.cishell.utilities/src/org/cishell/utilities/database/InvalidRepresentationException.java =================================================================== --- trunk/core/org.cishell.utilities/src/org/cishell/utilities/database/InvalidRepresentationException.java (rev 0) +++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/database/InvalidRepresentationException.java 2010-01-21 20:31:28 UTC (rev 1020) @@ -0,0 +1,14 @@ +package org.cishell.utilities.database; + +public class InvalidRepresentationException extends Exception { + + /** + * + */ + private static final long serialVersionUID = 1L; + + public InvalidRepresentationException(String message) { + super(message); + } + +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <tan...@us...> - 2010-01-14 21:02:12
|
Revision: 1019 http://cishell.svn.sourceforge.net/cishell/?rev=1019&view=rev Author: tankchintan Date: 2010-01-14 21:02:06 +0000 (Thu, 14 Jan 2010) Log Message: ----------- * Fix for Mangled Date when parseDate in the DateUtilities was used. Joseph, Chintan & Patrick Modified Paths: -------------- trunk/core/org.cishell.utilities/src/org/cishell/utilities/DateUtilities.java Modified: trunk/core/org.cishell.utilities/src/org/cishell/utilities/DateUtilities.java =================================================================== --- trunk/core/org.cishell.utilities/src/org/cishell/utilities/DateUtilities.java 2010-01-13 17:13:46 UTC (rev 1018) +++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/DateUtilities.java 2010-01-14 21:02:06 UTC (rev 1019) @@ -228,7 +228,7 @@ public static Date parseDate(String dateString, boolean fixYear) throws ParseException { - return (parseDate(dateString, MONTH_DAY_YEAR_DATE_FORMATS)); + return (parseDate(dateString, MONTH_DAY_YEAR_DATE_FORMATS, fixYear)); } public static Date parseDate(String dateString, String suggestedDateFormat) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mwl...@us...> - 2010-01-13 17:13:54
|
Revision: 1018 http://cishell.svn.sourceforge.net/cishell/?rev=1018&view=rev Author: mwlinnem Date: 2010-01-13 17:13:46 +0000 (Wed, 13 Jan 2010) Log Message: ----------- Changed to use database cleaning code from an open source apache derby test suite. Modified Paths: -------------- trunk/core/org.cishell.reference.service.database/src/org/cishell/reference/service/database/DerbyDatabaseService.java Added Paths: ----------- trunk/core/org.cishell.reference.service.database/src/org/cishell/reference/service/database/utility/ trunk/core/org.cishell.reference.service.database/src/org/cishell/reference/service/database/utility/DatabaseCleaner.java trunk/core/org.cishell.reference.service.database/src/org/cishell/reference/service/database/utility/JDBC.java Modified: trunk/core/org.cishell.reference.service.database/src/org/cishell/reference/service/database/DerbyDatabaseService.java =================================================================== --- trunk/core/org.cishell.reference.service.database/src/org/cishell/reference/service/database/DerbyDatabaseService.java 2010-01-13 16:55:34 UTC (rev 1017) +++ trunk/core/org.cishell.reference.service.database/src/org/cishell/reference/service/database/DerbyDatabaseService.java 2010-01-13 17:13:46 UTC (rev 1018) @@ -18,6 +18,7 @@ import org.apache.commons.pool.KeyedObjectPoolFactory; import org.apache.commons.pool.impl.GenericKeyedObjectPoolFactory; import org.apache.commons.pool.impl.GenericObjectPool; +import org.cishell.reference.service.database.utility.DatabaseCleaner; import org.cishell.service.database.Database; import org.cishell.service.database.DatabaseCreationException; import org.cishell.service.database.DatabaseService; @@ -68,7 +69,7 @@ try { for (InternalDerbyDatabase internalDatabase : internalDatabases) { Connection internalDatabaseConnection = internalDatabase.getConnection(); - removeAllNonSystemDatabaseTables(internalDatabaseConnection); + //DatabaseCleaner.cleanDatabase(internalDatabaseConnection, false); internalDatabase.shutdown(); } } catch (Exception e) { @@ -94,7 +95,7 @@ //if this database existed on disk from a previous session, clean it to be like new - removeAllNonSystemDatabaseTables(db.getConnection()); + DatabaseCleaner.cleanDatabase(db.getConnection(), false); //keep track of our new database for this CIShell session internalDatabases.add(db); @@ -167,31 +168,31 @@ private static final int TABLE_NAME_INDEX = 3; private static final String NONSYSTEM_SCHEMA_NAME = "APP"; - //(removes all non-system tables from the provided databases) - private void removeAllNonSystemDatabaseTables(Connection dbConnection) throws SQLException { - DatabaseMetaData dbMetadata = dbConnection.getMetaData(); - //using the TABLE type means we get no system tables. - ResultSet allTableNames = dbMetadata.getTables(null, null, null, new String[]{"TABLE"}); - - Statement removeTables = dbConnection.createStatement(); - - while (allTableNames.next()) { - String dropTableQuery = formDropTableQuery(allTableNames.getString(SCHEMA_NAME_INDEX), - allTableNames.getString(TABLE_NAME_INDEX)); - removeTables.addBatch(dropTableQuery); - } - - removeTables.executeBatch(); +// //(removes all non-system tables from the provided databases) +// private void removeAllNonSystemDatabaseTables(Connection dbConnection) throws SQLException { +// DatabaseMetaData dbMetadata = dbConnection.getMetaData(); +// ResultSet allTableNames = dbMetadata.getTables(null, null, null, null); +// +// Statement removeTables = dbConnection.createStatement(); +// +// while (allTableNames.next()) { +// if (!hasSystemSchema(allTableNames.getString(SCHEMA_NAME_INDEX))) { +// String dropTableQuery = formDropTableQuery(allTableNames.getString(TABLE_NAME_INDEX)); +// removeTables.addBatch(dropTableQuery); +// } +// } +// +// removeTables.executeBatch(); +// } + + private boolean hasSystemSchema(String tableSchemaName) { + return tableSchemaName.indexOf(NONSYSTEM_SCHEMA_NAME) == -1; } - private String formDropTableQuery(String schema, String tableName) { - String schemaPrefix = ""; - if(schema != null && !"".equals(schema)) { - schemaPrefix = schema + "."; - } + private String formDropTableQuery(String tableName) { String removeTableSQL = "DROP TABLE " - + schemaPrefix + "." + tableName; + + NONSYSTEM_SCHEMA_NAME + "." + tableName; return removeTableSQL; } } Added: trunk/core/org.cishell.reference.service.database/src/org/cishell/reference/service/database/utility/DatabaseCleaner.java =================================================================== --- trunk/core/org.cishell.reference.service.database/src/org/cishell/reference/service/database/utility/DatabaseCleaner.java (rev 0) +++ trunk/core/org.cishell.reference.service.database/src/org/cishell/reference/service/database/utility/DatabaseCleaner.java 2010-01-13 17:13:46 UTC (rev 1018) @@ -0,0 +1,179 @@ +package org.cishell.reference.service.database.utility; + +import java.sql.CallableStatement; +import java.sql.Connection; +import java.sql.DatabaseMetaData; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +//taken from http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/CleanDatabaseTestSetup.java?view=markup +/* + * + * Derby - Class org.apache.derbyTesting.functionTests.util.CleanDatabase + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific + * language governing permissions and limitations under the License. + */ + +public class DatabaseCleaner { + + + /** + * Clean a complete database + * @param conn Connection to be used, must not be in auto-commit mode. + * @param compress True if selected system tables are to be compressed + * to avoid potential ordering differences in test output. + * @throws SQLException database error + */ + public static void cleanDatabase(Connection conn, boolean compress) throws SQLException { + clearProperties(conn); + removeObjects(conn); + if (compress) + compressObjects(conn); + //removeRoles(conn); + } + + /** + * Set of database properties that will be set to NULL (unset) + * as part of cleaning a database. + */ + private static final String[] CLEAR_DB_PROPERTIES = + { + "derby.database.classpath", + }; + + /** + * Clear all database properties. + */ + private static void clearProperties(Connection conn) throws SQLException { + + PreparedStatement ps = conn.prepareCall( + "CALL SYSCS_UTIL.SYSCS_SET_DATABASE_PROPERTY(?, NULL)"); + + for (int i = 0; i < CLEAR_DB_PROPERTIES.length; i++) + { + ps.setString(1, CLEAR_DB_PROPERTIES[i]); + ps.executeUpdate(); + } + ps.close(); + conn.commit(); + } + + + /** + * Remove all objects in all schemas from the database. + */ + private static void removeObjects(Connection conn) throws SQLException { + + DatabaseMetaData dmd = conn.getMetaData(); + + SQLException sqle = null; + // Loop a number of arbitary times to catch cases + // where objects are dependent on objects in + // different schemas. + for (int count = 0; count < 5; count++) { + // Fetch all the user schemas into a list + List schemas = new ArrayList(); + ResultSet rs = dmd.getSchemas(); + while (rs.next()) { + + String schema = rs.getString("TABLE_SCHEM"); + if (schema.startsWith("SYS")) + continue; + if (schema.equals("SQLJ")) + continue; + if (schema.equals("NULLID")) + continue; + + schemas.add(schema); + } + rs.close(); + + // DROP all the user schemas. + sqle = null; + for (Iterator i = schemas.iterator(); i.hasNext();) { + String schema = (String) i.next(); + try { + JDBC.dropSchema(dmd, schema); + } catch (SQLException e) { + sqle = e; + } + } + // No errors means all the schemas we wanted to + // drop were dropped, so nothing more to do. + if (sqle == null) + return; + } + throw sqle; + } + + private static void removeRoles(Connection conn) throws SQLException { + // No metadata for roles, so do a query against SYSROLES + Statement stm = conn.createStatement(); + Statement dropStm = conn.createStatement(); + + // cast to overcome territory differences in some cases: + ResultSet rs = stm.executeQuery( + "select roleid from sys.sysroles where " + + "cast(isdef as char(1)) = 'Y'"); + + while (rs.next()) { + dropStm.executeUpdate("DROP ROLE " + JDBC.escape(rs.getString(1))); + } + + stm.close(); + dropStm.close(); + conn.commit(); + } + + /** + * Set of objects that will be compressed as part of cleaning a database. + */ + private static final String[] COMPRESS_DB_OBJECTS = + { + "SYS.SYSDEPENDS", + }; + + /** + * Compress the objects in the database. + * + * @param conn the db connection + * @throws SQLException database error + */ + private static void compressObjects(Connection conn) throws SQLException { + + CallableStatement cs = conn.prepareCall + ("CALL SYSCS_UTIL.SYSCS_INPLACE_COMPRESS_TABLE(?, ?, 1, 1, 1)"); + + for (int i = 0; i < COMPRESS_DB_OBJECTS.length; i++) + { + int delim = COMPRESS_DB_OBJECTS[i].indexOf("."); + cs.setString(1, COMPRESS_DB_OBJECTS[i].substring(0, delim) ); + cs.setString(2, COMPRESS_DB_OBJECTS[i].substring(delim+1) ); + cs.execute(); + } + + cs.close(); + conn.commit(); + } + + + +} \ No newline at end of file Added: trunk/core/org.cishell.reference.service.database/src/org/cishell/reference/service/database/utility/JDBC.java =================================================================== --- trunk/core/org.cishell.reference.service.database/src/org/cishell/reference/service/database/utility/JDBC.java (rev 0) +++ trunk/core/org.cishell.reference.service.database/src/org/cishell/reference/service/database/utility/JDBC.java 2010-01-13 17:13:46 UTC (rev 1018) @@ -0,0 +1,625 @@ +package org.cishell.reference.service.database.utility; + +//taken from http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/junit/CleanDatabaseTestSetup.java?view=markup + +/* + * + * Derby - Class org.apache.derbyTesting.junit.JDBC + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific + * language governing permissions and limitations under the License. + */ + +import java.io.IOException; +import java.sql.BatchUpdateException; +import java.sql.Connection; +import java.sql.DatabaseMetaData; +import java.sql.ParameterMetaData; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.ResultSetMetaData; +import java.sql.SQLException; +import java.sql.SQLWarning; +import java.sql.Statement; +import java.sql.Types; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.BitSet; +import java.util.Iterator; +import java.util.ListIterator; +import java.util.Locale; + + +/** + * JDBC utility methods for the JUnit tests. + * Note that JSR 169 is a subset of JDBC 3 and + * JDBC 3 is a subset of JDBC 4. + * The base level for the Derby tests is JSR 169. + */ +public class JDBC { + + /** + * Helper class whose <code>equals()</code> method returns + * <code>true</code> for all strings on this format: SQL061021105830900 + */ + public static class GeneratedId { + public boolean equals(Object o) { + // unless JSR169, use String.matches... + if (JDBC.vmSupportsJDBC3()) + { + return o instanceof String && + ((String) o).matches("SQL[0-9]{15}"); + } + else + { + String tmpstr = (String)o; + boolean b = true; + if (!(o instanceof String)) + b = false; + if (!(tmpstr.startsWith("SQL"))) + b = false; + if (tmpstr.length() != 18) + b = false; + for (int i=3 ; i<18 ; i++) + { + if (Character.isDigit(tmpstr.charAt(i))) + continue; + else + { + b = false; + break; + } + } + return b; + } + } + public String toString() { + return "xxxxGENERATED-IDxxxx"; + } + } + + /** + * Constant to pass to DatabaseMetaData.getTables() to fetch + * just tables. + */ + public static final String[] GET_TABLES_TABLE = new String[] {"TABLE"}; + /** + * Constant to pass to DatabaseMetaData.getTables() to fetch + * just views. + */ + public static final String[] GET_TABLES_VIEW = new String[] {"VIEW"}; + /** + * Constant to pass to DatabaseMetaData.getTables() to fetch + * just synonyms. + */ + public static final String[] GET_TABLES_SYNONYM = + new String[] {"SYNONYM"}; + + /** + * Types.SQLXML value without having to compile with JDBC4. + */ + public static final int SQLXML = 2009; + + /** + * Tell if we are allowed to use DriverManager to create database + * connections. + */ + private static final boolean HAVE_DRIVER + = haveClass("java.sql.Driver"); + + /** + * Does the Savepoint class exist, indicates + * JDBC 3 (or JSR 169). + */ + private static final boolean HAVE_SAVEPOINT + = haveClass("java.sql.Savepoint"); + + /** + * Does the java.sql.SQLXML class exist, indicates JDBC 4. + */ + private static final boolean HAVE_SQLXML + = haveClass("java.sql.SQLXML"); + + /** + * Can we load a specific class, use this to determine JDBC level. + * @param className Class to attempt load on. + * @return true if class can be loaded, false otherwise. + */ + static boolean haveClass(String className) + { + try { + Class.forName(className); + return true; + } catch (Throwable e) { + return false; + } + } + /** + * Return true if the virtual machine environment + * supports JDBC4 or later. JDBC 4 is a superset + * of JDBC 3 and of JSR169. + * <BR> + * This method returns true in a JDBC 4 environment + * and false in a JDBC 3 or JSR 169 environment. + */ + public static boolean vmSupportsJDBC4() + { + return HAVE_DRIVER + && HAVE_SQLXML; + } + /** + * Return true if the virtual machine environment + * supports JDBC3 or later. JDBC 3 is a super-set of JSR169 + * and a subset of JDBC 4. + * <BR> + * This method will return true in a JDBC 3 or JDBC 4 + * environment, but false in a JSR169 environment. + */ + public static boolean vmSupportsJDBC3() + { + return HAVE_DRIVER + && HAVE_SAVEPOINT; + } + + /** + * Return true if the virtual machine environment + * supports JSR169. JSR169 is a subset of JDBC 3 + * and hence a subset of JDBC 4 as well. + * <BR> + * This method returns true only in a JSR 169 + * environment. + */ + public static boolean vmSupportsJSR169() + { + return !HAVE_DRIVER + && HAVE_SAVEPOINT; + } + + /** + * Rollback and close a connection for cleanup. + * Test code that is expecting Connection.close to succeed + * normally should just call conn.close(). + * + * <P> + * If conn is not-null and isClosed() returns false + * then both rollback and close will be called. + * If both methods throw exceptions + * then they will be chained together and thrown. + * @throws SQLException Error closing connection. + */ + public static void cleanup(Connection conn) throws SQLException + { + if (conn == null) + return; + if (conn.isClosed()) + return; + + SQLException sqle = null; + try { + conn.rollback(); + } catch (SQLException e) { + sqle = e; + } + + try { + conn.close(); + } catch (SQLException e) { + if (sqle == null) + sqle = e; + else + sqle.setNextException(e); + throw sqle; + } + } + + /** + * Drop a database schema by dropping all objects in it + * and then executing DROP SCHEMA. If the schema is + * APP it is cleaned but DROP SCHEMA is not executed. + * + * TODO: Handle dependencies by looping in some intelligent + * way until everything can be dropped. + * + + * + * @param dmd DatabaseMetaData object for database + * @param schema Name of the schema + * @throws SQLException database error + */ + public static void dropSchema(DatabaseMetaData dmd, String schema) throws SQLException + { + Connection conn = dmd.getConnection(); + Statement s = dmd.getConnection().createStatement(); + + // Functions - not supported by JDBC meta data until JDBC 4 + // Need to use the CHAR() function on A.ALIASTYPE + // so that the compare will work in any schema. + PreparedStatement psf = conn.prepareStatement( + "SELECT ALIAS FROM SYS.SYSALIASES A, SYS.SYSSCHEMAS S" + + " WHERE A.SCHEMAID = S.SCHEMAID " + + " AND CHAR(A.ALIASTYPE) = ? " + + " AND S.SCHEMANAME = ?"); + psf.setString(1, "F" ); + psf.setString(2, schema); + ResultSet rs = psf.executeQuery(); + dropUsingDMD(s, rs, schema, "ALIAS", "FUNCTION"); + + // Procedures + rs = dmd.getProcedures((String) null, + schema, (String) null); + + dropUsingDMD(s, rs, schema, "PROCEDURE_NAME", "PROCEDURE"); + + // Views + rs = dmd.getTables((String) null, schema, (String) null, + GET_TABLES_VIEW); + + dropUsingDMD(s, rs, schema, "TABLE_NAME", "VIEW"); + + // Tables + rs = dmd.getTables((String) null, schema, (String) null, + GET_TABLES_TABLE); + + dropUsingDMD(s, rs, schema, "TABLE_NAME", "TABLE"); + + // At this point there may be tables left due to + // foreign key constraints leading to a dependency loop. + // Drop any constraints that remain and then drop the tables. + // If there are no tables then this should be a quick no-op. + ResultSet table_rs = dmd.getTables((String) null, schema, (String) null, + GET_TABLES_TABLE); + + while (table_rs.next()) { + String tablename = table_rs.getString("TABLE_NAME"); + rs = dmd.getExportedKeys((String) null, schema, tablename); + while (rs.next()) { + short keyPosition = rs.getShort("KEY_SEQ"); + if (keyPosition != 1) + continue; + String fkName = rs.getString("FK_NAME"); + // No name, probably can't happen but couldn't drop it anyway. + if (fkName == null) + continue; + String fkSchema = rs.getString("FKTABLE_SCHEM"); + String fkTable = rs.getString("FKTABLE_NAME"); + + String ddl = "ALTER TABLE " + + JDBC.escape(fkSchema, fkTable) + + " DROP FOREIGN KEY " + + JDBC.escape(fkName); + s.executeUpdate(ddl); + } + rs.close(); + } + table_rs.close(); + conn.commit(); + + // Tables (again) + rs = dmd.getTables((String) null, schema, (String) null, + GET_TABLES_TABLE); + dropUsingDMD(s, rs, schema, "TABLE_NAME", "TABLE"); + + // drop UDTs + psf.setString(1, "A" ); + psf.setString(2, schema); + rs = psf.executeQuery(); + dropUsingDMD(s, rs, schema, "ALIAS", "TYPE"); + psf.close(); + + // Synonyms - need work around for DERBY-1790 where + // passing a table type of SYNONYM fails. + rs = dmd.getTables((String) null, schema, (String) null, + GET_TABLES_SYNONYM); + + dropUsingDMD(s, rs, schema, "TABLE_NAME", "SYNONYM"); + + // sequences + if ( sysSequencesExists( conn ) ) + { + psf = conn.prepareStatement + ( + "SELECT SEQUENCENAME FROM SYS.SYSSEQUENCES A, SYS.SYSSCHEMAS S" + + " WHERE A.SCHEMAID = S.SCHEMAID " + + " AND S.SCHEMANAME = ?"); + psf.setString(1, schema); + rs = psf.executeQuery(); + dropUsingDMD(s, rs, schema, "SEQUENCENAME", "SEQUENCE"); + psf.close(); + } + + // Finally drop the schema if it is not APP + if (!schema.equals("APP")) { + s.executeUpdate("DROP SCHEMA " + JDBC.escape(schema) + " RESTRICT"); + } + conn.commit(); + s.close(); + } + + /** + * Return true if the SYSSEQUENCES table exists. + */ + private static boolean sysSequencesExists( Connection conn ) throws SQLException + { + PreparedStatement ps = null; + ResultSet rs = null; + try { + ps = conn.prepareStatement + ( + "select count(*) from sys.systables t, sys.sysschemas s\n" + + "where t.schemaid = s.schemaid\n" + + "and ( cast(s.schemaname as varchar(128)))= 'SYS'\n" + + "and ( cast(t.tablename as varchar(128))) = 'SYSSEQUENCES'" ); + rs = ps.executeQuery(); + rs.next(); + return ( rs.getInt( 1 ) > 0 ); + } + finally + { + if ( rs != null ) { rs.close(); } + if ( ps != null ) { ps.close(); } + } + } + + /** + * DROP a set of objects based upon a ResultSet from a + * DatabaseMetaData call. + * + * TODO: Handle errors to ensure all objects are dropped, + * probably requires interaction with its caller. + * + * @param s Statement object used to execute the DROP commands. + * @param rs DatabaseMetaData ResultSet + * @param schema Schema the objects are contained in + * @param mdColumn The column name used to extract the object's + * name from rs + * @param dropType The keyword to use after DROP in the SQL statement + * @throws SQLException database errors. + */ + private static void dropUsingDMD( + Statement s, ResultSet rs, String schema, + String mdColumn, + String dropType) throws SQLException + { + String dropLeadIn = "DROP " + dropType + " "; + + // First collect the set of DROP SQL statements. + ArrayList ddl = new ArrayList(); + while (rs.next()) + { + String objectName = rs.getString(mdColumn); + String raw = dropLeadIn + JDBC.escape(schema, objectName); + if ( "TYPE".equals( dropType ) ) { raw = raw + " restrict "; } + ddl.add( raw ); + } + rs.close(); + if (ddl.isEmpty()) + return; + + // Execute them as a complete batch, hoping they will all succeed. + s.clearBatch(); + int batchCount = 0; + for (Iterator i = ddl.iterator(); i.hasNext(); ) + { + Object sql = i.next(); + if (sql != null) { + s.addBatch(sql.toString()); + batchCount++; + } + } + + int[] results; + boolean hadError; + try { + results = s.executeBatch(); + hadError = false; + } catch (BatchUpdateException batchException) { + results = batchException.getUpdateCounts(); + hadError = true; + } + + // Remove any statements from the list that succeeded. + boolean didDrop = false; + for (int i = 0; i < results.length; i++) + { + int result = results[i]; + if (result == Statement.EXECUTE_FAILED) + hadError = true; + else if (result == Statement.SUCCESS_NO_INFO || result >= 0) { + didDrop = true; + ddl.set(i, null); + } + } + s.clearBatch(); + if (didDrop) { + // Commit any work we did do. + s.getConnection().commit(); + } + + // If we had failures drop them as individual statements + // until there are none left or none succeed. We need to + // do this because the batch processing stops at the first + // error. This copes with the simple case where there + // are objects of the same type that depend on each other + // and a different drop order will allow all or most + // to be dropped. + if (hadError) { + do { + hadError = false; + didDrop = false; + for (ListIterator i = ddl.listIterator(); i.hasNext();) { + Object sql = i.next(); + if (sql != null) { + try { + s.executeUpdate(sql.toString()); + i.set(null); + didDrop = true; + } catch (SQLException e) { + hadError = true; + } + } + } + if (didDrop) + s.getConnection().commit(); + } while (hadError && didDrop); + } + } + /** + * Convert byte array to String. + * Each byte is converted to a hexadecimal string representation. + * + * @param ba Byte array to be converted. + * @return Hexadecimal string representation. Returns null on null input. + */ + private static String bytesToString(byte[] ba) + { + if (ba == null) return null; + StringBuffer s = new StringBuffer(); + for (int i = 0; i < ba.length; ++i) { + s.append(Integer.toHexString(ba[i] & 0x00ff)); + } + return s.toString(); + } + + /** + * Escape a non-qualified name so that it is suitable + * for use in a SQL query executed by JDBC. + */ + public static String escape(String name) + { + StringBuffer buffer = new StringBuffer(name.length() + 2); + buffer.append('"'); + for (int i = 0; i < name.length(); i++) { + char c = name.charAt(i); + // escape double quote characters with an extra double quote + if (c == '"') buffer.append('"'); + buffer.append(c); + } + buffer.append('"'); + return buffer.toString(); + } + + + /** + * Compress 2 adjacent (single or double) quotes into a single (s or d) + * quote when found in the middle of a String. + * + * NOTE: """" or '''' will be compressed into "" or ''. + * This function assumes that the leading and trailing quote from a + * string or delimited identifier have already been removed. + * @param source string to be compressed + * @param quotes string containing two single or double quotes. + * @return String where quotes have been compressed + */ + private static String compressQuotes(String source, String quotes) + { + String result = source; + int index; + + /* Find the first occurrence of adjacent quotes. */ + index = result.indexOf(quotes); + + /* Replace each occurrence with a single quote and begin the + * search for the next occurrence from where we left off. + */ + while (index != -1) { + result = result.substring(0, index + 1) + + result.substring(index + 2); + index = result.indexOf(quotes, index + 1); + } + + return result; + } + + + /** + * Convert a SQL identifier to case normal form. + * + * Normalize a SQL identifer, up-casing if <regular identifer>, + * and handling of <delimited identifer> (SQL 2003, section 5.2). + * The normal form is used internally in Derby. + */ + public static String identifierToCNF(String id) + { + if (id == null || id.length() == 0) { + return id; + } + + if (id.charAt(0) == '"' && + id.length() >= 3 && + id.charAt(id.length() - 1) == '"') { + // assume syntax is OK, thats is, any quotes inside are doubled: + + return compressQuotes( + id.substring(1, id.length() - 1), "\"\""); + + } else { + return id.toUpperCase(Locale.ENGLISH); + } + } + + + /** + * Escape a schama-qualified name so that it is suitable + * for use in a SQL query executed by JDBC. + */ + public static String escape(String schema, String name) + { + return escape(schema) + "." + escape(name); + } + + /** + * Return Type name from jdbc type + * + * @param jdbcType jdbc type to translate + */ + public static String sqlNameFromJdbc(int jdbcType) { + switch (jdbcType) { + case Types.BIT : return "Types.BIT"; + case Types.BOOLEAN : return "Types.BOOLEAN"; + case Types.TINYINT : return "Types.TINYINT"; + case Types.SMALLINT : return "SMALLINT"; + case Types.INTEGER : return "INTEGER"; + case Types.BIGINT : return "BIGINT"; + + case Types.FLOAT : return "Types.FLOAT"; + case Types.REAL : return "REAL"; + case Types.DOUBLE : return "DOUBLE"; + + case Types.NUMERIC : return "Types.NUMERIC"; + case Types.DECIMAL : return "DECIMAL"; + + case Types.CHAR : return "CHAR"; + case Types.VARCHAR : return "VARCHAR"; + case Types.LONGVARCHAR : return "LONG VARCHAR"; + case Types.CLOB : return "CLOB"; + + case Types.DATE : return "DATE"; + case Types.TIME : return "TIME"; + case Types.TIMESTAMP : return "TIMESTAMP"; + + case Types.BINARY : return "CHAR () FOR BIT DATA"; + case Types.VARBINARY : return "VARCHAR () FOR BIT DATA"; + case Types.LONGVARBINARY: return "LONG VARCHAR FOR BIT DATA"; + case Types.BLOB : return "BLOB"; + + case Types.OTHER : return "Types.OTHER"; + case Types.NULL : return "Types.NULL"; + default : return String.valueOf(jdbcType); + } + } + + +} + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pat...@us...> - 2010-01-13 16:55:41
|
Revision: 1017 http://cishell.svn.sourceforge.net/cishell/?rev=1017&view=rev Author: pataphil Date: 2010-01-13 16:55:34 +0000 (Wed, 13 Jan 2010) Log Message: ----------- * Added StringUtilities.allAreEmptyOrWhiteSpace (which wraps StringUtilities.isEmptyOrWhiteSpace). * Added org.cishell.utilities.osgi.logging.LogMessageHandler. Modified Paths: -------------- trunk/core/org.cishell.utilities/.classpath trunk/core/org.cishell.utilities/.settings/org.eclipse.jdt.core.prefs trunk/core/org.cishell.utilities/META-INF/MANIFEST.MF trunk/core/org.cishell.utilities/src/org/cishell/utilities/StringUtilities.java Added Paths: ----------- trunk/core/org.cishell.utilities/src/org/cishell/utilities/osgi/ trunk/core/org.cishell.utilities/src/org/cishell/utilities/osgi/logging/ trunk/core/org.cishell.utilities/src/org/cishell/utilities/osgi/logging/LogMessageHandler.java Modified: trunk/core/org.cishell.utilities/.classpath =================================================================== --- trunk/core/org.cishell.utilities/.classpath 2010-01-07 22:49:43 UTC (rev 1016) +++ trunk/core/org.cishell.utilities/.classpath 2010-01-13 16:55:34 UTC (rev 1017) @@ -1,6 +1,6 @@ <?xml version="1.0" encoding="UTF-8"?> <classpath> - <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.4"/> + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/> <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> <classpathentry kind="src" path="src"/> <classpathentry kind="output" path="bin"/> Modified: trunk/core/org.cishell.utilities/.settings/org.eclipse.jdt.core.prefs =================================================================== --- trunk/core/org.cishell.utilities/.settings/org.eclipse.jdt.core.prefs 2010-01-07 22:49:43 UTC (rev 1016) +++ trunk/core/org.cishell.utilities/.settings/org.eclipse.jdt.core.prefs 2010-01-13 16:55:34 UTC (rev 1017) @@ -1,12 +1,12 @@ -#Tue Oct 13 13:58:27 EDT 2009 +#Wed Jan 13 11:39:50 EST 2010 eclipse.preferences.version=1 org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.2 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve -org.eclipse.jdt.core.compiler.compliance=1.4 +org.eclipse.jdt.core.compiler.compliance=1.5 org.eclipse.jdt.core.compiler.debug.lineNumber=generate org.eclipse.jdt.core.compiler.debug.localVariable=generate org.eclipse.jdt.core.compiler.debug.sourceFile=generate -org.eclipse.jdt.core.compiler.problem.assertIdentifier=warning -org.eclipse.jdt.core.compiler.problem.enumIdentifier=warning -org.eclipse.jdt.core.compiler.source=1.3 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.5 Modified: trunk/core/org.cishell.utilities/META-INF/MANIFEST.MF =================================================================== --- trunk/core/org.cishell.utilities/META-INF/MANIFEST.MF 2010-01-07 22:49:43 UTC (rev 1016) +++ trunk/core/org.cishell.utilities/META-INF/MANIFEST.MF 2010-01-13 16:55:34 UTC (rev 1017) @@ -3,13 +3,14 @@ Bundle-Name: Utilities Plug-in Bundle-SymbolicName: org.cishell.utilities Bundle-Version: 1.0.0 -Bundle-RequiredExecutionEnvironment: J2SE-1.4 +Bundle-RequiredExecutionEnvironment: J2SE-1.5 Import-Package: org.cishell.framework;version="1.0.0", org.cishell.framework.algorithm;version="1.0.0", org.cishell.framework.data, org.cishell.reference.service.metatype, org.cishell.service.database, org.osgi.framework;version="1.4.0", + org.osgi.service.log;version="1.3.0", org.osgi.service.metatype;version="1.1.0", prefuse, prefuse.data, @@ -21,4 +22,5 @@ Export-Package: org.cishell.utilities, org.cishell.utilities.mutateParameter, org.cishell.utilities.mutateParameter.defaultvalue, - org.cishell.utilities.mutateParameter.dropdown + org.cishell.utilities.mutateParameter.dropdown, + org.cishell.utilities.osgi.logging Modified: trunk/core/org.cishell.utilities/src/org/cishell/utilities/StringUtilities.java =================================================================== --- trunk/core/org.cishell.utilities/src/org/cishell/utilities/StringUtilities.java 2010-01-07 22:49:43 UTC (rev 1016) +++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/StringUtilities.java 2010-01-13 16:55:34 UTC (rev 1017) @@ -98,6 +98,16 @@ return (trimmed.length() == 0); } + + public static boolean allAreEmptyOrWhiteSpace(String... tests) { + for (String test : tests) { + if (!isEmptyOrWhiteSpace(test)) { + return false; + } + } + + return true; + } public static int countOccurrencesOfChar( CharSequence characters, char target) { Added: trunk/core/org.cishell.utilities/src/org/cishell/utilities/osgi/logging/LogMessageHandler.java =================================================================== --- trunk/core/org.cishell.utilities/src/org/cishell/utilities/osgi/logging/LogMessageHandler.java (rev 0) +++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/osgi/logging/LogMessageHandler.java 2010-01-13 16:55:34 UTC (rev 1017) @@ -0,0 +1,101 @@ +package org.cishell.utilities.osgi.logging; + +import java.util.HashMap; +import java.util.Map; + +import org.osgi.service.log.LogService; + +// TODO: Get reviewed. +// TODO: Make 1.4 compatible and move to cishell utilities? +public class LogMessageHandler { + private LogService logger; + private Map<MessageTypeIndicator, MessageType> messageTypes = + new HashMap<MessageTypeIndicator, MessageType>(); + + public LogMessageHandler(LogService logger) { + this.logger = logger; + } + + /** + * If typeIndicator is already an added message type, its count will be + * reset and maximum count overridden. + */ + public MessageTypeIndicator addMessageType( + String description, int maximumCount) { + MessageTypeIndicator typeIndicator = new MessageTypeIndicator(); + this.messageTypes.put( + typeIndicator, new MessageType(description, maximumCount)); + + return typeIndicator; + } + + /** + * logMessage will always be logged if typeIndicator has not been added + * prior to calling this. + */ + public void logMessage( + MessageTypeIndicator typeIndicator, + int logLevel, + String logMessage) { + MessageType messageType = this.messageTypes.get(typeIndicator); + + if (messageType != null) { + if (messageType.messageLogged()) { + this.logger.log(logLevel, logMessage); + } + } else { + this.logger.log(logLevel, logMessage); + } + } + + public void printOverloadedMessageTypes(int logLevel) { + for (MessageType messageType : this.messageTypes.values()) { + if (messageType.wasOverloaded()) { + this.logger.log(logLevel, messageType.toString()); + } + } + } + + public class MessageTypeIndicator {} + + private class MessageType { + private String description; + private int maximumCount; + private int foundCount = 0; + private int overLoadedCount = 0; + + public MessageType(String description, int maximumCount) { + this.description = description; + this.maximumCount = maximumCount; + } + + public boolean hasAnyLeft() { + return this.foundCount != this.maximumCount; + } + + public boolean wasOverloaded() { + return this.overLoadedCount > 0; + } + + public boolean messageLogged() { + if (hasAnyLeft()) { + this.foundCount++; + + return true; + } else { + this.overLoadedCount++; + + return false; + } + } + + public String toString() { + return + "Found " + + this.overLoadedCount + + " more " + + this.description + + "."; + } + } +} \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pat...@us...> - 2010-01-07 22:49:53
|
Revision: 1016 http://cishell.svn.sourceforge.net/cishell/?rev=1016&view=rev Author: pataphil Date: 2010-01-07 22:49:43 +0000 (Thu, 07 Jan 2010) Log Message: ----------- * Added StringUtilities.multiplyWithSeparator. Modified Paths: -------------- trunk/core/org.cishell.utilities/src/org/cishell/utilities/StringUtilities.java Modified: trunk/core/org.cishell.utilities/src/org/cishell/utilities/StringUtilities.java =================================================================== --- trunk/core/org.cishell.utilities/src/org/cishell/utilities/StringUtilities.java 2010-01-07 20:18:16 UTC (rev 1015) +++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/StringUtilities.java 2010-01-07 22:49:43 UTC (rev 1016) @@ -126,6 +126,13 @@ } } + public static String multiplyWithSeparator(String target, String separator, int count) { + String multipliedWithExtraSeparator = multiply(target + separator, count); + + return multipliedWithExtraSeparator.substring( + 0, multipliedWithExtraSeparator.length() - separator.length()); + } + public static String emptyStringIfNull(Object object) { if (object == null) { return ""; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fu...@us...> - 2010-01-07 20:18:22
|
Revision: 1015 http://cishell.svn.sourceforge.net/cishell/?rev=1015&view=rev Author: fugu13 Date: 2010-01-07 20:18:16 +0000 (Thu, 07 Jan 2010) Log Message: ----------- Add configurable error message. Modified Paths: -------------- trunk/core/org.cishell.utilities/src/org/cishell/utilities/DatabaseUtilities.java Modified: trunk/core/org.cishell.utilities/src/org/cishell/utilities/DatabaseUtilities.java =================================================================== --- trunk/core/org.cishell.utilities/src/org/cishell/utilities/DatabaseUtilities.java 2010-01-07 20:06:17 UTC (rev 1014) +++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/DatabaseUtilities.java 2010-01-07 20:18:16 UTC (rev 1015) @@ -15,13 +15,13 @@ } } - public static Connection connect(Database database) + public static Connection connect(Database database, String messageIfError) throws AlgorithmExecutionException { Connection connection; try { connection = database.getConnection(); } catch (SQLException e) { - throw new AlgorithmExecutionException("Unable to communicate with the database.", e); + throw new AlgorithmExecutionException(messageIfError, e); } return connection; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fu...@us...> - 2010-01-07 20:06:33
|
Revision: 1014 http://cishell.svn.sourceforge.net/cishell/?rev=1014&view=rev Author: fugu13 Date: 2010-01-07 20:06:17 +0000 (Thu, 07 Jan 2010) Log Message: ----------- Needed for database utilities. Modified Paths: -------------- trunk/core/org.cishell.utilities/META-INF/MANIFEST.MF Modified: trunk/core/org.cishell.utilities/META-INF/MANIFEST.MF =================================================================== --- trunk/core/org.cishell.utilities/META-INF/MANIFEST.MF 2010-01-07 20:05:55 UTC (rev 1013) +++ trunk/core/org.cishell.utilities/META-INF/MANIFEST.MF 2010-01-07 20:06:17 UTC (rev 1014) @@ -8,6 +8,7 @@ org.cishell.framework.algorithm;version="1.0.0", org.cishell.framework.data, org.cishell.reference.service.metatype, + org.cishell.service.database, org.osgi.framework;version="1.4.0", org.osgi.service.metatype;version="1.1.0", prefuse, This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fu...@us...> - 2010-01-07 20:06:01
|
Revision: 1013 http://cishell.svn.sourceforge.net/cishell/?rev=1013&view=rev Author: fugu13 Date: 2010-01-07 20:05:55 +0000 (Thu, 07 Jan 2010) Log Message: ----------- Add some database utilities. Typical usage will be like so: execute() { //get out database Connection connection = DatabaseUtilities.connect(database); try { //do stuff } catch (SQLException e) { } catch(FooException e) { } finally { DatabaseUtilities.closeConnectionQuietly(connection); } } Added Paths: ----------- trunk/core/org.cishell.utilities/src/org/cishell/utilities/DatabaseUtilities.java Added: trunk/core/org.cishell.utilities/src/org/cishell/utilities/DatabaseUtilities.java =================================================================== --- trunk/core/org.cishell.utilities/src/org/cishell/utilities/DatabaseUtilities.java (rev 0) +++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/DatabaseUtilities.java 2010-01-07 20:05:55 UTC (rev 1013) @@ -0,0 +1,28 @@ +package org.cishell.utilities; + +import java.sql.Connection; +import java.sql.SQLException; + +import org.cishell.framework.algorithm.AlgorithmExecutionException; +import org.cishell.service.database.Database; + +public class DatabaseUtilities { + public static void closeConnectionQuietly(Connection connection) { + try { + connection.close(); + } catch (SQLException e) { + //quietly! Use this only in finally blocks, pretty much, and right before throwing exceptions that will leave the scope of the Connection object. + } + } + + public static Connection connect(Database database) + throws AlgorithmExecutionException { + Connection connection; + try { + connection = database.getConnection(); + } catch (SQLException e) { + throw new AlgorithmExecutionException("Unable to communicate with the database.", e); + } + return connection; + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fu...@us...> - 2010-01-06 21:21:52
|
Revision: 1012 http://cishell.svn.sourceforge.net/cishell/?rev=1012&view=rev Author: fugu13 Date: 2010-01-06 21:21:45 +0000 (Wed, 06 Jan 2010) Log Message: ----------- Make this truly delete all non-system tables. Modified Paths: -------------- trunk/core/org.cishell.reference.service.database/src/org/cishell/reference/service/database/DerbyDatabaseService.java Modified: trunk/core/org.cishell.reference.service.database/src/org/cishell/reference/service/database/DerbyDatabaseService.java =================================================================== --- trunk/core/org.cishell.reference.service.database/src/org/cishell/reference/service/database/DerbyDatabaseService.java 2010-01-06 21:18:10 UTC (rev 1011) +++ trunk/core/org.cishell.reference.service.database/src/org/cishell/reference/service/database/DerbyDatabaseService.java 2010-01-06 21:21:45 UTC (rev 1012) @@ -170,28 +170,28 @@ //(removes all non-system tables from the provided databases) private void removeAllNonSystemDatabaseTables(Connection dbConnection) throws SQLException { DatabaseMetaData dbMetadata = dbConnection.getMetaData(); - ResultSet allTableNames = dbMetadata.getTables(null, null, null, null); + //using the TABLE type means we get no system tables. + ResultSet allTableNames = dbMetadata.getTables(null, null, null, new String[]{"TABLE"}); Statement removeTables = dbConnection.createStatement(); while (allTableNames.next()) { - if (!hasSystemSchema(allTableNames.getString(SCHEMA_NAME_INDEX))) { - String dropTableQuery = formDropTableQuery(allTableNames.getString(TABLE_NAME_INDEX)); - removeTables.addBatch(dropTableQuery); - } + String dropTableQuery = formDropTableQuery(allTableNames.getString(SCHEMA_NAME_INDEX), + allTableNames.getString(TABLE_NAME_INDEX)); + removeTables.addBatch(dropTableQuery); } removeTables.executeBatch(); } - private boolean hasSystemSchema(String tableSchemaName) { - return tableSchemaName.indexOf(NONSYSTEM_SCHEMA_NAME) == -1; - } - - private String formDropTableQuery(String tableName) { + private String formDropTableQuery(String schema, String tableName) { + String schemaPrefix = ""; + if(schema != null && !"".equals(schema)) { + schemaPrefix = schema + "."; + } String removeTableSQL = "DROP TABLE " - + NONSYSTEM_SCHEMA_NAME + "." + tableName; + + schemaPrefix + "." + tableName; return removeTableSQL; } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pat...@us...> - 2010-01-06 21:18:16
|
Revision: 1011 http://cishell.svn.sourceforge.net/cishell/?rev=1011&view=rev Author: pataphil Date: 2010-01-06 21:18:10 +0000 (Wed, 06 Jan 2010) Log Message: ----------- * Moved IntegerParserWithDefault out of edu.iu.scipolicy.loader.isi.db.utilities.parser and into org.cishell.utilities. Added Paths: ----------- trunk/core/org.cishell.utilities/src/org/cishell/utilities/IntegerParserWithDefault.java Added: trunk/core/org.cishell.utilities/src/org/cishell/utilities/IntegerParserWithDefault.java =================================================================== --- trunk/core/org.cishell.utilities/src/org/cishell/utilities/IntegerParserWithDefault.java (rev 0) +++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/IntegerParserWithDefault.java 2010-01-06 21:18:10 UTC (rev 1011) @@ -0,0 +1,13 @@ +package org.cishell.utilities; + +public class IntegerParserWithDefault { + public static final int DEFAULT = -1; + + public static int parse(String target) { + try { + return Integer.parseInt(target); + } catch (Exception e) { + return DEFAULT; + } + } +} \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fu...@us...> - 2010-01-06 19:46:30
|
Revision: 1010 http://cishell.svn.sourceforge.net/cishell/?rev=1010&view=rev Author: fugu13 Date: 2010-01-06 19:46:24 +0000 (Wed, 06 Jan 2010) Log Message: ----------- Increase code re-use. Modified Paths: -------------- trunk/core/org.cishell.utilities/src/org/cishell/utilities/mutateParameter/dropdown/DropdownMutator.java Modified: trunk/core/org.cishell.utilities/src/org/cishell/utilities/mutateParameter/dropdown/DropdownMutator.java =================================================================== --- trunk/core/org.cishell.utilities/src/org/cishell/utilities/mutateParameter/dropdown/DropdownMutator.java 2010-01-06 18:17:25 UTC (rev 1009) +++ trunk/core/org.cishell.utilities/src/org/cishell/utilities/mutateParameter/dropdown/DropdownMutator.java 2010-01-06 19:46:24 UTC (rev 1010) @@ -1,6 +1,7 @@ package org.cishell.utilities.mutateParameter.dropdown; import java.util.ArrayList; +import java.util.Arrays; import java.util.Iterator; import java.util.List; @@ -89,22 +90,8 @@ } private static List swapToFront(List list, String target) { - if (list.contains(target)) { - int targetIndex = list.indexOf(target); - - List swappedList = new ArrayList(list.size()); - - for (Iterator listIt = list.iterator(); listIt.hasNext();) { - swappedList.add(listIt.next()); - } - - swappedList.set(0, list.get(targetIndex)); - swappedList.set(targetIndex, list.get(0)); - - return swappedList; - } else { - return list; - } + String[] temp = (String[]) list.toArray(new String[]{}); + return Arrays.asList(swapToFront(temp, target)); } private static String[] swapToFront(String[] array, String target) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mwl...@us...> - 2010-01-06 18:17:32
|
Revision: 1009 http://cishell.svn.sourceforge.net/cishell/?rev=1009&view=rev Author: mwlinnem Date: 2010-01-06 18:17:25 +0000 (Wed, 06 Jan 2010) Log Message: ----------- Fixed bad refactor (wasn't calling method to form "drop table" query) Modified Paths: -------------- trunk/core/org.cishell.reference.service.database/src/org/cishell/reference/service/database/DerbyDatabaseService.java Modified: trunk/core/org.cishell.reference.service.database/src/org/cishell/reference/service/database/DerbyDatabaseService.java =================================================================== --- trunk/core/org.cishell.reference.service.database/src/org/cishell/reference/service/database/DerbyDatabaseService.java 2010-01-05 21:19:39 UTC (rev 1008) +++ trunk/core/org.cishell.reference.service.database/src/org/cishell/reference/service/database/DerbyDatabaseService.java 2010-01-06 18:17:25 UTC (rev 1009) @@ -176,7 +176,7 @@ while (allTableNames.next()) { if (!hasSystemSchema(allTableNames.getString(SCHEMA_NAME_INDEX))) { - String dropTableQuery = allTableNames.getString(TABLE_NAME_INDEX); + String dropTableQuery = formDropTableQuery(allTableNames.getString(TABLE_NAME_INDEX)); removeTables.addBatch(dropTableQuery); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pat...@us...> - 2010-01-05 21:19:46
|
Revision: 1008 http://cishell.svn.sourceforge.net/cishell/?rev=1008&view=rev Author: pataphil Date: 2010-01-05 21:19:39 +0000 (Tue, 05 Jan 2010) Log Message: ----------- * Removed unneeded imports. Modified Paths: -------------- trunk/clients/gui/org.cishell.reference.gui.persistence/.classpath trunk/clients/gui/org.cishell.reference.gui.persistence/.settings/org.eclipse.jdt.core.prefs trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileLoad.java trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileLoadFactory.java trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/save/Save.java trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/view/core/DatabaseSchemaOverviewGenerator.java trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/viewwith/FileViewWithFactory.java Added Paths: ----------- trunk/clients/gui/org.cishell.reference.gui.persistence/.settings/org.eclipse.jdt.ui.prefs trunk/clients/gui/org.cishell.reference.gui.persistence/.settings/org.eclipse.ltk.core.refactoring.prefs Modified: trunk/clients/gui/org.cishell.reference.gui.persistence/.classpath =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/.classpath 2010-01-05 20:56:33 UTC (rev 1007) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/.classpath 2010-01-05 21:19:39 UTC (rev 1008) @@ -1,6 +1,6 @@ <?xml version="1.0" encoding="UTF-8"?> <classpath> - <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.4"/> + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/> <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> <classpathentry kind="src" path="src"/> <classpathentry kind="output" path="bin"/> Modified: trunk/clients/gui/org.cishell.reference.gui.persistence/.settings/org.eclipse.jdt.core.prefs =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/.settings/org.eclipse.jdt.core.prefs 2010-01-05 20:56:33 UTC (rev 1007) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/.settings/org.eclipse.jdt.core.prefs 2010-01-05 21:19:39 UTC (rev 1008) @@ -1,12 +1,12 @@ -#Tue Jul 28 13:21:05 EDT 2009 +#Tue Jan 05 16:05:42 EST 2010 eclipse.preferences.version=1 org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.2 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve -org.eclipse.jdt.core.compiler.compliance=1.4 +org.eclipse.jdt.core.compiler.compliance=1.5 org.eclipse.jdt.core.compiler.debug.lineNumber=generate org.eclipse.jdt.core.compiler.debug.localVariable=generate org.eclipse.jdt.core.compiler.debug.sourceFile=generate -org.eclipse.jdt.core.compiler.problem.assertIdentifier=warning -org.eclipse.jdt.core.compiler.problem.enumIdentifier=warning -org.eclipse.jdt.core.compiler.source=1.3 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.5 Added: trunk/clients/gui/org.cishell.reference.gui.persistence/.settings/org.eclipse.jdt.ui.prefs =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/.settings/org.eclipse.jdt.ui.prefs (rev 0) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/.settings/org.eclipse.jdt.ui.prefs 2010-01-05 21:19:39 UTC (rev 1008) @@ -0,0 +1,3 @@ +#Tue Jan 05 16:05:42 EST 2010 +eclipse.preferences.version=1 +org.eclipse.jdt.ui.text.custom_code_templates=<?xml version\="1.0" encoding\="UTF-8" standalone\="no"?><templates/> Added: trunk/clients/gui/org.cishell.reference.gui.persistence/.settings/org.eclipse.ltk.core.refactoring.prefs =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/.settings/org.eclipse.ltk.core.refactoring.prefs (rev 0) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/.settings/org.eclipse.ltk.core.refactoring.prefs 2010-01-05 21:19:39 UTC (rev 1008) @@ -0,0 +1,3 @@ +#Tue Jan 05 16:05:42 EST 2010 +eclipse.preferences.version=1 +org.eclipse.ltk.core.refactoring.enable.project.refactoring.history=false Modified: trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileLoad.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileLoad.java 2010-01-05 20:56:33 UTC (rev 1007) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileLoad.java 2010-01-05 21:19:39 UTC (rev 1008) @@ -10,7 +10,6 @@ import org.cishell.framework.algorithm.AlgorithmFactory; import org.cishell.framework.data.BasicData; import org.cishell.framework.data.Data; -import org.cishell.service.guibuilder.GUIBuilderService; import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.FileDialog; Modified: trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileLoadFactory.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileLoadFactory.java 2010-01-05 20:56:33 UTC (rev 1007) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/load/FileLoadFactory.java 2010-01-05 21:19:39 UTC (rev 1008) @@ -1,7 +1,6 @@ package org.cishell.reference.gui.persistence.load; import java.util.Dictionary; -import java.util.Enumeration; import java.util.Hashtable; import org.cishell.framework.CIShellContext; Modified: trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/save/Save.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/save/Save.java 2010-01-05 20:56:33 UTC (rev 1007) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/save/Save.java 2010-01-05 21:19:39 UTC (rev 1008) @@ -1,23 +1,16 @@ package org.cishell.reference.gui.persistence.save; import java.util.Dictionary; -import java.util.Hashtable; import org.cishell.framework.CIShellContext; import org.cishell.framework.algorithm.Algorithm; import org.cishell.framework.algorithm.AlgorithmExecutionException; -import org.cishell.framework.algorithm.AlgorithmFactory; -import org.cishell.framework.algorithm.AlgorithmProperty; -import org.cishell.framework.data.BasicData; import org.cishell.framework.data.Data; import org.cishell.service.conversion.Converter; import org.cishell.service.conversion.DataConversionService; -import org.cishell.service.guibuilder.GUIBuilderService; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.PlatformUI; -import org.osgi.framework.ServiceReference; -import org.osgi.service.log.LogService; /** * Save algorithm for persisting a data object * Modified: trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/view/core/DatabaseSchemaOverviewGenerator.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/view/core/DatabaseSchemaOverviewGenerator.java 2010-01-05 20:56:33 UTC (rev 1007) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/view/core/DatabaseSchemaOverviewGenerator.java 2010-01-05 21:19:39 UTC (rev 1008) @@ -1,7 +1,6 @@ package org.cishell.reference.gui.persistence.view.core; import java.io.File; -import java.io.IOException; import java.sql.Connection; import java.sql.DatabaseMetaData; import java.sql.ResultSet; Modified: trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/viewwith/FileViewWithFactory.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/viewwith/FileViewWithFactory.java 2010-01-05 20:56:33 UTC (rev 1007) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/viewwith/FileViewWithFactory.java 2010-01-05 21:19:39 UTC (rev 1008) @@ -8,7 +8,6 @@ import org.cishell.framework.algorithm.ParameterMutator; import org.cishell.framework.data.Data; import org.cishell.reference.service.metatype.BasicAttributeDefinition; -import org.cishell.reference.service.metatype.BasicMetaTypeProvider; import org.cishell.reference.service.metatype.BasicObjectClassDefinition; import org.eclipse.swt.program.Program; import org.eclipse.swt.widgets.Display; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pat...@us...> - 2010-01-05 20:56:40
|
Revision: 1007 http://cishell.svn.sourceforge.net/cishell/?rev=1007&view=rev Author: pataphil Date: 2010-01-05 20:56:33 +0000 (Tue, 05 Jan 2010) Log Message: ----------- * Added shortcut keys to Load, Save, View, and View With operations. Modified Paths: -------------- trunk/clients/gui/org.cishell.reference.gui.persistence/OSGI-INF/load.properties trunk/clients/gui/org.cishell.reference.gui.persistence/OSGI-INF/save.properties trunk/clients/gui/org.cishell.reference.gui.persistence/OSGI-INF/save.xml trunk/clients/gui/org.cishell.reference.gui.persistence/OSGI-INF/view.properties trunk/clients/gui/org.cishell.reference.gui.persistence/OSGI-INF/viewwith.properties trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/save/SaveFactory.java Modified: trunk/clients/gui/org.cishell.reference.gui.persistence/OSGI-INF/load.properties =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/OSGI-INF/load.properties 2010-01-04 20:01:51 UTC (rev 1006) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/OSGI-INF/load.properties 2010-01-05 20:56:33 UTC (rev 1007) @@ -1,6 +1,7 @@ menu_path=File/start label=Load... -description=This converter allows users to select file from the file system and load it to Data Model window +shortcut=ctrl+alt+o +description=This allows users to select file from the file system and load it to Data Model window in_data=null out_data=java.lang.Object service.pid=org.cishell.reference.gui.persistence.load.FileLoad Modified: trunk/clients/gui/org.cishell.reference.gui.persistence/OSGI-INF/save.properties =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/OSGI-INF/save.properties 2010-01-04 20:01:51 UTC (rev 1006) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/OSGI-INF/save.properties 2010-01-05 20:56:33 UTC (rev 1007) @@ -1,7 +1,10 @@ menu_path=File/start label=Save... +shortcut=ctrl+alt+s description=Saves data to disk in_data=java.lang.Object out_data=null service.pid=org.cishell.reference.gui.persistence.save.Save -remoteable=false +remoteable=true +prefs_published=local +receive_prefs=true \ No newline at end of file Modified: trunk/clients/gui/org.cishell.reference.gui.persistence/OSGI-INF/save.xml =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/OSGI-INF/save.xml 2010-01-04 20:01:51 UTC (rev 1006) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/OSGI-INF/save.xml 2010-01-05 20:56:33 UTC (rev 1007) @@ -6,7 +6,7 @@ <reference name="MTS" interface="org.osgi.service.metatype.MetaTypeService"/> <service> - <provide interface= - "org.cishell.framework.algorithm.AlgorithmFactory"/> + <provide interface="org.cishell.framework.algorithm.AlgorithmFactory"/> + <provide interface="org.osgi.service.cm.ManagedService"/> </service> </component> \ No newline at end of file Modified: trunk/clients/gui/org.cishell.reference.gui.persistence/OSGI-INF/view.properties =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/OSGI-INF/view.properties 2010-01-04 20:01:51 UTC (rev 1006) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/OSGI-INF/view.properties 2010-01-05 20:56:33 UTC (rev 1007) @@ -1,5 +1,6 @@ menu_path=File/additions label=View... +shortcut=ctrl+alt+v description=This algorithm does this and this... in_data=java.lang.Object out_data=null Modified: trunk/clients/gui/org.cishell.reference.gui.persistence/OSGI-INF/viewwith.properties =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/OSGI-INF/viewwith.properties 2010-01-04 20:01:51 UTC (rev 1006) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/OSGI-INF/viewwith.properties 2010-01-05 20:56:33 UTC (rev 1007) @@ -1,5 +1,6 @@ menu_path=File/additions label=View with... +shortcut=ctrl+alt+w description=This algorithm does this and this... in_data=java.lang.Object out_data=null Modified: trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/save/SaveFactory.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/save/SaveFactory.java 2010-01-04 20:01:51 UTC (rev 1006) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/save/SaveFactory.java 2010-01-05 20:56:33 UTC (rev 1007) @@ -7,6 +7,8 @@ import org.cishell.framework.algorithm.Algorithm; import org.cishell.framework.algorithm.AlgorithmFactory; import org.cishell.framework.data.Data; +import org.osgi.service.cm.ConfigurationException; +import org.osgi.service.cm.ManagedService; import org.osgi.service.component.ComponentContext; /** @@ -16,7 +18,7 @@ * no final file:X->file-ext:* converter. * */ -public class SaveFactory implements AlgorithmFactory { +public class SaveFactory implements AlgorithmFactory, ManagedService { private CIShellContext ciShellContext; /** @@ -27,6 +29,9 @@ ciShellContext = new LocalCIShellContext(componentContext.getBundleContext()); } + + public void updated(Dictionary properties) throws ConfigurationException { + } /** * Create a Save algorithm This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fu...@us...> - 2010-01-04 20:01:57
|
Revision: 1006 http://cishell.svn.sourceforge.net/cishell/?rev=1006&view=rev Author: fugu13 Date: 2010-01-04 20:01:51 +0000 (Mon, 04 Jan 2010) Log Message: ----------- Update metadata to be 1.5 Modified Paths: -------------- trunk/core/org.cishell.reference.service.database/.classpath Added Paths: ----------- trunk/core/org.cishell.reference.service.database/.settings/org.eclipse.jdt.core.prefs Modified: trunk/core/org.cishell.reference.service.database/.classpath =================================================================== --- trunk/core/org.cishell.reference.service.database/.classpath 2010-01-04 17:45:34 UTC (rev 1005) +++ trunk/core/org.cishell.reference.service.database/.classpath 2010-01-04 20:01:51 UTC (rev 1006) @@ -1,6 +1,6 @@ <?xml version="1.0" encoding="UTF-8"?> <classpath> - <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.4"/> + <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/> <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> <classpathentry kind="src" path="src"/> <classpathentry kind="output" path="bin"/> Added: trunk/core/org.cishell.reference.service.database/.settings/org.eclipse.jdt.core.prefs =================================================================== --- trunk/core/org.cishell.reference.service.database/.settings/org.eclipse.jdt.core.prefs (rev 0) +++ trunk/core/org.cishell.reference.service.database/.settings/org.eclipse.jdt.core.prefs 2010-01-04 20:01:51 UTC (rev 1006) @@ -0,0 +1,8 @@ +#Mon Jan 04 15:00:54 EST 2010 +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 +org.eclipse.jdt.core.compiler.compliance=1.5 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.5 This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fu...@us...> - 2010-01-04 17:45:43
|
Revision: 1005 http://cishell.svn.sourceforge.net/cishell/?rev=1005&view=rev Author: fugu13 Date: 2010-01-04 17:45:34 +0000 (Mon, 04 Jan 2010) Log Message: ----------- This should have been in the repository a good while back. Added Paths: ----------- trunk/templates/org.cishell.templates.tasks/src/org/cishell/templates/staticexecutable/nwb/ trunk/templates/org.cishell.templates.tasks/src/org/cishell/templates/staticexecutable/nwb/IntegrationTask.java Added: trunk/templates/org.cishell.templates.tasks/src/org/cishell/templates/staticexecutable/nwb/IntegrationTask.java =================================================================== --- trunk/templates/org.cishell.templates.tasks/src/org/cishell/templates/staticexecutable/nwb/IntegrationTask.java (rev 0) +++ trunk/templates/org.cishell.templates.tasks/src/org/cishell/templates/staticexecutable/nwb/IntegrationTask.java 2010-01-04 17:45:34 UTC (rev 1005) @@ -0,0 +1,171 @@ +/* **************************************************************************** + * CIShell: Cyberinfrastructure Shell, An Algorithm Integration Framework. + * + * All rights reserved. This program and the accompanying materials are made + * available under the terms of the Apache License v2.0 which accompanies + * this distribution, and is available at: + * http://www.apache.org/licenses/LICENSE-2.0.html + * + * Created on Aug 2, 2006 at Indiana University. + * + * Contributors: + * Indiana University - + * ***************************************************************************/ +package org.cishell.templates.staticexecutable.nwb; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.ArrayList; +import java.util.Enumeration; +import java.util.List; +import java.util.Properties; + +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.Task; +import org.apache.tools.ant.taskdefs.Replace; +import org.apache.tools.ant.util.FileUtils; + + +public class IntegrationTask extends Task { + private PrintWriter mf; + private String componentAttr; + private File baseDir; + private File baseProperties; + private FileUtils util; + private File template; + private String symbolicName; + + public IntegrationTask() { + componentAttr = new String(); + util = FileUtils.getFileUtils(); + symbolicName = "unknown"; + } + + public void setTemplate(File file) { + template = file; + } + + public void setBasedir(File file) { + baseDir = file; + } + + public void setBaseproperties(File file) { + this.baseProperties = file; + } + + public void execute() throws BuildException { + if (baseDir != null && baseDir.exists() && baseDir.isDirectory() && + baseProperties != null && baseProperties.exists() && + template != null && template.exists()) { + try { + setupManifest(); + + File[] files = baseDir.listFiles(); + for (int i=0; i < files.length; i++) { + if (files[i].isDirectory() && + !files[i].getName().equalsIgnoreCase("default")) { + addAlgorithm(files[i]); + } + } + + writeManifest(); + } catch (Throwable e) { + e.printStackTrace(); + throw new BuildException(e); + } + } else { + throw new BuildException("Invalid or missing argument(s)."); + } + } + + protected void addAlgorithm(File dir) throws IOException { + File serviceFile = null; + File configFile = null; + List osDirs = new ArrayList(); + + File[] files = dir.listFiles(); + for (int i=0; i < files.length; i++) { + String name = files[i].getName(); + if (name.equalsIgnoreCase("config.properties")) { + configFile = files[i]; + } else if (name.equalsIgnoreCase("service.properties")) { + serviceFile = files[i]; + } else if (files[i].isDirectory() && + !name.equalsIgnoreCase("default")) { + osDirs.add(files[i]); + } + } + + if (serviceFile != null && configFile != null) { + File componentFile = new File(serviceFile.getParentFile().getPath()+ + File.separator+"component.xml"); + util.copyFile(template, componentFile); + + String algName = serviceFile.getParentFile().getName(); + replace(componentFile,"${service.properties}",algName+"/"+serviceFile.getName()); + replace(componentFile,"${component.id}",symbolicName+"." + algName + ".component"); + replace(componentFile,"${alg.dir}",algName); + + if (componentAttr.length() != 0) { + componentAttr += ", "; + } + componentAttr += algName+"/component.xml"; + } + } + + protected void replace(File file, String token, String value) { + Replace replace = new Replace(); + replace.setProject(getProject()); + replace.setFile(file); + replace.setToken(token); + + replace.setValue(value); + replace.execute(); + } + + protected void writeManifest() { + mf.println("Service-Component: " + componentAttr); + mf.close(); + } + + protected void setupManifest() throws IOException { + File mfDir = new File(baseDir.getPath()+File.separator+"META-INF"); + File mfFile = new File(mfDir+File.separator+"MANIFEST.MF"); + mfDir.mkdirs(); + + mf = new PrintWriter(new FileOutputStream(mfFile)); + + mf.println("Manifest-Version: 1.0"); + mf.println("Bundle-ManifestVersion: 2"); + + Properties properties = new Properties(); + properties.load(new FileInputStream(baseProperties)); + + for (Enumeration i=properties.keys(); i.hasMoreElements(); ) { + String key = (String)i.nextElement(); + String value = properties.getProperty(key); + + if ("Bundle-SymbolicName".equals(key)) { + symbolicName = value; + } + + mf.println(key+": "+value); + } + + mf.println("Bundle-Localization: plugin"); + mf.println("X-AutoStart: true"); + mf.println("Import-Package: org.cishell.framework.algorithm, " + + "org.cishell.framework.data, " + + "org.osgi.framework;version=\"1.3.0\", " + + "org.cishell.templates.staticexecutable, " + + "org.osgi.service.component;version=\"1.0.0\", " + + "org.osgi.service.metatype;version=\"1.1.0\", " + + "org.osgi.service.log," + + "edu.iu.nwb.templates.staticexecutable.nwb," + + "edu.iu.nwb.util.nwbfile," + + "org.cishell.reference.service.metatype"); + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mwl...@us...> - 2010-01-04 17:30:23
|
Revision: 1004 http://cishell.svn.sourceforge.net/cishell/?rev=1004&view=rev Author: mwlinnem Date: 2010-01-04 17:30:10 +0000 (Mon, 04 Jan 2010) Log Message: ----------- Modified to show a text file with a databases schema when a user chooses to "View" a database. Modified Paths: -------------- trunk/clients/gui/org.cishell.reference.gui.persistence/META-INF/MANIFEST.MF trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/view/FileView.java trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/view/core/FileViewer.java trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/viewwith/FileViewWith.java Added Paths: ----------- trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/view/core/DatabaseSchemaOverviewGenerator.java Modified: trunk/clients/gui/org.cishell.reference.gui.persistence/META-INF/MANIFEST.MF =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/META-INF/MANIFEST.MF 2010-01-04 17:29:08 UTC (rev 1003) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/META-INF/MANIFEST.MF 2010-01-04 17:30:10 UTC (rev 1004) @@ -12,6 +12,7 @@ org.cishell.reference.service.conversion, org.cishell.reference.service.metatype, org.cishell.service.conversion;version="1.0.0", + org.cishell.service.database, org.cishell.service.guibuilder;version="1.0.0", org.cishell.utilities, org.osgi.framework;version="1.3.0", @@ -24,4 +25,4 @@ Service-Component: OSGI-INF/load.xml, OSGI-INF/save.xml, OSGI-INF/view.xml, OSGI-INF/viewwith.xml Require-Bundle: org.eclipse.swt, org.eclipse.ui -Bundle-RequiredExecutionEnvironment: J2SE-1.4 +Bundle-RequiredExecutionEnvironment: J2SE-1.5 Modified: trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/view/FileView.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/view/FileView.java 2010-01-04 17:29:08 UTC (rev 1003) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/view/FileView.java 2010-01-04 17:30:10 UTC (rev 1004) @@ -33,7 +33,8 @@ try { FileViewer.viewDataFile(this.dataToView[ii], this.ciShellContext, - this.conversionManager); + this.conversionManager, + this.logger); } catch (FileViewingException fileViewingException) { String logMessage = "Error: Unable to view data \"" + Added: trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/view/core/DatabaseSchemaOverviewGenerator.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/view/core/DatabaseSchemaOverviewGenerator.java (rev 0) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/view/core/DatabaseSchemaOverviewGenerator.java 2010-01-04 17:30:10 UTC (rev 1004) @@ -0,0 +1,129 @@ +package org.cishell.reference.gui.persistence.view.core; + +import java.io.File; +import java.io.IOException; +import java.sql.Connection; +import java.sql.DatabaseMetaData; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; + +import org.cishell.service.database.Database; +import org.cishell.utilities.FileUtilities; + +public class DatabaseSchemaOverviewGenerator { + + private static final String newLine = System.getProperty("line.separator"); + + public static File generateDatabaseSchemaOverview(Database db) throws Exception { + + // Setup + + Connection dbConnection = db.getConnection(); + String applicationSchemaName = db.getApplicationSchemaName(); + + StringBuffer dbOverview = new StringBuffer(); + + // Generating text + + String headerText = getHeaderText(); + dbOverview.append(headerText); + List<String> tableNames = getTableNames(dbConnection, applicationSchemaName); + for (String tableName : tableNames) { + + String tableSchemaText = getTableSchemaAsText(dbConnection, tableName, + applicationSchemaName); + String foreignKeyReferencesText = getForeignKeyReferencesAsText(dbConnection, + tableName, applicationSchemaName); + + dbOverview.append(tableSchemaText); + dbOverview.append(foreignKeyReferencesText); + dbOverview.append(newLine); + } + + // Returning text as file + + File dbOverviewFile = FileUtilities.writeTextIntoTemporaryDirectory(dbOverview.toString(), + "txt"); + return dbOverviewFile; + } + + private static String getHeaderText() { + StringBuffer headerText = new StringBuffer(); + + headerText.append("Database Tables:" + newLine); + headerText.append("********************" + newLine); + headerText.append(newLine); + headerText.append(newLine); + + return headerText.toString(); + } + + // write the table's name, and the names and types of all the columns in + // that table + private static String getTableSchemaAsText(Connection dbConnection, String tableName, + String applicationSchemaName) throws SQLException { + + StringBuffer tableSchemaAsText = new StringBuffer(); + tableSchemaAsText.append(tableName + " ("); + + ResultSet columns = dbConnection.getMetaData().getColumns(null, applicationSchemaName, + tableName, null); + while (columns.next()) { + String columnName = columns.getString("COLUMN_NAME"); + String columnType = columns.getString("TYPE_NAME"); + + tableSchemaAsText.append(" " + columnName + " " + columnType + ","); + } + tableSchemaAsText.deleteCharAt(tableSchemaAsText.length() - 1); // (delete + // final + // comma) + tableSchemaAsText.append(")" + newLine); + + return tableSchemaAsText.toString(); + } + + // write which foreign keys in the table reference which other tables + private static String getForeignKeyReferencesAsText(Connection dbConnection, String tableName, + String applicationSchemaName) throws SQLException { + StringBuffer foreignKeyReferencesAsText = new StringBuffer(); + + ResultSet foreignKeys = dbConnection.getMetaData().getImportedKeys(null, + applicationSchemaName, tableName); + while (foreignKeys.next()) { + String foreignKey = foreignKeys.getString("FKCOLUMN_NAME"); + String referencedTable = foreignKeys.getString("PKTABLE_NAME"); + String referencedTableKey = foreignKeys.getString("PKCOLUMN_NAME"); + + foreignKeyReferencesAsText.append(" " + foreignKey + " -----> " + referencedTable + + "." + referencedTableKey); + foreignKeyReferencesAsText.append(newLine); + } + return foreignKeyReferencesAsText.toString(); + } + + // ---UTIL-- + + private static List<String> getTableNames(Connection dbConnection, String defaultSchemaName) + throws SQLException { + DatabaseMetaData dbMetadata = dbConnection.getMetaData(); + ResultSet allTableNames = dbMetadata.getTables(null, defaultSchemaName, null, null); + + // Names of tables that are not system tables. + List<String> nonSystemTableNames = new ArrayList<String>(); + while (allTableNames.next()) { + String schemaName = allTableNames.getString("TABLE_SCHEM"); + if (isNonSystemSchemaName(schemaName, defaultSchemaName)) { + String tableName = allTableNames.getString("TABLE_NAME"); + nonSystemTableNames.add(tableName); + } + } + + return nonSystemTableNames; + } + + private static boolean isNonSystemSchemaName(String tableSchemaName, String defaultSchemaName) { + return tableSchemaName.indexOf(defaultSchemaName) != -1; + } +} \ No newline at end of file Modified: trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/view/core/FileViewer.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/view/core/FileViewer.java 2010-01-04 17:29:08 UTC (rev 1003) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/view/core/FileViewer.java 2010-01-04 17:30:10 UTC (rev 1004) @@ -14,6 +14,7 @@ import org.cishell.service.conversion.ConversionException; import org.cishell.service.conversion.Converter; import org.cishell.service.conversion.DataConversionService; +import org.cishell.service.database.Database; import org.cishell.utilities.FileCopyingException; import org.cishell.utilities.FileUtilities; import org.eclipse.swt.program.Program; @@ -32,35 +33,57 @@ public static final String CSV_MIME_TYPE = "file:text/csv"; public static final String TEMPORARY_CSV_FILE_NAME = "xxx-Session-"; public static final String CSV_FILE_EXTENSION = "csv"; + public static final String TXT_FILE_EXTENSION = "txt"; public static final String ANY_FILE_FORMAT_PATTERN = "(file:.*)|(file-ext:.*)"; public static void viewDataFile(Data data, CIShellContext ciShellContext, - DataConversionService conversionManager) + DataConversionService conversionManager, + LogService logger) throws FileViewingException { - viewDataFileWithProgram(data, "", ciShellContext, conversionManager); + viewDataFileWithProgram(data, "", ciShellContext, conversionManager, logger); } public static void viewDataFileWithProgram( Data data, String customFileExtension, CIShellContext ciShellContext, - DataConversionService converterManager) + DataConversionService converterManager, + LogService logger) throws FileViewingException { FileWithExtension fileWithExtension = - convertDataForViewing(data, ciShellContext, converterManager); + convertDataForViewing(data, ciShellContext, converterManager, + logger); viewFileWithExtension(fileWithExtension, customFileExtension); } private static FileWithExtension convertDataForViewing( Data data, CIShellContext ciShellContext, - DataConversionService converterManager) - throws FileViewingException { + DataConversionService converterManager, + LogService logger) throws FileViewingException { try { String dataFormat = data.getFormat(); //TODO: Add image viewing support here (shouldn't be too hard) + if (dataIsDB(data, converterManager)) { + try { + Data genericDBData = converterManager.convert(data, Database.GENERIC_DB_MIME_TYPE); + Database genericDatabase = (Database) genericDBData.getData(); + + File dbSchemaOverview = + DatabaseSchemaOverviewGenerator.generateDatabaseSchemaOverview(genericDatabase); + + return new FileWithExtension(dbSchemaOverview, TXT_FILE_EXTENSION); + } catch (ConversionException e) { + //continue attempts to view for other formats + } catch (Exception e) { + String message = "Unexpected error occurred while generating " + + "database schema overview. Attempting to view the data item" + + "by other means."; + logger.log(LogService.LOG_WARNING, message, e); + } + } if (isCSVFormat(data)) { /* * The data is already a CSV file, so it just needs to @@ -97,7 +120,7 @@ * text-viewing program. */ return new FileWithExtension( - prepareTextFileForViewing(data), "txt"); + prepareTextFileForViewing(data), TXT_FILE_EXTENSION); } else if (convertersExist( data, ANY_FILE_EXTENSION_FILTER, converterManager)) { /* @@ -176,6 +199,21 @@ } } + private static boolean dataIsDB ( + Data data, + DataConversionService converterManager) { + if (has_DB_MimeType_Prefix(data) || + convertersExist(data, Database.GENERIC_DB_MIME_TYPE, converterManager)) { + return true; + } else { + return false; + } + } + + private static boolean has_DB_MimeType_Prefix(Data data) { + return data.getFormat().startsWith(Database.DB_MIME_TYPE_PREFIX); + } + private static boolean dataIsFile(Data data, String dataFormat) { if (data.getData() instanceof File || dataFormat.startsWith(ANY_MIME_TYPE) || Modified: trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/viewwith/FileViewWith.java =================================================================== --- trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/viewwith/FileViewWith.java 2010-01-04 17:29:08 UTC (rev 1003) +++ trunk/clients/gui/org.cishell.reference.gui.persistence/src/org/cishell/reference/gui/persistence/viewwith/FileViewWith.java 2010-01-04 17:30:10 UTC (rev 1004) @@ -41,7 +41,8 @@ this.dataToView[ii], viewWithType, this.ciShellContext, - this.conversionManager); + this.conversionManager, + this.logger); } catch (FileViewingException fileViewingException) { String logMessage = "Error: Unable to view data \"" + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <mwl...@us...> - 2010-01-04 17:29:16
|
Revision: 1003 http://cishell.svn.sourceforge.net/cishell/?rev=1003&view=rev Author: mwlinnem Date: 2010-01-04 17:29:08 +0000 (Mon, 04 Jan 2010) Log Message: ----------- Modified to incorporate database-related constants into this service (before they were duplicated in various other areas). Modified Paths: -------------- trunk/core/org.cishell.reference.service.database/META-INF/MANIFEST.MF trunk/core/org.cishell.reference.service.database/src/org/cishell/reference/service/database/DerbyDatabaseService.java trunk/core/org.cishell.reference.service.database/src/org/cishell/reference/service/database/ExternalDatabase.java trunk/core/org.cishell.reference.service.database/src/org/cishell/reference/service/database/InternalDerbyDatabase.java trunk/core/org.cishell.service.database/META-INF/MANIFEST.MF trunk/core/org.cishell.service.database/src/org/cishell/service/database/Database.java Added Paths: ----------- trunk/core/org.cishell.reference.service.database/.checkstyle trunk/core/org.cishell.service.database/bin/ Removed Paths: ------------- trunk/core/org.cishell.service.database/src/org/cishell/service/database/DataSourceWithID.java Added: trunk/core/org.cishell.reference.service.database/.checkstyle =================================================================== --- trunk/core/org.cishell.reference.service.database/.checkstyle (rev 0) +++ trunk/core/org.cishell.reference.service.database/.checkstyle 2010-01-04 17:29:08 UTC (rev 1003) @@ -0,0 +1,7 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<fileset-config file-format-version="1.2.0" simple-config="true"> + <fileset name="all" enabled="true" check-config-name="CNS Checks (Eclipse)" local="false"> + <file-match-pattern match-pattern="." include-pattern="true"/> + </fileset> +</fileset-config> Modified: trunk/core/org.cishell.reference.service.database/META-INF/MANIFEST.MF =================================================================== --- trunk/core/org.cishell.reference.service.database/META-INF/MANIFEST.MF 2009-12-30 20:55:04 UTC (rev 1002) +++ trunk/core/org.cishell.reference.service.database/META-INF/MANIFEST.MF 2010-01-04 17:29:08 UTC (rev 1003) @@ -3,7 +3,6 @@ Bundle-Name: Database Plug-in Bundle-SymbolicName: org.cishell.reference.service.database Bundle-Version: 1.0.0 -Bundle-RequiredExecutionEnvironment: J2SE-1.4 Bundle-Activator: org.cishell.reference.service.database.DerbyDatabaseService X-AutoStart: true Import-Package: org.apache.commons.dbcp, @@ -20,3 +19,4 @@ org.osgi.service.log;version="1.3.0", org.osgi.util.tracker;version="1.3.3" Service-Component: OSGI-INF/component.xml +Bundle-RequiredExecutionEnvironment: J2SE-1.5 Modified: trunk/core/org.cishell.reference.service.database/src/org/cishell/reference/service/database/DerbyDatabaseService.java =================================================================== --- trunk/core/org.cishell.reference.service.database/src/org/cishell/reference/service/database/DerbyDatabaseService.java 2009-12-30 20:55:04 UTC (rev 1002) +++ trunk/core/org.cishell.reference.service.database/src/org/cishell/reference/service/database/DerbyDatabaseService.java 2010-01-04 17:29:08 UTC (rev 1003) @@ -89,8 +89,10 @@ try { //connect to and create a 'new' database String databaseName = INTERNAL_DB_NAME_PREFIX + id; - InternalDerbyDatabase db = new InternalDerbyDatabase(createNewInternalDataSource(databaseName)); + InternalDerbyDatabase db = + new InternalDerbyDatabase(createNewInternalDataSource(databaseName)); + //if this database existed on disk from a previous session, clean it to be like new removeAllNonSystemDatabaseTables(db.getConnection()); @@ -115,7 +117,8 @@ throws DatabaseCreationException { DataSource dataSource = createNewDataSource(driver, url, username, password); - Database db = new ExternalDatabase(dataSource); + //TODO: See if we can get the default schema as a property somehow. + Database db = new ExternalDatabase(dataSource, "APP"); return db; } Modified: trunk/core/org.cishell.reference.service.database/src/org/cishell/reference/service/database/ExternalDatabase.java =================================================================== --- trunk/core/org.cishell.reference.service.database/src/org/cishell/reference/service/database/ExternalDatabase.java 2009-12-30 20:55:04 UTC (rev 1002) +++ trunk/core/org.cishell.reference.service.database/src/org/cishell/reference/service/database/ExternalDatabase.java 2010-01-04 17:29:08 UTC (rev 1003) @@ -10,9 +10,11 @@ public class ExternalDatabase implements Database { private DataSource dataSource; + private String schemaName; - public ExternalDatabase(DataSource dataSource) { + public ExternalDatabase(DataSource dataSource, String schemaName) { this.dataSource = dataSource; + this.schemaName = schemaName; } public Connection getConnection() throws SQLException { @@ -27,4 +29,8 @@ throws SQLException { return dataSource.getConnection(username, password); } + + public String getApplicationSchemaName() { + return schemaName; + } } Modified: trunk/core/org.cishell.reference.service.database/src/org/cishell/reference/service/database/InternalDerbyDatabase.java =================================================================== --- trunk/core/org.cishell.reference.service.database/src/org/cishell/reference/service/database/InternalDerbyDatabase.java 2009-12-30 20:55:04 UTC (rev 1002) +++ trunk/core/org.cishell.reference.service.database/src/org/cishell/reference/service/database/InternalDerbyDatabase.java 2010-01-04 17:29:08 UTC (rev 1003) @@ -27,4 +27,10 @@ + DerbyDatabaseService.DEFAULT_SHUTDOWN_CONNECTION_STRING; DriverManager.getConnection(shutdownDatabaseCommand); } + + + //TODO: We might want to expose our different 'databases' as different schemas at some point instead. + public String getApplicationSchemaName() { + return "APP"; + } } Modified: trunk/core/org.cishell.service.database/META-INF/MANIFEST.MF =================================================================== --- trunk/core/org.cishell.service.database/META-INF/MANIFEST.MF 2009-12-30 20:55:04 UTC (rev 1002) +++ trunk/core/org.cishell.service.database/META-INF/MANIFEST.MF 2010-01-04 17:29:08 UTC (rev 1003) @@ -3,6 +3,6 @@ Bundle-Name: Database Plug-in Bundle-SymbolicName: org.cishell.service.database Bundle-Version: 1.0.0 -Bundle-RequiredExecutionEnvironment: J2SE-1.4 +Bundle-RequiredExecutionEnvironment: J2SE-1.5 Export-Package: org.cishell.service.database Import-Package: org.apache.commons.dbcp Deleted: trunk/core/org.cishell.service.database/src/org/cishell/service/database/DataSourceWithID.java =================================================================== --- trunk/core/org.cishell.service.database/src/org/cishell/service/database/DataSourceWithID.java 2009-12-30 20:55:04 UTC (rev 1002) +++ trunk/core/org.cishell.service.database/src/org/cishell/service/database/DataSourceWithID.java 2010-01-04 17:29:08 UTC (rev 1003) @@ -1,25 +0,0 @@ -package org.cishell.service.database; - -import java.io.PrintWriter; -import java.sql.Connection; -import java.sql.SQLException; - -import javax.sql.DataSource; - -public interface DataSourceWithID extends DataSource { - - public abstract int getID(); - - public abstract Connection getConnection() throws SQLException; - - public abstract Connection getConnection(String username, String password) throws SQLException; - - public abstract PrintWriter getLogWriter() throws SQLException; - - public abstract void setLogWriter(PrintWriter out) throws SQLException; - - public abstract int getLoginTimeout() throws SQLException; - - public abstract void setLoginTimeout(int seconds) throws SQLException; - -} \ No newline at end of file Modified: trunk/core/org.cishell.service.database/src/org/cishell/service/database/Database.java =================================================================== --- trunk/core/org.cishell.service.database/src/org/cishell/service/database/Database.java 2009-12-30 20:55:04 UTC (rev 1002) +++ trunk/core/org.cishell.service.database/src/org/cishell/service/database/Database.java 2010-01-04 17:29:08 UTC (rev 1003) @@ -3,8 +3,18 @@ import java.sql.Connection; import java.sql.SQLException; -import org.apache.commons.dbcp.ConnectionFactory; + public interface Database { + public static final String DB_MIME_TYPE_PREFIX = "db:"; + public static final String GENERIC_DB_MIME_TYPE = "db:any"; + public Connection getConnection() throws SQLException; + + /** + * + * @return the name of the schema where the non-system tables we are interested in reside. + */ + public String getApplicationSchemaName(); + } \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |