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

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


        FieldDescriptor tempField = null;
        ClassDescriptor tempCd = clsDesc;
        Object[] retVal;

        while (tempCd != null) {
            tempField = new ClassDescriptorJDONature(tempCd).getField(fieldName);
            if (tempField != null) {
                field = tempField;
                cd = tempCd;
            }
            tempCd = tempCd.getExtends();
        }
    
        if (field == null) { return null; }

        // prepare the return value
        retVal = new Object[] {field, cd};
        if (cd != clsDesc) {
            // now add inner join for "extends"
            ClassDescriptorJDONature clsDescNature;
            clsDescNature = new ClassDescriptorJDONature(clsDesc);
            String tableAlias1 = clsDescNature.getTableName();
            ClassDescriptorJDONature cdNature;
            cdNature = new ClassDescriptorJDONature(cd);
            String tableAlias2 = cdNature.getTableName();
            if (tableIndex > 0) {
                tableAlias1 = buildTableAlias(tableAlias1, path, tableIndex);
                tableAlias2 = buildTableAlias(tableAlias2, path, tableIndex);
            }
            expr.addTable(new ClassDescriptorJDONature(cd).getTableName(), tableAlias2);
            String[] clsDescIdNames = SQLHelper.getIdentitySQLNames(clsDesc);
            String[] cdIdNames = SQLHelper.getIdentitySQLNames(cd);
            expr.addInnerJoin(
                    clsDescNature.getTableName(), clsDescIdNames, tableAlias1,
                    cdNature.getTableName(), cdIdNames, tableAlias2);
        }
        return retVal;
    }
View Full Code Here


            selectPart = _parseTree.getChild(1);
        } else {
            selectPart = _parseTree.getChild(0);
        }

        _queryExpr.addTable(new ClassDescriptorJDONature(_clsDesc).getTableName());

        // add table names and joins for all base classes
        ClassDescriptor oldDesc = _clsDesc;
        ClassDescriptor tempDesc = _clsDesc.getExtends();
        while (tempDesc != null) {
            String tableName = new ClassDescriptorJDONature(tempDesc).getTableName();
            _queryExpr.addTable(tableName);
           
            FieldDescriptor leftField = oldDesc.getIdentity();
            FieldDescriptor rightField = tempDesc.getIdentity();
           
            _queryExpr.addInnerJoin(
                    new ClassDescriptorJDONature(oldDesc).getTableName(),
                    new FieldDescriptorJDONature(leftField).getSQLName(),
                    new ClassDescriptorJDONature(tempDesc).getTableName(),
                    new FieldDescriptorJDONature(rightField).getSQLName());

            oldDesc = tempDesc;
            tempDesc = tempDesc.getExtends();
        }
View Full Code Here

            ClassDescriptor clsDesc = fieldDesc.getClassDescriptor();
            FieldDescriptorJDONature fieldJDONature = new FieldDescriptorJDONature(fieldDesc);
            if (clsDesc != null) {
                //we must add this table as a join
                ClassDescriptorJDONature sourceClassJDONature =
                    new ClassDescriptorJDONature(sourceClass);
                if (fieldJDONature.getManyKey() == null) {
                    //a many -> one relationship
                    FieldDescriptor foreignKey = clsDesc.getIdentity();
                    String sourceTableAlias = sourceClassJDONature.getTableName();
                    if (i > 1) {
                        sourceTableAlias = buildTableAlias(sourceTableAlias, path, i - 1);
                    }

                    ClassDescriptorJDONature clsDescNature;
                    clsDescNature = new ClassDescriptorJDONature(clsDesc);
                    _queryExpr.addInnerJoin(
                            sourceClassJDONature.getTableName(),
                            new FieldDescriptorJDONature(fieldDesc).getSQLName(),
                            sourceTableAlias,
                            clsDescNature.getTableName(),
                            new FieldDescriptorJDONature(foreignKey).getSQLName(),
                            buildTableAlias(clsDescNature.getTableName(), path, i));
                } else if (fieldJDONature.getManyTable() == null) {
                    //a one -> many relationship
                    FieldDescriptor identity = sourceClass.getIdentity();
                    String sourceTableAlias = sourceClassJDONature.getTableName();
                    if (i > 1) {
                        sourceTableAlias = buildTableAlias(sourceTableAlias, path, i - 1);
                    }

                    ClassDescriptorJDONature clsDescNature;
                    clsDescNature = new ClassDescriptorJDONature(clsDesc);
                    _queryExpr.addInnerJoin(
                            sourceClassJDONature.getTableName(),
                            new FieldDescriptorJDONature(identity).getSQLName(),
                            sourceTableAlias,
                            clsDescNature.getTableName(),
                            fieldJDONature.getManyKey(),
                            buildTableAlias(clsDescNature.getTableName(), path, i));
                } else {
                    //a many -> many relationship
                    FieldDescriptor identity = sourceClass.getIdentity();
                    FieldDescriptor foreignKey = clsDesc.getIdentity();
                    String manyTableAlias = fieldJDONature.getManyTable();
                    String sourceTableAlias = sourceClassJDONature.getTableName();
                    if (i > 1) {
                        manyTableAlias = buildTableAlias(manyTableAlias, path, i - 1);
                        sourceTableAlias = buildTableAlias(sourceTableAlias, path, i - 1);
                    }

                    _queryExpr.addInnerJoin(
                            sourceClassJDONature.getTableName(),
                            new FieldDescriptorJDONature(identity).getSQLName(),
                            sourceTableAlias,
                            fieldJDONature.getManyTable(),
                            fieldJDONature.getManyKey(),
                            manyTableAlias);

                    ClassDescriptorJDONature clsDescNature;
                    clsDescNature = new ClassDescriptorJDONature(clsDesc);
                    _queryExpr.addInnerJoin(
                            fieldJDONature.getManyTable(),
                            new FieldDescriptorJDONature(fieldDesc).getSQLName(),
                            manyTableAlias,
                            clsDescNature.getTableName(),
                            new FieldDescriptorJDONature(foreignKey).getSQLName(),
                            buildTableAlias(clsDescNature.getTableName(), path, i));
                }
                sourceClass = clsDesc;
            }
        }
    }
