Package org.objectweb.jorm.mapper.rdb.metainfo

Examples of org.objectweb.jorm.mapper.rdb.metainfo.RdbClassMultiMapping


    public ClassMapping createClassMapping(
            Class clazz,
            SpeedoClass sc,
            Mapping mapping) throws PException, SpeedoException {
        //build ClassMapping instance
        RdbClassMultiMapping rcm =
            new RdbClassMultiMapping("multi-table", clazz, mapping);
        mapping.setClassMapping(rcm);

        //Build JORM meta objects for the main table
        if (sc.mainTable != null) {
            if (debug) {
                logger.log(BasicLevel.DEBUG, "define main table '"
                        + sc.mainTable.name + "' of the class '"
                        + sc.getFQName() + "'.");
            }
            rcm.createRdbTable(sc.mainTable.name);
        }
        //Build JORM meta objects for the secondary (external) tables
        if (sc.joinToExtTables != null) {
            for (int i = 0; i < sc.joinToExtTables.length; i++) {
                RdbExternalTable extTable = rcm
                        .createRdbExternalTable(sc.joinToExtTables[i].extTable.name);
                RdbJoin join = extTable.createRdbJoin("_" + i);
                if (debug) {
                    logger.log(BasicLevel.DEBUG, "define external table '"
                            + sc.joinToExtTables[i].extTable.name
                            + "' for the class '" + sc.getFQName() + "'.");
                }
                for (Iterator it = sc.joinToExtTables[i].columns.iterator(); it
                        .hasNext();) {
                    SpeedoJoinColumn jc = (SpeedoJoinColumn) it.next();
                    join.addJoinColumnNames(jc.targetColumn,
                            jc.column.name);
                    if (debug) {
                        logger.log(BasicLevel.DEBUG,
                                "\tdefine join between columns '"
                                        + jc.column.name + "' and '"
                                        + jc.column.targetColumn + "'.");
                    }
                }
            }
        }

        //manage inheritance
        if (sc.inheritance != null && sc.inheritance.superClassName != null) {
            String ruleName = null;
            if (sc.inheritance.isFilteredMapping()) {
                ruleName = RdbClassMapping.MAP_NEW_FIELDS_TO_EXTENDED_STRUCTURES;
            } else if (sc.inheritance.isHorizontalMapping()) {
                ruleName = RdbClassMapping.REMAP_FIELDS_TO_NEW_STRUCTURES;
            } else if (sc.inheritance.isVerticalMapping()) {
                ruleName = RdbClassMapping.MAP_NEW_FIELDS_TO_ADDED_STRUCTURES;
                //TODO: link the main table to the one of the parent
            }
            SpeedoClass parent = sc.getSpeedoClassFromContext(sc
                    .getSuperClassName());
            rcm.createParentClassMapping(ruleName, sc.jormclass
                    .getSuperClass(parent.getFQName()));
            //Add inter dependencies between the parent and its child
            if (debug) {
                logger.log(BasicLevel.DEBUG, "Add dependencies between "
                        + parent.getFQName() + " and " + sc.getFQName());
            }
            rcm.addDependency(parent.getFQName());
            getClassMapping(mapping, parent.jormclass).addDependency(
                    sc.getFQName());
        }
        return rcm;
    }
