Example usage for org.springframework.transaction TransactionDefinition PROPAGATION_REQUIRED

List of usage examples for org.springframework.transaction TransactionDefinition PROPAGATION_REQUIRED

Introduction

In this page you can find the example usage for org.springframework.transaction TransactionDefinition PROPAGATION_REQUIRED.

Prototype

int PROPAGATION_REQUIRED

To view the source code for org.springframework.transaction TransactionDefinition PROPAGATION_REQUIRED.

Click Source Link

Document

Support a current transaction; create a new one if none exists.

Usage

From source file:com.krawler.spring.profileHandler.profileHandlerController.java

public ModelAndView changePassword(HttpServletRequest request, HttpServletResponse response)
        throws ServletException {
    JSONObject jobj = new JSONObject();
    KwlReturnObject kmsg = null;//ww  w. j a  va 2 s.c  om
    //Create transaction
    DefaultTransactionDefinition def = new DefaultTransactionDefinition();
    def.setName("JE_Tx");
    def.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
    def.setIsolationLevel(TransactionDefinition.ISOLATION_READ_UNCOMMITTED);
    TransactionStatus status = txnManager.getTransaction(def);
    try {
        //String platformURL = this.getServletContext().getInitParameter("platformURL");
        String platformURL = ConfigReader.getinstance().get("platformURL");
        HashMap<String, Object> requestParams = new HashMap<String, Object>();
        requestParams.put("currentpassword", StringUtil.checkForNull(request.getParameter("currentpassword")));
        requestParams.put("changepassword", StringUtil.checkForNull(request.getParameter("changepassword")));
        requestParams.put("platformURL", platformURL);
        requestParams.put("userid", sessionHandlerImpl.getUserid(request));
        requestParams.put("companyid", sessionHandlerImpl.getCompanyid(request));

        kmsg = profileHandlerDAOObj.changePassword(requestParams);
        jobj = (JSONObject) kmsg.getEntityList().get(0);
        jobj.put("success", kmsg.isSuccessFlag());
        txnManager.commit(status);
    } catch (Exception e) {
        logger.warn("General exception in changePassword()", e);
        txnManager.rollback(status);
    }
    return new ModelAndView("jsonView", "model", jobj.toString());
}

From source file:com.wakacommerce.common.util.StreamingTransactionCapableUtil.java

@Override
public <G extends Throwable> void runStreamingTransactionalOperation(
        final StreamCapableTransactionalOperation streamOperation, Class<G> exceptionType) throws G {
    runStreamingTransactionalOperation(streamOperation, exceptionType,
            TransactionDefinition.PROPAGATION_REQUIRED, TransactionDefinition.ISOLATION_DEFAULT);
}

From source file:com.wakacommerce.common.util.StreamingTransactionCapableUtil.java

@Override
public <G extends Throwable> void runTransactionalOperation(StreamCapableTransactionalOperation operation,
        Class<G> exceptionType) throws G {
    runTransactionalOperation(operation, exceptionType, TransactionDefinition.PROPAGATION_REQUIRED,
            TransactionDefinition.ISOLATION_DEFAULT);
}

From source file:com.wakacommerce.common.util.StreamingTransactionCapableUtil.java

@Override
public <G extends Throwable> void runOptionalTransactionalOperation(
        StreamCapableTransactionalOperation operation, Class<G> exceptionType, boolean useTransaction)
        throws G {
    runOptionalTransactionalOperation(operation, exceptionType, useTransaction,
            TransactionDefinition.PROPAGATION_REQUIRED, TransactionDefinition.ISOLATION_DEFAULT);
}

From source file:edu.ur.file.db.service.DefaultFileServerServiceTest.java

/**
 * Test File Database persistence/*from  ww  w .j av  a2 s .  com*/
 * 
 * - Make sure a file database can be created.
 * - Makes sure a file database can be found.
 * @throws LocationAlreadyExistsException 
 * 
 */
@Test
public void createFileDatabaseTest() throws LocationAlreadyExistsException {

    // Start the transaction this is for lazy loading
    TransactionDefinition td = new DefaultTransactionDefinition(TransactionDefinition.PROPAGATION_REQUIRED);
    TransactionStatus ts = tm.getTransaction(td);

    DefaultFileServer fs = dfss.createFileServer("service_file_server");

    DefaultFileDatabase fileDatabase = fs.createFileDatabase("nates file server", "file_server_1",
            properties.getProperty("defaultFileServerService.server_path"), "description");

    dfss.saveFileServer(fs);

    //commit the transaction this will assing an id to the 
    //file database
    tm.commit(ts);

    //begin a new transaction
    td = new DefaultTransactionDefinition(TransactionDefinition.PROPAGATION_REQUIRED);
    ts = tm.getTransaction(td);
    assert dfss.getDatabaseById(fileDatabase.getId(), false)
            .equals(fileDatabase) : "the databases should be equal";

    assert dfss.getDatabaseByName(fs.getId(),
            fileDatabase.getName()) != null : "should be able to find the file database";

    tm.commit(ts);

    dfss.deleteFileServer(fs.getName());
    assert dfss.getFileServer(fs.getName()) == null : "Should not find the file server";

}

