Package org.objectweb.speedo.api

Examples of org.objectweb.speedo.api.SpeedoException


                ptype = getPrimitivePType(ufm.getStorageType().getName());
                if (ptype == null) {
                    className = ufm.getStorageType().getName();
                }
            } catch (Exception e) {
                throw new SpeedoException(
                        "Impossible to instanciate the UserFieldMapping class '"
                        + se.value + "' for the field '" + sp.name
                        + "' of the class '" + sc.getFQName() + "':", e);
            }
        } else {
View Full Code Here


              }
                // reference to a class
                SpeedoClass tsc = sc.moPackage.xmlDescriptor
                        .getSpeedoClass(javatype, true);
                if (tsc == null) {
                    throw new SpeedoException("No persistent class '"
                            + javatype + "' found in the file: "
                            + sc.moPackage.xmlDescriptor.xmlFile);
                }
                Class tclass = manager.getClass(tsc.getFQName());
                if (tclass == null) {
                    manager.createClass(tsc.getFQName());
                }
                ClassRef cr = clazz.createClassRef(sp.name, tclass);
                NameDef refNd = cr.createRefNameDef();
                nmf.getNamingManager(tsc)
                  .defineClassReferenceNameDef(refNd, cr, sp, sc, cm, this, mb);
                if ( cm != null) {
                    cm.createReferenceMapping(sp.name, refNd);
                    cm.addDependency(tsc.getFQName());
                }

            } else {
                //                reference to a generic class                //
                //============================================================//
                String innerType = getInnerType(sp);
                if (innerType == null) {
                    throw new SpeedoException("The inner element type is " +
                            "required for the multivalued field '" + sp.name
                            + "' of the class '" + sc.getFQName()
                            + "' in the .jdo file '"
                            + sc.moPackage.xmlDescriptor.xmlFile + "'");
                }
                PType type = getPrimitivePType(innerType);
              if (type == null && !isPersistentClass(innerType, sc.moPackage.name, manager)) {
                logger.log(BasicLevel.INFO, "The field '" + sc.getFQName()
                        + "." + sp.name + " is managed as a Serialized field.");
                type = PTypeSpace.SERIALIZED;
              }
              if (debug) {
          logger.log(BasicLevel.DEBUG, "GenClass reference field: "
              + sp.name + " / javatype: " + javatype
              + " / innerType: " + innerType
            + " / ptype=" + (type == null ? null : type.getJavaName()));
              }
                GenClassRef gcr = clazz.createGenClassRef(sp.name, javatype);
                GenClassMapping gcm = null;
                ClassRef cr = null;
                SpeedoClass tsc = null;

                //element of the gen class
                if (type != null) {
                    // gen class of primitive type
                    gcr.createPrimitiveElement(type, PType.NOSIZE, PType.NOSIZE);
                } else if (!isGenClassRef(innerType)) {
                    // gen class of classref
                    tsc = sc.moPackage.xmlDescriptor.smi
                            .getSpeedoClass(innerType, sc.moPackage);
                    if (tsc == null) {
                        throw new SpeedoException("The persistent class '"
                                + sc.getFQName()
                                + "' tries to reference (througth the field '"
                                + sp.name
                                + "') the class '" + innerType
                                + "' not defined in the .jdo file '"
                                + sc.moPackage.xmlDescriptor.xmlFile + "'");
                    }
                    Class tclass = manager.getClass(tsc.getFQName());
                    if (tclass == null) {
                        throw new SpeedoException("The inner element class '"
                            + tsc.getFQName() + "' of the multivalued field '"
                            + sp.name + "' of the class '" + sc.getFQName()
                            + "' in the .jdo file '"
                            + sc.moPackage.xmlDescriptor.xmlFile
                                + "' has not been found among the persitent classes : "
                            + manager.getClasses());
                    }
                    cr = gcr.createClassRef(tclass);
                } else {
                    throw new SpeedoException(
                            "unmanaged the inner-element of the field '"
                            + sp.name + "' of the class '" + sc.getFQName()
                            + "' : " + innerType);
                }
                //Map the element of the generic class
                if (mapping != null) {
                    gcm = mb.createGenClassMapping(gcr, sp, mapping);
                    if (gcr.isPrimitive()) {
                        mb.createGenClassElementMapping(gcr.getPrimitiveElement(), sp, gcm);
                    } else {
                        NameDef elemNd = cr.createRefNameDef();
                        nmf.getNamingManager(tsc).defineClassReferenceNameDef(elemNd, cr, sp, sc, gcm, this, mb);
                        //fillNameDef(elemNd, tsc, sc, gcr, gcr, gcm, mb, false, true, true, createdMOs);
                        gcm.createReferenceMapping(sp.name, elemNd);
                        cm.addDependency(tsc.getFQName());
                    }
                }

                // reference to a generic class from the class
                NameDef refNd = gcr.createRefNameDef();
                nmf.getNamingManager(sc).defineGenClassReferenceNameDef(refNd, gcr, sp, sc, cm, this, mb);
                //fillNameDef(refNd, sc, sc, clazz, gcr, cm, mb, false, false, false, createdMOs);
                if (cm != null) {
                    cm.createReferenceMapping(sp.name, refNd);
                }

                //identifier of the gen class
                NameDef gcidNd = gcr.createIdNameDef();
                nmf.getNamingManager(sc).defineGenClassIdentifierNameDef(
                        gcidNd, gcr, sp, sc, gcm, this, mb);
                //fillNameDef(gcidNd, sc, sc, gcr, gcr, gcm, mb, true, true, true, createdMOs);
                if (gcm != null) {
                    gcm.createIdentifierMapping(gcidNd);
                }

                //index of the gen class
                java.lang.Class gcClass;
                try {
                    gcClass = java.lang.Class.forName(javatype);
                } catch (ClassNotFoundException e) {
                    throw new SpeedoException(
                            "The multivalued field '" + sp.name
                            + "' of the class '" + sc.getFQName()
                            + "' is not a well known class " + javatype, e);
                }
                if (isSubType(gcClass, java.util.List.class)) {
View Full Code Here

                if (se instanceof SpeedoField) {
                    filter = ((SpeedoField) se).name;
                } else if (se instanceof SpeedoNoFieldColumn) {
                    filter = HIDDEN_FIELD_CLASS_NAME;
                } else {
                    throw new SpeedoException("Unmanaged filter element: " + se);
                }
        } else {
            throw new SpeedoException(
                    "Composite inheritance discriminator not yet supported in Speedo");
        }
        if (filter != null) {
            sc.jormclass.setInheritanceFilter(nd, filter);
            logger.log(BasicLevel.DEBUG, "Assign filter: " + filter);
        }
            if (sc.inheritance.discriminator.elements != null
                    && sc.inheritance.discriminator.elements.size() == 1) {
                SpeedoElement se = (SpeedoElement) sc.inheritance.discriminator.elements.get(0);
                if (se instanceof SpeedoNoFieldColumn) {
                    if (sc.getSuper() == null) {
                        // The discriminator is a column not mapped to a
                        // persistent field. then we have to create a constant
                        // hidden field.
                        PrimitiveElement pe = sc.jormclass.createHiddenField(
                            HIDDEN_FIELD_CLASS_NAME, PTypeSpace.STRING, PType.NOSIZE, PType.NOSIZE);
                        pe.setStatus(PrimitiveElement.CONSTANT_PERSISTENT);
                        mb.createFieldMapping(pe, (SpeedoNoFieldColumn) se, cm);
                    }
                    if (sc.inheritance.discriminator.strategy ==
                                SpeedoDiscriminator.STRATEGY_CLASS_NAME
                                && sc.inheritance.discriminatorValues != null) {
                        // declare the constant value of the field
                        sc.jormclass.setConstantValue(HIDDEN_FIELD_CLASS_NAME,
                                (String) sc.inheritance.discriminatorValues.get(se));
                    }
                }
            }
    }
    if (sc.inheritance != null && sc.inheritance.discriminatorValues != null) {
        Object key = sc.inheritance.discriminatorValues.values().iterator().next();
          logger.log(BasicLevel.DEBUG, "Assign key: " + key);
      sc.jormclass.setInheritanceNamingKey(nd, key);
    }

    if (sc.getSuperClassName() == null) {
      return;
    }
    SpeedoClass parent = sc.getSpeedoClassFromContext(sc.getSuperClassName());
    String im = sc.getExtensionValueByKey(SpeedoProperties.INHERITANCE_MAPPING);

    // Map the inherited field if required
    if (sc.inheritance.isHorizontalMapping()) {
        for (Iterator it = sc.inheritance.remappedInheritedFields.values().iterator(); it.hasNext();) {
                SpeedoInheritedField sif = (SpeedoInheritedField) it.next();
        if (debug) {
          logger.log(BasicLevel.DEBUG, "Map the inherited field '"
            + sif.name + "'.");
        }
                TypedElement te = sif.inheritedField.moClass.jormclass.getTypedElement(sif.inheritedField.name);
                if (te == null) {
                    throw new SpeedoException("No inherited field '"
                            + sif.name + "' found from "
                            + sc.getSourceDesc());
                } else if (te instanceof PrimitiveElement) {
          mb.createFieldMapping((PrimitiveElement) te, sif, cm);
                } else if (te instanceof ClassRef) {
View Full Code Here

    }

    private PType getMapKeyPType(SpeedoField sf) throws SpeedoException {
        SpeedoMap sm = (SpeedoMap) sf.jdoTuple;
        if (sm.keyType == null) {
            throw new SpeedoException(
                "It is required to define a key-type for the Map field'"
                + sf.name + "' of the class '" + sf.moClass.getFQName() +"' ");
        }
        PType res = getPrimitivePType((String) sm.keyType);
      boolean isPersistClass = isPersistentClass(
          (String) sm.keyType, sf.moClass.moPackage.name, manager);
      if (res == null && !isPersistClass) {
        logger.log(BasicLevel.INFO, "The field '" + sf.moClass.getFQName()
                + "." + sf.name + " is managed as a Serialized field.");
        res = PTypeSpace.SERIALIZED;
      }
        if (res == null) {
            throw new SpeedoException("The key-type '" + sm.keyType
                    + "' of the Map field'" + sf.name + "' of the class '"
                    + sf.moClass.getFQName() +"' is not supported");
        }
        return res;
    }
View Full Code Here

        if (mo instanceof Class) {
            sf = ((Class) mo).createHiddenField(fn, type, size, scale);
        } else if (mo instanceof GenClassRef) {
            sf = ((GenClassRef) mo).createHiddenField(fn, type, size, scale);
        } else {
            throw new SpeedoException(
                    "Impossible to create hidden field on this meta object: " + mo);
        }
        return sf;
    }
View Full Code Here

        }
        try {
            //visit the tree
            visit(speedoql);
        } catch (Exception e) {
            throw new SpeedoException("Error during the parsing of JDOQL:", e);
        }
        if (orders != null) {
            for(int i=0; i<orders.size(); i++) {
                String fieldName = (String) orders.get(i);
                int idx = fieldName.indexOf(' ');
View Full Code Here

   
    private void treatIdValue(IdValue iv, List toTreat) throws SpeedoException {
        if (iv.nameType != EXTENT) {
            IdValue dependency = (IdValue) ids.get(iv.name[0]);
            if (dependency == null) {
                throw new SpeedoException("Dependency unresolved: " + iv.name[0]);
            }
            if (toTreat.contains(dependency)) {
                treatIdValue(dependency, toTreat);
            }
        }
        toTreat.remove(iv);

        QueryBuilder theqb = qb;
        if (iv.nameType == MEMBEROF) {
            //a.b.cs.contains(x)  ==> a.b.PNAME IN cs.id
            String rest = mergePath(iv.name, 1, iv.name.length - 1);
            theqb = new QueryBuilder(qb);
            try {
                theqb.define("", qb.navigate(iv.name[0]));
            } catch (MedorException e) {
                throw new SpeedoException(e);
            }
        }

        try {
            String n = iv.alias + "." + Field.PNAMENAME;
            fields.put(n, theqb.project(iv.alias, define(theqb, iv.alias, iv.alias)));
            for (int i = 0; i < iv.getDeclaredPathLength(); i++) {
                String path = iv.getMergedPath(i);
                if (!testcontains.contains(path) && !isEmptys.contains(path)) {
                    fields.put(path, theqb.project(path, define(theqb, path, null)));
                }
          }
        } catch (Exception e) {
            throw new SpeedoException("Error during the parsing of JDOQL:", e);
        }
    }
View Full Code Here

        QueryTreeField qtf = (QueryTreeField) fields.get(path);
        if (qtf == null) {
            try {
                qtf = qb.project(define(qb, path, null));
            } catch (Exception e) {
                throw new SpeedoException(e);
            }
            fields.put(path, qtf);
        }
        return qtf;
    }
View Full Code Here

          //use a kfpnc
          sb.append(NamingRules.kfpncName(ancestor.getFQName()));
        }
      } catch (Exception e) {
        logger.log(BasicLevel.ERROR, "Error while retrieving the inheritance filter of the namedef:" + nd.toString());
        throw new SpeedoException("Error while retrieving the inheritance filter of the namedef:" + nd.toString(), e);
      }
      className = ancestor.getFQName();
    }
    sb.append(HINTS_SEP);
    sb.append(className);
View Full Code Here

    }

    public void compile() throws SpeedoException, MedorException,
            ExpressionException {
        if (status == UNDEFINED)
            throw new SpeedoException(
                    "Impossible to compile an undefined query");
        if (status == COMPILED)
            return;
        long timeToCompile = System.currentTimeMillis();
        boolean debug = logger.isLoggable(BasicLevel.DEBUG);
        // create a speedoQL object with a filter string
        String query = qd.query;

        // create representations of the parameters list and the variable list
        /*
        toHashtableParams(qd.parameters, ";,");
        toHashtableVars(qd.variables, ";,");
        */
        Manager miManager = mapper.getMetaInfoManager();
        if (miManager == null)
            throw new SpeedoException(
                    "A non null Meta information manager is needed");
        SimpleNode node = null;
        try {
            node = new EJBQL(new CharArrayReader(query.toCharArray()))
                    .EJBQL();
        } catch (ParseException e) {
            throw new SpeedoException(
                    "Impossible to parse the query and to create AST", e);
        }
       
        EJBQLVariableVisitor eqvv = new EJBQLVariableVisitor(node);
        Map fields = eqvv.getFields();
View Full Code Here

TOP

Related Classes of org.objectweb.speedo.api.SpeedoException

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.