You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cayenne.apache.org by "Lucas Holt (Created) (JIRA)" <ji...@apache.org> on 2012/02/03 17:15:54 UTC

[jira] [Created] (CAY-1661) Ingres interactions with transactions

Ingres interactions with transactions
-------------------------------------

                 Key: CAY-1661
                 URL: https://issues.apache.org/jira/browse/CAY-1661
             Project: Cayenne
          Issue Type: Bug
          Components: Database integration
    Affects Versions: 3.0.2
         Environment: Ingres 10 64 bit for Linux, client is freebsd 9 with openjdk 6, cayenne 3.0.2
            Reporter: Lucas Holt
            Priority: Minor


I've written some code to insert new records using a SQLTemplate (as I can't use new object, see other bug)  and noticed that I must explicitly create a new transaction in order for the code to work.  The code block starts with a result iterator and if i do not explicitly create transactions inside the loop, the program terminates early with the result iterator after about 24 rows (there are over a million).

Ingres doesn't have auto commit by default and I'm wondering if this is the problem.  (Even select's need commit)  

The insert piece is just a normal sqltemplate call on the same thread.  I'll include the code below that loops:

   public void generate() throws CayenneException, ServiceException {
        DataContext context;
        context = (DataContext) BaseContext.getThreadObjectContext(); 

        context.setValidatingObjectsOnCommit(false);
        DataDomain domain = Configuration.getSharedConfiguration().getDomain();

        SelectQuery query;
        Expression qualifier;
        
        if (!update) {
            qualifier = Expression.fromString("variationMeta+.lastName = $vm and msnNameVarList.indivId > 0");
            HashMap<String, String> map = new HashMap<String, String>();
            map.put("vm", null);
            qualifier = qualifier.expWithParameters(map);
        } else {
            qualifier = Expression.fromString("msnNameVarList.indivId > 0");
        }
         query = new SelectQuery(MsnVariation.class, qualifier);

        query.setStatementFetchSize(1000);
        query.setCacheStrategy(QueryCacheStrategy.NO_CACHE);

        ResultIterator it = context.performIteratedQuery(query);

        try {
            while (it.hasNextRow()) {
                Transaction tx = domain.createTransaction();
                Transaction.bindThreadTransaction(tx);
                tx.setStatus(Transaction.STATUS_ACTIVE);

                try {
                    MsnVariation variation = context.objectFromDataRow(MsnVariation.class, (DataRow) it.nextRow(), false);
                    if (variation == null) {
                        log.error("variation is null?");
                        continue;
                    }
                    if (verbose) {
                        System.out.println("Var: " + DataObjectUtils.intPKForObject(variation) + ": " + variation.getNameTxt());
                    }

                    if (variation.getVariationMeta() == null) {
                        variationService.createMeta(variation);
                    } else if (update) {
                        variationService.updateMeta(variation);
                    }
                    tx.commit();
                } catch (Exception ex) {
                    log.error(ex);
                    tx.setRollbackOnly();
                } finally {
                    if (tx.getStatus() == Transaction.STATUS_MARKED_ROLLEDBACK) {
                        try {
                            tx.rollback();
                        } catch (Exception rollbackEx) {
                        }
                    }
                }
            }
        } catch (Exception s) {
            log.error(s);
        } finally {
            try {
                // explicit closing of the iterator is required !!!
                it.close();
            } catch (CayenneException closeEx) {
                log.error(closeEx);
            }
        }
    }

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Closed] (CAY-1661) Ingres interactions with transactions

Posted by "Andrus Adamchik (Closed) (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/CAY-1661?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Andrus Adamchik closed CAY-1661.
--------------------------------

    Resolution: Won't Fix

Closing. Please reopen if there is still an indication that this is a Cayenne problem.
                
