Package org.apache.ojb.broker.metadata

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


        super(broker);
    }

    public void afterStore(JdbcAccess dbAccess, ClassDescriptor cld, Object obj) throws SequenceManagerException
    {
        FieldDescriptor identityField = extractIdentityColumnField(cld);
        if(identityField != null)
        {
            ifNotReadOnlyFail(identityField);
            long newId = getLastInsert(cld, identityField);
            setFieldValue(obj, identityField, new Long(newId));
View Full Code Here


        if (cld.getFieldDescriptions() != null)
        {
            it = new ArrayIterator(cld.getFieldDescriptions());
            while (it.hasNext())
            {
                FieldDescriptor fieldDesc = (FieldDescriptor)it.next();
                newChildren.add(new OjbMetaFieldDescriptorNode(
                        this.getOjbMetaTreeModel().getRepository(),
                        this.getOjbMetaTreeModel(),
                        this,
                        fieldDesc));
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

        // an unmaterialized proxy object can never have nullified PK's
        IndirectionHandler handler = ProxyHelper.getIndirectionHandler(obj);
        if(handler == null || handler.alreadyMaterialized())
        {
            if(handler != null) obj = handler.getRealSubject();
            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

    {
        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(assignAutoincrement && 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);
            }
            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

    public boolean assertValidPksForStore(FieldDescriptor[] fieldDescriptors, Object[] pkValues)
    {
        int fieldDescriptorSize = fieldDescriptors.length;
        for(int i = 0; i < fieldDescriptorSize; i++)
        {
            FieldDescriptor fld = fieldDescriptors[i];
            /**
             * a pk field is valid if it is either managed by OJB
             * (autoincrement or locking) or if it does contain a
             * valid non-null value.
             */
            if(!(fld.isAutoIncrement()
                    || fld.isLocking()
                    || !representsNull(fld, pkValues[i])))
            {
                return false;
            }
        }
View Full Code Here

     */
    public boolean assertValidPkForDelete(ClassDescriptor cld, Object obj)
    {
        if(!ProxyHelper.isProxy(obj))
        {
            FieldDescriptor fieldDescriptors[] = cld.getPkFields();
            int fieldDescriptorSize = fieldDescriptors.length;
            for(int i = 0; i < fieldDescriptorSize; i++)
            {
                FieldDescriptor fd = fieldDescriptors[i];
                Object pkValue = fd.getPersistentField().get(obj);
                if (representsNull(fd, pkValue))
                {
                    return false;
                }
            }
View Full Code Here

    {
        boolean result = false;
        FieldDescriptor[] fkFields = rds.getForeignKeyFieldDescriptors(cld);
        for(int i = 0; i < fkFields.length; i++)
        {
            FieldDescriptor fkField = fkFields[i];
            if(fkField.isAnonymous())
            {
                result = true;
                break;
            }
        }
View Full Code Here

    private static Collection getExtentClasses(ClassDescriptor cld)
    {
        /**
         * 1. check if this class has a ojbConcreteClass attribute
         */
        FieldDescriptor fd = cld.getFieldDescriptorByName(ClassDescriptor.OJB_CONCRETE_CLASS);
        Collection classes = new HashSet()// use same class only once
        if (fd != null)
        {
            classes.add(cld.getClassOfObject().getName());
        }
View Full Code Here

     * @throws SQLException
     */
    private int bindStatementValue(PreparedStatement stmt, int index, Object attributeOrQuery, Object value, ClassDescriptor cld)
            throws SQLException
    {
        FieldDescriptor fld = null;
        // if value is a subQuery bind it
        if (value instanceof Query)
        {
            Query subQuery = (Query) value;
            return bindStatement(stmt, subQuery, cld.getRepository().getDescriptorFor(subQuery.getSearchClass()), index);
        }

        // if attribute is a subQuery bind it
        if (attributeOrQuery instanceof Query)
        {
            Query subQuery = (Query) attributeOrQuery;
            bindStatement(stmt, subQuery, cld.getRepository().getDescriptorFor(subQuery.getSearchClass()), index);
        }
        else
        {
            fld = cld.getFieldDescriptorForPath((String) attributeOrQuery);
        }

        if (fld != null)
        {
            // BRJ: use field conversions and platform
            if (value != null)
            {
                m_platform.setObjectForStatement(stmt, index, fld.getFieldConversion().javaToSql(value), fld.getJdbcType().getType());
            }
            else
            {
                m_platform.setNullForStatement(stmt, index, fld.getJdbcType().getType());
            }
        }
        else
        {
            if (value != null)
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.