From source file:edu.ur.file.db.service.DefaultFileServerServiceTest.java

/**
 * Test File Folder persistence/*from w w w.j a  va2 s  .  c om*/
 * 
 * - Make sure a file folder can be created.
 * - Makes sure a file folder can be found.
 * @throws LocationAlreadyExistsException 
 * 
 */
@Test
public void createFileFolderTest() throws LocationAlreadyExistsException {
    // Start the transaction this is for lazy loading
    TransactionDefinition td = new DefaultTransactionDefinition(TransactionDefinition.PROPAGATION_REQUIRED);
    TransactionStatus ts = tm.getTransaction(td);

    DefaultFileServer fs = dfss.createFileServer("service_file_server");

    DefaultFileDatabase fileDatabase = fs.createFileDatabase("nates file server", "file_server_1",
            properties.getProperty("defaultFileServerService.server_path"), "description");

    TreeFolderInfo treeFolderInfo = fileDatabase.createRootFolder("Nates Folder", "folder 1");

    dfss.saveFileServer(fs);

    //commit the transaction this will assing an id to the 
    //file database and folder information
    tm.commit(ts);

    //begin a new transaction
    td = new DefaultTransactionDefinition(TransactionDefinition.PROPAGATION_REQUIRED);
    ts = tm.getTransaction(td);

    assert dfss.getTreeFolderInfoById(treeFolderInfo.getId(), true)
            .equals(treeFolderInfo) : "The folder information should be the same";

    tm.commit(ts);

    dfss.deleteFileServer(fs.getName());
    assert dfss.getFileServer(fs.getName()) == null : "Should not find the file server";

}

From source file:edu.ur.file.db.service.DefaultFileServerServiceTest.java

/**
 * Test File persistence// w ww.  jav  a 2s.  c o  m
 * 
 * - Make sure a file can be created.
 * - Makes sure a file can be found.
 * @throws LocationAlreadyExistsException 
 * @throws IllegalFileSystemNameException 
 * 
 */
@Test
public void createFileTest() throws LocationAlreadyExistsException, IllegalFileSystemNameException {
    // Start the transaction this is for lazy loading
    TransactionDefinition td = new DefaultTransactionDefinition(TransactionDefinition.PROPAGATION_REQUIRED);
    TransactionStatus ts = tm.getTransaction(td);

    DefaultFileServer fs = dfss.createFileServer("service_file_server");

    DefaultFileDatabase fileDatabase = fs.createFileDatabase("nates file server", "file_server_1",
            properties.getProperty("defaultFileServerService.server_path"), "description");

    TreeFolderInfo treeFolderInfo = fileDatabase.createRootFolder("Nates Folder", "folder_1");
    assert fileDatabase
            .setCurrentFileStore(treeFolderInfo.getName()) : "Should be able to set current file store";

    dfss.saveFileServer(fs);

    //commit the transaction this will assing an id to the 
    //file database and folder information
    tm.commit(ts);

    //begin a new transaction
    td = new DefaultTransactionDefinition(TransactionDefinition.PROPAGATION_REQUIRED);
    ts = tm.getTransaction(td);
    // create the first file to store in the temporary folder
    String tempDirectory = properties.getProperty("file_db_temp_directory");
    File directory = new File(tempDirectory);

    // helper to create the file
    FileUtil testUtil = new FileUtil();
    testUtil.createDirectory(directory);

    File f = testUtil.creatFile(directory, "basicFile1", "Hello  -  This file is for equals 1");

    DefaultFileInfo info = dfss.addFile(fileDatabase, f, "file_service_file", "txt");

    // commit the transaction
    tm.commit(ts);

    //begin a new transaction
    td = new DefaultTransactionDefinition(TransactionDefinition.PROPAGATION_REQUIRED);
    ts = tm.getTransaction(td);

    DefaultFileInfo myInfo = (DefaultFileInfo) dfss.getFileById(info.getId(), false);

    assert myInfo.equals(info) : "The file information should be the same";

    assert myInfo.getFileInfoChecksums().size() >= 1 : "The file checksum should not be calculated size = "
            + myInfo.getFileInfoChecksums().size();

    assert dfss.findFile(info.getName()).equals(info) : "The file information should be the same";

    File myFile = new File(info.getFullPath());
    assert myFile.exists() : "File " + myFile.getAbsolutePath() + " should exist ";
    assert dfss.deleteFile(dfss.getFileById(info.getId(), false)) : "File " + info + " should be deleted";

    assert !myFile.exists() : "File " + myFile.getAbsolutePath() + " Should no longer exist";

    tm.commit(ts);

    dfss.deleteFileServer(fs.getName());
    assert dfss.getFileServer(fs.getName()) == null : "Should not find the file server";
}

