Package org.apache.ojb.otm

Examples of org.apache.ojb.otm.OTMConnection


    /**
     * @see org.apache.ojb.otm.transaction.TransactionFactory#acquireConnection(PBKey)
     */
    public OTMConnection acquireConnection (PBKey pbKey)
    {
        OTMConnection newConnection = new LocalConnection(pbKey);
        // Ensure the transaction is established for this connection.
        getTransactionForConnection(newConnection);
        return newConnection;
    }
View Full Code Here


     * @param product The product to store
     */
    public static void storeProduct(Product product) throws LockingException
    {
        OTMKit        kit  = SimpleKit.getInstance();
        OTMConnection conn = null;
        Transaction   tx   = null;

        try
        {
            conn = kit.acquireConnection(PersistenceBrokerFactory.getDefaultKey());
            tx   = kit.getTransaction(conn);

            tx.begin();

            conn.makePersistent(product);

            tx.commit();
        }
        catch (LockingException ex)
        {
            if (tx.isInProgress())
            {
                tx.rollback();
            }
            throw ex;
        }
        finally
        {
            conn.close();
        }
    }
View Full Code Here

     * @param product The product to remove
     */
    public static void removeProduct(Product product) throws LockingException
    {
        OTMKit        kit  = SimpleKit.getInstance();
        OTMConnection conn = null;
        Transaction   tx   = null;

        try
        {
            conn = kit.acquireConnection(PersistenceBrokerFactory.getDefaultKey());
            tx   = kit.getTransaction(conn);

            tx.begin();

            conn.deletePersistent(product);

            tx.commit();
        }
        catch (LockingException ex)
        {
            if (tx.isInProgress())
            {
                tx.rollback();
            }
            throw ex;
        }
        finally
        {
            conn.close();
        }
    }
View Full Code Here

     * @return The iterator
     */
    public Iterator findByCriteria(Query query)
    {
        OTMKit        kit  = SimpleKit.getInstance();
        OTMConnection conn = null;
        Transaction   tx   = null;
        try
        {
            conn = kit.acquireConnection(PersistenceBrokerFactory.getDefaultKey());
            tx   = kit.getTransaction(conn);

            tx.begin();

            Iterator results = conn.getIteratorByQuery(query);

            tx.commit();

            return results;
        }
        finally
        {
            conn.close();
        }
    }
View Full Code Here

     * @return The iterator
     */
    public Iterator findByCriteriaWithLock(Query query, int lock)
    {
        OTMKit        kit  = SimpleKit.getInstance();
        OTMConnection conn = null;
        Transaction   tx   = null;
        try
        {
            conn = kit.acquireConnection(PersistenceBrokerFactory.getDefaultKey());
            tx   = kit.getTransaction(conn);

            tx.begin();

            Iterator results = conn.getIteratorByQuery(query, lock);

            tx.commit();

            return results;
        }
        finally
        {
            conn.close();
        }
    }
View Full Code Here

     * @return The iterator
     */
    public Iterator findByOQL(String query, Object[] queryParams) throws Exception
    {
        OTMKit        kit  = SimpleKit.getInstance();
        OTMConnection conn = null;
        Transaction   tx   = null;

        try
        {
            conn = kit.acquireConnection(PersistenceBrokerFactory.getDefaultKey());
            tx   = kit.getTransaction(conn);

            OQLQuery oql = conn.newOQLQuery();

            oql.create(query);

            if (queryParams != null)
            {
                for (int idx = 0; idx < queryParams.length; ++idx)
                {
                    oql.bind(queryParams[idx]);
                }
            }

            tx.begin();

            Iterator results = conn.getIteratorByOQLQuery(oql);

            tx.commit();

            return results;
        }
        catch (QueryInvalidException ex)
        {
            if (tx.isInProgress())
            {
                tx.rollback();
            }
            throw new Exception("Invalid OQl expression given");
        }
        catch (QueryParameterCountInvalidException ex)
        {
            if (tx.isInProgress())
            {
                tx.rollback();
            }
            throw new Exception("Incorrect number of bindings given");
        }
        catch (QueryParameterTypeInvalidException ex)
        {
            if (tx.isInProgress())
            {
                tx.rollback();
            }
            throw new Exception("Incorrect type of object given as binding");
        }
        finally
        {
            conn.close();
        }
    }
View Full Code Here

     * @return The iterator
     */
    public Iterator moreRealisticQueryByCriteria(Query query, int lock)
    {
        OTMKit        kit  = SimpleKit.getInstance();
        OTMConnection conn = null;
        Transaction   tx   = null;
        try
        {
            conn = kit.acquireConnection(PersistenceBrokerFactory.getDefaultKey());
            tx   = kit.getTransaction(conn);

            boolean auto = !tx.isInProgress();

            if (auto)
            {
                tx.begin();
            }

            Iterator results = conn.getIteratorByQuery(query, lock);

            if (auto)
            {
                tx.commit();
            }

            return results;
        }
        finally
        {
            conn.close();
        }
    }
View Full Code Here

     * Sample method that renames all product with a specific name.
     */
    public void renameWidgetExample()
    {
        OTMKit        kit  = SimpleKit.getInstance();
        OTMConnection conn = null;
        Transaction   tx   = null;

        try
        {
            conn = kit.acquireConnection(PersistenceBrokerFactory.getDefaultKey());
            tx   = kit.getTransaction(conn);

            tx.begin();

            Product sample = new Product();

            sample.setName("Wonder Widget");

            Query    query         = QueryFactory.newQueryByExample(sample);
            Iterator wonderWidgets = moreRealisticQueryByCriteria(query, LockType.WRITE_LOCK);

            while (wonderWidgets.hasNext())
            {
                Product widget = (Product)wonderWidgets.next();

                widget.setName("Improved Wonder Widget");
            }

            tx.commit();
        }
        finally
        {
            conn.close();
        }
    }
View Full Code Here

    Util.log("In OTMJCAManagedConnectionFactory.createManagedConnection");
    try
    {
      Kit kit = getKit();
      PBKey key = ((OTMConnectionRequestInfo) info).getPbKey();
      OTMConnection connection = kit.acquireConnection(key);
      return new OTMJCAManagedConnection(this, connection, key);
    }
    catch (ResourceException e)
    {
      throw new OTMConnectionRuntimeException(e.getMessage());
View Full Code Here

     * @param product The product to store
     */
    public static void storeProduct(Product product) throws LockingException
    {
        OTMKit        kit  = SimpleKit.getInstance();
        OTMConnection conn = null;
        Transaction   tx   = null;

        try
        {
            conn = kit.acquireConnection(PersistenceBrokerFactory.getDefaultKey());
            tx   = kit.getTransaction(conn);

            tx.begin();

            conn.makePersistent(product);

            tx.commit();
        }
        catch (LockingException ex)
        {
            if (tx.isInProgress())
            {
                tx.rollback();
            }
            throw ex;
        }
        finally
        {
            conn.close();
        }
    }
View Full Code Here

TOP

Related Classes of org.apache.ojb.otm.OTMConnection

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.