本文整理匯總了Java中org.apache.commons.dbutils.DbUtils.rollbackAndCloseQuietly方法的典型用法代碼示例。如果您正苦於以下問題:Java DbUtils.rollbackAndCloseQuietly方法的具體用法?Java DbUtils.rollbackAndCloseQuietly怎麽用?Java DbUtils.rollbackAndCloseQuietly使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.commons.dbutils.DbUtils
的用法示例。
在下文中一共展示了DbUtils.rollbackAndCloseQuietly方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: update
import org.apache.commons.dbutils.DbUtils; //導入方法依賴的package包/類
/**
* {@inheritDoc}
* <p>
* 此操作會清空 Cache 中 authorities 對應的 value 和
* key = auth.getValue() 的數據,下次請求時裝載。
* @see #getAll()
*/
public void update(Authority auth) throws JibuException {
Connection conn = null;
try {
conn = ConnectionUtils.getConnection();
Authority old = authDAO.get(conn,auth.getId());
authDAO.update(conn,auth);
DbUtils.commitAndClose(conn);
Cache cache = CacheUtils.getAuthCache();
cache.remove("authorities");
cache.remove(old.getValue());
} catch(SQLException e) {
DbUtils.rollbackAndCloseQuietly(conn);
throw new JibuException(e.getMessage());
}
}
示例2: update
import org.apache.commons.dbutils.DbUtils; //導入方法依賴的package包/類
public void update(User user) throws JibuException {
Connection conn = null;
if (null != user.getPassword()) {
String cryptpassword = MD5.encodeString(user.getPassword(),null);
user.setPassword(cryptpassword);
}
try {
conn = ConnectionUtils.getConnection();
userDAO.update(conn,user);
DbUtils.commitAndClose(conn);
} catch(SQLException e) {
DbUtils.rollbackAndCloseQuietly(conn);
throw new JibuException(e.getMessage());
}
}
示例3: updateMe
import org.apache.commons.dbutils.DbUtils; //導入方法依賴的package包/類
public void updateMe(List<Integer> ids, User user) throws JibuException {
Connection conn = null;
try {
conn = ConnectionUtils.getConnection();
if (null != user.getPassword()) {
String cryptpassword = MD5.encodeString(user.getPassword(),null);
user.setPassword(cryptpassword);
}
int uid = user.getId();
userDAO.update(conn,user);
settingDAO.unbindAll(conn,uid);
Setting setting = null;
for(Integer id:ids) {
setting = settingDAO.get(conn,id);
if(setting.getSortindex()!=0) {
settingDAO.bind(conn,id,uid);
}
}
// 如果選擇的是一個默認配置,不用bind
DbUtils.commitAndClose(conn);
} catch(SQLException e) {
DbUtils.rollbackAndCloseQuietly(conn);
throw new JibuException(e.getMessage());
}
}
示例4: delete
import org.apache.commons.dbutils.DbUtils; //導入方法依賴的package包/類
public void delete(Role role) throws JibuException {
Connection conn = null;
try {
conn = ConnectionUtils.getConnection();
role = roleDAO.get(conn,role.getId());
if ((role.getRgt()-role.getLft()) > 1)
throw new RoleException("The role is not leaf node.");
roleDAO.delete(conn,role);
DbUtils.commitAndClose(conn);
} catch(SQLException e) {
DbUtils.rollbackAndCloseQuietly(conn);
throw new JibuException(e.getMessage());
} finally {
DbUtils.closeQuietly(conn);
}
}
示例5: update
import org.apache.commons.dbutils.DbUtils; //導入方法依賴的package包/類
/**
* {@inheritDoc}
* <p>
* 如果修改 Role,那麽所有用於權限驗證的 Cache 要重置。
*/
public void update(Role role) throws JibuException {
Connection conn = null;
try {
conn = ConnectionUtils.getConnection();
// 更新時不能破化樹形結構
role.setLft(null);
role.setRgt(null);
roleDAO.update(conn,role);
DbUtils.commitAndClose(conn);
CacheUtils.getAuthCache().clear();
CacheUtils.getUserCache().clear();
} catch(SQLException e) {
DbUtils.rollbackAndCloseQuietly(conn);
throw new JibuException(e.getMessage());
}
}
示例6: clearTable
import org.apache.commons.dbutils.DbUtils; //導入方法依賴的package包/類
/**
* 測試用例運行前需要清空所有表的數據。
* 清表的順序參考:
* http://10.10.1.10/docs/jibu-schema/v2.0.0/deletionOrder.txt
*/
protected void clearTable() {
Connection conn = null;
try {
conn = ConnectionUtils.getConnection();
QueryRunner run = new QueryRunner();
run.update(conn, "DELETE from user_setting_map");
run.update(conn, "DELETE from user_role_map");
run.update(conn, "DELETE from role_authority_map");
run.update(conn, "DELETE from tokens");
run.update(conn, "DELETE from settings");
run.update(conn, "DELETE from authorities ");
run.update(conn, "DELETE from roles");
run.update(conn, "DELETE from userbase");
DbUtils.commitAndClose(conn);
} catch(SQLException e) {
DbUtils.rollbackAndCloseQuietly(conn);
System.out.println(e.getMessage());
}
}
示例7: call
import org.apache.commons.dbutils.DbUtils; //導入方法依賴的package包/類
public SearchResult call() {
SearchResult result = new SearchResult();
Connection topicConnection = null;
QueryRunner runner = new QueryRunner();
try {
topicConnection = MonetaEnvironment.getConfiguration()
.getConnection(topic.getDataSourceName());
RecordResultSetHandler handler = new RecordResultSetHandler();
handler.setMaxRows(this.getMaxRows());
handler.setStartRow(this.getStartRow());
handler.getAliasMap().putAll(topic.getAliasMap());
result.setResultData(runner.query(topicConnection, sqlStmt.getSqlText(),
handler, sqlStmt.getHostVariableValueList().toArray()));
if (topicConnection.getAutoCommit()) {
DbUtils.closeQuietly(topicConnection);
}
else {
DbUtils.commitAndCloseQuietly(topicConnection);
}
}
catch (Exception e) {
result.setErrorCode(500);
result.setErrorMessage(ExceptionUtils.getStackTrace(e));
DbUtils.rollbackAndCloseQuietly(topicConnection);
}
return result;
}
示例8: add
import org.apache.commons.dbutils.DbUtils; //導入方法依賴的package包/類
/**
* {@inheritDoc}
* <p>
* 此操作會清空 Cache 中 authorities 對應的 value,下次請求時裝載。
* @see #getAll()
*/
public void add(Authority auth) throws JibuException {
Connection conn = null;
try {
conn = ConnectionUtils.getConnection();
authDAO.save(conn,auth);
DbUtils.commitAndClose(conn);
Cache cache = CacheUtils.getAuthCache();
cache.remove("authorities");
} catch(SQLException e) {
DbUtils.rollbackAndCloseQuietly(conn);
throw new JibuException(e.getMessage());
}
}
示例9: delete
import org.apache.commons.dbutils.DbUtils; //導入方法依賴的package包/類
/**
* {@inheritDoc}
* <p>
* 此操作會清空 Cache 中 authorities 對應的 value,下次請求時裝載。
* @see #getAll()
*/
public void delete(Authority auth) throws JibuException {
Connection conn = null;
try {
conn = ConnectionUtils.getConnection();
authDAO.delete(conn,auth);
DbUtils.commitAndClose(conn);
Cache cache = CacheUtils.getAuthCache();
cache.remove("authorities");
} catch(SQLException e) {
DbUtils.rollbackAndCloseQuietly(conn);
throw new JibuException(e.getMessage());
}
}
示例10: generateToken
import org.apache.commons.dbutils.DbUtils; //導入方法依賴的package包/類
public Token generateToken(String username) {
Connection conn = null;
Token token = null;
try {
conn = ConnectionUtils.getConnection();
User user = userDAO.get(conn,username);
if (user == null) return null;
Random randomGenerator = new Random();
long randomLong = randomGenerator.nextLong();
// Date date = new Date();
Calendar calendar = Calendar.getInstance();
//calendar.setTime(date);
calendar.add(calendar.DAY_OF_MONTH, +1);
long time = calendar.getTimeInMillis();
Timestamp ts = new Timestamp(time);
String key = MD5.encodeString(Long.toString(randomLong) + time, null);
token = new Token(key,"password",ts,user.getId());
tokenDAO.save(conn,token);
DbUtils.commitAndClose(conn);
} catch(SQLException e) {
DbUtils.rollbackAndCloseQuietly(conn);
logger.error(e.getMessage());
return null;
} finally {
DbUtils.closeQuietly(conn);
}
return token;
}
示例11: resetPassword
import org.apache.commons.dbutils.DbUtils; //導入方法依賴的package包/類
public void resetPassword(String tokenValue, String password) throws JibuException {
Connection conn = null;
try {
conn = ConnectionUtils.getConnection();
Token token = tokenDAO.get(conn,tokenValue);
if (token == null) throw new TokenException("Token is null");
Calendar calendar = Calendar.getInstance();
long time = calendar.getTimeInMillis();
Timestamp ts = new Timestamp(time);
if(ts.after(token.getExpiration())) throw new TokenException("Token expired.");
if (password == null || password.isEmpty()) {
throw new JibuException("Password is invalid.");
}
User user = new User();
String cryptpassword = MD5.encodeString(password,null);
user.setPassword(cryptpassword);
user.setId(token.getUser_id());
userDAO.update(conn,user);
DbUtils.commitAndClose(conn);
} catch(SQLException e) {
DbUtils.rollbackAndCloseQuietly(conn);
throw new JibuException(e.getMessage());
} finally {
DbUtils.closeQuietly(conn);
}
}
示例12: add
import org.apache.commons.dbutils.DbUtils; //導入方法依賴的package包/類
public void add(User user) throws JibuException {
Connection conn = null;
if (null != user.getPassword()) {
String cryptpassword = MD5.encodeString(user.getPassword(),null);
user.setPassword(cryptpassword);
}
try {
conn = ConnectionUtils.getConnection();
userDAO.save(conn,user);
DbUtils.commitAndClose(conn);
} catch(SQLException e) {
DbUtils.rollbackAndCloseQuietly(conn);
throw new JibuException(e.getMessage());
}
}
示例13: delete
import org.apache.commons.dbutils.DbUtils; //導入方法依賴的package包/類
public void delete(User user) throws JibuException {
Connection conn = null;
try {
conn = ConnectionUtils.getConnection();
userDAO.delete(conn,user);
DbUtils.commitAndClose(conn);
} catch(SQLException e) {
DbUtils.rollbackAndCloseQuietly(conn);
throw new JibuException(e.getMessage());
}
}
示例14: bind
import org.apache.commons.dbutils.DbUtils; //導入方法依賴的package包/類
/**
* {@inheritDoc}
* <p>
* 從 cache 中刪除此 auth 對應的 roles。下次條用時裝載。
*/
public void bind(Role role, Authority auth) throws JibuException {
Connection conn = null;
try {
conn = ConnectionUtils.getConnection();
Authority a = authDAO.get(conn,auth.getId());
roleDAO.bind(conn, role, a);
DbUtils.commitAndClose(conn);
Cache cache = CacheUtils.getAuthCache();
cache.remove(a.getValue());
} catch(SQLException e) {
DbUtils.rollbackAndCloseQuietly(conn);
throw new JibuException(e.getMessage());
}
}
示例15: unbind
import org.apache.commons.dbutils.DbUtils; //導入方法依賴的package包/類
/**
* {@inheritDoc}
* <p>
* 從 cache 中刪除此 auth 對應的 roles。
*/
public void unbind(Role role, Authority auth) throws JibuException {
Connection conn = null;
try {
conn = ConnectionUtils.getConnection();
Authority a = authDAO.get(conn,auth.getId());
roleDAO.unbind(conn, role, a);
DbUtils.commitAndClose(conn);
Cache cache = CacheUtils.getAuthCache();
cache.remove(a.getValue());
} catch(SQLException e) {
DbUtils.rollbackAndCloseQuietly(conn);
throw new JibuException(e.getMessage());
}
}