From source file:edu.ur.file.db.service.DefaultFileServerServiceTest.java

/**
 * Test Empty File persistence/*ww  w .  j a  va 2s.  c o m*/
 * 
 * - Make sure an empty file can be created.
 * - Makes sure an empty file can be found.
 * @throws LocationAlreadyExistsException 
 * @throws IllegalFileSystemNameException 
 * 
 */
@Test
public void createEmptyFileTest() throws LocationAlreadyExistsException, IllegalFileSystemNameException {

    // Start the transaction this is for lazy loading
    TransactionDefinition td = new DefaultTransactionDefinition(TransactionDefinition.PROPAGATION_REQUIRED);
    TransactionStatus ts = tm.getTransaction(td);

    DefaultFileServer fs = dfss.createFileServer("service_file_server");

    DefaultFileDatabase fileDatabase = fs.createFileDatabase("nates file server", "file_server_1",
            properties.getProperty("defaultFileServerService.server_path"), "description");

    TreeFolderInfo treeFolderInfo = fileDatabase.createRootFolder("Nates Folder", "folder_1");
    assert fileDatabase
            .setCurrentFileStore(treeFolderInfo.getName()) : "Should be able to set current file store";

    dfss.saveFileServer(fs);

    //commit the transaction this will assing an id to the 
    //file database and folder information
    tm.commit(ts);

    //begin a new transaction
    td = new DefaultTransactionDefinition(TransactionDefinition.PROPAGATION_REQUIRED);
    ts = tm.getTransaction(td);

    DefaultFileInfo info = dfss.createEmptyFile(fileDatabase, "empty_file_service_file", "txt");
    // commit the transaction
    tm.commit(ts);

    //begin a new transaction
    td = new DefaultTransactionDefinition(TransactionDefinition.PROPAGATION_REQUIRED);
    ts = tm.getTransaction(td);

    assert dfss.getFileById(info.getId(), false).equals(info) : "The file information should be the same";

    assert dfss.findFile(info.getName()).equals(info) : "The file information should be the same";

    File myFile = new File(info.getFullPath());
    assert myFile.exists() : "File " + myFile.getAbsolutePath() + " should exist ";
    assert dfss.deleteFile(dfss.getFileById(info.getId(), false)) : "File " + info + " should be deleted";

    assert !myFile.exists() : "File " + myFile.getAbsolutePath() + " Should no longer exist";

    tm.commit(ts);

    dfss.deleteFileServer(fs.getName());
    assert dfss.getFileServer(fs.getName()) == null : "Should not find the file server";
}

From source file:edu.ur.file.db.service.DefaultFileServerServiceTest.java

/**
 * Test creating a folder.//from  ww w .  j  a  v  a 2 s.  co m
 * 
 * - Make sure a folder location can be created.
 * @throws LocationAlreadyExistsException 
 * 
 */
@Test
public void createFolderTest() throws LocationAlreadyExistsException {
    // Start the transaction this is for lazy loading
    TransactionDefinition td = new DefaultTransactionDefinition(TransactionDefinition.PROPAGATION_REQUIRED);
    TransactionStatus ts = tm.getTransaction(td);

    DefaultFileServer fs = dfss.createFileServer("service_file_server");

    DefaultFileDatabase fileDatabase = fs.createFileDatabase("nates file server", "file_server_1",
            properties.getProperty("defaultFileServerService.server_path"), "description");

    TreeFolderInfo treeFolderInfo = fileDatabase.createRootFolder("Nates Folder", "folder_1");
    assert fileDatabase
            .setCurrentFileStore(treeFolderInfo.getName()) : "Should be able to set current file store";

    dfss.saveFileServer(fs);
    //commit the transaction this will assigning an id to the 
    //file database and folder information
    tm.commit(ts);

    //begin a new transaction
    td = new DefaultTransactionDefinition(TransactionDefinition.PROPAGATION_REQUIRED);
    ts = tm.getTransaction(td);

    FolderInfo info = dfss.createFolder(fileDatabase, "a_folder_name");
    Long id = info.getId();

    URI uri = info.getUri();

    File f = new File(uri.getPath());

    assert f.exists() : "File " + f.getAbsolutePath() + " does not exist!";
    tm.commit(ts);

    //make sure the folder exists.
    //begin a new transaction
    td = new DefaultTransactionDefinition(TransactionDefinition.PROPAGATION_REQUIRED);
    ts = tm.getTransaction(td);

    info = dfss.getFolder(id, false);

    assert info != null : "folder info fo id " + id + " could not be found";

    dfss.deleteFolder(info);
    tm.commit(ts);

    //make sure the folder has been deleted.
    //begin a new transaction
    td = new DefaultTransactionDefinition(TransactionDefinition.PROPAGATION_REQUIRED);
    ts = tm.getTransaction(td);
    info = dfss.getFolder(id, false);
    assert info == null : "folder info fo id " + id + " was found and SHOULD NOT be";
    tm.commit(ts);

    dfss.deleteFileServer(fs.getName());

}

