Esempio n. 1
0
  public Component getEntityByCFCName(String cfcName, boolean unique) throws PageException {
    String name = cfcName;
    int pointIndex = cfcName.lastIndexOf('.');
    if (pointIndex != -1) {
      name = cfcName.substring(pointIndex + 1);
    } else cfcName = null;

    ComponentPro cfc;
    String[] names = null;
    // search array (array exist when cfcs is in generation)

    if (arr != null) {
      names = new String[arr.size()];
      int index = 0;
      Iterator<ComponentPro> it2 = arr.iterator();
      while (it2.hasNext()) {
        cfc = it2.next();
        names[index++] = cfc.getName();
        if (isEntity(cfc, cfcName, name)) // if(cfc.equalTo(name))
        return unique ? (Component) cfc.duplicate(false) : cfc;
      }
    } else {
      // search cfcs
      Iterator<Entry<String, CFCInfo>> it = cfcs.entrySet().iterator();
      Entry<String, CFCInfo> entry;
      while (it.hasNext()) {
        entry = it.next();
        cfc = entry.getValue().getCFC();
        if (isEntity(cfc, cfcName, name)) // if(cfc.instanceOf(name))
        return unique ? (Component) cfc.duplicate(false) : cfc;

        // if(name.equalsIgnoreCase(HibernateCaster.getEntityName(cfc)))
        //	return cfc;
      }
      names = cfcs.keySet().toArray(new String[cfcs.size()]);
    }

    // search by entityname //TODO is this ok?
    CFCInfo info = cfcs.get(name.toLowerCase());
    if (info != null) {
      cfc = info.getCFC();
      return unique ? (Component) cfc.duplicate(false) : cfc;
    }

    throw new ORMException(
        this,
        "entity ["
            + name
            + "] "
            + (StringUtil.isEmpty(cfcName) ? "" : "with cfc name [" + cfcName + "] ")
            + "does not exist, existing  entities are ["
            + railo.runtime.type.List.arrayToList(names, ", ")
            + "]");
  }
Esempio n. 2
0
 private ComponentPro _create(PageContext pc, String entityName, boolean unique)
     throws PageException {
   CFCInfo info = cfcs.get(id(entityName));
   if (info != null) {
     ComponentPro cfc = info.getCFC();
     if (unique) {
       cfc = (ComponentPro) cfc.duplicate(false);
       if (cfc.contains(pc, INIT)) cfc.call(pc, "init", new Object[] {});
     }
     return cfc;
   }
   return null;
 }
Esempio n. 3
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));
    }
  }
Esempio n. 4
0
  public Component getEntityByEntityName(String entityName, boolean unique) throws PageException {
    ComponentPro cfc;

    CFCInfo info = cfcs.get(entityName.toLowerCase());
    if (info != null) {
      cfc = info.getCFC();
      return unique ? (Component) cfc.duplicate(false) : cfc;
    }

    if (arr != null) {
      Iterator<ComponentPro> it2 = arr.iterator();
      while (it2.hasNext()) {
        cfc = it2.next();
        if (HibernateCaster.getEntityName(cfc).equalsIgnoreCase(entityName))
          return unique ? (Component) cfc.duplicate(false) : cfc;
      }
    }

    throw new ORMException(this, "entity [" + entityName + "] does not exist");
  }