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

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


        // Instantiate title field descriptor
        idFieldDescr = new FieldDescriptorImpl(idFieldName, idType, idHandler, false);
       
        idFieldDescr.addNature(FieldDescriptorJDONature.class.getName());
        FieldDescriptorJDONature idJdoNature = new FieldDescriptorJDONature(idFieldDescr);
       
        idJdoNature.setSQLName(new String[] { idFieldName });
        idJdoNature.setSQLType(new int[] { SQLTypeInfos.javaType2sqlTypeNum(java.lang.Integer.class) });
        idJdoNature.setManyKey(null);
        idJdoNature.setDirtyCheck(false);
        idJdoNature.setReadOnly(false);

        // Set parent class descriptor
        idFieldDescr.setContainingClassDescriptor(this);
        idFieldDescr.setClassDescriptor(this);
        idFieldDescr.setIdentity(true);
View Full Code Here


        /*
         * FieldDescriptorJDONature
         */
        descriptor.addNature(FieldDescriptorJDONature.class.getName());
        FieldDescriptorJDONature jdoNature = new FieldDescriptorJDONature(
                descriptor);

        /*
         * working!
         */

        /*
         * interim setters for not implemented getters!
         */
        jdoNature.setManyKey(null);
        jdoNature.setManyTable(null);
        jdoNature.setSQLType(null);
        jdoNature.setSQLName(null);
        jdoNature.setTypeConvertor(null);
        jdoNature.setDirtyCheck(true);
        jdoNature.setReadOnly(false);

        /* JPA.@Id */

        return descriptor;
    }
View Full Code Here

        _sql = sql;
        ClassDescriptorImpl cdi = (ClassDescriptorImpl) _engine.getDescriptor();
        _identSqlType = new int[cdi.getIdentities().length];
        for (int i = 0; i < _identSqlType.length; i++) {
            FieldDescriptor fldDesc = cdi.getIdentities()[i];
            _identSqlType[i] new FieldDescriptorJDONature(fldDesc).getSQLType()[0];
        }
       
        _isCallSql = isCallSql;
    }
View Full Code Here

        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]);

                // Does the key generator support the sql type specified in the mapping?
                keyGen.supportsSqlType(tempType[0]);
View Full Code Here

                if (!(field.hasNature(FieldDescriptorJDONature.class.getName()))) {
                    throw new IllegalStateException(
                            "Identity field must be of type JDOFieldDescriptor");
                }
               
                String[] sqlName = new FieldDescriptorJDONature(field).getSQLName();
                if (sqlName == null) {
                    throw new MappingException("mapping.noSqlName",
                            field.getFieldName(), javaClass.getName());
                }
View Full Code Here

        // if SQL mapping declares transient
        if (sql.getTransient()) {
            fieldDescriptor.setTransient(true);
        }
       
        FieldDescriptorJDONature fieldJdoNature =
            new FieldDescriptorJDONature(fieldDescriptor);
       
        fieldJdoNature.setTypeConvertor(typeInfo.getConvertorFrom());
        if (sqlName.length > 0) {
            fieldJdoNature.setSQLName(sqlName);
        }
        fieldJdoNature.setSQLType(sqlTypeNum);
        fieldJdoNature.setManyTable(sql.getManyTable());
        if (sql.getManyKey().length > 0) {
            fieldJdoNature.setManyKey(sql.getManyKey());
        }
        fieldJdoNature.setDirtyCheck(!SqlDirtyType.IGNORE.equals(sql.getDirty()));
        fieldJdoNature.setReadOnly(sql.getReadOnly());
       
        return fieldDescriptor;
    }
