From 7be3033699e88382058daf5f634acb28a334f42b Mon Sep 17 00:00:00 2001 From: Will Ezell Date: Wed, 17 Jan 2018 17:18:06 -0500 Subject: [PATCH] #13424 fixes the mysql lockup issue --- .../dotmarketing/common/db/DotConnect.java | 49 ++++--------------- .../contentlet/ajax/ContentletAjax.java | 32 +++++------- 2 files changed, 22 insertions(+), 59 deletions(-) diff --git a/dotCMS/src/main/java/com/dotmarketing/common/db/DotConnect.java b/dotCMS/src/main/java/com/dotmarketing/common/db/DotConnect.java index b8a65097589f..1cff78d32b4f 100644 --- a/dotCMS/src/main/java/com/dotmarketing/common/db/DotConnect.java +++ b/dotCMS/src/main/java/com/dotmarketing/common/db/DotConnect.java @@ -23,6 +23,9 @@ import com.dotmarketing.util.json.JSONObject; import static com.dotcms.util.CollectionsUtils.*; +import com.dotcms.business.CloseDBIfOpened; +import com.dotcms.business.WrapInTransaction; + /** * Description of the Class * @@ -1114,42 +1117,15 @@ public int executeUpdate (final String preparedStatement, * @return int rows affected * @throws DotDataException */ + public int executeUpdate (final String preparedStatement, Boolean logException, final Object... parameters) throws DotDataException { - final boolean isNewTransaction = DbConnectionFactory.startTransactionIfNeeded(); - Connection connection = null; - int rowsAffected = 0; - - try { + return this.executeUpdate(DbConnectionFactory.getConnection(), + preparedStatement, logException, parameters); - connection = DbConnectionFactory.getConnection(); - rowsAffected = this.executeUpdate(connection, - preparedStatement, logException, parameters); - if (isNewTransaction) { - connection.commit(); - } - } catch (DotDataException e) { - if (isNewTransaction) { - this.rollback(connection); - } - throw e; - } catch (Exception e) { - - if (logException) { - Logger.error(DotConnect.class, e.getMessage(), e); - } - throw new DotDataException(e.getMessage(), e); - } finally { - - if (isNewTransaction) { - closeQuietly(connection); - } - } - - return rowsAffected; } // executeUpdate. protected void rollback(final Connection connection) throws DotDataException { @@ -1186,29 +1162,24 @@ public int executeUpdate (final Connection connection, final String preparedStat * @return int rows affected * @throws DotDataException */ + @CloseDBIfOpened public int executeUpdate (final Connection connection, final String preparedStatementString, Boolean logException, final Object... parameters) throws DotDataException { - PreparedStatement preparedStatement = null; - int rowsAffected = 0; - try { - preparedStatement = connection.prepareStatement(preparedStatementString); + PreparedStatement preparedStatement = connection.prepareStatement(preparedStatementString); this.setParams(preparedStatement, parameters); - rowsAffected = preparedStatement.executeUpdate(); + return preparedStatement.executeUpdate(); } catch (SQLException e) { if (logException) { Logger.error(DotConnect.class, e.getMessage(), e); } throw new DotDataException(e.getMessage(), e); - } finally { + } - closeQuietly(preparedStatement); - } - return rowsAffected; } // executeUpdate. private static void setTimestampWithTimezone(PreparedStatement statement, int parameterIndex, Object timestamp) { diff --git a/dotCMS/src/main/java/com/dotmarketing/portlets/contentlet/ajax/ContentletAjax.java b/dotCMS/src/main/java/com/dotmarketing/portlets/contentlet/ajax/ContentletAjax.java index 8ea60bb26481..f7fc28dce7e8 100644 --- a/dotCMS/src/main/java/com/dotmarketing/portlets/contentlet/ajax/ContentletAjax.java +++ b/dotCMS/src/main/java/com/dotmarketing/portlets/contentlet/ajax/ContentletAjax.java @@ -19,8 +19,6 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpSession; -import com.dotcms.business.CloseDB; -import com.dotcms.business.CloseDBIfOpened; import com.dotcms.content.elasticsearch.util.ESUtils; import com.dotcms.enterprise.FormAJAXProxy; import com.dotcms.enterprise.LicenseUtil; @@ -383,7 +381,6 @@ private List> getContentSiblingsData(String inode) {//GIT-10 * @throws DotDataException * @throws DotStateException */ - @CloseDB @SuppressWarnings("rawtypes") public List searchContentlet(String structureInode, List fields, List categories, boolean showDeleted, boolean filterSystemHost, int page, int perPage, String orderBy) throws DotStateException, DotDataException, DotSecurityException { @@ -400,7 +397,7 @@ public List searchContentlet(String structureInode, List fields, List fields, List categories, boolean showDeleted, boolean filterSystemHost, int page, String orderBy, String modDateFrom, String modDateTo) throws DotStateException, DotDataException, DotSecurityException { return searchContentlets(structureInode, fields, categories, showDeleted, filterSystemHost, page, orderBy, modDateFrom, modDateTo, true); @@ -424,14 +421,13 @@ public List searchContentlets(String structureInode, List fields, List fields, List categories, boolean showDeleted, boolean filterSystemHost, boolean filterUnpublish, boolean filterLocked, int page, String orderBy, String modDateFrom, String modDateTo) throws DotStateException, DotDataException, DotSecurityException { return searchContentlets(structureInode,fields,categories,showDeleted,filterSystemHost,filterUnpublish,filterLocked,page,0,orderBy,modDateFrom,modDateTo); } - @CloseDB + @SuppressWarnings("rawtypes") public List searchContentlets(String structureInode, List fields, List categories, boolean showDeleted, boolean filterSystemHost, boolean filterUnpublish, boolean filterLocked, int page, int perPage,String orderBy, String modDateFrom, @@ -465,7 +461,6 @@ public List searchContentlets(String structureInode, List fields, List searchFormWidget(String formStructureInode) throws DotDataException, DotSecurityException { FormAJAXProxy fp = new FormAJAXProxy(); return fp.searchFormWidget(formStructureInode); @@ -510,7 +505,6 @@ public Map searchFormWidget(String formStructureInode) throws Do * @throws DotStateException * A system error has occurred. */ - @CloseDB @SuppressWarnings("rawtypes") @LogTime public List searchContentletsByUser(String structureInode, List fields, List categories, boolean showDeleted, boolean filterSystemHost, boolean filterUnpublish, boolean filterLocked, int page, String orderBy,int perPage, final User currentUser, HttpSession sess,String modDateFrom, String modDateTo) throws DotStateException, DotDataException, DotSecurityException { @@ -873,7 +867,7 @@ else if( fieldbcontentname.startsWith("date") ){ searchResult = new HashMap(); Structure s = CacheLocator.getContentTypeCache().getStructureByInode(con.getStructureInode()); - searchResult.put("typeVariable", s.getVelocityVarName()); + for (String fieldContentlet : fieldsMapping.keySet()) { String fieldValue = null; if (con.getMap() != null && con.getMap().get(fieldContentlet) != null) { @@ -1085,7 +1079,7 @@ else if( fieldbcontentname.startsWith("date") ){ return results; } - @CloseDB + @NotNull private JSONArray getAvailableWorkflowActionsJson(final User currentUser, final Contentlet contentlet) throws DotDataException { @@ -1147,7 +1141,7 @@ private JSONArray getAvailableWorkflowActionsJson(final User currentUser, return wfActionMapList; } - @CloseDB + public ArrayList doSearchGlossaryTerm(String valueToComplete, String language) throws Exception { ArrayList list = new ArrayList(15); @@ -1180,7 +1174,6 @@ private List retrieveProperties(long langId) throws Exception { * @param languageId if set to 0 will publish for all languages * @return */ - @CloseDB public List> publishContentlets(List identifiersList, boolean isPublish, long languageId) { List> rows = new ArrayList>(); HttpServletRequest req = WebContextFactory.get().getHttpServletRequest(); @@ -1248,7 +1241,6 @@ public List> publishContentlets(List identifiersList * @throws LanguageException */ //http://jira.dotmarketing.net/browse/DOTCMS-2273 - @CloseDB public Map saveContent(List formData, boolean isAutoSave,boolean isCheckin, boolean publish) throws LanguageException, PortalException, SystemException { Map contentletFormData = new HashMap(); Map callbackData = new HashMap(); @@ -1778,7 +1770,7 @@ else if(key.equals(DotContentletValidationException.VALIDATION_FAILED_BAD_CARDIN callbackData.put("referer", referer); return callbackData; } - @CloseDB + //http://jira.dotmarketing.net/browse/DOTCMS-2273 public String cancelContentEdit(String workingContentletInode,String currentContentletInode,String referer,String language){ @@ -1819,7 +1811,7 @@ public String cancelContentEdit(String workingContentletInode,String currentCont return referer; } - @CloseDB + public Map saveContentProperties(String inode, List formData, boolean isAutoSave,boolean isCheckin,boolean isPublish) throws PortalException, SystemException, DotDataException, DotSecurityException{ HttpServletRequest req = WebContextFactory.get().getHttpServletRequest(); User user = com.liferay.portal.util.PortalUtil.getUser((HttpServletRequest)req); @@ -2011,7 +2003,7 @@ else if(key.equals(DotContentletValidationException.VALIDATION_FAILED_BAD_REL)) return callbackData; } - @CloseDB + public void removeSiblingBinaryFromSession(String fieldContentlet){ //http://jira.dotmarketing.net/browse/DOTCMS-5802 if(UtilMethods.isSet(fieldContentlet)){ @@ -2019,7 +2011,7 @@ public void removeSiblingBinaryFromSession(String fieldContentlet){ req.getSession().removeAttribute(fieldContentlet+"-sibling"); } } - @CloseDB + public String unrelateContent(String contentletIdentifier, String identifierToUnrelate, String relationshipInode){ // User info @@ -2064,7 +2056,7 @@ public String unrelateContent(String contentletIdentifier, String identifierToU return resultStr; } - @CloseDB + public Map lockContent(String contentletInode) throws DotContentletStateException, DotDataException, DotSecurityException, LanguageException{ // User info HttpServletRequest req = WebContextFactory.get().getHttpServletRequest(); @@ -2095,7 +2087,7 @@ public Map lockContent(String contentletInode) throws DotContent } - @CloseDB + public Map unlockContent(String contentletInode) throws DotContentletStateException, DotDataException, DotSecurityException, LanguageException{ // User info HttpServletRequest req = WebContextFactory.get().getHttpServletRequest(); @@ -2111,7 +2103,7 @@ public Map unlockContent(String contentletInode) throws DotConte ret.put("lockedIdent", contentletInode ); return ret; } - @CloseDB + public Map saveBinaryFileOnContent(String fileName, String fieldInode) throws DotContentletValidationException, Exception{ Map callbackData = new HashMap();