public static Mapx getSiteInfo(String file) throws Exception { FileInputStream fin = null; try { fin = new FileInputStream(file); fin.read(); byte[] bs = new byte[8]; fin.read(bs); bs = new byte[4]; if (!bufferRead(bs, fin)) { return null; } int len = NumberUtil.toInt(bs); byte[] bs = new byte[len]; if (!bufferRead(bs, fin)) return null; int len; byte[] bs = new byte[4]; if (!bufferRead(bs, fin)) { return null; } int len = NumberUtil.toInt(bs); byte[] bs = new byte[len]; if (!bufferRead(bs, fin)) return null; int len; byte[] bs = ZipUtil.unzip(bs); DataTable dt = (DataTable) FileUtil.unserialize(bs); return dt.getDataRow(0).toCaseIgnoreMapx(); } finally { if (fin != null) try { fin.close(); } catch (IOException e) { e.printStackTrace(); } } }
public boolean importSite(String poolName) { User.UserData user = new User.UserData(); user.setUserName("admin"); user.setBranchInnerCode("86"); user.setLogin(true); user.setManager(true); User.setCurrent(user); this.isNewSite = (("0".equals(this.map.getString("ID"))) || (StringUtil.isEmpty(this.map.getString("ID")))); this.NoRelas = SiteTableRela.getNoRelaArray(); this.TableRelas = SiteTableRela.getRelas(); this.da = new DataAccess(); FileInputStream fin = null; try { fin = new FileInputStream(this.file); this.da.setAutoCommit(false); this.ExportCharset = ((fin.read() == 1) ? "GBK" : "UTF-8"); byte[] bs = new byte[8]; fin.read(bs); this.siteID = NumberUtil.toLong(bs); boolean flag = true; int i = 0; while (true) { bs = new byte[4]; if (!bufferRead(bs, fin)) { break; } int len = NumberUtil.toInt(bs); bs = new byte[len]; if (!bufferRead(bs, fin)) { flag = false; break; } Object obj = FileUtil.unserialize(bs); bs = new byte[4]; if (!bufferRead(bs, fin)) { flag = false; break; } len = NumberUtil.toInt(bs); bs = new byte[len]; if (!bufferRead(bs, fin)) { flag = false; break; } bs = ZipUtil.unzip(bs); this.task.setPercent(i * 100 / 200); dealOneEntry(bs, obj); ++i; } if (flag) { this.da.commit(); } else { LogUtil.error("读取站点导出文件时发生错误!"); this.da.rollback(); } this.da.setAutoCommit(true); Site.updatePrivAndFile(this.map.getString("Alias")); return flag; } catch (Exception e1) { e1.printStackTrace(); try { this.da.rollback(); } catch (SQLException e) { e.printStackTrace(); } return false; } finally { try { this.da.setAutoCommit(true); } catch (Exception e) { e.printStackTrace(); } try { this.da.close(); } catch (Exception e) { e.printStackTrace(); } try { fin.close(); } catch (Exception e) { e.printStackTrace(); } } }
public void dealOneEntry(byte[] bs, Object obj) throws Exception { if ((bs == null) || (obj == null)) { return; } if (obj instanceof String) { String name = obj.toString(); if (name.startsWith("File:")) { dealFile(name, bs); } else if (name.startsWith("CustomTable:")) { name = name.substring("CustomTable:".length()); this.task.setCurrentInfo("正在导入自定义表:" + name); DataTable dt = (DataTable) FileUtil.unserialize(bs); try { if (!this.customTableMap.containsKey(name)) { QueryBuilder qb = new QueryBuilder( "select * from ZCCustomTableColumn where exists (select ID from ZCCustomTable where SiteID=? and Code=? and Type='Custom' and ZCCustomTableColumn.TableID=ID)", this.newSiteID, name); DataTable cdt = this.da.executeDataTable(qb); SchemaColumn[] scs = new SchemaColumn[cdt.getRowCount()]; for (int j = 0; j < scs.length; ++j) { DataRow cdr = cdt.getDataRow(j); int type = Integer.parseInt(cdr.getString("DataType")); SchemaColumn sc = new SchemaColumn( cdr.getString("Code"), type, j, cdr.getInt("Length"), 0, "Y".equals(cdr.getString("isMandatory")), "Y".equals(cdr.getString("isPrimaryKey"))); scs[j] = sc; } TableCreator tc = new TableCreator(this.da.getConnection().getDBConfig().DBType); tc.createTable(scs, name, true); tc.executeAndClear(this.da.getConnection()); this.customTableMap.put(name, ""); StringBuffer sb = new StringBuffer("insert into " + name + "("); for (int j = 0; j < cdt.getRowCount(); ++j) { if (j != 0) { sb.append(","); } sb.append(cdt.get(j, "Code")); } sb.append(") values ("); for (int j = 0; j < cdt.getRowCount(); ++j) { if (j != 0) { sb.append(","); } sb.append("?"); } sb.append(")"); this.insertQB = new QueryBuilder(sb.toString()); this.insertQB.setBatchMode(true); } dealCustomTable(dt, this.insertQB); } catch (Exception e) { LogUtil.warn("未成功导入表" + name); e.printStackTrace(); } } else { dealSiteIDTable(name, (DataTable) FileUtil.unserialize(bs)); } } else { dealRelaTable((SiteTableRela.TableRela) obj, (DataTable) FileUtil.unserialize(bs)); } }