private static void update0(int _nProductForm) throws PureException { IStatement query = null; IObjects result = null; try { int[] aValues = { // // 1964,// // 1978, 1979,// // 1980, 1981, 1982, 1983, 1984, 1985, 1986, 1987, 1988, 1989,// 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, // 2000, 2001, 2002, 2003, 2004, 2005, 2006 // }; IProductMgr mgr = (IProductMgr) ArkContentHelper.getContentMgrOf(Product.class); String strSQL = "SELECT {this.id},{this.serialNo},{this.publishDate} FROM {this}0 WHERE {this.productForm}=" + _nProductForm + " AND year({this.publishDate})=?"; for (int j = 0; j < aValues.length; j++) { query = mgr.createQuery(strSQL, 0); query.setInt(0, aValues[j]); result = query.executeQuery(); int max = getMaxSerialNo( "SELECT MAX({this.serialNo}) AS _MAX FROM {this} WHERE {this.productForm}=" + _nProductForm + " AND year({this.publishDate})=" + aValues[j]); // int max=2005608586; int i = max; for (Iterator iter = result.iterator(); iter.hasNext(); i++) { Product product = (Product) iter.next(); int nSerialNo = 0; if (max > 1) { nSerialNo = i; } else { nSerialNo = aValues[j] * 1000000 + 100000 * _nProductForm + i; } System.out.println(product.getId() + " : " + nSerialNo); product.setProperty("serialNo", nSerialNo); mgr.saveToTemp(product, false); } } } finally { DolphinHelper.clear(result, query); } }
private static int getMaxSerialNo(String _sSQL) throws PureException { IStatement query = null; IObjects result = null; try { IProductMgr mgr = (IProductMgr) ArkContentHelper.getContentMgrOf(Product.class); query = mgr.createQuery(_sSQL, 0); result = query.executeQuery(); Product product = (Product) result.next(); if (product == null) { return 1; } return product.getIntProperty("_MAX", 0) + 1; } finally { DolphinHelper.clear(result, query); } }
private static void update3index() throws PureException { IStatement query = null; IObjects result = null; try { int[] aValues = { // // 1964,// // 1978, 1979,// // 1980, 1981, 1982, 1983, 1984, 1985, 1986, 1987, 1988, 1989,// 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, // 2000, 2001, 2002, 2003, 2004, 2005, 2006 // }; IProductMgr mgr = (IProductMgr) ArkContentHelper.getContentMgrOf(Product.class); String strSQL = "SELECT {this.id},{this.serialNo} FROM {this} WHERE {this.productForm}=3 AND {this.indexIndexDate}=?"; for (int j = 0; j < aValues.length; j++) { query = mgr.createQuery(strSQL, 0); query.setInt(0, aValues[j]); result = query.executeQuery(); int i = 1; for (Iterator iter = result.iterator(); iter.hasNext(); i++) { Product product = (Product) iter.next(); int nSerialNo = aValues[j] * 1000000 + 300000 + i; System.out.println(product.getId() + " : " + nSerialNo); product.setProperty("serialNo", nSerialNo); mgr.save(product); } } } finally { DolphinHelper.clear(result, query); } }