本文整理汇总了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();
}
}
示例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;
}
示例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);
}
}
示例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;
}
}
示例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();
}
}