View Full Code Here

            throw new RuntimeException(e1.getMessage());
        }
        // Instantiate ssnr field descriptor
        ssnrFieldDescr = new FieldDescriptorImpl(ssnrFieldName, ssnrType,ssnrHandler, false);
        ssnrFieldDescr.addNature(FieldDescriptorJDONature.class.getName());
        FieldDescriptorJDONature ssnrFieldJdoNature = new FieldDescriptorJDONature(ssnrFieldDescr);
        ssnrFieldJdoNature.setSQLName(new String[] { "ssnr" });
        ssnrFieldJdoNature.setSQLType(new int[] {SQLTypeInfos.javaType2sqlTypeNum(java.lang.Long.class) });
        ssnrFieldJdoNature.setManyTable(null);
        ssnrFieldJdoNature.setManyKey(new String[] {});
        ssnrFieldJdoNature.setDirtyCheck(false);
        ssnrFieldJdoNature.setReadOnly(false);

        ssnrFieldDescr.setContainingClassDescriptor(this);
        ssnrFieldDescr.setIdentity(true);
        ssnrFM.setIdentity(true);
        ssnrFM.setDirect(false);
        ssnrFM.setName("ssnr");
        ssnrFM.setRequired(true);
        ssnrFM.setSetMethod("setSsnr");
        ssnrFM.setGetMethod("getSsnr");
        Sql ssnrSql = new Sql();
        ssnrSql.addName("ssnr");
        ssnrSql.setType("integer");
        ssnrFM.setSql(ssnrSql);
        ssnrFM.setType("long");
        choice.addFieldMapping(ssnrFM);

        //firstName field
        String firstNameFieldName = "firstName";
        FieldDescriptorImpl firstNameFieldDescr;
        FieldMapping firstNameFM = new FieldMapping();
        TypeInfo firstNameType = new TypeInfo(java.lang.String.class);
        // Set columns required (= not null)
        firstNameType.setRequired(true);

        FieldHandler firstNameHandler;
        try {
            Method firstNameGetMethod = Father.class.getMethod("getFirstName", null);
            Method firstNameSetMethod = Father.class.getMethod("setFirstName", new Class[]{
                java.lang.String.class});

            firstNameHandler = new FieldHandlerImpl(firstNameFieldName, null, null,
                firstNameGetMethod, firstNameSetMethod, firstNameType);

        } catch (SecurityException e1) {
            throw new RuntimeException(e1.getMessage());
        } catch (MappingException e1) {
            throw new RuntimeException(e1.getMessage());
        } catch (NoSuchMethodException e1) {
            throw new RuntimeException(e1.getMessage());
        }
        // Instantiate firstName field descriptor
        firstNameFieldDescr = new FieldDescriptorImpl(firstNameFieldName, firstNameType,firstNameHandler, false);
        firstNameFieldDescr.addNature(FieldDescriptorJDONature.class.getName());
        FieldDescriptorJDONature firstNameFieldJdoNature = new FieldDescriptorJDONature(firstNameFieldDescr);
        firstNameFieldJdoNature.setSQLName(new String[] { "firstName" });
        firstNameFieldJdoNature.setSQLType(new int[] {SQLTypeInfos.javaType2sqlTypeNum(java.lang.String.class) });
        firstNameFieldJdoNature.setManyTable(null);
        firstNameFieldJdoNature.setManyKey(new String[] {});
        firstNameFieldJdoNature.setDirtyCheck(false);
        firstNameFieldJdoNature.setReadOnly(false);

        firstNameFieldDescr.setContainingClassDescriptor(this);
        firstNameFieldDescr.setIdentity(false);
        firstNameFM.setIdentity(false);
        firstNameFM.setDirect(false);
        firstNameFM.setName("firstName");
        firstNameFM.setRequired(true);
        firstNameFM.setSetMethod("setFirstName");
        firstNameFM.setGetMethod("getFirstName");
        Sql firstNameSql = new Sql();
        firstNameSql.addName("firstName");
        firstNameSql.setType("varchar");
        firstNameFM.setSql(firstNameSql);
        firstNameFM.setType("java.lang.String");
        choice.addFieldMapping(firstNameFM);

        //lastName field
        String lastNameFieldName = "lastName";
        FieldDescriptorImpl lastNameFieldDescr;
        FieldMapping lastNameFM = new FieldMapping();
        TypeInfo lastNameType = new TypeInfo(java.lang.String.class);
        // Set columns required (= not null)
        lastNameType.setRequired(true);

        FieldHandler lastNameHandler;
        try {
            Method lastNameGetMethod = Father.class.getMethod("getLastName", null);
            Method lastNameSetMethod = Father.class.getMethod("setLastName", new Class[]{
                java.lang.String.class});

            lastNameHandler = new FieldHandlerImpl(lastNameFieldName, null, null,
                lastNameGetMethod, lastNameSetMethod, lastNameType);

        } catch (SecurityException e1) {
            throw new RuntimeException(e1.getMessage());
        } catch (MappingException e1) {
            throw new RuntimeException(e1.getMessage());
        } catch (NoSuchMethodException e1) {
            throw new RuntimeException(e1.getMessage());
        }
        // Instantiate lastName field descriptor
        lastNameFieldDescr = new FieldDescriptorImpl(lastNameFieldName, lastNameType,lastNameHandler, false);
        lastNameFieldDescr.addNature(FieldDescriptorJDONature.class.getName());
        FieldDescriptorJDONature lastNameFieldJdoNature = new FieldDescriptorJDONature(lastNameFieldDescr);
        lastNameFieldJdoNature.setSQLName(new String[] { "lastName" });
        lastNameFieldJdoNature.setSQLType(new int[] {SQLTypeInfos.javaType2sqlTypeNum(java.lang.String.class) });
        lastNameFieldJdoNature.setManyTable(null);
        lastNameFieldJdoNature.setManyKey(new String[] {});
        lastNameFieldJdoNature.setDirtyCheck(false);
        lastNameFieldJdoNature.setReadOnly(false);

        lastNameFieldDescr.setContainingClassDescriptor(this);
        lastNameFieldDescr.setIdentity(false);
        lastNameFM.setIdentity(false);
        lastNameFM.setDirect(false);