View Full Code Here

        ClassDescriptor classDescriptor = null;
        for (Iterator iter = extendingClassDescriptors.iterator(); iter.hasNext(); ) {
            classDescriptor = (ClassDescriptor) iter.next();
            classDescriptorsToAdd.add (classDescriptor);
            ClassDescriptorJDONature nature = new ClassDescriptorJDONature(classDescriptor);
            addExtendingClassDescriptors(classDescriptorsToAdd, nature.getExtended());
        }
    }
View Full Code Here

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

        AbstractProperties properties = CPAProperties.getInstance();
        _useJDBC30 = properties.getBoolean(CPAProperties.USE_JDBC30, false);
View Full Code Here

    private KeyGenerator getKeyGenerator(final SQLEngine engine,
            final PersistenceFactory factory) throws MappingException {
        KeyGenerator keyGen = null;
        if (engine.getDescriptor().getExtends() == null) {
            KeyGeneratorDescriptor keyGenDesc =
                new ClassDescriptorJDONature(engine.getDescriptor()).getKeyGeneratorDescriptor();
            if (keyGenDesc != null) {
                FieldDescriptor fldDesc = engine.getDescriptor().getIdentity();
                int[] tempType = new FieldDescriptorJDONature(fldDesc).getSQLType();
                keyGen = keyGenDesc.getKeyGeneratorRegistry().getKeyGenerator(
                        factory, keyGenDesc, (tempType == null) ? 0 : tempType[0]);
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);
                }
            }
           
            // we only need to care on JDBC 3.0 at after INSERT.
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);
                }
            }
           
            // generate key before INSERT.
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);
                }
            }
           
            stmt = conn.prepareCall(_statement);
View Full Code Here

                throw new IllegalStateException(
                        "ContainingClass of " + field.toString() + " is null !");
            }
           
            String clsTableAlias;
            ClassDescriptorJDONature classDescriptorJDONature =
                new ClassDescriptorJDONature(clsDesc);
                if (tokenType == TokenType.DOT && path != null && path.size() > 2) {
              clsTableAlias = buildTableAlias(
                      classDescriptorJDONature.getTableName(), path, path.size() - 2);
              ClassDescriptor srcDesc = _clsDesc;
              for (int i = 1; i < path.size(); i++) {
                Object[] fieldAndClass = getFieldAndClassDesc(
                                                              (String) path.elementAt(i),
                                                              srcDesc, _queryExpr, path, i - 1);
                if (fieldAndClass == null) {
                  throw new IllegalStateException("Field not found: "
                                                  + path.elementAt(i) + " class "
                                                  + srcDesc.getJavaClass());
                }
                FieldDescriptor fieldDesc = (FieldDescriptor) fieldAndClass[0];
                srcDesc = fieldDesc.getClassDescriptor();
              }
            } else {
              clsTableAlias = buildTableAlias(classDescriptorJDONature.getTableName(), path, 9999);
            }
           
            return _queryExpr.encodeColumn(clsTableAlias,
                    new FieldDescriptorJDONature(field).getSQLName()[0]);
        case TokenType.DOLLAR:
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.