If anybody implemented transactional writing to file,please, assist me.
Related topic was discussed in earlier thread(transactional write).
Use case is following
As far nobody answers, I try do that from my latest experience.
Useful documentataion:
example2(.ppt)
Simplified algorithm looks like(actually,depicted in example2):
1. initialize FileResourceManager
2. start FileResourceManager
3. get transaction Id from FileResourceManager instance
4. start transaction with transaction Id from step 3
5. write resource you need - here is mentioned write it transactionally
,so looks like it's the major step!
6. commit or rollback transaction
Note: resourceId,about i asked in ,my question, is simply name of transactional file. This naming doesn't depict very good this attribute.
Code, I used:
private static final org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger(FileAppender.class);
private static LoggerFacade loggerFacade = new Log4jLogger(logger);
private static String tempDir = (String) System.getProperties().get("java.io.tmpdir");
private FileResourceManager frm = new FileResourceManager(tempDir, tempDir, false, loggerFacade);
private static OutputStream outputStream;
public void writeOut(E event) throws IOException {
Object txId = null;
try {
frm.start();
txId = frm.generatedUniqueTxId();
frm.startTransaction(txId);
outputStream = frm.writeResource(txId, fileName, true);
frm.commitTransaction(txId);
}
catch (Exception e) {
throw new IOException("DB rollback");
}
}