View Full Code Here

                FieldDescriptor[] fd = ((ClassDescriptorImpl) clsDesc).getIdentities();
                for (int j = 0; j < fmId.length; j++) {
                    idSQL[j] = fmId[j].getSql().getName()[0];

                    if (fd[j].hasNature(FieldDescriptorJDONature.class.getName())) {
                        int[] type = new FieldDescriptorJDONature(fd[j]).getSQLType();
                        idType[j] = (type == null) ? 0 : type[0];
                        FieldHandlerImpl fh = (FieldHandlerImpl) fd[j].getHandler();
                        idConvertTo[j] = fh.getConvertTo();
                        idConvertFrom[j] = fh.getConvertFrom();
                    } else {
                        throw new MappingException(
                                "Identity type must contains sql information: " + _name);
                    }
                }

                ClassDescriptor relDesc = null;
                try {
                    JDOClassDescriptorResolver jdoCDR;
                    jdoCDR = (JDOClassDescriptorResolver) classDescrResolver;
                    relDesc = jdoCDR.resolve(fmFields[i].getType());
                } catch (ResolverException e) {
                    throw new MappingException("Problem resolving class descriptor for class "
                            + fmFields.getClass(), e);
                }
                               
                if (relDesc.hasNature(ClassDescriptorJDONature.class.getName())) {
                    FieldDescriptor[] relatedIds = ((ClassDescriptorImpl) relDesc).getIdentities();
                    relatedIdSQL = new String[relatedIds.length];
                    relatedIdType = new int[relatedIds.length];
                    relatedIdConvertTo = new TypeConvertor[relatedIds.length];
                    relatedIdConvertFrom = new TypeConvertor[relatedIds.length];
                    for (int j = 0; j < relatedIdSQL.length; j++) {
                        if (relatedIds[j].hasNature(FieldDescriptorJDONature.class.getName())) {
                            FieldDescriptorJDONature nature;
                            nature = new FieldDescriptorJDONature(relatedIds[j]);
                            String[] tempId = nature.getSQLName();
                            relatedIdSQL[j] = (tempId == null) ? null : tempId[0];
                            int[] tempType =  nature.getSQLType();
                            relatedIdType[j] = (tempType == null) ? 0 : tempType[0];
                            FieldHandlerImpl fh = (FieldHandlerImpl) relatedIds[j].getHandler();
                            relatedIdConvertTo[j] = fh.getConvertTo();
                            relatedIdConvertFrom[j] = fh.getConvertFrom();
                        } else {
View Full Code Here

            }

            FieldDescriptor[] relids = ((ClassDescriptorImpl) related).getIdentities();
            String[] relnames = new String[relids.length];
            for (int i = 0; i < relids.length; i++) {
                relnames[i] = new FieldDescriptorJDONature(relids[i]).getSQLName()[0];
                if (relnames[i] == null) {
                    throw new MappingException("Related class identities field does "
                            + "not contains sql information!");
                }
            }
           
            FieldDescriptor[] classids = ((ClassDescriptorImpl) clsDesc).getIdentities();
            String[] classnames = new String[classids.length];
            for (int i = 0; i < classids.length; i++) {
                classnames[i] = new FieldDescriptorJDONature(classids[i]).getSQLName()[0];
                if (classnames[i] == null) {
                    throw new MappingException("Related class identities field does "
                            + "not contains sql information!");
                }
            }

            String[] names = relnames;
            if (!(fieldDesc.hasNature(FieldDescriptorJDONature.class.getName()))) {
                _tableName = new ClassDescriptorJDONature(related).getTableName();
                _store = false;
                _multi = fieldDesc.isMultivalued();
                _joined = true;
                _joinFields = classnames;
                _dirtyCheck = true;
            } else {
                final FieldDescriptorJDONature jdoFieldNature =
                    new FieldDescriptorJDONature(fieldDesc);

                names = jdoFieldNature.getSQLName();
                if ((names != null) && (names.length != relids.length)) {
                    throw new MappingException("The number of column of foreign keys "
                            + "doesn't not match with what specified in manyKey");
                }
                names = (names != null) ? names : relnames;

                String[] joins = jdoFieldNature.getManyKey();
                if ((joins != null) && (joins.length != classids.length)) {
                    throw new MappingException("The number of column of foreign keys "
                            + "doesn't not match with what specified in manyKey");
                }

                if (jdoFieldNature.getManyTable() != null) {
                    _tableName = jdoFieldNature.getManyTable();
                    _store = false;
                    _multi = fieldDesc.isMultivalued();
                    _joined = true;
                    _joinFields = (joins != null) ? joins : classnames;
                } else if (jdoFieldNature.getSQLName() != null) {
                    _tableName = classTable;
                    _store = !ext && !jdoFieldNature.isReadonly();
                    _multi = false;
                    _joined = false;
                    _joinFields = classnames;
                } else {
                    _tableName = new ClassDescriptorJDONature(related).getTableName();
                    _store = false;
                    _multi = fieldDesc.isMultivalued();
                    _joined = true;
                    _joinFields = (joins != null) ? joins : classnames;
                }

                _dirtyCheck = jdoFieldNature.isDirtyCheck();
            }

            _columns = new SQLColumnInfo[relids.length];
            for (int i = 0; i < relids.length; i++) {
                if (!(relids[i].hasNature(FieldDescriptorJDONature.class.getName()))) {
                    throw new MappingException("Related class identities field does "
                            + "not contains sql information!");
                }

                FieldDescriptor relId = relids[i];
                FieldHandlerImpl fh = (FieldHandlerImpl) relId.getHandler();
                _columns[i] = new SQLColumnInfo(names[i],
                        new FieldDescriptorJDONature(relId).getSQLType()[0],
                        fh.getConvertTo(), fh.getConvertFrom());
            }
        } else {
            final FieldDescriptorJDONature jdoFieldNature =
                new FieldDescriptorJDONature(fieldDesc);

            _tableName = classTable;
            _store = !ext && !new FieldDescriptorJDONature(fieldDesc).isReadonly();
            _multi = false;
            _joined = false;
            _joinFields = null;
            _dirtyCheck = jdoFieldNature.isDirtyCheck();
           
            _columns = new SQLColumnInfo[1];
            String sqlName = fieldDesc.getFieldName();
            if (jdoFieldNature.getSQLName() != null) {
                sqlName = jdoFieldNature.getSQLName()[0];
            }
            FieldHandlerImpl fh = (FieldHandlerImpl) fieldDesc.getHandler();
            _columns[0] = new SQLColumnInfo(sqlName,
                    jdoFieldNature.getSQLType()[0],
                    fh.getConvertTo(), fh.getConvertFrom());
        }
    }
