📄 databasefilemgr.java
字号:
package org.jbpm.persistence.filemgr;
import org.apache.commons.logging.*;
import org.jbpm.*;
import org.jbpm.model.definition.impl.*;
import org.jbpm.persistence.*;
public class DatabaseFileMgr implements FileMgr {
protected PersistenceSessionFactory persistenceSessionFactory = null;
public DatabaseFileMgr( JbpmConfiguration jbpmConfiguration ) {
persistenceSessionFactory = (PersistenceSessionFactory) jbpmConfiguration.instantiate( "jbpm.persistence.session.factory", PersistenceSessionFactory.class );
}
public void storeBytes(Long definitionId, String fileName, byte[] bytes) {
FileImpl file = new FileImpl( definitionId, fileName, bytes );
PersistenceSessionTx sessionTx = null;
try {
log.info( "storing file '" + fileName + "' for definition '" + definitionId + "'..." );
// get a persistence session with a transaction
sessionTx = persistenceSessionFactory.createPersistenceSessionTx();
// save all changes made in the process instance
sessionTx.save( file );
// commit the transaction
sessionTx.commitAndClose();
sessionTx = null;
if ( log.isDebugEnabled() ) log.debug( "stored file '" + fileName + "' successfully" );
} finally {
if ( sessionTx != null ) {
sessionTx.rollbackAndClose();
}
}
}
public byte[] retrieveBytes(Long definitionId, String fileName) {
byte[] bytes = null;
PersistenceSession session = null;
try {
if ( log.isDebugEnabled() ) log.info( "retrieving file '" + fileName + "' for definition '" + definitionId + "' from database..." );
// get a persistence session with a transaction
session = persistenceSessionFactory.createPersistenceSession();
// save all changes made in the process instance
FileImpl file = session.findFile( definitionId, fileName );
if ( file != null ) {
bytes = file.getBytes();
}
if ( log.isDebugEnabled() ) log.debug( "retrieved file '" + fileName + "' successfully" );
} finally {
if ( session != null ) {
session.close();
}
}
return bytes;
}
private static Log log = LogFactory.getLog(DatabaseFileMgr.class);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -