Package org.apache.ojb.broker.metadata

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


     * @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


    /**
     * Get FieldDescriptor from joined superclass.
     */
    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

     * 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 getBroker().serviceIdentity().buildIdentity(
                getQueryObject().getClassDescriptor().getClassOfObject(), getTopLevelClass(), pkValues);
View Full Code Here

    /**
     * Get FieldDescriptor from Reference
     */
    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

        FieldDescriptor[] fields = cod.getForeignKeyFieldDescriptors(refCld);
        Criteria criteria = new Criteria();

        for (int i = 0; i < fields.length; i++)
        {
            FieldDescriptor fld = fields[i];
            criteria.addEqualTo(fld.getAttributeName(), container[i].getValue());
        }

        return QueryFactory.newQuery(refCld.getClassOfObject(), criteria);
    }
View Full Code Here

        FieldDescriptor[] fields = cld.getPkFields();
        Criteria criteria = new Criteria();

        for (int i = 0; i < fields.length; i++)
        {
            FieldDescriptor fld = fields[i];
            criteria.addEqualTo(fld.getAttributeName(), values[i]);
        }
        return QueryFactory.newQuery(cld.getClassOfObject(), criteria);
    }
View Full Code Here

    {
        stmt.append(" WHERE ");

        for(int i = 0; i < fields.length; i++)
        {
            FieldDescriptor fmd = fields[i];

            stmt.append(fmd.getColumnName());
            stmt.append(" = ? ");
            if(i < fields.length - 1)
            {
                stmt.append(" AND ");
            }
View Full Code Here

            FieldDescriptor[] fieldDescriptors = cld.getPkFields();
            if(fieldDescriptors == null || fieldDescriptors.length == 0)
            {
                throw new OJBRuntimeException("No PK fields defined in metadata for " + cld.getClassNameOfObject());
            }
            FieldDescriptor field = fieldDescriptors[0];

            stmt.append(SELECT);
            stmt.append(field.getColumnName());
            stmt.append(FROM);
            stmt.append(cld.getFullTableName());
            appendWhereClause(cld, false, stmt);

            sql = stmt.toString();
View Full Code Here

    public void testSequenceNameAttribute() throws Exception
    {
        // sequence name used in the repository
        String fieldName = "stringKey";
        PersistenceBroker broker = PersistenceBrokerFactory.defaultPersistenceBroker();
        FieldDescriptor field = broker.getClassDescriptor(Repository.SMKey.class).getFieldDescriptorByName(fieldName);
        String result = SequenceManagerHelper.buildSequenceName(broker, field, true);

        assertEquals(TEST_SEQUENCE_NAME, result);
        broker.close();
    }
View Full Code Here

            // allow per thread changes of persistent object data
            mm.setEnablePerThreadChanges(true);
            DescriptorRepository dr = mm.copyOfGlobalRepository();
            ClassDescriptor cld = dr.getDescriptorFor(SMAutoNaming.class);
            FieldDescriptor field = cld.getAutoIncrementFields()[0];

            // set sequence name for persistent object to null
            field.setSequenceName(null);
            mm.setDescriptor(dr);

            broker = PersistenceBrokerFactory.createPersistenceBroker(tempKey);
            try
            {
                /*
                persistent object descriptor doesn't has a sequence name
                and autoNaming is false --> expect an exception
                */
                SMAutoNaming obj = new SMAutoNaming("testAutoNaming_1");
                sd = broker.serviceConnectionManager().getConnectionDescriptor().getSequenceDescriptor();
                assertTrue("false".equals(sd.getAttribute("autoNaming")));

                broker.beginTransaction();
                broker.store(obj);
                broker.commitTransaction();
                fail("If sequence manager implementation supports 'autoNaming' feature,"
                        +" this test should cause an exception (else ignore this failure).");
            }
            catch (PersistenceBrokerException e)
            {
                assertTrue(true);
                broker.abortTransaction();
            }

            try
            {
                /* attribute 'auto-naming' is still false,
                but now we set a sequence name for autoincrement field
                --> should pass
                */
                field.setSequenceName("AA_testAutoNaming_user_set");
                SMAutoNaming obj = new SMAutoNaming("testAutoNaming_2");
                broker.beginTransaction();
                broker.store(obj);
                broker.commitTransaction();
            }
            catch (PersistenceBrokerException e)
            {
                e.printStackTrace();
                broker.close();
                throw e;
            }

            try
            {
                // let OJB re-initialize sequence-manager
                broker.close();
                PersistenceBrokerFactory.releaseAllInstances();
                /*
                remove sequence name of autoincrement field
                but enable automatic sequence name generation
                --> should pass
                */
                field.setSequenceName(null);
                sd.addAttribute("autoNaming", "true");
                broker = PersistenceBrokerFactory.createPersistenceBroker(tempKey);
                SMAutoNaming obj = new SMAutoNaming("testAutoNaming_3");
                broker.beginTransaction();
                broker.store(obj);
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.