Hi Stefan,

> When I use PBCapsule() in J2EE environment, I get the
ClassCastException at
> broker = ((HasBroker) tx).getBroker();.
> tx is instance of NarrowTransaction.
>
> Is there a good description how to use OJB in JBOSS with scenario ->
using
> PB fetched from ODMG ( as it is implemented in OQLQuery.execute() ), I
want
> to use PB query stuff, especially "example" object.

Currently there is no 'offical' way to do that. PBCapsule was only a
intern helper class, don't use this class in your code.
Matthew and Rahgu working on the JBoss (J2EE) integration of OJB,
therefore the intern code of the J2EE integration for OJB is
under construction.

You could replace NarrowTransaction by a extended version of
NarrowTransaction by implementing the HasBroker interface (source code
see below). Then it's possible for you to use PB in the following way:

tx = Implementation.currentTransaction();
broker = ((HasBroker) tx).getBroker();

Don't close this broker after usage!
But keep in mind that this could change in further versions of OJB.

regards,
Armin


public class NarrowTransaction implements Transaction, HasBroker
{
    private Transaction tx;

    public NarrowTransaction(Transaction tx)
    {
        this.tx = tx;
    }

    /**
     * Return associated PB instance, or null if not found.
     */
    public PersistenceBroker getBroker()
    {
        if(this.tx instanceof HasBroker)
        {
            return ((HasBroker)this.tx).getBroker();
        }
        return null;
    }

    /**
     * Not supported!!
     */
    public void join()
    {
        throw new UnsupportedOperationException("Not supported
operation");
    }

    /**
     * Not supported!!
     */
    public void leave()
    {
        throw new UnsupportedOperationException("Not supported
operation");
    }

    /**
     * Not supported!!
     */
    public void begin()
    {
        throw new UnsupportedOperationException("Not supported
operation");
    }

    /**
     * Not supported!!
     */
    public boolean isOpen()
    {
        return tx.isOpen();
    }

    /**
     * Not supported!!
     */
    public void commit()
    {
        throw new UnsupportedOperationException("Not supported
operation");
    }

    /**
     * Abort the underlying odmg-transaction
     */
    public void abort()
    {
        tx.abort();
    }

    /**
     * Not supported!!
     */
    public void checkpoint()
    {
        throw new UnsupportedOperationException("Not supported
operation");
    }

    /**
     * lock the given object
     * @see Transaction#lock
     */
    public void lock(Object obj, int lockMode)
            throws LockNotGrantedException
    {
        tx.lock(obj, lockMode);
    }

    /**
     * lock the given object if possible
     * @see Transaction#tryLock
     */
    public boolean tryLock(Object obj, int lockMode)
    {
        return tx.tryLock(obj, lockMode);
    }
}










>
> Thanx Stefan
>
>
>
> --
> To unsubscribe, e-mail:
<mailto:[EMAIL PROTECTED]>
> For additional commands, e-mail:
<mailto:[EMAIL PROTECTED]>
>
>
>


--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to