Package railo.runtime.type

Examples of railo.runtime.type.Struct


      Array types=CommonUtil.createArray();
      String name;
      //ColumnInfo ci;
      int t;
      Object obj;
      Struct sct;
      String fieldType;
      for(int i=0;i<properties.length;i++){
        obj = properties[i].getMetaData();
        if(obj instanceof Struct) {
          sct=(Struct) obj;
          fieldType = CommonUtil.toString(sct.get(CommonUtil.FIELDTYPE,null),null);
          if("one-to-many".equalsIgnoreCase(fieldType) || "many-to-many".equalsIgnoreCase(fieldType) || "many-to-one".equalsIgnoreCase(fieldType) || "one-to-one".equalsIgnoreCase(fieldType))
            continue;
         
        }
       
View Full Code Here


  private static final Collection.Key TYPE = CommonUtil.createKey("type");
  
  public static void createXMLMapping(PageContext pc,DatasourceConnection dc, Component cfc,Element hibernateMapping,SessionFactoryData data) throws PageException {
   
    // MUST Support for embeded objects
    Struct meta = cfc.getMetaData(pc);
   
    String extend = cfc.getExtends();
    boolean isClass=Util.isEmpty(extend);

    // MZ: Fetches all inherited persistent properties
    //Property[] _props=getAllPersistentProperties(pc,cfc,dc,meta,isClass);

    Property[] _props=getProperties(pc,cfc,dc,meta,isClass, true,data);

   

    Map<String, PropertyCollection> joins=new HashMap<String, PropertyCollection>();
    PropertyCollection propColl = splitJoins(cfc,joins, _props,data);
   
   
   
    // create class element and attach
    Document doc = CommonUtil.getDocument(hibernateMapping);
   
    StringBuilder comment=new StringBuilder();
    comment.append("\nsource:").append(cfc.getPageSource().getDisplayPath());
    comment.append("\ncompilation-time:").append(CommonUtil.createDateTime(HibernateUtil.getCompileTime(pc,cfc.getPageSource()))).append("\n");
   
    hibernateMapping.appendChild(doc.createComment(comment.toString()));
   
    //print.e(cfc.getAbsName()+";"+isClass+" -> "+cfci.getBaseAbsName()+":"+cfci.isBasePeristent());
    if(!isClass && !cfc.isBasePeristent()) {
      isClass=true;
    }
   
   
    Element join=null;
    boolean doTable=true;
   
    Element clazz;
    if(isClass)  {
      clazz = doc.createElement("class");
      hibernateMapping.appendChild(clazz);
    }
    // extended CFC
    else{
      // MZ: Fetches one level deep
      _props=getProperties(pc,cfc,dc,meta,isClass, false,data);
      // MZ: Reinitiate the property collection
      propColl = splitJoins(cfc,joins, _props,data);

      String ext = CommonUtil.last(extend,'.').trim();
      try {
        Component base = data.getEntityByCFCName(ext, false);
        ext = HibernateCaster.getEntityName(base);
      }
      catch(Throwable t){}
     
     
      String discriminatorValue = toString(cfc,null,meta,"discriminatorValue",data);
      if(!Util.isEmpty(discriminatorValue,true)) {
        doTable=false;
        clazz = doc.createElement("subclass");
        hibernateMapping.appendChild(clazz);
            //addClassAttributes(classNode);
            clazz.setAttribute("extends", ext);
            clazz.setAttribute("discriminator-value", discriminatorValue);
           
            String joincolumn = toString(cfc,null,meta,"joincolumn",false,data);
            if(!Util.isEmpty(joincolumn)){
              join = doc.createElement("join");
              clazz.appendChild(join);
              doTable=true;
              Element key = doc.createElement("key");
              join.appendChild(key);
              key.setAttribute("column", formatColumn(joincolumn,data));
            }
           
      }
      else {
        // MZ: Match on joinColumn for a joined subclass, otherwise use a union subclass
        String joinColumn = toString(cfc,null,meta,"joincolumn",false,data);
        if (!Util.isEmpty(joinColumn,true)) {
          clazz = doc.createElement("joined-subclass");
          hibernateMapping.appendChildclazz);
          clazz.setAttribute("extends",ext);
          Element key = doc.createElement("key");
          clazz.appendChild(key);
          key.setAttribute("column", formatColumn(joinColumn,data));
        }
        else {
          // MZ: When no joinColumn exists, default to an explicit table per class
          clazz = doc.createElement("union-subclass");
          clazz.setAttribute("extends",ext);
          doTable = true;
          hibernateMapping.appendChildclazz);
        }

      }
    }

    //createXMLMappingTuplizer(clazz,pc);

    addGeneralClassAttributes(pc,cfc,meta,clazz,data);
    String tableName=getTableName(pc,meta,cfc,data);
   
    if(join!=null) clazz=join;
    if(doTable)addGeneralTableAttributes(pc,cfc,meta,clazz,data);
   
   
       
       
        Struct columnsInfo=null;
        if(data.getORMConfiguration().useDBForMapping()){
          columnsInfo = data.getTableInfo(dc,getTableName(pc, meta, cfc,data));
        }

        if(isClass)setCacheStrategy(cfc,null,doc, meta, clazz,data);
