Package atg.dtm

Examples of atg.dtm.TransactionDemarcation


        GSARepository songsRepository = (GSARepository) resolveNucleusComponent(
                "/GettingStarted/SongsRepository"
        );
        assertNotNull(songsRepository);

        final TransactionDemarcation td = new TransactionDemarcation();
        assertNotNull(td);

        try {
            // Start a new transaction
            td.begin(songsRepository.getTransactionManager());
            // Create a new artist
            MutableRepositoryItem artist = songsRepository.createItem("artist");
            artist.setPropertyValue("name", "joe");
            // Persist to the repository
            songsRepository.addItem(artist);
            // Try to get it back from the repository
            String id = artist.getRepositoryId();
            RepositoryItem retrievedArtist = songsRepository.getItem(
                    id, "artist"
            );

            assertEquals(artist, retrievedArtist);
        } finally {
            // End the transaction, roll-back to restore original database state
            td.end(true);
        }
    }
View Full Code Here


        );

        // Start Nucleus
        Nucleus n = startNucleus(configpath);

        TransactionDemarcation td = new TransactionDemarcation();
        MutableRepository r = (MutableRepository) n.resolveName("/SimpleRepository");

        try {
            // Start a new transaction
            td.begin(((GSARepository) r).getTransactionManager());
            // Create the item
            MutableRepositoryItem item = r.createItem("simpleItem");
            item.setPropertyValue("name", "simpleName");
            // Persist to the repository
            r.addItem(item);
            // Try to get it back from the repository
            String id = item.getRepositoryId();
            RepositoryItem item2 = r.getItem(id, "simpleItem");
            assertNotNull(
                    " We did not get back the item just created from the repository.", item2
            );
            rollback = false;
        } finally {
            // End the transaction, rollback on error
            td.end(rollback);
            // shut down Nucleus
            n.stopService();
            // Shut down HSQLDB
            db.shutdown();
        }
View Full Code Here

     * @throws TransactionDemarcationException
     *                      if there is a tx problem
     */
    public void executeSQL(String pSQL)
            throws SQLException, TransactionDemarcationException {
        TransactionDemarcation td = new TransactionDemarcation();
        try {
            td.begin(getTransactionManager(), TransactionDemarcation.REQUIRES_NEW);
            Connection c = null;
            Statement s = null;
            try {
                // get DB connection
                c = getConnection();
                if ( isSetAutoCommit() ) {
                    c.setAutoCommit(true);
                }

                //most of this method is annoying try/catch/finally blocks
                //inflicted on us by JTA. the real work is here.
                s = c.createStatement();
                logger.debug("Executing SQL [{}]", pSQL);
                s.execute(pSQL);
            } finally {
                close(s);
                close(c);
            }
        } finally {
            td.end();
        }
    }
View Full Code Here

     *                      if a tx error occurs
     */
    public List<?> executeQuery(String pQuery, String pColumnName)
            throws SQLException, TransactionDemarcationException {
        List<Object> results = new LinkedList<Object>();
        TransactionDemarcation td = new TransactionDemarcation();
        //int rows = 0;
        try {
            td.begin(getTransactionManager(), TransactionDemarcation.REQUIRES_NEW);
            Connection c = null;
            Statement s = null;
            ResultSet rs = null;
            try {
                // get DB connection
                c = getConnection();

                //most of this method is annoying try/catch/finally blocks
                //inflicted on us by JTA. the real work is here.
                s = c.createStatement();
                logger.debug("Executing query [{}]", pQuery);
                rs = s.executeQuery(pQuery);

                while ( rs.next() ) {
                    results.add(rs.getObject(pColumnName));
                }
            } finally {
                close(rs);
                close(s);
                close(c);
            }
        } finally {
            td.end();
        }
        return results;
    }
