public void dealSiteIDTable(String tableName, DataTable dt) throws Exception { this.task.setCurrentInfo("正在向表" + tableName + "插入站点数据"); if (tableName.equalsIgnoreCase("ZCSite")) { dealZCSite(dt.getDataRow(0)); } else { SchemaSet set = (SchemaSet) Class.forName("com.zving.schema." + tableName + "Set").newInstance(); if (!tableName.equalsIgnoreCase("ZDMember")) { for (int i = 0; i < dt.getRowCount(); ++i) { Schema schema = (Schema) Class.forName("com.zving.schema." + tableName + "Schema").newInstance(); DataRow dr = dt.getDataRow(i); setSiteIDTableMaxNo(tableName, dr, true); schema.setValue(dt.getDataRow(i)); set.add(schema); } this.da.insert(set); } else { Schema schema = (Schema) Class.forName("com.zving.schema." + tableName + "Schema").newInstance(); SchemaColumn[] scs = SchemaUtil.getColumns(schema); QueryBuilder qb = new QueryBuilder("select count(1) from " + tableName + " where 1=1 "); for (int i = 0; i < scs.length; ++i) { if (scs[i].isPrimaryKey()) { qb.append(" and " + scs[i].getColumnName() + "=?"); } } for (int i = 0; i < dt.getRowCount(); ++i) { schema = (Schema) Class.forName("com.zving.schema." + tableName + "Schema").newInstance(); DataRow dr = dt.getDataRow(i); qb.getParams().clear(); for (int j = 0; j < scs.length; ++j) { if (scs[j].isPrimaryKey()) { qb.add(dr.get(scs[j].getColumnName())); } } int count = qb.executeInt(); if (count > 0) setSiteIDTableMaxNo(tableName, dr, false); else { setSiteIDTableMaxNo(tableName, dr, true); } schema.setValue(dt.getDataRow(i)); set.add(schema); } this.da.deleteAndInsert(set); } } }
private void dealCustomTable(DataTable dt, QueryBuilder qb) throws Exception { try { qb.clearBatches(); qb.getParams().clear(); for (int i = 0; i < dt.getRowCount(); ++i) { for (int j = 0; j < dt.getColCount() - 1; ++j) { String v = dt.getString(i, j); if (StringUtil.isEmpty(v)) { v = null; } qb.add(v); } qb.addBatch(); } this.da.executeNoQuery(qb); } catch (Throwable t) { t.printStackTrace(); } }