View Full Code Here


    private PrimitiveElementMapping createFieldMapping(PrimitiveElement pe,
            SpeedoCommonField sf,
            ClassMapping cm) throws PException, SpeedoException {
        String colName;
        String colType;
        RdbClassMultiMapping rcm = (RdbClassMultiMapping) cm;
        RdbTable t;
        RdbJoin join = null;
        if (sf == null) {
            //auto compute column name
            colName = pe.getName();
            colType = null;
            //get the main table as default
            t = rcm.getMainRdbTable();
        } else {
            //find the column corresponding to the primitive field
            SpeedoColumn[] cols = sf.columns;
            if (cols == null || cols.length == 0) {
                throw new SpeedoException("No column defined for the "
                        + sf.getSourceDesc());
            }
            if (cols.length > 1) {
                throw new SpeedoException("More than one column for the "
                        + sf.getSourceDesc());
            }
            SpeedoColumn col = cols[0];
            colName = col.name;
            colType = col.sqlType;
            //Find the table (JORM Meta object)
            if (sf.join == null) {
                t = rcm.getMainRdbTable();
            } else {
                t = rcm.getRdbExternalTable(sf.join.extTable.name);
                int idx = sf.moClass.getJoinIndex(sf.join);
                if (idx != -1) {
                    join = ((RdbExternalTable) t).getRdbJoin("_" + idx);
                }
            }
View Full Code Here

     */
    public void createClassRefNameDefMapping(
            ClassMapping cm,
            NameDef nd,
            SpeedoCommonField sf) throws PException, SpeedoException {
        RdbClassMultiMapping rcm = (RdbClassMultiMapping) cm;
        SpeedoClass tclass = null;
        if (sf instanceof SpeedoField) {
            tclass = ((SpeedoField) sf).getReferencedClass();
        } else if (sf instanceof SpeedoInheritedField) {
            tclass = ((SpeedoInheritedField) sf).inheritedField.getReferencedClass();
        }
        RdbClassMultiMapping trcm = (RdbClassMultiMapping) tclass.jormclass
                .getClassProject(cm.getProjectName()).getMapping(
                        cm.getMapperName()).getClassMapping();
        NameDef tnd = (NameDef) trcm.getIdentifierMapping().getLinkedMO();
        Class jclass = sf.moClass.jormclass;
        if (sf.join == null) {
            createLocalClassRefNameDefMapping(rcm, jclass, sf, nd, tnd, tclass);
        } else {
            createExternalClassRefNameDefMapping(rcm, jclass, sf, nd, trcm, tnd, tclass);
        }
        //add the dependency
        trcm.addDependency(sf.moClass.getFQName());
    }
View Full Code Here

        if (nd.isFieldName()) {
            createPEMInGC(gcr.getHiddenField(nd.getFieldName()),
                    sf.columns[0], table, nd, null);
        } else {
            SpeedoClass tclass = sf.getReferencedClass();
            RdbClassMultiMapping trcm = getClassMapping(
                    (Mapping) gcm.getParent(), tclass.jormclass);
            NameDef tnd = (NameDef) trcm.getIdentifierMapping().getLinkedMO();
            Map tndproj = tnd.getNameRef().getProjection();
            Iterator it = nd.getNameRef().getProjection().entrySet()
                    .iterator();
            while (it.hasNext()) {
                Map.Entry me = (Map.Entry) it.next();
View Full Code Here

            PrimitiveElement pe = gcr.getHiddenField(nd.getFieldName());
            SpeedoJoinColumn col = (SpeedoJoinColumn) sf.join.columns.get(0);
            createPEMInGC(pe, col.column, table, nd, null);
        } else {
            //get the ClassMapping of class owning the generic class
            RdbClassMultiMapping rcmOwner = (RdbClassMultiMapping) sf.moClass.jormclass
                    .getClassProject(rgcm.getProjectName()).getMapping(
                            rgcm.getMapperName()).getClassMapping();
            //get the namedef identifier of the generic class owner
            NameDef ndIdOwner = (NameDef) rcmOwner.getIdentifierMapping()
                    .getLinkedMO();
            //:compute the prefix for genclass field(s) used as identifier
            String prefix = mibh.getNameDefFieldPrefix(gcr, true, true, sf);
            Map classNdProj = ndIdOwner.getNameRef().getProjection();
            Iterator it = nd.getNameRef().getProjection().entrySet().iterator();
View Full Code Here

                            );
                }
                break;
            case SpeedoField.ONE_MANY_BI_RELATION:
                reverseField = sf.getReverseField();
              RdbClassMultiMapping trcm = (RdbClassMultiMapping) getClassMapping(
                    mapping, targetClassJMO);
              if (sf.mappedByReversefield) {
                  RdbTable tTable;
                  SpeedoTable table;
                  if (reverseField.join != null) {
                      table = reverseField.join.extTable;
                      tTable = trcm.getRdbExternalTable(table.name);
                  } else {
                      table = reverseField.moClass.mainTable;
                      tTable = trcm.getRdbTable();
                  }
                  t = rgcm.createRdbTable(table.name);
                  tTable.setColocated(true);
                    t.setColocated(true);
                  tTable.setColocatedMaster(true);
                    t.setColocatedMaster(false);
                  trcm.addDependency(sf.moClass.getFQName());
                  if (sf.isCoherentReverseField) {
                      //optimisation: the reverse field assumes the coherence.
                      // Then there is no need to write the generic class.
                      t.setReadOnly(true);
                  }
              } else if (sf.join != null) {
                  t = rgcm.createRdbTable(sf.join.extTable.name);
              }
                if (t != null && logger.isLoggable(BasicLevel.DEBUG)) {
                    logger.log(BasicLevel.DEBUG, "One-Many relation,"
                            + " join table: " + t.getName()
                            + (t.isColocated()?", colocated":"")
                            + (t.isColocatedMaster()?", master":"")
                            + (t.isReadOnly()?", readonly":"")
                            );
                }
                break;
            default:
                //Create the RdbTable for the Generic class
                rgcm.createRdbTable(sf.join.extTable.name);
              //add the dependency
              trcm = (RdbClassMultiMapping) getClassMapping(mapping, targetClassJMO);
              trcm.addDependency(sf.moClass.getFQName());
              if (t != null && logger.isLoggable(BasicLevel.DEBUG)) {
                  logger.log(BasicLevel.DEBUG, "GCR field,"
                        + " join table: " + sf.join.extTable.name);
              }
                break;
View Full Code Here

            Mapping map,
            String fieldName) throws PException {
        SpeedoClass current = sc;
        RdbPrimitiveElementMapping pem = null;
        while(pem == null) {
          RdbClassMultiMapping trcm = getClassMapping(map, current.jormclass);
          pem = (RdbPrimitiveElementMapping)
            trcm.getPrimitiveElementMapping(fieldName, true);
            current = sc.getSuper();
        }
        if (pem == null) {
            throw new PException("No mapping found for the field '"
                    + fieldName + "' for the class '" + sc.getFQName()
View Full Code Here

TOP

Related Classes of org.objectweb.jorm.mapper.rdb.metainfo.RdbClassMultiMapping

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.