Example #1
0
  public void setRelaTableMaxNo(SiteTableRela.TableRela tr, DataRow dr, boolean newIDFlag) {
    for (int i = 0; i < this.NoRelas.length; ++i) {
      SiteTableRela.NoType nr = this.NoRelas[i];
      if (nr.TableCode.equalsIgnoreCase(tr.TableCode)) {
        String id = dr.getString(nr.FieldName);
        if (newIDFlag) {
          id = String.valueOf(NoUtil.getMaxID(nr.NoType));
        }
        addIDMapping(nr.TableCode + "." + nr.FieldName, dr.getString(nr.FieldName), id);
        dr.set(nr.FieldName, id);
      }
    }
    for (int i = 0; i < this.TableRelas.length; ++i)
      if (this.TableRelas[i].TableCode.equals(tr.TableCode)) {
        String type = this.TableRelas[i].RelaTable;
        if ((((type.equals("ZCArticle"))
                || (type.equals("ZCAttachment"))
                || (type.equals("ZCImage"))
                || (type.equals("ZCAudio"))
                || (type.equals("ZCVideo"))))
            && (this.TableRelas[i].RelaField.equals("ID"))) {
          type = "Document";
        }

        String id =
            getIDMapping(
                type + "." + this.TableRelas[i].RelaField,
                dr.getString(this.TableRelas[i].KeyField));
        if (StringUtil.isNotEmpty(id)) dr.set(this.TableRelas[i].KeyField, id);
      }
  }
Example #2
0
  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);
      }
    }
  }
Example #3
0
  public void setSiteIDTableMaxNo(String tableName, DataRow dr, boolean newIDFlag) {
    try {
      if (dr.getDataColumn("SiteID") != null)
        dr.set("SiteID", getIDMapping("ZCSite", String.valueOf(this.siteID)));
    } catch (Throwable t) {
      t.printStackTrace();
      LogUtil.warn(tableName);
    }
    for (int i = 0; i < this.NoRelas.length; ++i) {
      SiteTableRela.NoType nr = this.NoRelas[i];
      if (nr.TableCode.equalsIgnoreCase(tableName)) {
        String id = dr.getString(nr.FieldName);
        if (newIDFlag) {
          if ((nr.TableCode.equals("ZCCatalog")) && (nr.FieldName.equals("InnerCode")))
            if (id.length() == 6) {
              id = CatalogUtil.createCatalogInnerCode(null);
            } else {
              String parent = id.substring(0, id.length() - 6);
              parent = getIDMapping(nr.TableCode + "." + nr.FieldName, parent);
              id = CatalogUtil.createCatalogInnerCode(parent);
            }
          else {
            id = String.valueOf(NoUtil.getMaxID(nr.NoType));
          }
        }
        String type = nr.TableCode;
        if ((((type.equals("ZCArticle"))
                || (type.equals("ZCAttachment"))
                || (type.equals("ZCImage"))
                || (type.equals("ZCAudio"))
                || (type.equals("ZCVideo"))))
            && (nr.NoType.equals("DocID"))) {
          type = "Document";
        }

        addIDMapping(type + "." + nr.FieldName, dr.getString(nr.FieldName), id);
        dr.set(nr.FieldName, id);
      }
    }
    for (int i = 0; i < this.TableRelas.length; ++i)
      if (this.TableRelas[i].TableCode.equals(tableName)) {
        String type = this.TableRelas[i].RelaTable;
        if ((((type.equals("ZCArticle"))
                || (type.equals("ZCAttachment"))
                || (type.equals("ZCImage"))
                || (type.equals("ZCAudio"))
                || (type.equals("ZCVideo"))))
            && (this.TableRelas[i].RelaField.equals("ID"))) {
          type = "Document";
        }

        String id =
            getIDMapping(
                type + "." + this.TableRelas[i].RelaField,
                dr.getString(this.TableRelas[i].KeyField));
        if (StringUtil.isNotEmpty(id)) dr.set(this.TableRelas[i].KeyField, id);
      }
  }
Example #4
0
  public void dealZCSite(DataRow dr) {
    if (this.isNewSite) {
      if ((LicenseInfo.getName().equals("TrailUser"))
          && (new QueryBuilder("select count(*) from ZCSite").executeInt() >= 1)) {
        throw new RuntimeException("站点数超出限制,请联系泽元软件更换License!");
      }
      this.newSiteID = NoUtil.getMaxID("SiteID");
      ZCSiteSchema site = new ZCSiteSchema();
      site.setValue(dr);
      site.setID(this.newSiteID);
      site.setName(this.map.getString("Name"));
      site.setAlias(this.map.getString("Alias"));
      site.setURL(this.map.getString("URL"));
      site.setHitCount(0L);
      site.setChannelCount(0L);
      site.setSpecialCount(0L);
      site.setMagzineCount(0L);
      site.setArticleCount(0L);
      site.setImageLibCount(1L);
      site.setVideoLibCount(1L);
      site.setAudioLibCount(1L);
      site.setAttachmentLibCount(1L);
      site.setBranchInnerCode(User.getBranchInnerCode());
      site.setAddTime(new Date());
      site.setAddUser(User.getUserName());
      site.setConfigXML(ConfigImageLib.imageLibConfigDefault);
      this.da.insert(site);
      Transaction trans = new Transaction();
      Site.addDefaultPriv(this.newSiteID, trans);
      trans.setDataAccess(this.da);
      trans.commit(false);
      addIDMapping("ZCSite", String.valueOf(this.siteID), String.valueOf(this.newSiteID));
    } else {
      ZCSiteSchema site = new ZCSiteSchema();
      site.setID(this.map.getString("ID"));
      this.newSiteID = site.getID();
      site.fill();

      this.task.setCurrentInfo("正在备份数据,可能需要较长时间,请耐心等待");

      SiteExporter se = new SiteExporter(site.getID());
      se.exportSite(
          Config.getContextRealPath()
              + "WEB-INF/data/backup/"
              + site.getAlias()
              + "_"
              + System.currentTimeMillis()
              + ".dat");

      addIDMapping("ZCSite", dr.getString("ID"), String.valueOf(site.getID()));
      this.da.deleteAndBackup(site);
      BlockingTransaction tran = new BlockingTransaction(this.da);
      Site.delSiteRela(site.getID(), tran);

      String sitePath =
          Config.getContextRealPath()
              + Config.getValue("Statical.TemplateDir")
              + "/"
              + site.getAlias();
      FileUtil.delete(sitePath);

      site = new ZCSiteSchema();
      site.setValue(dr);

      this.da.insert(site);
    }
  }
Example #5
0
 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));
   }
 }