Package org.apache.ojb.broker.metadata

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


    {
        ValueContainer[] result = new ValueContainer[fields.length];

        for(int i = 0; i < fields.length; i++)
        {
            FieldDescriptor fd = fields[i];
            Object cv = fd.getPersistentField().get(obj);

            /*
            handle autoincrement attributes if
            - is a autoincrement field
            - field represents a 'null' value, is nullified
            and generate a new value
            */
            if(fd.isAutoIncrement() && representsNull(fd, cv))
            {
                /*
                setAutoIncrementValue returns a value that is
                properly typed for the java-world.  This value
                needs to be converted to it's corresponding
                sql type so that the entire result array contains
                objects that are properly typed for sql.
                */
                cv = setAutoIncrementValue(fd, obj, cv);
            }
            if(convertToSql)
            {
                // apply type and value conversion
                cv = fd.getFieldConversion().javaToSql(cv);
            }
            // create ValueContainer
            result[i] = new ValueContainer(cv, fd.getJdbcType());
        }
        return result;
    }
View Full Code Here


        ArrayList columnList = new ArrayList();
        int i = 0;

        if (fieldDescriptors != null)
        {
            FieldDescriptor field = null;
            for (int j = 0; j < fieldDescriptorLength; j++)
            {
                field = fieldDescriptors[j];
                if (i > 0)
                {
                    buf.append(",");
                }
                buf.append(getSearchTable().alias);
                buf.append(".");
                buf.append(field.getColumnName());
                columnList.add(field.getAttributeName());
                i++;
            }
        }
        return columnList;
    }
View Full Code Here

            where.append(" AND ");
        }
        // get reference field in super class
        // TODO: do not use the superclassfield anymore, just assume that the id is the same in both tables - @see PBroker.storeToDb
        int superFieldRef = cld.getSuperClassFieldRef();
        FieldDescriptor refField = cld.getFieldDescriptorByIndex(superFieldRef);
        where.append(cldSuper.getFullTableName()).append(".").append(
                cldSuper.getAutoIncrementFields()[0].getColumnName());
        where.append(" = ");
        where.append(cld.getFullTableName()).append(".").append(refField.getColumnName());

    }
View Full Code Here

    private void appendSuperClassColumns(ClassDescriptor cldSub, ClassDescriptor cldSuper, StringBuffer buf)
    {
        FieldDescriptor[] fields = cldSuper.getFieldDescriptions();
        for (int i = 0; i < fields.length; i++)
        {
            FieldDescriptor field = fields[i];
            if (i > 0)
            {
                buf.append(",");
            }
            buf.append(cldSuper.getFullTableName());
            buf.append(".");
            buf.append(field.getColumnName());
            //columnList.add(field.getAttributeName());

        }

    }
View Full Code Here

     * @param translate
     * @return
     */
    protected String getColName(TableAlias aTableAlias, PathInfo aPathInfo, boolean translate)
    {
        FieldDescriptor fld = null;
        String result = null;

        if (translate)
        {
            // translate attribute name into column name
            fld = getFieldDescriptor(aTableAlias, aPathInfo);

            if (fld != null)
            {
                // added to suport the super reference descriptor
                if (!fld.getClassDescriptor().getFullTableName().equals(aTableAlias.table) && aTableAlias.hasJoins())
                {
                    Iterator itr = aTableAlias.joins.iterator();
                    while (itr.hasNext())
                    {
                        Join join = (Join) itr.next();
                        if (join.right.table.equals(fld.getClassDescriptor().getFullTableName()))
                        {
                            result = join.right.alias + "." + fld.getColumnName();
                            break;
                        }
                    }

                    if (result == null)
                    {
                        result = aPathInfo.column;
                    }
                }
                else
                {
                    result = aTableAlias.alias + "." + fld.getColumnName();
                }
            }
            else if ("*".equals(aPathInfo.column))
            {
                result = aPathInfo.column;
View Full Code Here

     */
    public static long getMaxIdForClass(
            PersistenceBroker brokerForClass, ClassDescriptor cldForOriginalOrExtent, FieldDescriptor original)
            throws PersistenceBrokerException
    {
        FieldDescriptor field = null;
        if (!original.getClassDescriptor().equals(cldForOriginalOrExtent))
        {
            // check if extent match not the same table
            if (!original.getClassDescriptor().getFullTableName().equals(
                    cldForOriginalOrExtent.getFullTableName()))
            {
                // we have to look for id's in extent class table
                field = cldForOriginalOrExtent.getFieldDescriptorByName(original.getAttributeName());
            }
        }
        else
        {
            field = original;
        }
        if (field == null)
        {
            // if null skip this call
            return 0;
        }

        String column = field.getColumnName();
        long result = 0;
        ResultSet rs = null;
        Statement stmt = null;
        String table = cldForOriginalOrExtent.getFullTableName();
        // String column = cld.getFieldDescriptorByName(fieldName).getColumnName();
View Full Code Here

     * @param aPathInfo
     * @return FieldDescriptor
     */
    protected FieldDescriptor getFieldDescriptor(TableAlias aTableAlias, PathInfo aPathInfo)
    {
        FieldDescriptor fld = null;
        String colName = aPathInfo.column;

        if (aTableAlias != null)
        {
            fld = aTableAlias.cld.getFieldDescriptorByName(colName);
View Full Code Here

     * @param aColName
     * @return
     */
    private FieldDescriptor getFldFromJoin(TableAlias aTableAlias, String aColName)
    {
        FieldDescriptor fld = null;

        // Search Join Structure for attribute
        if (aTableAlias.joins != null)
        {
            Iterator itr = aTableAlias.joins.iterator();
View Full Code Here

     * @param anOrd
     * @return
     */
    private FieldDescriptor getFldFromReference(TableAlias aTableAlias, ObjectReferenceDescriptor anOrd)
    {
        FieldDescriptor fld = null;

        if (aTableAlias == getRoot())
        {
            // no path expression
            FieldDescriptor[] fk = anOrd.getForeignKeyFieldDescriptors(aTableAlias.cld);
View Full Code Here

                            }
                            // provide all items in collection attributes
                            // with foreign key information before locking them!
                            for (int j = 0; j < itemFkFields.length; j++)
                            {
                                FieldDescriptor fld = itemFkFields[j];
                                fld.getPersistentField().set(item, objPkValues[j].getValue());
                            }
                        }
                        lock(item, lockMode);
                    }
                }
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.