|
From: fredrik <fre...@us...> - 2005-04-28 11:51:16
|
Update of /cvsroot/test-manager/main/src/testmanager/database In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14164/src/testmanager/database Modified Files: Database.java Log Message: Reorganizing servlets & adding bug tracking Index: Database.java =================================================================== RCS file: /cvsroot/test-manager/main/src/testmanager/database/Database.java,v retrieving revision 1.22 retrieving revision 1.23 diff -C2 -d -r1.22 -r1.23 *** Database.java 21 Apr 2005 17:33:33 -0000 1.22 --- Database.java 28 Apr 2005 11:51:06 -0000 1.23 *************** *** 4,17 **** import java.sql.Connection; import java.sql.DriverManager; ! import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import java.util.logging.Logger; ! import testmanager.tests.Attachment; ! import testmanager.tests.History; ! import testmanager.tests.TestCase; ! import testmanager.tests.TestCaseArea; ! import testmanager.tests.Tester; /** --- 4,20 ---- import java.sql.Connection; import java.sql.DriverManager; ! import java.sql.PreparedStatement; import java.sql.SQLException; import java.sql.Statement; import java.util.logging.Logger; ! import testmanager.database.tables.Attachment; ! import testmanager.database.tables.Bug; ! import testmanager.database.tables.BugLink; ! import testmanager.database.tables.History; ! import testmanager.database.tables.LoggedIn; ! import testmanager.database.tables.TestCase; ! import testmanager.database.tables.TestCaseArea; ! import testmanager.database.tables.Tester; /** *************** *** 26,30 **** /** * The name of the database created inside the derby database manager. This will also be the name of the ! * subdirectory that derby will create within the application directory. */ public static final String DATABASE_NAME = "database"; --- 29,33 ---- /** * The name of the database created inside the derby database manager. This will also be the name of the ! * subdirectory that derby will create within the application directory (thus the name "database"). */ public static final String DATABASE_NAME = "database"; *************** *** 47,77 **** */ ! /** ! * A utility method for a query that only returns a single string. ! * ! * @param connection ! * The connection to the database. ! * @param query ! * The SQL query that is to result in a single string. ! * @return The string result of the query or null if the query had an empty result. ! * @throws SQLException ! * If one occurs while executing the Query. ! * @throws IllegalArgumentException ! * If the query results in more than one result. ! */ ! public static String stringQuery(Connection connection, String query) throws SQLException { ! ResultSet result = connection.createStatement().executeQuery(query); ! if (result.next()) { ! String returnValue = result.getString(1); ! if (result.next()) { ! // The result contains more than ! throw new IllegalArgumentException("In Database.stringQuery() the query \"" + query ! + "\" returned several rows"); ! } else { ! return returnValue; ! } ! } else { ! return null; ! } } --- 50,57 ---- */ ! // TODO: Remove ! public void createAdminAccount(String adminPassword) throws SQLException { ! Connection connection = getConnection(); ! PreparedStatement statement = connection.prepareStatement("INSERT INTO Tester "); } *************** *** 119,188 **** Connection connection = null; ! if (newDirectory) { - try { connection = DriverManager.getConnection("jdbc:derby:" + DATABASE_NAME + ";create=true"); - Statement statement = connection.createStatement(); // Create the database tables ! logger.info("Adding initial test data to the database... "); ! statement.addBatch(TestCaseArea.createTableStatement); statement.addBatch(Attachment.createTableStatement); statement.addBatch(History.createTableStatement); ! statement.addBatch(Tester.createTableStatement); statement.addBatch(TestCase.createTableStatement); ! ! // Insert some dummy data for testing ! statement ! .addBatch("INSERT INTO Tester (UserName, Password, FullName, MailAddress) VALUES ('fredrik', 'mellon', 'Fredrik Fornwall', 'fre...@gm...')"); ! statement ! .addBatch("INSERT INTO Tester (UserName, Password, FullName, MailAddress) VALUES ('goran', 'mellon', 'Goran Soderman', 'gor...@ch...')"); ! statement ! .addBatch("INSERT INTO Tester (UserName, Password, FullName, MailAddress) VALUES ('faina', 'mellon', 'Faina Barknell', 'bar...@ho...')"); ! statement ! .addBatch("INSERT INTO Tester (UserName, Password, FullName, MailAddress) VALUES ('czeslaw', 'mellon', 'Czeslaw Kolodziejski', 'cz...@ch...')"); ! ! statement.addBatch("INSERT INTO TestCaseArea (Name, Description) VALUES ('Design', '...')"); ! statement.addBatch("INSERT INTO TestCaseArea (Name, Description) VALUES ('Data', '...')"); ! statement.addBatch("INSERT INTO TestCaseArea (Name, Description) VALUES ('Installation', '...')"); ! ! statement ! .addBatch("INSERT INTO TestCase (Title, AuthorId, ResponsibleID, AreaID, ExecutionDate, CreationDate, DueDate, Status, Type, Description) " ! + "VALUES ('Login', 2, 1, 2, CURRENT_DATE, CURRENT_DATE, '2008-03-23', 2, 1, 'How to reprodue: TODO')"); ! statement ! .addBatch("INSERT INTO TestCase (Title, AuthorId, ResponsibleID, AreaID, ExecutionDate, CreationDate, DueDate, Status, Type, Description) " ! + "VALUES ('Just Testing', 1, 2, 1, CURRENT_DATE, CURRENT_DATE, '2006-04-05', 1, 2, 'This is a description')"); ! statement ! .addBatch("INSERT INTO TestCase (Title, AuthorId, ResponsibleID, AreaID, ExecutionDate, CreationDate, DueDate, Status, Type, Description) " ! + "VALUES ('Adding a new user to the testers list', 1, 3, 1, CURRENT_DATE, CURRENT_DATE, '2006-04-15', 1, 2, 'This test case describes how to add a new user to the testers list.')"); ! statement ! .addBatch("INSERT INTO TestCase (Title, AuthorId, ResponsibleID, AreaID, ExecutionDate, CreationDate, DueDate, Status, Type, Description) " ! + "VALUES ('Print a project summary', 3, 3, 1, CURRENT_DATE, CURRENT_DATE, '2006-04-15', 1, 2, 'This test case describes how to print a summary of the project.')"); ! statement ! .addBatch("INSERT INTO TestCase (Title, AuthorId, ResponsibleID, AreaID, ExecutionDate, CreationDate, DueDate, Status, Type, Description) " ! + "VALUES ('Export to PDF', 3, 3, 1, CURRENT_DATE, CURRENT_DATE, '2005-09-23', 0, 2, 'Test that the overview can be exported to PDF.')"); ! ! // TODO: just testing with some data ! for (int i = 0; i < 100; i++) { ! statement ! .addBatch("INSERT INTO TestCase (Title, AuthorId, ResponsibleID, AreaID, ExecutionDate, CreationDate, DueDate, Status, Type, Description) " ! + "VALUES ('Sample TestCase " ! + i ! + "', 3, 3, 1, CURRENT_DATE, CURRENT_DATE, '2005-09-23', 0, 2, 'This is just a sample test case.')"); ! } ! ! statement ! .addBatch("INSERT INTO History (TestCaseID, ResponsibleID, CreationTimestamp, Description, Comment) " ! + "VALUES (1, 1, CURRENT_TIMESTAMP, 'Changed test status to fail\n', 'Application crashes at startup')"); ! statement ! .addBatch("INSERT INTO History (TestCaseID, ResponsibleID, CreationTimestamp, Description, Comment) " ! + "VALUES (1, 2, CURRENT_TIMESTAMP, 'Changed test status to pass\n', 'I fixed it yesterday, updating the status.')"); ! ! // TEMP: ! statement.addBatch("CREATE TABLE LoggedIn (TesterID INTEGER NOT NULL)"); ! statement.executeBatch(); } finally { if (connection != null && !connection.isClosed()) { --- 99,125 ---- Connection connection = null; ! if (newDirectory) { try { connection = DriverManager.getConnection("jdbc:derby:" + DATABASE_NAME + ";create=true"); // Create the database tables ! logger.info("Creating database tables..."); ! ! Statement statement = connection.createStatement(); statement.addBatch(Attachment.createTableStatement); + statement.addBatch(Bug.createTableStatement); + statement.addBatch(BugLink.createTableStatement); statement.addBatch(History.createTableStatement); ! statement.addBatch(LoggedIn.createTableStatement); statement.addBatch(TestCase.createTableStatement); ! statement.addBatch(TestCaseArea.createTableStatement); ! statement.addBatch(Tester.createTableStatement); statement.executeBatch(); + + BugLink.initialize(connection); + logger.info("Adding initial example data to the database..."); + addDummyData(connection); } finally { if (connection != null && !connection.isClosed()) { *************** *** 192,205 **** } ! // Clear all logged in try { connection = getConnection(); connection.createStatement().executeUpdate("DELETE FROM LoggedIn"); ! } catch (Exception e) { if (connection != null && !connection.isClosed()) try { connection.close(); } catch (SQLException ee) { ! // TODO } } --- 129,144 ---- } ! // Clear all logged in each time we start up the database try { connection = getConnection(); connection.createStatement().executeUpdate("DELETE FROM LoggedIn"); ! } catch (SQLException e) { ! throw new SQLException("Could not delete table LoggedIn in: " + e.getMessage()); ! } finally { if (connection != null && !connection.isClosed()) try { connection.close(); } catch (SQLException ee) { ! logger.severe("Could not close connection in Database#startUp()"); } } *************** *** 208,210 **** --- 147,167 ---- } + private static void addDummyData(Connection connection) throws SQLException { + // Insert dummy data + try { + Tester.addDummyData(connection); + } catch (Tester.AlreadyExistsException e) { + throw new SQLException("Tester already exists when inserting dummy data: " + e.getMessage()); + } + + TestCaseArea.addNew(connection, "Shutdown", "..."); + TestCaseArea.addNew(connection, "Startup", "..."); + TestCaseArea.addNew(connection, "Installation", "..."); + + TestCase.addDummyData(connection); + History.addDummyData(connection); + + Bug.addDummyData(connection); + BugLink.addDummyData(connection); + } } \ No newline at end of file |