Package org.castor.ddlgen.schemaobject

Examples of org.castor.ddlgen.schemaobject.Field


        boolean hasPrimaryKey = false;
        StringBuffer sb = new StringBuffer();

        boolean isFirstField = true;
        for (int i = 0; i < table.getFieldCount(); i++) {
            Field field = table.getField(i);
            if (field.isIdentity()) {
                hasPrimaryKey = true;
                if (!isFirstField) { sb.append("_"); }
                isFirstField = false;
                sb.append(field.getName());
            }
        }
       
        //have no primary key
        if (!hasPrimaryKey) { return ""; }
View Full Code Here


        boolean hasPrimaryKey = false;
        StringBuffer sb = new StringBuffer();

        boolean isFirstField = true;
        for (int i = 0; i < table.getFieldCount(); i++) {
            Field field = table.getField(i);
            if (field.isIdentity()) {
                hasPrimaryKey = true;
                if (!isFirstField) { sb.append("_"); }
                isFirstField = false;
                sb.append(field.getType().getSqlType());
            }
        }
       
        if (!hasPrimaryKey) { return ""; }
        return sb.toString();
View Full Code Here

                    }
                }

                // Create fields.
                for (int i = 0; i < sqlnames.length; i++) {
                    Field field = _schemaFactory.createField();
                    field.setConfiguration(_configuration);

                    if (isUseReferenceType) {
                        // Each sqlname correspond to a identity of the reference table.
                        // Should be able to get the original type of the reference
                        // field.
                        typeInfo = _typeMapper.getType(refIdTypes[i]);
                        if (typeInfo == null) {
                            throw new TypeNotFoundException(
                                    "can not find reference type "
                                    + refIdTypes[i] + " of class " + cm.getName());
                        }
                    }

                    // process attributes of field
                    field.setName(sqlnames[i]);
                    field.setTable(table);
                    field.setType(typeInfo);
                    field.setIdentity(isFieldIdentity);
                    field.setRequired(fm.getRequired());
                    field.setKeyGenerator(keyGen);

                    table.addField(field);
                   
                    if (isFieldIdentity) {
                       primarykey.addField(field);
View Full Code Here

                    }
                }

                // Create fields.
                for (int i = 0; i < sqlnames.length; i++) {
                    Field field = _schemaFactory.createField();
                    field.setConfiguration(_configuration);

                    if (isUseReferenceType) {
                        // Each sqlname is correspond to an identity of the reference
                        // table so, it should be possible to get the original type of
                        // the reference field.
                        typeInfo = _typeMapper.getType(refIdTypes[i]);
                        if (typeInfo == null) {
                            throw new TypeNotFoundException(
                                    "can not find reference type "
                                            + refIdTypes[i] + " of class "
                                            + extendCm.getName());
                        }
                    }

                    field.setName(sqlnames[i]);
                    field.setTable(table);
                    field.setType(typeInfo);
                    field.setIdentity(isFieldIdentity);                   
                    field.setKeyGenerator(keyGen);
                   
                    if (isFieldIdentity) {
                        table.getPrimaryKey().addField(field);
                    }
View Full Code Here

        fk.setName(table.getName() + "_" + fm.getName());
       
        String[] fieldNames = fm.getSql().getName();
        for (int i = 0; i < fieldNames.length; i++) {
            for (int j = 0; j < table.getFieldCount(); j++) {
                Field field = table.getField(j);
                if (fieldNames[i].equals(field.getName())) { fk.addField(field); }
            }
        }

        ClassMapping cm = _mappingHelper.getClassMappingByName(fm.getType());

        if (cm == null) {
            throw new GeneratorException("can not find class " + fm.getType());
        }
       
        String referenceTableName = cm.getMapTo().getTable();
        Table referenceTable = null;
        referenceTable = table.getSchema().getTable(referenceTableName);
        fk.setReferenceTable(referenceTable);
       
        String[] manykeys = fm.getSql().getManyKey();
        if (manykeys == null || manykeys.length == 0) {
            manykeys = _mappingHelper.getClassMappingSqlIdentity(cm, true);
        }
        for (int i = 0; i < manykeys.length; i++) {
            for (int j = 0; j < referenceTable.getFieldCount(); j++) {
                Field field = referenceTable.getField(j);
                if (manykeys[i].equals(field.getName())) { fk.addReferenceField(field); }
            }
        }

        fk.setRelationType(ForeignKey.ONE_ONE);
        table.addForeignKey(fk);
View Full Code Here

TOP

Related Classes of org.castor.ddlgen.schemaobject.Field

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.