View Full Code Here

       
        if (_clsDesc.getExtends() == null) {
            ClassDescriptorJDONature nature = new ClassDescriptorJDONature(clsDesc);
            KeyGeneratorDescriptor keyGenDesc = nature.getKeyGeneratorDescriptor();
            if (keyGenDesc != null) {
                int[] tempType =  new FieldDescriptorJDONature(_clsDesc.getIdentity()).getSQLType();
                _keyGen = keyGenDesc.getKeyGeneratorRegistry().getKeyGenerator(
                        _factory, keyGenDesc, (tempType == null) ? 0 : tempType[0]);

                // Does the key generator support the sql type specified in the mapping?
                _keyGen.supportsSqlType(tempType[0]);
            }
        }

        // construct field and id info
        Vector idsInfo = new Vector();
        Vector fieldsInfo = new Vector();

        /*
         * Implementation Note:
         * Extends and Depends has some special mutual exclusive
         * properties, which implementator should aware of.
         *
         * A Depended class may depends on another depended class
         * A class should either extends or depends on other class
         * A class should not depend on extending class.
         *  because, it is the same as depends on the base class
         * A class may be depended by zero or more classes
         * A class may be extended by zero or more classes
         * A class may extends only zero or one class
         * A class may depends only zero or one class
         * A class may depend on extended class
         * A class may extend a dependent class.
         * A class may extend a depended class.
         * No loop or circle should exist
         */
        // then, we put depended class ids in the back
        ClassDescriptor base = clsDesc;

        // walk until the base class which this class extends
        base = clsDesc;
        Stack stack = new Stack();
        stack.push(base);
        while (base.getExtends() != null) {
            // if (base.getDepends() != null) {
            //     throw new MappingException(
            //             "Class should not both depends on and extended other classes");
            // }
            base = base.getExtends();
            stack.push(base);
            // do we need to add loop detection?
        }

        // now base is either the base of extended class, or
        // clsDesc
        // we always put the original id info in front
        // [oleg] except for SQL name, it may differ.
        FieldDescriptor[] baseIdDescriptors = ((ClassDescriptorImpl) base).getIdentities();
        FieldDescriptor[] idDescriptors = ((ClassDescriptorImpl) clsDesc).getIdentities();

        for (int i = 0; i < baseIdDescriptors.length; i++) {
            if (baseIdDescriptors[i].hasNature(FieldDescriptorJDONature.class.getName())) {
                String name = baseIdDescriptors[i].getFieldName();
                String[] sqlName =
                    new FieldDescriptorJDONature(baseIdDescriptors[i]).getSQLName();
                int[] sqlType =  new FieldDescriptorJDONature(baseIdDescriptors[i]).getSQLType();
                FieldHandlerImpl fh = (FieldHandlerImpl) baseIdDescriptors[i].getHandler();

                // The extending class may have other SQL names for identity fields
                for (int j = 0; j < idDescriptors.length; j++) {
                    if (name.equals(idDescriptors[j].getFieldName())
                            && (idDescriptors[j].hasNature(JDO_FIELD_NATURE))) {
                        sqlName = new FieldDescriptorJDONature(idDescriptors[j]).getSQLName();
                        break;
                    }
                }
                idsInfo.add(new SQLColumnInfo(sqlName[0], sqlType[0], fh.getConvertTo(),
                        fh.getConvertFrom()));
View Full Code Here

TOP

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

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.