wt.vc
Class MigrateHistoricalIterations

java.lang.Object
  extended bywt.vc.MigrateHistoricalIterations
All Implemented Interfaces:
JavaMigrator

public class MigrateHistoricalIterations
extends Object
implements JavaMigrator


Field Summary
static String BRANCH_ID
           
static String CABINET_ID
           
static String DOMAIN_ID
           
static String LATEST
           
static String OWNER_ID
           
 
Constructor Summary
MigrateHistoricalIterations()
           
 
Method Summary
 boolean runMigration(DirectiveServices directive_services)
          main method for initial testing of migrator and associated sql without actually performing the upgrade.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CABINET_ID

public static final String CABINET_ID
See Also:
Constant Field Values

DOMAIN_ID

public static final String DOMAIN_ID
See Also:
Constant Field Values

BRANCH_ID

public static final String BRANCH_ID
See Also:
Constant Field Values

OWNER_ID

public static final String OWNER_ID
See Also:
Constant Field Values

LATEST

public static final String LATEST
See Also:
Constant Field Values
Constructor Detail

MigrateHistoricalIterations

public MigrateHistoricalIterations()
Method Detail

runMigration

public boolean runMigration(DirectiveServices directive_services)
                     throws Throwable
main method for initial testing of migrator and associated sql without actually performing the upgrade. If you need to test this you can uncomment this code and execute it and it should return useful output about the which rows from which tables in the database need updating and what the update sql would look like to perform the update. public static void main(String[] args) throws Throwable { PreparedStatement query; PreparedStatement update; java.sql.DriverManager.registerDriver(new oracle.jdbc.OracleDriver()); Connection connection = java.sql.DriverManager.getConnection("jdbc:oracle:thin:@corvair:1526:pine", "ERASMUSSEN_X05_VIEW", "ERASMUSSEN_X05_VIEW"); ClassInfo iteratedClassInfo = WTIntrospector.getClassInfo(IteratedFoldered.class); ClassInfo[] iteratedDescendantsInfos = iteratedClassInfo.getDescendentInfos(); for (int i = 0; i < iteratedDescendantsInfos.length; i++) { if (!iteratedDescendantsInfos[i].isConcrete() || !iteratedDescendantsInfos[i].isPersistable()) continue; String concreteIteratedClassTableName = iteratedDescendantsInfos[i].getDatabaseInfo().getBaseTableInfo().getTablename(); String latestColumnName = iteratedDescendantsInfos[i].getDatabaseInfo().getBaseTableInfo().getColumnDescriptor(LATEST).getColumnName(); String branchIdIterationInfoColumnName = iteratedDescendantsInfos[i].getDatabaseInfo().getBaseTableInfo().getColumnDescriptor(BRANCH_ID).getColumnName(); String cabinetColumnName = iteratedDescendantsInfos[i].getDatabaseInfo().getBaseTableInfo().getColumnDescriptor(CABINET_ID).getColumnName(); String domainColumnName = iteratedDescendantsInfos[i].getDatabaseInfo().getBaseTableInfo().getColumnDescriptor(DOMAIN_ID).getColumnName(); String ownerColumnName = iteratedDescendantsInfos[i].getDatabaseInfo().getBaseTableInfo().getColumnDescriptor(OWNER_ID).getColumnName(); System.out.println("============== Processing Class: " + concreteIteratedClassTableName + " =============="); // Get all the columns needed for each latest iteration from the concrete class table. String latestSQL = "SELECT " + branchIdIterationInfoColumnName + ", " + cabinetColumnName + ", " + domainColumnName + ", " + ownerColumnName + " FROM " + concreteIteratedClassTableName + " WHERE " + latestColumnName + "=1"; System.out.println(latestSQL); query = connection.prepareStatement(latestSQL); ResultSet rows = query.executeQuery(); // Now loop through the rows from this table and update the historical iterations for // each latest iteration that needs updating. while (rows.next()) { long branchId = rows.getLong(1); long folderId = rows.getLong(2); long domainId = rows.getLong(3); long ownerId = rows.getLong(4); String SQL = "SELECT " + branchIdIterationInfoColumnName + ", " + cabinetColumnName + ", " + domainColumnName + ", " + ownerColumnName + " FROM " + concreteIteratedClassTableName + " WHERE (" + branchIdIterationInfoColumnName + "=" + branchId + " AND ((" + cabinetColumnName + "<>" + folderId + ") OR (" + domainColumnName + "<>" + domainId + ") OR (" + ownerColumnName + "<>" + ownerId + ")))"; String updateSQL = "UPDATE " + concreteIteratedClassTableName + " SET " + cabinetColumnName + "=?," + domainColumnName + "=?," + ownerColumnName + "=? WHERE (" + branchIdIterationInfoColumnName + "=" + branchId + " AND ((" + cabinetColumnName + "<>" + folderId + ") OR (" + domainColumnName + "<>" + domainId + ") OR (" + ownerColumnName + "<>" + ownerId + ")))"; System.out.println(SQL); System.out.println(updateSQL); update = connection.prepareStatement(SQL); ResultSet updateRows = update.executeQuery(); while (updateRows.next()) { long historicalBranchId = updateRows.getLong(1); long historicalFolderId = updateRows.getLong(2); long historicalDomainId = updateRows.getLong(3); long historicalOwnerId = updateRows.getLong(4); System.out.println("\tLATEST Values -- branchId: " + branchId + "\tfolderId: " + folderId + "\tdomainId: " + domainId + "\townerId: " + ownerId); System.out.println("\tHISTOR Values -- branchId: " + historicalBranchId + "\tfolderId: " + historicalFolderId + "\tdomainId: " + historicalDomainId + "\townerId: " + historicalOwnerId); } update.close(); // ONLY EXECUTE THE FOLLOWING CODE IF YOU WANT THE DATABASE ACTUALLY UPDATED! //update = connection.prepareStatement(updateSQL); //update.setLong(1, folderId); //update.setLong(2, domainId); //update.setLong(3, ownerId); //update.executeUpdate(); //update.close(); } } System.exit(0); }

Specified by:
runMigration in interface JavaMigrator
Parameters:
directive_services - provide access to database, logging, and versioning information
Throws:
Throwable - declared so that migrators can let exceptions contibuting to failure pass out of the method. The migrator runner will handle these by logging them.