Changeset 278
- Timestamp:
- 01/25/08 18:07:19 (1 year ago)
- Files:
-
- lex/trunk/src/com/qwirx/db/sql/SqlChange.java (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
lex/trunk/src/com/qwirx/db/sql/SqlChange.java
r275 r278 66 66 "WHERE id = " + id); 67 67 ResultSet rs = stmt.executeQuery(); 68 return new SqlChange(username, 69 rs.getString(1), 70 lookup(rs.getString(2)), 71 rs.getString(3), null, conn); 68 if (!rs.next()) 69 { 70 throw new IllegalArgumentException("No such changelog entry: " + 71 id); 72 } 73 String databaseName = rs.getString(1); 74 String commandType = rs.getString(2); 75 String tableName = rs.getString(3); 76 SqlChange ch = new SqlChange(username, databaseName, 77 lookup(commandType), tableName, null, conn); 78 ch.id = id; 79 return ch; 72 80 } 73 81 … … 689 697 public SqlChange[] reverse() throws DatabaseException 690 698 { 691 if (type == SqlChange.INSERT) 692 { 693 return new SqlChange[]{ 694 new SqlChange(username, database, SqlChange.DELETE, 695 table, conditions, conn) 696 }; 697 } 698 else if (type == SqlChange.UPDATE || type == SqlChange.DELETE) 699 if (type == SqlChange.INSERT || 700 type == SqlChange.UPDATE || 701 type == SqlChange.DELETE) 699 702 { 700 703 List changedRows = getChangedRows(); … … 706 709 SqlChange rev = null; 707 710 708 if (type == SqlChange.UPDATE) 711 if (type == SqlChange.INSERT) 712 { 713 rev = new SqlChange(username, database, SqlChange.DELETE, 714 table, "ID = " + cr.getUniqueID(), conn); 715 } 716 else if (type == SqlChange.UPDATE) 709 717 { 710 718 rev = new SqlChange(username, database, SqlChange.UPDATE, … … 717 725 } 718 726 719 for (Iterator j = cr.iterator(); j.hasNext();)727 if (rev.getType() != SqlChange.DELETE) 720 728 { 721 ChangedValue cv = (ChangedValue)j.next(); 722 rev.setObject(cv.getName(), cv.getOldValue()); 729 for (Iterator j = cr.iterator(); j.hasNext();) 730 { 731 ChangedValue cv = (ChangedValue)j.next(); 732 rev.setObject(cv.getName(), cv.getOldValue()); 733 } 723 734 } 724 735 … … 736 747 " cannot be reversed yet"); 737 748 } 749 750 /** 751 * Executes the reverse SqlChanges to undo the effects of executing() 752 * this change. 753 */ 754 public void undo() throws DatabaseException 755 { 756 SqlChange [] revs = reverse(); 757 for (int i = 0; i < revs.length; i++) 758 { 759 revs[i].execute(); 760 } 761 } 738 762 }
