1 40 package org.dspace.administer; 41 42 import org.dspace.content.DCDate; 43 import org.dspace.core.Context; 44 import org.dspace.storage.rdbms.DatabaseManager; 45 import org.dspace.storage.rdbms.TableRow; 46 import org.dspace.storage.rdbms.TableRowIterator; 47 48 55 public class Upgrade101To11 56 { 57 63 public static void main(String [] argv) 64 { 65 Context context = null; 66 67 try 68 { 69 context = new Context(); 70 71 TableRowIterator tri = DatabaseManager.queryTable(context, "item", 74 "SELECT * FROM item WHERE withdrawal_date IS NOT NULL"); 75 76 while (tri.hasNext()) 77 { 78 TableRow row = tri.next(); 79 DCDate d = new DCDate(row.getStringColumn("withdrawal_date")); 80 row.setColumn("last_modified", d.toDate()); 81 DatabaseManager.update(context, row); 82 } 83 tri.close(); 84 85 tri = DatabaseManager.query(context, 87 "SELECT item.item_id, dcvalue.text_value FROM item, dctyperegistry, "+ 88 "dcvalue WHERE item.item_id=dcvalue.item_id AND dcvalue.dc_type_id="+ 89 "dctyperegistry.dc_type_id AND dctyperegistry.element LIKE 'date' "+ 90 "AND dctyperegistry.qualifier LIKE 'available'"); 91 92 while (tri.hasNext()) 93 { 94 TableRow resultRow = tri.next(); 95 DCDate d = new DCDate(resultRow.getStringColumn("text_value")); 96 97 TableRow itemRow = DatabaseManager.find(context, "item", 99 resultRow.getIntColumn("item_id")); 100 itemRow.setColumn("last_modified", d.toDate()); 101 DatabaseManager.update(context, itemRow); 102 } 103 tri.close(); 104 105 DatabaseManager.updateQuery(context, 108 "UPDATE item SET last_modified=now() WHERE last_modified IS NULL"); 109 110 context.complete(); 111 112 System.out.println("Last modified dates set"); 113 114 System.exit(0); 115 } 116 catch (Exception e) 117 { 118 System.err.println("Exception occurred:" + e); 119 e.printStackTrace(); 120 121 if (context != null) 122 { 123 context.abort(); 124 } 125 126 System.exit(1); 127 } 128 } 129 } 130
| Popular Tags
|