View Full Code Here

     * @return the # of rows affected
     * @throws SQLProcessorException if there is DB or xact trouble
     */
    private int performSQL(String pSQL)
            throws SQLProcessorException {
        TransactionDemarcation td = new TransactionDemarcation();
        SQLProcessorException error = null;
        int rows = 0;
        try {
            td.begin(
                    mRepository.getTransactionManager(), TransactionDemarcation.REQUIRES_NEW
            );
            Connection c = null;
            Statement s = null;
            try {
                // get DB connection
                c = getConnection();

        /*
         * * most of this method is annoying try/catch/finally blocks* inflicted
         * on us by JTA. the real work is here.
         */
                s = c.createStatement();
                // rows = s.executeUpdate(pSQL);
                s.execute(pSQL);
            } catch ( SQLException sqle ) {
                error = new SQLProcessorException(sqle);
            } finally {
                close(s);
                close(c);
            }
        } catch ( TransactionDemarcationException e1 ) {
            // FIXME: yeah this doesn't work the way one might think
            if ( error == null ) {
                error = new SQLProcessorException(e1);
            } else if ( isLoggingError() ) {
                logError(e1);
            }
        } finally {
            try {
                td.end();
            } catch ( TransactionDemarcationException e2 ) {
                if ( error == null ) {
                    error = new SQLProcessorException(e2);
                } else if ( isLoggingError() ) {
                    logError(e2);
View Full Code Here

    private void executeSqlFiles(String[] pFiles, boolean pStopAtError)
            throws RepositoryException {
        // XXX: again with this bullshit
        SQLProcessor sp = new SQLProcessor(getTransactionManager(), getDataSource());
        boolean success = false;
        TransactionDemarcation td = new TransactionDemarcation();
        try {
            td.begin(
                    (TransactionManager) Nucleus.getGlobalNucleus().resolveName(
                            "/atg/dynamo/transaction/TransactionManager"
                    )
            );

            // for sql server auto-commit must be true
            // adamb: Hmm Marty added this, but it
            // breaks against MSSQL 8
            // if (getDatabaseType().equals(MICROSOFT))
            //  sp.setAutoCommit(true);
            SQLFileParser parser = new SQLFileParser();
            for (String file : pFiles) {
                // switch the file path so everything is forward slashes
                file = file.replace('\\', '/');
                String cmd;
                Iterator cmds;
                if (isLoggingInfo()) {
                    logInfo("Executing SQL file: " + file);
                }
                if (!new File(file).exists()) {
                    throw new RepositoryException("SQL file " + file + " does not exist.");
                }

                // parse the file to get commands...
                try {
                    Collection c = parser.parseSQLFile(file);
                    if (isLoggingDebug()) {
                        logDebug("Parsed " + c.size() + " SQL command(s) from file.");
                    }
                    cmds = c.iterator();
                } catch (Exception e) {
                    // an error parsing the file indicates something very wrong, so bail
                    throw new RepositoryException(
                            "Error encountered parsing SQL file " + file, e
                    );
                }

                // then execute the commands...
                while (cmds.hasNext()) {
                    cmd = (String) cmds.next();
                    if (cmd.trim().length() == 0) {
                        continue;
                    }
                    if (isLoggingDebug() || isLoggingCreateTables()) {
                        logDebug("Executing SQL cmd [" + cmd + "]");
                    }
                    try {
                        sp.executeSQL(cmd);
                    } catch (Exception e) {
                        if (pStopAtError) {
                            throw new RepositoryException(
                                    "Error received executing command ["
                                            + cmd
                                            + "] from SQL file "
                                            + file, e
                            );
                        }
                        else {
                            if (isLoggingWarning()) {
                                logWarning(
                                        "Error received executing command ["
                                                + cmd
                                                + "] from SQL file "
                                                + file
                                                + ": "
                                                + e.getMessage()
                                );
                            }
                        }
                    }
                }
            }
            success = true;
        } catch (TransactionDemarcationException e) {
            logError(e);
        } finally {
            try {
                td.end(!success);
            } catch (TransactionDemarcationException e) {
                logError(e);
            }
        }
    }
View Full Code Here

TOP

Related Classes of atg.dtm.TransactionDemarcation

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.