> Ingres interactions with transactions
> -------------------------------------
>
>                 Key: CAY-1661
>                 URL: https://issues.apache.org/jira/browse/CAY-1661
>             Project: Cayenne
>          Issue Type: Bug
>          Components: Database integration
>    Affects Versions: 3.0.2
>         Environment: Ingres 10 64 bit for Linux, client is freebsd 9 with openjdk 6, cayenne 3.0.2
>            Reporter: Lucas Holt
>            Priority: Minor
>
> I've written some code to insert new records using a SQLTemplate (as I can't use new object, see other bug)  and noticed that I must explicitly create a new transaction in order for the code to work.  The code block starts with a result iterator and if i do not explicitly create transactions inside the loop, the program terminates early with the result iterator after about 24 rows (there are over a million).
> Ingres doesn't have auto commit by default and I'm wondering if this is the problem.  (Even select's need commit)  
> The insert piece is just a normal sqltemplate call on the same thread.  I'll include the code below that loops:
>    public void generate() throws CayenneException, ServiceException {
>         DataContext context;
>         context = (DataContext) BaseContext.getThreadObjectContext(); 
>         context.setValidatingObjectsOnCommit(false);
>         DataDomain domain = Configuration.getSharedConfiguration().getDomain();
>         SelectQuery query;
>         Expression qualifier;
>         
>         if (!update) {
>             qualifier = Expression.fromString("variationMeta+.lastName = $vm and msnNameVarList.indivId > 0");
>             HashMap<String, String> map = new HashMap<String, String>();
>             map.put("vm", null);
>             qualifier = qualifier.expWithParameters(map);
>         } else {
>             qualifier = Expression.fromString("msnNameVarList.indivId > 0");
>         }
>          query = new SelectQuery(MsnVariation.class, qualifier);
>         query.setStatementFetchSize(1000);
>         query.setCacheStrategy(QueryCacheStrategy.NO_CACHE);
>         ResultIterator it = context.performIteratedQuery(query);
>         try {
>             while (it.hasNextRow()) {
>                 Transaction tx = domain.createTransaction();
>                 Transaction.bindThreadTransaction(tx);
>                 tx.setStatus(Transaction.STATUS_ACTIVE);
>                 try {
>                     MsnVariation variation = context.objectFromDataRow(MsnVariation.class, (DataRow) it.nextRow(), false);
>                     if (variation == null) {
>                         log.error("variation is null?");
>                         continue;
>                     }
>                     if (verbose) {
>                         System.out.println("Var: " + DataObjectUtils.intPKForObject(variation) + ": " + variation.getNameTxt());
>                     }
>                     if (variation.getVariationMeta() == null) {
>                         variationService.createMeta(variation);
>                     } else if (update) {
>                         variationService.updateMeta(variation);
>                     }
>                     tx.commit();
>                 } catch (Exception ex) {
>                     log.error(ex);
>                     tx.setRollbackOnly();
>                 } finally {
>                     if (tx.getStatus() == Transaction.STATUS_MARKED_ROLLEDBACK) {
>                         try {
>                             tx.rollback();
>                         } catch (Exception rollbackEx) {
>                         }
>                     }
>                 }
>             }
>         } catch (Exception s) {
>             log.error(s);
>         } finally {
>             try {
>                 // explicit closing of the iterator is required !!!
>                 it.close();
>             } catch (CayenneException closeEx) {
>                 log.error(closeEx);
>             }
>         }
>     }

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

[jira] [Commented] (CAY-1661) Ingres interactions with transactions

Posted by "Andrus Adamchik (Commented) (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/CAY-1661?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13211700#comment-13211700 ] 

Andrus Adamchik commented on CAY-1661:
--------------------------------------

An iterated query is executed within a tx , that is bound to the current thread until the iterator is closed. Auto-commit is set to false by Cayenne. So without a manual transaction your code commits over the same Connection as the SELECT in-progress. That probably causes the issue with Ingres. Maybe Keith from Ingres can comment on this one? Otherwise it seems to me that creating a separate TX is appropriate. (Maybe close the SELECT tx as well though).
                
> Ingres interactions with transactions
> -------------------------------------
>
>                 Key: CAY-1661
>                 URL: https://issues.apache.org/jira/browse/CAY-1661
>             Project: Cayenne
>          Issue Type: Bug
>          Components: Database integration
>    Affects Versions: 3.0.2
>         Environment: Ingres 10 64 bit for Linux, client is freebsd 9 with openjdk 6, cayenne 3.0.2
>            Reporter: Lucas Holt
>            Priority: Minor
>
> I've written some code to insert new records using a SQLTemplate (as I can't use new object, see other bug)  and noticed that I must explicitly create a new transaction in order for the code to work.  The code block starts with a result iterator and if i do not explicitly create transactions inside the loop, the program terminates early with the result iterator after about 24 rows (there are over a million).
> Ingres doesn't have auto commit by default and I'm wondering if this is the problem.  (Even select's need commit)  
> The insert piece is just a normal sqltemplate call on the same thread.  I'll include the code below that loops:
>    public void generate() throws CayenneException, ServiceException {
>         DataContext context;
>         context = (DataContext) BaseContext.getThreadObjectContext(); 
>         context.setValidatingObjectsOnCommit(false);
>         DataDomain domain = Configuration.getSharedConfiguration().getDomain();
>         SelectQuery query;
>         Expression qualifier;
>         
>         if (!update) {
>             qualifier = Expression.fromString("variationMeta+.lastName = $vm and msnNameVarList.indivId > 0");
>             HashMap<String, String> map = new HashMap<String, String>();
>             map.put("vm", null);
>             qualifier = qualifier.expWithParameters(map);
>         } else {
>             qualifier = Expression.fromString("msnNameVarList.indivId > 0");
>         }
>          query = new SelectQuery(MsnVariation.class, qualifier);
>         query.setStatementFetchSize(1000);
>         query.setCacheStrategy(QueryCacheStrategy.NO_CACHE);
>         ResultIterator it = context.performIteratedQuery(query);
>         try {
>             while (it.hasNextRow()) {
>                 Transaction tx = domain.createTransaction();
>                 Transaction.bindThreadTransaction(tx);
>                 tx.setStatus(Transaction.STATUS_ACTIVE);
>                 try {
>                     MsnVariation variation = context.objectFromDataRow(MsnVariation.class, (DataRow) it.nextRow(), false);
>                     if (variation == null) {
>                         log.error("variation is null?");
>                         continue;
>                     }
>                     if (verbose) {
>                         System.out.println("Var: " + DataObjectUtils.intPKForObject(variation) + ": " + variation.getNameTxt());
>                     }
>                     if (variation.getVariationMeta() == null) {
>                         variationService.createMeta(variation);
>                     } else if (update) {
>                         variationService.updateMeta(variation);
>                     }
>                     tx.commit();
>                 } catch (Exception ex) {
>                     log.error(ex);
>                     tx.setRollbackOnly();
>                 } finally {
>                     if (tx.getStatus() == Transaction.STATUS_MARKED_ROLLEDBACK) {
>                         try {
>                             tx.rollback();
>                         } catch (Exception rollbackEx) {
>                         }
>                     }
>                 }
>             }
>         } catch (Exception s) {
>             log.error(s);
>         } finally {
>             try {
>                 // explicit closing of the iterator is required !!!
>                 it.close();
>             } catch (CayenneException closeEx) {
>                 log.error(closeEx);
>             }
>         }
>     }

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira