• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java TransactionDemarcation类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中atg.dtm.TransactionDemarcation的典型用法代码示例。如果您正苦于以下问题:Java TransactionDemarcation类的具体用法?Java TransactionDemarcation怎么用?Java TransactionDemarcation使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



TransactionDemarcation类属于atg.dtm包,在下文中一共展示了TransactionDemarcation类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: executeSQL

import atg.dtm.TransactionDemarcation; //导入依赖的package包/类
/**
 * Perform the specified SQL statement in a new transaction which is committed.  Autocommit
 * on the connection is set to true if isSetAutoCommit() is true.
 *
 * @param pSQL SQL to execute
 *
 * @throws SQLException if there is DB problem
 * @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();
    }
}
 
开发者ID:jvz,项目名称:dynunit,代码行数:38,代码来源:SQLProcessor.java


示例2: executeQuery

import atg.dtm.TransactionDemarcation; //导入依赖的package包/类
/**
 * executes the specified query and returns a List of values for the specified column name.
 * for example, executeQuery( "select * from user", "first_name" ) would return a List of
 * the first names of all entries in the user table.
 *
 * @return List of Object values
 * @throws SQLException if a sql error occurs
 * @throws TransactionDemarcationException
 *                      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;
}
 
开发者ID:jvz,项目名称:dynunit,代码行数:44,代码来源:SQLProcessor.java


示例3: songsRepositoryTest

import atg.dtm.TransactionDemarcation; //导入依赖的package包/类
private void songsRepositoryTest()
        throws TransactionDemarcationException, RepositoryException, IOException {
    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);
    }
}
 
开发者ID:jvz,项目名称:dynunit,代码行数:31,代码来源:SongsRepositoryTest.java


示例4: performSQL

import atg.dtm.TransactionDemarcation; //导入依赖的package包/类
/**
 * Perform the specified SQL statement in a new transaction which is committed.
 *
 * @param pSQL SQL to execute
 *
 * @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);
            }
        }
    }

    if ( error != null ) {
        throw error;
    } else {
        return rows;
    }
}
 
开发者ID:jvz,项目名称:dynunit,代码行数:62,代码来源:SQLProcessorEngine.java


示例5: testSimple

import atg.dtm.TransactionDemarcation; //导入依赖的package包/类
public void testSimple()
        throws Exception {

    // setup the repository
    File configpath = new File(
            "target/test-classes/config".replace(
                    "/", File.separator
            )
    );

    // Define the path to our repository definition file called
    // "simpleRepository.xml"
    final String[] definitionFiles = { "/test/simpleRepository.xml" };
    log.info("definitionFile[0]={}", definitionFiles[0]);

    // Copy all related properties and definition files to the previously
    // configured configpath
    FileUtil.copyDirectory(
            "src/test/resources/config",
            configpath.getPath(),
            Arrays.asList(".svn")
    );

    // Use the DBUtils utility class to get JDBC properties for an in memory
    // HSQL DB called "testdb".
    Properties props = DBUtils.getHSQLDBInMemoryDBConnection("testdb");

    // Start up our database
    DBUtils db = initDB(props);

    boolean rollback = true;

    // Setup our testing configpath
    // RH: disabled logging (last argument to false) to get rid of the double
    // logging statements
    GSATestUtils.getGSATestUtils().initializeMinimalConfigpath(
            configpath, "/SimpleRepository", definitionFiles, props, null, null, null, false
    );

    // 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();
    }
}
 
开发者ID:jvz,项目名称:dynunit,代码行数:70,代码来源:SimpleRepositoryTest.java



注:本文中的atg.dtm.TransactionDemarcation类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java LockException类代码示例发布时间:2022-05-16
下一篇:
Java PropertyAdapter类代码示例发布时间:2022-05-16
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap