Package org.exolab.castor.jdo.engine.nature

Examples of org.exolab.castor.jdo.engine.nature.ClassDescriptorJDONature


        MapTo mapTo = new MapTo();

        LOG.debug("Constructor invoked");

        // Set DB table name
        new ClassDescriptorJDONature(this).setTableName("address");
        // Set corresponding Java class
        setJavaClass(Address.class);
        // Set access mode
        new ClassDescriptorJDONature(this).setAccessMode(AccessMode.Shared);
        // Set cache key
        new ClassDescriptorJDONature(this).addCacheParam("name", "org.castor.cpa.functional.onetoone.Address");

        // Configure class mapping
        mapping.setAccess(ClassMappingAccessType.SHARED);
        mapping.setAutoComplete(true);
        mapping.setName("org.castor.cpa.functional.onetoone.Address");
View Full Code Here


        JPAClassNature nature = new JPAClassNature(classInfo);

        ClassDescriptorImpl descriptor = new ClassDescriptorImpl();
        descriptor.addNature(ClassDescriptorJDONature.class.getName());
        ClassDescriptorJDONature jdoNature = new ClassDescriptorJDONature(
                descriptor);

        /*
         * set classDescriptor infos
         */

        /*
         * working
         */
        descriptor.setJavaClass(classInfo.getDescribedClass());
        descriptor.setExtends(null);
        Class<?> extendedClass = classInfo.getExtendedClass();

        if (extendedClass != null && extendedClass != Object.class) {
            ClassDescriptor extendedClassDescriptor = command
                    .resolve(extendedClass);
            if (extendedClassDescriptor == null) {
                throw new MappingException("mapping.extendsMissing", classInfo
                        .getDescribedClass(), extendedClass);
            }
            descriptor.setExtends(extendedClassDescriptor);
            if (extendedClassDescriptor
                    .hasNature(ClassDescriptorJDONature.class.getName())) {
                new ClassDescriptorJDONature(extendedClassDescriptor)
                        .addExtended(descriptor);
            }
        }

        /*
         * interm setters of not working features
         */
        descriptor.setDepends(null);
        descriptor.setMapping(null);

        /*
         * set ClassDescriptorJDONature infos
         */

        /*
         * working
         */
        /*
         * interm setters of not working features
         */
        jdoNature.setTableName(null);
        jdoNature.setAccessMode(null);
        jdoNature.setKeyGeneratorDescriptor(null);

        /*
         * generate and set FieldDescriptors for fields
         */
        FieldDescriptor[] fields = new FieldDescriptor[classInfo
View Full Code Here

    public SQLStatementLoad(final SQLEngine engine, final PersistenceFactory factory)
    throws MappingException {
        _engine = engine;
        _factory = factory;
        _type = engine.getDescriptor().getJavaClass().getName();
        _mapTo = new ClassDescriptorJDONature(engine.getDescriptor()).getTableName();

        // obtain the number of ClassDescriptor that extend this one.
        _numberOfExtendLevels = SQLHelper.numberOfExtendingClassDescriptors(engine.getDescriptor());
        _extendingClassDescriptors =
            new ClassDescriptorJDONature(engine.getDescriptor()).getExtended();

        buildStatement();
    }
View Full Code Here

            while (curDesc.getExtends() != null) {
                baseDesc = curDesc.getExtends();
                String[] curDescIdNames = SQLHelper.getIdentitySQLNames(curDesc);
                String[] baseDescIdNames = SQLHelper.getIdentitySQLNames(baseDesc);
                expr.addInnerJoin(
                        new ClassDescriptorJDONature(curDesc).getTableName(), curDescIdNames,
                        new ClassDescriptorJDONature(baseDesc).getTableName(), baseDescIdNames);
                joinTables.add(new ClassDescriptorJDONature(baseDesc).getTableName());
                curDesc = baseDesc;
            }
           
            SQLColumnInfo[] ids = _engine.getColumnInfoForIdentities();
            SQLFieldInfo[] fields = _engine.getInfo();

            // join all the related/depended table
            String aliasOld = null;
            String alias = null;
           
            for (int i = 0; i < fields.length; i++) {
                SQLFieldInfo field = fields[i];
               
                if (i > 0) { aliasOld = alias; }
                alias = field.getTableName();

                // add id fields for root table if first field points to a separate table
                if ((i == 0) && field.isJoined()) {
                    String[] identities = SQLHelper.getIdentitySQLNames(_engine.getDescriptor());
                    for (int j = 0; j < identities.length; j++) {
                        expr.addColumn(
                                new ClassDescriptorJDONature(curDesc).getTableName(),
                                identities[j]);
                    }
                    identitiesUsedForTable.put(
                            new ClassDescriptorJDONature(curDesc).getTableName(),
                            Boolean.TRUE);
                }
               
                // add id columns to select statement
                if (!alias.equals(aliasOld) && !field.isJoined()) {
                    ClassDescriptor classDescriptor =
                        field.getFieldDescriptor().getContainingClassDescriptor();
                    boolean isTableNameAlreadyAdded = identitiesUsedForTable.containsKey(
                            new ClassDescriptorJDONature(classDescriptor).getTableName());
                    if (!isTableNameAlreadyAdded) {
                        String[] identities = SQLHelper.getIdentitySQLNames(classDescriptor);
                        for (int j = 0; j < identities.length; j++) {
                            expr.addColumn(alias, identities[j]);
                        }
                        identitiesUsedForTable.put(
                                new ClassDescriptorJDONature(classDescriptor).getTableName(),
                                Boolean.TRUE);
                    }
                }

                if (field.isJoined()) {
                    int offset = 0;
                    String[] rightCol = field.getJoinFields();
                    String[] leftCol = new String[ids.length - offset];
                    for (int j = 0; j < leftCol.length; j++) {
                        leftCol[j] = ids[j + offset].getName();
                    }
                    ClassDescriptor clsDescriptor = _engine.getDescriptor();
                    ClassDescriptorJDONature nature = new ClassDescriptorJDONature(clsDescriptor);
                    if (joinTables.contains(field.getTableName())
                            || nature.getTableName().equals(field.getTableName())) {
                       
                        // should not mix with aliases in ParseTreeWalker
                        alias = alias.replace('.', '_') + "_f" + i;
                        expr.addOuterJoin(_mapTo, leftCol, field.getTableName(), rightCol, alias);
                    } else {
                        expr.addOuterJoin(_mapTo, leftCol, field.getTableName(), rightCol);
                        joinTables.add(field.getTableName());
                    }
                }

                for (int j = 0; j < field.getColumnInfo().length; j++) {
                    expr.addColumn(alias, field.getColumnInfo()[j].getName());
                }
               
                expr.addTable(field.getTableName(), alias);
            }

            // 'join' all the extending tables
            List classDescriptorsToAdd = new LinkedList();
            ClassDescriptor classDescriptor = null;
            SQLHelper.addExtendingClassDescriptors(classDescriptorsToAdd,
                    new ClassDescriptorJDONature(_engine.getDescriptor()).getExtended());
           
            if (classDescriptorsToAdd.size() > 0) {
                for (Iterator iter = classDescriptorsToAdd.iterator(); iter.hasNext(); ) {
                    classDescriptor = (ClassDescriptor) iter.next();
                    ClassDescriptorJDONature clsDescNature =
                        new ClassDescriptorJDONature(classDescriptor);
                    if (LOG.isTraceEnabled()) {
                        LOG.trace("Adding outer left join for "
                                + classDescriptor.getJavaClass().getName() + " on table "
                                + clsDescNature.getTableName());
                    }
                   
                    String[] engDescIdNames = SQLHelper.getIdentitySQLNames(
                            _engine.getDescriptor());
                    String[] clsDescIdNames = SQLHelper.getIdentitySQLNames(classDescriptor);
                    expr.addOuterJoin(_mapTo, engDescIdNames,
                            clsDescNature.getTableName(), clsDescIdNames);

                    Persistence persistenceEngine;
                    try {
                        persistenceEngine = _factory.getPersistence(classDescriptor);
                    } catch (MappingException e) {
                        throw new QueryException(
                                "Problem obtaining persistence engine for ClassDescriptor "
                                + classDescriptor.getJavaClass().getName(), e);
                    }

                    SQLEngine engine = (SQLEngine) persistenceEngine;
                    SQLColumnInfo[] idInfos = engine.getColumnInfoForIdentities();
                    for (int i = 0; i < idInfos.length; i++) {
                        expr.addColumn(clsDescNature.getTableName(), idInfos[i].getName());
                    }
                   
                    SQLFieldInfo[] fieldInfos = ((SQLEngine) persistenceEngine).getInfo();
                    for (int i = 0; i < fieldInfos.length; i++) {
                        boolean hasFieldToAdd = false;
                        SQLColumnInfo[] columnInfos = fieldInfos[i].getColumnInfo();
                        if (clsDescNature.getTableName().equals(fieldInfos[i].getTableName())) {
                            for (int j = 0; j < columnInfos.length; j++) {
                                expr.addColumn(clsDescNature.getTableName(),
                                        fieldInfos[i].getColumnInfo()[j].getName());
                            }
                            hasFieldToAdd = true;
                        }
                       
                        if (hasFieldToAdd) {
                            expr.addTable(clsDescNature.getTableName());
                        }
                    }
                }
            }
           
View Full Code Here

            int columnIndex = ids.length + 1;
           
            Set processedTables = new HashSet();
            if (fields.length > 0 && fields[0].isJoined()) {
                ClassDescriptor clsDesc = _engine.getDescriptor();
                processedTables.add(new ClassDescriptorJDONature(clsDesc).getTableName());
            }
            boolean notNull;
            // index in fields[] for storing result of SQLTypes.getObject()
            fieldIndex = 1;
            String tableName = null;
            for (int i = 0; i < fields.length; ++i) {
                SQLFieldInfo field = fields[i];
                SQLColumnInfo[] columns = field.getColumnInfo();
                tableName = field.getTableName();
                if (i > 0 && !field.isJoined() && !processedTables.contains(tableName)) {
                    columnIndex = columnIndex + ids.length;
                }
                processedTables.add(tableName);
               
                if (!field.isJoined() && (field.getJoinFields() == null)) {
                    entity.setField(columns[0].toJava(SQLTypeInfos.getValue(
                            rs, columnIndex++, columns[0].getSqlType())), i);
                    fieldIndex++;
                } else if (!field.isMulti()) {
                    notNull = false;
                    Object[] id = new Object[columns.length];
                    for (int j = 0; j < columns.length; j++) {
                        id[j] = columns[j].toJava(SQLTypeInfos.getValue(
                                rs, columnIndex++, columns[j].getSqlType()));
                        fieldIndex++;
                        if (id[j] != null) { notNull = true; }
                    }
                    entity.setField(((notNull) ? new Identity(id) : null), i);
                } else {
                    ArrayList res = new ArrayList();
                    notNull = false;
                    Object[] id = new Object[columns.length];
                    for (int j = 0; j < columns.length; j++) {
                        id[j] = columns[j].toJava(SQLTypeInfos.getValue(
                                rs, columnIndex, columns[j].getSqlType()));
                        if (id[j] != null) { notNull = true; }
                        fieldIndex++;
                        columnIndex++;
                    }
                    if (notNull) { res.add(new Identity(id)); }
                    entity.setField(res, i);
                }
            }

            while (rs.next()) {
                fieldIndex = 1;
                columnIndex = ids.length + 1;
                processedTables.clear();
                if (fields[0].isJoined()) {
                    ClassDescriptor clsDesc = _engine.getDescriptor();
                    processedTables.add(new ClassDescriptorJDONature(clsDesc).getTableName());
                }

                for (int i = 0; i < fields.length; ++i) {
                    SQLFieldInfo field = fields[i];
                    SQLColumnInfo[] columns = field.getColumnInfo();
View Full Code Here

        // Instead of creating new Object[] and ArrayList for each
        // "multi field" each fetchRaw is called, we might reuse them.

        int originalFieldNumber = _requestedEngine.getInfo().length;
        Collection extendingClassDescriptors =
            new ClassDescriptorJDONature(_requestedEngine.getDescriptor()).getExtended();
        if (extendingClassDescriptors.size() > 0) {
            int numberOfExtendLevels = SQLHelper.numberOfExtendingClassDescriptors(
                    _requestedEngine.getDescriptor());
            ClassDescriptor leafDescriptor = null;
            Object[] returnValues = null;
View Full Code Here

            // must create record in the parent table first. all other dependents
            // are created afterwards. quick and very dirty hack to try to make
            // multiple class on the same table work.
            if (extended != null) {
                ClassDescriptor extDesc = extended.getDescriptor();
                if (!new ClassDescriptorJDONature(extDesc).getTableName().equals(_mapTo)) {
                    internalIdentity = extended.create(database, conn, entity, internalIdentity);
                }
            }
           
            if ((internalIdentity == null) && _useJDBC30) {
View Full Code Here

        }

        // Create the class descriptor, and register the JDO nature with it.
        ClassDescriptorImpl clsDesc = new ClassDescriptorImpl();
        clsDesc.addNature(ClassDescriptorJDONature.class.getName());
        ClassDescriptorJDONature jdoNature = new ClassDescriptorJDONature(clsDesc);
       
        // Set reference to class mapping on class descriptor.
        clsDesc.setMapping(classMapping);
       
        // Obtain the Java class.
        Class javaClass = resolveType(classMapping.getName());
        if (!Types.isConstructable(javaClass, true)) {
            throw new MappingException(
                    "mapping.classNotConstructable", javaClass.getName());
        }
        clsDesc.setJavaClass(javaClass);
       
        // If this class extends another class, we need to obtain the extended
        // class and make sure this class indeed extends it.
        ClassDescriptor extDesc = getExtended(classMapping, javaClass);
        if (extDesc != null) {
            if (!(extDesc.hasNature(ClassDescriptorJDONature.class.getName()))) {
                throw new IllegalArgumentException(
                        "Extended class does not have a JDO descriptor");
            }
           
            new ClassDescriptorJDONature(extDesc).addExtended(clsDesc);
        }
        clsDesc.setExtends(extDesc);
       
        // If this class depends on another class, obtain the depended class.
        clsDesc.setDepends(getDepended(classMapping, javaClass));
       
        // Create all field descriptors.
        FieldDescriptorImpl[] allFields = createFieldDescriptors(classMapping, javaClass);

        // Make sure there are no two fields with the same name.
        checkFieldNameDuplicates(allFields, javaClass);

        // Set class descriptor containing the field
        for (int i = 0; i < allFields.length; i++) {
            allFields[i].setContainingClassDescriptor(clsDesc);
        }
       
        // Identify identity and normal fields. Note that order must be preserved.
        List fieldList = new ArrayList(allFields.length);
        List idList = new ArrayList();
        if (extDesc == null) {
            // Sort fields into 2 lists based on identity definition of field.
            for (int i = 0; i < allFields.length; i++) {
                if (!allFields[i].isIdentity()) {
                    fieldList.add(allFields[i]);
                } else {
                    idList.add(allFields[i]);
                }
            }
           
            if (idList.size() == 0) {
                // Found no identities based on identity definition of field.
                // Try to find identities based on identity definition on class.
                String[] idNames = classMapping.getIdentity();
                if ((idNames == null) || (idNames.length == 0)) {
                    // There are also no identity definitions on class.
                    throw new MappingException("mapping.noIdentity", javaClass.getName());
                }

                FieldDescriptor identity;
                for (int i = 0; i < idNames.length; i++) {
                    identity = findIdentityByName(fieldList, idNames[i], javaClass);
                    if (identity != null) {
                        idList.add(identity);
                    } else {
                        throw new MappingException("mapping.identityMissing",
                                idNames[i], javaClass.getName());
                    }
                }
            }
        } else {
            // Add all fields of extending class to field list.
            for (int i = 0; i < allFields.length; i++) { fieldList.add(allFields[i]); }
           
            // Add all identities of extended class to identity list.
            FieldDescriptor[] extIds = ((ClassDescriptorImpl) extDesc).getIdentities();
            for (int i = 0; i < extIds.length; i++) { idList.add(extIds[i]); }
           
            // Search redefined identities in extending class.
            FieldDescriptor identity;
            for (int i = 0; i < idList.size(); i++) {
                String idName = ((FieldDescriptor) idList.get(i)).getFieldName();
                identity = findIdentityByName(fieldList, idName, javaClass);
                if (identity != null) { idList.set(i, identity); }
            }
        }
       
        // Set identities on class descriptor.
        FieldDescriptor[] ids = new FieldDescriptor[idList.size()];
        clsDesc.setIdentities(((FieldDescriptor[]) idList.toArray(ids)));

        // Set fields on class descriptor.
        FieldDescriptor[] fields = new FieldDescriptor[fieldList.size()];
        clsDesc.setFields((FieldDescriptor[]) fieldList.toArray(fields));
       
        jdoNature.setTableName(classMapping.getMapTo().getTable());
       
        extractAndSetAccessMode(jdoNature, classMapping);
        extractAndAddCacheParams(jdoNature, classMapping, javaClass);
        extractAndAddNamedQueries(jdoNature, classMapping);
        extractAndSetKeyGeneratorDescriptor(jdoNature, classMapping.getKeyGenerator());
View Full Code Here

        ClassMapping mapping = new ClassMapping();
        ClassChoice choice = new ClassChoice();
        MapTo mapTo = new MapTo();

        addNature(ClassDescriptorJDONature.class.getName());
        ClassDescriptorJDONature jdoNature = new ClassDescriptorJDONature(this);
        jdoNature.setTableName("Father");
        setJavaClass(Father.class);
        jdoNature.setAccessMode(AccessMode.valueOf("shared"));
        jdoNature.addCacheParam("name", "org.exolab.castor.builder.cdr.generated.simple.Father");

        mapping.setAccess(ClassMappingAccessType.valueOf("shared"));
        mapping.setAutoComplete(true);
        mapping.setName("org.exolab.castor.builder.cdr.generated.simple.Father");
        mapping.setClassChoice(choice);
View Full Code Here

    public SQLStatementStore(final SQLEngine engine, final PersistenceFactory factory,
                             final String load) {
        _engine = engine;
        _factory = factory;
        _type = engine.getDescriptor().getJavaClass().getName();
        _mapTo = new ClassDescriptorJDONature(engine.getDescriptor()).getTableName();
       
        // iterate through all fields to check whether there is a field
        // to persist at all; in the case of extend relationships where no
        // additional attributes are defined in the extending class, this
        // might NOT be the case
View Full Code Here

TOP

Related Classes of org.exolab.castor.jdo.engine.nature.ClassDescriptorJDONature

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.