View Full Code Here

          throw ExceptionUtil.createException(data,cfc,"missing id property for entity ["+HibernateCaster.getEntityName(cfc)+"]",null);
  }
 

  private static PropertyCollection splitJoins(Component cfc,Map<String, PropertyCollection> joins,Property[] props,SessionFactoryData data) {
    Struct sct=CommonUtil.createStruct();
    ArrayList<Property> others = new ArrayList<Property>();
    java.util.List<Property> list;
    String table;
    Property prop;
    String fieldType;
    boolean isJoin;
    for(int i=0;i<props.length;i++){
      prop=props[i];
      table=getTable(cfc,prop,data);
      // joins
      if(!Util.isEmpty(table,true)){
        isJoin=true;
        // wrong field type
        try {
          fieldType = toString(cfc, prop, sct, FIELDTYPE,false,data);
         
          if("collection".equalsIgnoreCase(fieldType)) isJoin=false;
          else if("primary".equals(fieldType)) isJoin=false;
          else if("version".equals(fieldType)) isJoin=false;
          else if("timestamp".equals(fieldType)) isJoin=false;
        }
        catch (PageException e) {}
       
        // missing column
        String columns=null;
        try {
          if(ORMUtil.isRelated(props[i])){
                columns=toString(cfc,props[i], prop.getDynamicAttributes(), "fkcolumn",data);
              }
              else {
                columns=toString(cfc,props[i], prop.getDynamicAttributes(), "joincolumn",data);
              }
        }
        catch(PageException e){}
        if(Util.isEmpty(columns)) isJoin=false;
       
        if(isJoin){
          table=table.trim();
          list = (java.util.List<Property>) sct.get(table,null);
          if(list==null){
            list=new ArrayList<Property>();
            sct.setEL(CommonUtil.createKey(table), list);
          }
          list.add(prop);
          continue;
        }
      }
      others.add(prop);
    }
   
    // fill to joins
    Iterator<Entry<Key, Object>> it = sct.entryIterator();
    Entry<Key, Object> e;
    while(it.hasNext()){
      e = it.next();
      list=(java.util.List<Property>) e.getValue();
      joins.put(e.getKey().getString(), new PropertyCollection(e.getKey().getString(),list));
View Full Code Here




  private static void createXMLMappingCompositeId(Component cfc,Element clazz, Property[] props,Struct columnsInfo,String tableName, SessionFactoryData data) throws PageException {
    Struct meta;
   
    Document doc = CommonUtil.getDocument(clazz);
    Element cid = doc.createElement("composite-id");
    clazz.appendChild(cid);
   
View Full Code Here

    }
  }
 
 
  private static void createXMLMappingId(Component cfc,Element clazz, Property prop,Struct columnsInfo,String tableName,SessionFactoryData data) throws PageException {
    Struct meta = prop.getDynamicAttributes();
    String str;
   
    Document doc = CommonUtil.getDocument(clazz);
    Element id = doc.createElement("id");
    clazz.appendChild(id);
View Full Code Here

          if(cfc!=null){
            Property[] ids = getIds(cfc,cfc.getProperties(true),null,true,data);
            if(ids!=null && ids.length>0){
              Property id = ids[0];
              id.getDynamicAttributes();
              Struct meta = id.getDynamicAttributes();
              if(meta!=null){
                String type=CommonUtil.toString(meta.get(TYPE,null));
               
                if(!Util.isEmpty(type) && (!type.equalsIgnoreCase("any") && !type.equalsIgnoreCase("object"))){
                  return type;
                }
               
                  String g=CommonUtil.toString(meta.get(GENERATOR,null));
                  if(!Util.isEmpty(g)){
                    return getDefaultTypeForGenerator(g,foreignCFC,data);
                  }
               
              }
View Full Code Here

      }
    return null;
  }*/

  private static String createXMLMappingGenerator(Element id,Component cfc,Property prop,StringBuilder foreignCFC, SessionFactoryData data) throws PageException {
    Struct meta = prop.getDynamicAttributes();
   
    // generator
    String className=toString(cfc,prop,meta,"generator",data);
    if(Util.isEmpty(className,true)) return null;
   

    Document doc = CommonUtil.getDocument(id);
    Element generator = doc.createElement("generator");
    id.appendChild(generator);
   
    generator.setAttribute("class", className);
   
    //print.e("generator:"+className);
   
    // params
    Object obj=meta.get(PARAMS,null);
    //if(obj!=null){
      Struct sct=null;
      if(obj==null) obj=CommonUtil.createStruct();
      else if(obj instanceof String) obj=ORMUtil.convertToSimpleMap((String)obj);
     
      if(CommonUtil.isStruct(obj)) sct=CommonUtil.toStruct(obj);
      else throw ExceptionUtil.createException(data,cfc,"invalid value for attribute [params] of tag [property]",null);
      className=className.trim().toLowerCase();
     
      // special classes
      if("foreign".equals(className)){
        if(!sct.containsKey(PROPERTY)) sct.setEL(PROPERTY, toString(cfc,prop,meta, PROPERTY,true,data));
       
        if(sct.containsKey(PROPERTY)){
          String p = CommonUtil.toString(sct.get(PROPERTY),null);
          if(!Util.isEmpty(p))foreignCFC.append(p);
        }
       
       
      }
      else if("select".equals(className)){
        //print.e("select:"+toString(meta, "selectKey",true));
        if(!sct.containsKey(KEY)) sct.setEL(KEY, toString(cfc,prop,meta, "selectKey",true,data));
      }
      else if("sequence".equals(className)){
        if(!sct.containsKey(SEQUENCE)) sct.setEL(SEQUENCE, toString(cfc,prop,meta, "sequence",true,data));
      }
     
      //Key[] keys = sct.keys();
      Iterator<Entry<Key, Object>> it = sct.entryIterator();
      Entry<Key, Object> e;
      Element param;
      while(it.hasNext()){
        e = it.next();
        param = doc.createElement("param");
View Full Code Here

 

 

  private static void createXMLMappingProperty(Element clazz, PageContext pc,Component cfc,Property prop,Struct columnsInfo,String tableName,SessionFactoryData data) throws PageException {
    Struct meta = prop.getDynamicAttributes();
   
       
   
    // get table name
    String columnName=toString(cfc,prop,meta,"column",data);
      if(Util.isEmpty(columnName,true)) columnName=prop.getName();
     
      ColumnInfo info=getColumnInfo(columnsInfo,tableName,columnName,null);
   
    Document doc = CommonUtil.getDocument(clazz);
    final Element property = doc.createElement("property");
    clazz.appendChild(property);
   
    //name
    property.setAttribute("name",prop.getName());
   
    // type
    String str = getType(info, cfc,prop, meta, "string",data);
    property.setAttribute("type",str);
   
   
   
    // formula or column
    str=toString(cfc,prop,meta,"formula",data);
        Boolean b;
    if(!Util.isEmpty(str,true))  {
          property.setAttribute("formula","("+str+")");
        }
        else {
          //property.setAttribute("column",columnName);
         
          Element column = doc.createElement("column");
          property.appendChild(column);
          column.setAttribute("name", escape(HibernateUtil.convertColumnName(data,columnName)));

            // check
            str=toString(cfc,prop,meta,"check",data);
            if(!Util.isEmpty(str,true)) column.setAttribute("check",str);
           
          // default
          str=toString(cfc,prop,meta,"dbDefault",data);
          if(!Util.isEmpty(str,true)) column.setAttribute("default",str);
           
            // index
            str=toString(cfc,prop,meta,"index",data);
            if(!Util.isEmpty(str,true)) column.setAttribute("index",str);
         
          // length
            Integer i = toInteger(cfc,meta,"length",data);
            if(i!=null && i>0) column.setAttribute("length",CommonUtil.toString(i.intValue()));
           
            // not-null
            b=toBoolean(cfc,meta,"notnull",data);
            if(b!=null && b.booleanValue())column.setAttribute("not-null","true");
           
            // precision
            i=toInteger(cfc,meta,"precision",data);
            if(i!=null && i>-1) column.setAttribute("precision",CommonUtil.toString(i.intValue()));
           
            // scale
            i=toInteger(cfc,meta,"scale",data);
            if(i!=null && i>-1) column.setAttribute("scale",CommonUtil.toString(i.intValue()));
           
            // sql-type
            str=toString(cfc,prop,meta,"sqltype",data);
            if(!Util.isEmpty(str,true)) column.setAttribute("sql-type",str);
           
        // unique
            b=toBoolean(cfc,meta,"unique",data);
          if(b!=null && b.booleanValue())column.setAttribute("unique","true");
         
          // unique-key
          str=toString(cfc,prop,meta,"uniqueKey",data);
          if(Util.isEmpty(str))str=CommonUtil.toString(meta.get(UNIQUE_KEY_NAME,null),null);
          if(!Util.isEmpty(str,true)) column.setAttribute("unique-key",str);
         
         
        }
       
View Full Code Here

  <cfproperty
    persistent="true|false"
   >
   * */
  private static void createXMLMappingOneToOne(Element clazz, PageContext pc,Component cfc,Property prop,SessionFactoryData data) throws PageException {
    Struct meta = prop.getDynamicAttributes();
   
    Boolean b;
   
    Document doc = CommonUtil.getDocument(clazz);
    Element x2o;
View Full Code Here




  private static void createXMLMappingCollection(Element clazz, PageContext pc,Component cfc,Property prop,SessionFactoryData data) throws PageException {
    Struct meta = prop.getDynamicAttributes();
    Document doc = CommonUtil.getDocument(clazz);
    Element el=null;
           
    // collection type
    String str=prop.getType();
View Full Code Here

TOP

Related Classes of railo.runtime.type.Struct

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.