Package org.apache.ojb.broker.metadata

Examples of org.apache.ojb.broker.metadata.FieldDescriptor


                int foreignKeyIndex = ((Integer) obj).intValue();
                columnName = classDescriptor.getFieldDescriptorByIndex(foreignKeyIndex).getColumnName();
            }
            else
            {
                    FieldDescriptor fld = classDescriptor.getFieldDescriptorByName((String) obj);
                    if(fld == null)
                    {
            logger.debug( "FieldDescriptor for foreign key parameter \n" + obj + " was not found in ClassDescriptor \n" + classDescriptor );
                    }
                    else columnName = fld.getColumnName();
            }

            FieldDescriptor foreignColumn = foreignClassDescriptor.getPkFields()[i];
            String foreignColumnName = foreignColumn.getColumnName();
            buildReferenceForColumn(buffer, columnName, foreignColumnName);
        }
        buffer.append("        </foreign-key>\n");
        addReferenceToTable(classDescriptor.getFullTableName(), buffer.toString());
    }
View Full Code Here


    public void generateMappingTables(StringBuffer buffer, String indexTablespaceName) {
        Iterator mappingTables = this.foreignKeyPreprocessor.getMappingTables().values().iterator();
        while (mappingTables.hasNext()) {
            TableDescriptor mappingTable = (TableDescriptor) mappingTables.next();
            FieldDescriptor descriptors[] = (FieldDescriptor[]) (mappingTable.getColumns().toArray(new FieldDescriptor[0]));
            if (descriptors != null && descriptors.length > 0) {
                generateTableHeader(buffer, mappingTable, indexTablespaceName);
                this.fieldGenerator.generateMappingFieldDescriptors(descriptors, buffer);
                generateForeignKeys(mappingTable, buffer);
                buffer.append("    </table>\n");
View Full Code Here

    }

    public void generateFieldDescriptors(FieldDescriptor[] descriptors, StringBuffer buffer) {
        if (descriptors != null) {
            for (int i = 0; i < descriptors.length; i++) {
                FieldDescriptor descriptor = descriptors[i];
                generateFieldDescriptor(descriptor, descriptor.getColumnName(), descriptor.isRequired(), descriptor.isAutoIncrement(), descriptor.isPrimaryKey(), buffer);
            }
        }
    }
View Full Code Here

    }

    public void generateMappingFieldDescriptors(FieldDescriptor[] descriptors, StringBuffer buffer) {
        if (descriptors != null) {
            for (int i = 0; i < descriptors.length; i++) {
                FieldDescriptor descriptor = descriptors[i];
                StringBuffer fieldBuffer = new StringBuffer();
                generateFieldDescriptor(descriptor, descriptor.getColumnName(), true, false, true, fieldBuffer);
                buffer.append(fieldBuffer);
            }
        }
    }
View Full Code Here

     * @throws PersistenceBrokerException if there ewas an error creating the new object
     */
    protected Object buildOrRefreshObject(Map row, ClassDescriptor targetClassDescriptor, Object targetObject)
    {
        Object result = targetObject;
        FieldDescriptor fmd = null;

        if(targetObject == null)
        {
            // 1. create new object instance if needed
            result = ClassHelper.buildNewObjectInstance(targetClassDescriptor);
        }

        // 2. fill all scalar attributes of the new object
        FieldDescriptor[] fields = targetClassDescriptor.getFieldDescriptions();
        for (int i = 0; i < fields.length; i++)
        {
            fmd = fields[i];
            fmd.getPersistentField().set(result, row.get(fmd.getColumnName()));
        }

        if(targetObject == null)
        {
            // 3. for new build objects, invoke the initialization method for the class if one is provided
View Full Code Here

    protected void readValuesFrom(ResultSet rs, Map row, FieldDescriptor[] fields)
    {
        int size = fields.length;
        Object val = null;
        FieldDescriptor fld = null;
        try
        {
            for (int j = 0; j < size; j++)
            {
                fld = fields[j];
                val = fld.getJdbcType().getObjectFromColumn(rs, fld.getColumnName());
                row.put(fld.getColumnName(), fld.getFieldConversion().sqlToJava(val));
            }
        }
        catch (SQLException t)
        {
            throw new PersistenceBrokerException("Error reading class type: " + m_cld.getClassNameOfObject()
                    + " from result set, current read field was " + (fld != null ? fld.getPersistentField().getName() : null), t);
        }
    }
View Full Code Here

     * Check if there is an attribute which tells us which concrete class is to be instantiated.
     */
    protected ClassDescriptor selectClassDescriptor(Map row) throws PersistenceBrokerException
    {
        // check if there is an attribute which tells us which concrete class is to be instantiated
        FieldDescriptor concreteClassFD = m_cld.getOjbConcreteClassField();

        if (concreteClassFD == null)
            return m_cld;
        else
        {
            try
            {
                String concreteClass = (String) row.get(concreteClassFD.getColumnName());
                if (concreteClass == null || concreteClass.trim().length() == 0)
                {
                    throw new PersistenceBrokerException(
                            "ojbConcreteClass field returned null or 0-length string");
                }
View Full Code Here

     * returns an Identity object representing the current resultset row
     */
    protected Identity getIdentityFromResultSet() throws PersistenceBrokerException
    {
        // fill primary key values from Resultset
        FieldDescriptor fld;
        FieldDescriptor[] pkFields = getQueryObject().getClassDescriptor().getPkFields();
        Object[] pkValues = new Object[pkFields.length];

        for (int i = 0; i < pkFields.length; i++)
        {
            fld = pkFields[i];
            pkValues[i] = getRow().get(fld.getColumnName());
        }

        // return identity object build up from primary keys
        return new Identity(getQueryObject().getClassDescriptor().getClassOfObject(), getTopLevelClass(), pkValues);
    }
View Full Code Here

        try
        {
            for(int i = 0; i < result.length; i++)
            {
                FieldDescriptor fd = pkFields[i];
                Object cv = pkValues[i];
                if(convertToSql)
                {
                    // BRJ : apply type and value mapping
                    cv = fd.getFieldConversion().javaToSql(cv);
                }
                result[i] = new ValueContainer(cv, fd.getJdbcType());
            }
        }
        catch(Exception e)
        {
            throw new PersistenceBrokerException("Can't generate primary key values for given Identity " + oid, e);
View Full Code Here

     */
    public boolean hasNullPKField(ClassDescriptor cld, Object obj)
    {
        FieldDescriptor[] fields = cld.getPkFields();
        boolean hasNull = false;
        FieldDescriptor fld;
        for(int i = 0; i < fields.length; i++)
        {
            fld = fields[i];
            hasNull = representsNull(fld, fld.getPersistentField().get(obj));
            if(hasNull) break;
        }
        return hasNull;
    }
View Full Code Here

TOP

Related Classes of org.apache.ojb.broker.metadata.FieldDescriptor

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.