From source file:edu.ur.file.db.service.DefaultFileServerServiceTest.java

/**
 * Test MaxFilesFileStorage Strategy /*from  w w  w  .j a  va  2 s.  c  o m*/
 * 
 * - Make sure a new root folder is created when the max number of files
 * is reached.
 * @throws LocationAlreadyExistsException 
 * @throws IllegalFileSystemNameException 
 * 
 */
@Test
public void maxFilesStoreStrategy() throws LocationAlreadyExistsException, IllegalFileSystemNameException {
    // Start the transaction this is for lazy loading
    TransactionDefinition td = new DefaultTransactionDefinition(TransactionDefinition.PROPAGATION_REQUIRED);
    TransactionStatus ts = tm.getTransaction(td);

    DefaultFileServer fs = dfss.createFileServer("service_file_server");

    // set the store strategy to 1 and set it in the service
    maxFileStoreStrategy.setMaxNumberOfFilesPerFolder(1l);
    dfss.setDefaultDatabaseFileStoreStrategy(maxFileStoreStrategy);

    DefaultFileDatabase fileDatabase = fs.createFileDatabase("nates file server", "file_server_1",
            properties.getProperty("defaultFileServerService.server_path"), "description");

    TreeFolderInfo treeFolderInfo = fileDatabase.createRootFolder("Nates Folder", "folder_1");
    assert fileDatabase
            .setCurrentFileStore(treeFolderInfo.getName()) : "Should be able to set current file store";

    dfss.saveFileServer(fs);

    //commit the transaction this will assing an id to the 
    //file database and folder information
    tm.commit(ts);

    //begin a new transaction
    td = new DefaultTransactionDefinition(TransactionDefinition.PROPAGATION_REQUIRED);
    ts = tm.getTransaction(td);
    // create the first file to store in the temporary folder
    String tempDirectory = properties.getProperty("file_db_temp_directory");
    File directory = new File(tempDirectory);

    // helper to create the file
    FileUtil testUtil = new FileUtil();
    testUtil.createDirectory(directory);

    File f1 = testUtil.creatFile(directory, "basicFile1", "Hello  -  This file is for equals 1");
    File f2 = testUtil.creatFile(directory, "basicFile2", "Hello  -  This file is for equals 2");

    fileDatabase = dfss.getDatabaseById(fileDatabase.getId(), false);
    assert fileDatabase.getFullPath() != null : "Path for file database is null " + fileDatabase.getFullPath();
    TreeFolderInfo currentDefaultFolder1 = fileDatabase.getCurrentFileStore();
    assert currentDefaultFolder1.getFileDatabase() != null : "file databas is null for "
            + currentDefaultFolder1.getFileDatabase();
    assert currentDefaultFolder1.getFullPath() != null : "should be able to get path but couldn't";

    DefaultFileInfo info1 = dfss.addFile(fileDatabase, f1, "file_service_file", "txt");
    TreeFolderInfo currentDefaultFolder2 = dfss.getDatabaseById(fileDatabase.getId(), false)
            .getCurrentFileStore();
    DefaultFileInfo info2 = dfss.addFile(fileDatabase, f2, "file_service_file", "txt");
    assert !currentDefaultFolder1.equals(currentDefaultFolder2) : "Folders should NOT be the same but are "
            + " current folder 1 = " + currentDefaultFolder1 + " current folder 2 = " + currentDefaultFolder2;

    // commit the transaction
    tm.commit(ts);

    //begin a new transaction
    td = new DefaultTransactionDefinition(TransactionDefinition.PROPAGATION_REQUIRED);
    ts = tm.getTransaction(td);

    DefaultFileInfo myInfo = (DefaultFileInfo) dfss.getFileById(info1.getId(), false);
    DefaultFileInfo myInfo2 = (DefaultFileInfo) dfss.getFileById(info2.getId(), false);

    assert myInfo != null : "Was not able to find " + info1;
    assert myInfo2 != null : "Was not able to find " + info2;

    tm.commit(ts);

    dfss.deleteFileServer(fs.getName());
    assert dfss.getFileServer(fs.getName()) == null : "Should not find the file server";
}