List of usage examples for com.liferay.portal.kernel.dao.jdbc DataAccess cleanUp
public static void cleanUp(Connection connection, Statement statement, ResultSet resultSet)
From source file:com.custom.portal.upgrade.v6_2_0.CustomUpgradeSocial.java
License:Open Source License
protected void addActivity(long activityId, long groupId, long companyId, long userId, Timestamp createDate, long mirrorActivityId, long classNameId, long classPK, int type, String extraData, long receiverUserId) throws Exception { Connection con = null;/*from w w w . j a v a 2s . com*/ PreparedStatement ps = null; ResultSet rs = null; boolean isCreateDateUnique = false; long updatedCreateDate = createDate.getTime(); isCreateDateUnique = checkCreateDate(updatedCreateDate, classNameId, classPK); while (!isCreateDateUnique) { updatedCreateDate += 1; isCreateDateUnique = checkCreateDate(updatedCreateDate, classNameId, classPK); } try { con = DataAccess.getUpgradeOptimizedConnection(); StringBundler sb = new StringBundler(5); sb.append("insert into SocialActivity (activityId, groupId, "); sb.append("companyId, userId, createDate, mirrorActivityId, "); sb.append("classNameId, classPK, type_, extraData, "); sb.append("receiverUserId) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, "); sb.append("?)"); ps = con.prepareStatement(sb.toString()); ps.setLong(1, activityId); ps.setLong(2, groupId); ps.setLong(3, companyId); ps.setLong(4, userId); ps.setLong(5, updatedCreateDate); ps.setLong(6, mirrorActivityId); ps.setLong(7, classNameId); ps.setLong(8, classPK); ps.setInt(9, type); ps.setString(10, extraData); ps.setLong(11, receiverUserId); ps.executeUpdate(); } catch (Exception e) { if (_log.isWarnEnabled()) { _log.warn("Unable to add activity " + activityId, e); } } finally { DataAccess.cleanUp(con, ps, rs); } }
From source file:com.liferay.counter.service.persistence.CounterFinderImpl.java
License:Open Source License
public List<String> getNames() throws SystemException { Connection connection = null; PreparedStatement preparedStatement = null; ResultSet resultSet = null;//w w w . j av a 2 s . c o m try { connection = getConnection(); preparedStatement = connection.prepareStatement(_SQL_SELECT_NAMES); resultSet = preparedStatement.executeQuery(); List<String> list = new ArrayList<String>(); while (resultSet.next()) { list.add(resultSet.getString(1)); } return list; } catch (SQLException sqle) { throw processException(sqle); } finally { DataAccess.cleanUp(connection, preparedStatement, resultSet); } }
From source file:com.liferay.counter.service.persistence.CounterFinderImpl.java
License:Open Source License
protected CounterRegister createCounterRegister(String name, long size) throws SystemException { long rangeMin = -1; int rangeSize = getRangeSize(name); Connection connection = null; PreparedStatement preparedStatement = null; ResultSet resultSet = null;/* w w w. java 2 s . co m*/ try { connection = getConnection(); preparedStatement = connection.prepareStatement(_SQL_SELECT_ID_BY_NAME); preparedStatement.setString(1, name); resultSet = preparedStatement.executeQuery(); if (!resultSet.next()) { rangeMin = _DEFAULT_CURRENT_ID; if (size > rangeMin) { rangeMin = size; } resultSet.close(); preparedStatement.close(); preparedStatement = connection.prepareStatement(_SQL_INSERT); preparedStatement.setString(1, name); preparedStatement.setLong(2, rangeMin); preparedStatement.executeUpdate(); } } catch (Exception e) { throw processException(e); } finally { DataAccess.cleanUp(connection, preparedStatement, resultSet); } CounterHolder counterHolder = _obtainIncrement(name, rangeSize, size); return new CounterRegister(name, counterHolder, rangeSize); }
From source file:com.liferay.knowledgebase.hook.upgrade.v1_0_0.UpgradeRatingsEntry.java
License:Open Source License
protected long getClassNameId(String className) throws Exception { Connection con = null;/*www. j a v a 2 s. c om*/ PreparedStatement ps = null; ResultSet rs = null; try { con = DataAccess.getConnection(); ps = con.prepareStatement("select classNameId from ClassName_ where value = ?"); ps.setString(1, className); rs = ps.executeQuery(); if (rs.next()) { return rs.getLong("classNameId"); } return 0; } finally { DataAccess.cleanUp(con, ps, rs); } }
From source file:com.liferay.knowledgebase.hook.upgrade.v1_0_0.UpgradeRatingsEntry.java
License:Open Source License
protected void updateRatingsEntries() throws Exception { Connection con = null;/*from w w w. j a v a 2 s . co m*/ PreparedStatement ps = null; ResultSet rs = null; try { con = DataAccess.getConnection(); long classNameId = getClassNameId(_ARTICLE_CLASS_NAME); ps = con.prepareStatement("select entryId, score from RatingsEntry where classNameId = " + classNameId); rs = ps.executeQuery(); while (rs.next()) { long entryId = rs.getLong("entryId"); double score = rs.getDouble("score"); StringBundler sb = new StringBundler(4); sb.append("update RatingsEntry set score = "); sb.append(score * 2); sb.append(" where entryId = "); sb.append(entryId); runSQL(sb.toString()); } } finally { DataAccess.cleanUp(con, ps, rs); } }
From source file:com.liferay.knowledgebase.hook.upgrade.v1_0_0.UpgradeRatingsStats.java
License:Open Source License
protected void updateRatingsStats() throws Exception { Connection con = null;//from ww w . j av a2 s. c om PreparedStatement ps = null; ResultSet rs = null; try { con = DataAccess.getConnection(); long classNameId = getClassNameId(_ARTICLE_CLASS_NAME); ps = con.prepareStatement("select statsId, totalScore, averageScore from RatingsStats " + "where classNameId = " + classNameId); rs = ps.executeQuery(); while (rs.next()) { long statsId = rs.getLong("statsId"); double totalScore = rs.getDouble("totalScore"); double averageScore = rs.getDouble("averageScore"); StringBundler sb = new StringBundler(6); sb.append("update RatingsStats set totalScore = "); sb.append(totalScore * 2); sb.append(", averageScore = "); sb.append(averageScore * 2); sb.append(" where statsId = "); sb.append(statsId); runSQL(sb.toString()); } } finally { DataAccess.cleanUp(con, ps, rs); } }
From source file:com.liferay.knowledgebase.hook.upgrade.v1_1_0.UpgradeResourceAction.java
License:Open Source License
protected boolean hasResourceAction(String name) throws Exception { Connection con = null;//from w w w .j a v a2 s . co m PreparedStatement ps = null; ResultSet rs = null; try { con = DataAccess.getConnection(); ps = con.prepareStatement("select count(*) from ResourceAction where name = ?"); ps.setString(1, name); rs = ps.executeQuery(); while (rs.next()) { int count = rs.getInt(1); if (count > 0) { return true; } } return false; } finally { DataAccess.cleanUp(con, ps, rs); } }
From source file:com.liferay.knowledgebase.hook.upgrade.v1_1_0.UpgradeResourcePermission.java
License:Open Source License
protected boolean hasResourcePermission(String name) throws Exception { Connection con = null;/*from w w w. ja v a2s . c o m*/ PreparedStatement ps = null; ResultSet rs = null; try { con = DataAccess.getConnection(); ps = con.prepareStatement("select count(*) from ResourcePermission where name = ?"); ps.setString(1, name); rs = ps.executeQuery(); while (rs.next()) { int count = rs.getInt(1); if (count > 0) { return true; } } return false; } finally { DataAccess.cleanUp(con, ps, rs); } }
From source file:com.liferay.knowledgebase.hook.upgrade.v1_3_0.UpgradeKBAttachments.java
License:Open Source License
@Override protected void updateAttachments() throws Exception { Connection con = null;//from w w w.ja v a 2s. c om PreparedStatement ps = null; ResultSet rs = null; try { con = DataAccess.getUpgradeOptimizedConnection(); StringBundler sb = new StringBundler(5); sb.append("select MIN(kbArticleId) as kbArticleId, "); sb.append("resourcePrimKey, groupId, companyId, "); sb.append("MIN(userId) as userId, MIN(userName) as userName, "); sb.append("MIN(status) as status from KBArticle "); sb.append("group by resourcePrimKey, groupId, companyId"); ps = con.prepareStatement(sb.toString()); rs = ps.executeQuery(); while (rs.next()) { long kbArticleId = rs.getLong("kbArticleId"); long resourcePrimKey = rs.getLong("resourcePrimKey"); long groupId = rs.getLong("groupId"); long companyId = rs.getLong("companyId"); long userId = rs.getLong("userId"); String userName = rs.getString("userName"); int status = rs.getInt("status"); long classPK = resourcePrimKey; if (status != WorkflowConstants.STATUS_APPROVED) { classPK = kbArticleId; } updateEntryAttachments(companyId, groupId, classPK, 0, userId, userName); } } finally { DataAccess.cleanUp(con, ps, rs); } }
From source file:com.liferay.knowledgebase.hook.upgrade.v1_3_4.UpgradeResourceAction.java
License:Open Source License
private boolean _hasViewFeedbackResourceAction() throws SQLException { Connection con = null;// ww w . j a v a 2 s . c om PreparedStatement ps = null; ResultSet rs = null; try { con = DataAccess.getUpgradeOptimizedConnection(); ps = con.prepareStatement("select count(*) from ResourceAction where actionId = ?"); ps.setString(1, _ACTION_ID_VIEW_KB_FEEDBACK); rs = ps.executeQuery(); if (rs.next()) { return rs.getInt(1) > 0; } return false; } finally { DataAccess.cleanUp(con, ps, rs); } }