コード例 #1
0
  public void createMapping(
      PageContext pc, Component cfc, DatasourceConnection dc, ORMConfiguration ormConf)
      throws PageException {
    ComponentPro cfcp = ComponentUtil.toComponentPro(cfc);
    String id = id(HibernateCaster.getEntityName(cfcp));
    CFCInfo info = cfcs.get(id);
    // Long modified=cfcs.get(id);
    String xml;
    long cfcCompTime = ComponentUtil.getCompileTime(pc, cfcp.getPageSource());
    if (info == null
        || (ORMUtil.equals(info.getCFC(), cfcp))) { // && info.getModified()!=cfcCompTime
      StringBuilder sb = new StringBuilder();

      long xmlLastMod = loadMapping(sb, ormConf, cfcp);
      Element root;
      // create maaping
      if (true || xmlLastMod < cfcCompTime) { // MUSTMUST
        configuration = null;
        Document doc = null;
        try {
          doc = XMLUtil.newDocument();
        } catch (Throwable t) {
          t.printStackTrace();
        }

        root = doc.createElement("hibernate-mapping");
        doc.appendChild(root);
        pc.addPageSource(cfcp.getPageSource(), true);
        try {
          HBMCreator.createXMLMapping(pc, dc, cfcp, ormConf, root, this);
        } finally {
          pc.removeLastPageSource(true);
        }
        xml = XMLCaster.toString(root.getChildNodes(), true);
        saveMapping(ormConf, cfcp, root);
      }
      // load
      else {
        xml = sb.toString();
        root = Caster.toXML(xml).getOwnerDocument().getDocumentElement();
        /*print.o("1+++++++++++++++++++++++++++++++++++++++++");
        print.o(xml);
        print.o("2+++++++++++++++++++++++++++++++++++++++++");
        print.o(root);
        print.o("3+++++++++++++++++++++++++++++++++++++++++");*/

      }
      cfcs.put(id, new CFCInfo(ComponentUtil.getCompileTime(pc, cfcp.getPageSource()), xml, cfcp));
    }
  }