From b96d174e1ffb7567dabb00574848c482e929a3cd Mon Sep 17 00:00:00 2001 From: Derek Hulley Date: Mon, 18 Jan 2010 16:39:18 +0000 Subject: [PATCH] SAIL-232: AppliedPatch.hbm.xml - Basic CREATE script for core tables: AlfrescoCreate-3.3-RepoTables.sql - Removed Hibernate control of alf_applied_patch git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@18101 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- config/alfresco/bootstrap-context.xml | 1 + config/alfresco/dao/dao-context.xml | 76 ++-- .../AlfrescoCreate-3.3-RepoTables.sql | 24 ++ config/alfresco/ehcache-default.xml | 7 - .../ehcache-custom.xml.sample.cluster | 17 - config/alfresco/hibernate-context.xml | 2 - .../alfresco/ibatis/alfresco-SqlMapConfig.xml | 1 + config/alfresco/ibatis/ibatis-context.xml | 159 ++++---- .../appliedpatch-common-SqlMap.xml | 119 ++++++ config/alfresco/import-export-context.xml | 4 +- .../alfresco/patch/patch-services-context.xml | 10 +- .../patch/AppliedPatch.java} | 107 +++-- .../repo/admin/patch/PatchExecuter.java | 4 +- .../repo/admin/patch/PatchService.java | 4 +- .../repo/admin/patch/PatchServiceImpl.java | 49 ++- .../alfresco/repo/admin/patch/PatchTest.java | 386 +++++++++--------- .../HibernatePatchDaoServiceImpl.java | 137 ------- .../alfresco/repo/domain/AppliedPatch.java | 59 --- .../alfresco/repo/domain/DomainTestSuite.java | 2 + .../patch/AbstractAppliedPatchDAOImpl.java | 99 +++++ .../patch/AppliedPatchDAO.java} | 32 +- .../domain/patch/AppliedPatchDAOTest.java | 153 +++++++ .../patch/AppliedPatchEntity.java} | 39 +- .../patch/ibatis/AppliedPatchDAOImpl.java | 114 ++++++ .../domain/patch/ibatis/PatchDAOImpl.java | 16 +- .../system/SystemExporterImporter.java | 16 +- 26 files changed, 941 insertions(+), 696 deletions(-) create mode 100644 config/alfresco/dbscripts/create/3.3/org.hibernate.dialect.MySQLInnoDBDialect/AlfrescoCreate-3.3-RepoTables.sql create mode 100644 config/alfresco/ibatis/org.hibernate.dialect.Dialect/appliedpatch-common-SqlMap.xml rename source/java/org/alfresco/repo/{domain/hibernate/AppliedPatchImpl.java => admin/patch/AppliedPatch.java} (59%) delete mode 100644 source/java/org/alfresco/repo/admin/patch/hibernate/HibernatePatchDaoServiceImpl.java delete mode 100644 source/java/org/alfresco/repo/domain/AppliedPatch.java create mode 100644 source/java/org/alfresco/repo/domain/patch/AbstractAppliedPatchDAOImpl.java rename source/java/org/alfresco/repo/{admin/patch/PatchDaoService.java => domain/patch/AppliedPatchDAO.java} (68%) create mode 100644 source/java/org/alfresco/repo/domain/patch/AppliedPatchDAOTest.java rename source/java/org/alfresco/repo/{admin/patch/PatchInfo.java => domain/patch/AppliedPatchEntity.java} (64%) create mode 100644 source/java/org/alfresco/repo/domain/patch/ibatis/AppliedPatchDAOImpl.java diff --git a/config/alfresco/bootstrap-context.xml b/config/alfresco/bootstrap-context.xml index 64ae6e2c2c..26f4227f84 100644 --- a/config/alfresco/bootstrap-context.xml +++ b/config/alfresco/bootstrap-context.xml @@ -68,6 +68,7 @@ + classpath:alfresco/dbscripts/create/3.3/${db.script.dialect}/AlfrescoCreate-3.3-RepoTables.sql diff --git a/config/alfresco/dao/dao-context.xml b/config/alfresco/dao/dao-context.xml index 4805156436..bb35f07160 100644 --- a/config/alfresco/dao/dao-context.xml +++ b/config/alfresco/dao/dao-context.xml @@ -15,6 +15,14 @@ + + + + + + + + @@ -67,48 +75,32 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - diff --git a/config/alfresco/dbscripts/create/3.3/org.hibernate.dialect.MySQLInnoDBDialect/AlfrescoCreate-3.3-RepoTables.sql b/config/alfresco/dbscripts/create/3.3/org.hibernate.dialect.MySQLInnoDBDialect/AlfrescoCreate-3.3-RepoTables.sql new file mode 100644 index 0000000000..c3de4f3526 --- /dev/null +++ b/config/alfresco/dbscripts/create/3.3/org.hibernate.dialect.MySQLInnoDBDialect/AlfrescoCreate-3.3-RepoTables.sql @@ -0,0 +1,24 @@ +-- +-- Title: Core Repository Tables +-- Database: MySQL InnoDB +-- Since: V3.3 Schema 4000 +-- Author: Derek Hulley +-- +-- Please contact support@alfresco.com if you need assistance with the upgrade. +-- + +CREATE TABLE alf_applied_patch +( + id VARCHAR(64) NOT NULL, + description TEXT, + fixes_from_schema INTEGER, + fixes_to_schema INTEGER, + applied_to_schema INTEGER, + target_schema INTEGER, + applied_on_date DATETIME, + applied_to_server VARCHAR(64), + was_executed BIT, + succeeded BIT, + report TEXT, + PRIMARY KEY (id) +) ENGINE=InnoDB; diff --git a/config/alfresco/ehcache-default.xml b/config/alfresco/ehcache-default.xml index 90f8318d0b..efb3463ad2 100644 --- a/config/alfresco/ehcache-default.xml +++ b/config/alfresco/ehcache-default.xml @@ -85,13 +85,6 @@ eternal="true" overflowToDisk="false" /> - - - - - - - org/alfresco/repo/domain/hibernate/Node.hbm.xml org/alfresco/repo/domain/hibernate/Transaction.hbm.xml org/alfresco/repo/domain/hibernate/VersionCount.hbm.xml - org/alfresco/repo/domain/hibernate/AppliedPatch.hbm.xml org/alfresco/repo/domain/hibernate/Permission.hbm.xml org/alfresco/repo/attributes/hibernate/Attributes.hbm.xml org/alfresco/repo/domain/hibernate/UsageDelta.hbm.xml @@ -177,7 +176,6 @@ ${cache.strategy} ${cache.strategy} ${cache.strategy} - ${cache.strategy} ${cache.strategy} ${cache.strategy} diff --git a/config/alfresco/ibatis/alfresco-SqlMapConfig.xml b/config/alfresco/ibatis/alfresco-SqlMapConfig.xml index 4be2ba87b3..3cd9df29be 100644 --- a/config/alfresco/ibatis/alfresco-SqlMapConfig.xml +++ b/config/alfresco/ibatis/alfresco-SqlMapConfig.xml @@ -10,6 +10,7 @@ + diff --git a/config/alfresco/ibatis/ibatis-context.xml b/config/alfresco/ibatis/ibatis-context.xml index 018e5e23f7..457d183846 100644 --- a/config/alfresco/ibatis/ibatis-context.xml +++ b/config/alfresco/ibatis/ibatis-context.xml @@ -1,79 +1,80 @@ - - - - - - - - - - org.hibernate.dialect.Dialect - - - - - - - - - - - - - javax.sql.DataSource - - - - - - - - - - - - - - - getConnection - - - - - - - - - classpath:alfresco/ibatis/activities-SqlMapConfig.xml - - - - - - - - - classpath:alfresco/ibatis/alfresco-SqlMapConfig.xml - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + org.hibernate.dialect.Dialect + + + + + + + + + + + + + javax.sql.DataSource + + + + + + + + + + + + + + + getConnection + + + + + + + + + classpath:alfresco/ibatis/activities-SqlMapConfig.xml + + + + + + + + + classpath:alfresco/ibatis/alfresco-SqlMapConfig.xml + + + + + + + + + + + + + + + + + + + + + + diff --git a/config/alfresco/ibatis/org.hibernate.dialect.Dialect/appliedpatch-common-SqlMap.xml b/config/alfresco/ibatis/org.hibernate.dialect.Dialect/appliedpatch-common-SqlMap.xml new file mode 100644 index 0000000000..c6a90bbe4f --- /dev/null +++ b/config/alfresco/ibatis/org.hibernate.dialect.Dialect/appliedpatch-common-SqlMap.xml @@ -0,0 +1,119 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + insert into alf_applied_patch + ( + id, description, + fixes_from_schema, fixes_to_schema, target_schema, + applied_to_schema, applied_on_date, applied_to_server, + was_executed, succeeded, report + ) + values + ( + #id#, #description#, + #fixesFromSchema#, #fixesToSchema#, #targetSchema#, + #appliedToSchema#, #appliedOnDate#, #appliedToServer#, + #wasExecuted#, #succeeded#, #report# + ) + + + + + + + + update alf_applied_patch + set + description = #description#, + fixes_from_schema = #fixesFromSchema#, + fixes_to_schema = #fixesToSchema#, + target_schema = #targetSchema#, + applied_to_schema = #appliedToSchema#, + applied_on_date = #appliedOnDate#, + applied_to_server = #appliedToServer#, + was_executed = #wasExecuted#, + succeeded = #succeeded#, + report = #report# + where + id = #id# + + + + + + + + + + + \ No newline at end of file diff --git a/config/alfresco/import-export-context.xml b/config/alfresco/import-export-context.xml index af35554754..0a83e61275 100644 --- a/config/alfresco/import-export-context.xml +++ b/config/alfresco/import-export-context.xml @@ -176,8 +176,8 @@ - - + + diff --git a/config/alfresco/patch/patch-services-context.xml b/config/alfresco/patch/patch-services-context.xml index c1d4a528ae..72775651b4 100644 --- a/config/alfresco/patch/patch-services-context.xml +++ b/config/alfresco/patch/patch-services-context.xml @@ -28,12 +28,6 @@ - - - - - - @@ -44,8 +38,8 @@ - - + + diff --git a/source/java/org/alfresco/repo/domain/hibernate/AppliedPatchImpl.java b/source/java/org/alfresco/repo/admin/patch/AppliedPatch.java similarity index 59% rename from source/java/org/alfresco/repo/domain/hibernate/AppliedPatchImpl.java rename to source/java/org/alfresco/repo/admin/patch/AppliedPatch.java index 533e0f955c..36e2f8ad56 100644 --- a/source/java/org/alfresco/repo/domain/hibernate/AppliedPatchImpl.java +++ b/source/java/org/alfresco/repo/admin/patch/AppliedPatch.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005-2007 Alfresco Software Limited. + * Copyright (C) 2005-2010 Alfresco Software Limited. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -22,59 +22,55 @@ * the FLOSS exception, and it is also available here: * http://www.alfresco.com/legal/licensing" */ -package org.alfresco.repo.domain.hibernate; +package org.alfresco.repo.admin.patch; -import java.io.Serializable; import java.util.Date; -import org.alfresco.repo.domain.AppliedPatch; - /** - * Hibernate-specific implementation of the persistent object. + * Applied patch bean * * @author Derek Hulley + * @since 3.3 */ -public class AppliedPatchImpl implements AppliedPatch, Serializable +public class AppliedPatch { - private static final long serialVersionUID = 2694230422651768785L; - private String id; private String description; private int fixesFromSchema; private int fixesToSchema; private int targetSchema; - private int appliedToSchema; private String appliedToServer; private Date appliedOnDate; private boolean wasExecuted; private boolean succeeded; private String report; - - public AppliedPatchImpl() - { - } - - @Override - public String toString() - { - StringBuilder sb = new StringBuilder(256); - sb.append("AppliedPatch") - .append("[ id=").append(id) - .append(", description=").append(description) - .append(", fixesFromSchema=").append(fixesFromSchema) - .append(", fixesToSchema=").append(fixesToSchema) - .append(", targetSchema=").append(targetSchema) - .append(", appliedToSchema=").append(appliedToSchema) - .append(", appliedToServer=").append(appliedToServer) - .append(", appliedOnDate=").append(appliedOnDate) - .append(", wasExecuted=").append(wasExecuted) - .append(", succeeded=").append(succeeded) - .append(", report=").append(report) - .append("]"); - return sb.toString(); - } + /** + * Default constructor + */ + public AppliedPatch() + { + } + + /** + * Construct an instance from another patch info-provider + */ + public AppliedPatch(AppliedPatch appliedPatch) + { + this.id = appliedPatch.getId(); + this.description = appliedPatch.getDescription(); + this.fixesFromSchema = appliedPatch.getFixesFromSchema(); + this.fixesToSchema = appliedPatch.getFixesToSchema(); + this.targetSchema = appliedPatch.getTargetSchema(); + this.appliedToSchema = appliedPatch.getAppliedToSchema(); + this.appliedToServer = appliedPatch.getAppliedToServer(); + this.appliedOnDate = appliedPatch.getAppliedOnDate(); + this.wasExecuted = appliedPatch.getWasExecuted(); + this.succeeded = appliedPatch.getSucceeded(); + this.report = appliedPatch.getReport(); + } + public String getId() { return id; @@ -90,60 +86,54 @@ public class AppliedPatchImpl implements AppliedPatch, Serializable } public void setDescription(String description) { - if (description != null && description.length() > 1024) - { - // truncate as necessary - description = (description.substring(0, 1020) + "..."); - } this.description = description; } - + public int getFixesFromSchema() { return fixesFromSchema; } - public void setFixesFromSchema(int version) + public void setFixesFromSchema(int fixesFromSchema) { - this.fixesFromSchema = version; + this.fixesFromSchema = fixesFromSchema; } - + public int getFixesToSchema() { return fixesToSchema; } - public void setFixesToSchema(int version) + public void setFixesToSchema(int fixesToSchema) { - this.fixesToSchema = version; + this.fixesToSchema = fixesToSchema; } - + public int getTargetSchema() { return targetSchema; } - public void setTargetSchema(int currentSchema) + public void setTargetSchema(int targetSchema) { - this.targetSchema = currentSchema; + this.targetSchema = targetSchema; } - + public int getAppliedToSchema() { return appliedToSchema; } - public void setAppliedToSchema(int version) + public void setAppliedToSchema(int appliedToSchema) { - this.appliedToSchema = version; + this.appliedToSchema = appliedToSchema; } - + public String getAppliedToServer() { return appliedToServer; } - public void setAppliedToServer(String appliedToServer) { this.appliedToServer = appliedToServer; } - + public Date getAppliedOnDate() { return appliedOnDate; @@ -170,18 +160,13 @@ public class AppliedPatchImpl implements AppliedPatch, Serializable { this.succeeded = succeeded; } - + public String getReport() { return report; } public void setReport(String report) { - if (report != null && report.length() > 1024) - { - // truncate as necessary - report = (report.substring(0, 1020) + "..."); - } this.report = report; } -} \ No newline at end of file +} diff --git a/source/java/org/alfresco/repo/admin/patch/PatchExecuter.java b/source/java/org/alfresco/repo/admin/patch/PatchExecuter.java index d402c1d753..91b0d39a41 100644 --- a/source/java/org/alfresco/repo/admin/patch/PatchExecuter.java +++ b/source/java/org/alfresco/repo/admin/patch/PatchExecuter.java @@ -90,7 +90,7 @@ public class PatchExecuter extends AbstractLifecycleBean Date after = new Date(System .currentTimeMillis() + 20000L); // 20 seconds ahead // get all the patches executed in the time - List appliedPatches = patchService.getPatches(before, after); + List appliedPatches = patchService.getPatches(before, after); // don't report anything if nothing was done if (appliedPatches.size() == 0) @@ -101,7 +101,7 @@ public class PatchExecuter extends AbstractLifecycleBean { boolean succeeded = true; // list all patches applied, including failures - for (PatchInfo patchInfo : appliedPatches) + for (AppliedPatch patchInfo : appliedPatches) { if (!patchInfo.getWasExecuted()) { diff --git a/source/java/org/alfresco/repo/admin/patch/PatchService.java b/source/java/org/alfresco/repo/admin/patch/PatchService.java index 7a2e2a2545..29394ff64b 100644 --- a/source/java/org/alfresco/repo/admin/patch/PatchService.java +++ b/source/java/org/alfresco/repo/admin/patch/PatchService.java @@ -27,8 +27,6 @@ package org.alfresco.repo.admin.patch; import java.util.Date; import java.util.List; -import org.alfresco.error.AlfrescoRuntimeException; - /** * Manages patches applied against the repository. *

@@ -73,5 +71,5 @@ public interface PatchService * the end date of the search, or null to g * @return Returns all applied patches (successful or not) */ - public List getPatches(Date fromDate, Date toDate); + public List getPatches(Date fromDate, Date toDate); } diff --git a/source/java/org/alfresco/repo/admin/patch/PatchServiceImpl.java b/source/java/org/alfresco/repo/admin/patch/PatchServiceImpl.java index 69a1615312..3d4b97dec4 100644 --- a/source/java/org/alfresco/repo/admin/patch/PatchServiceImpl.java +++ b/source/java/org/alfresco/repo/admin/patch/PatchServiceImpl.java @@ -32,8 +32,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import org.springframework.extensions.surf.util.I18NUtil; -import org.alfresco.repo.domain.AppliedPatch; +import org.alfresco.repo.domain.patch.AppliedPatchDAO; import org.alfresco.repo.transaction.TransactionServiceImpl; import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback; import org.alfresco.service.cmr.admin.PatchException; @@ -42,6 +41,7 @@ import org.alfresco.service.descriptor.Descriptor; import org.alfresco.service.descriptor.DescriptorService; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.springframework.extensions.surf.util.I18NUtil; /** @@ -68,7 +68,7 @@ public class PatchServiceImpl implements PatchService private DescriptorService descriptorService; private TransactionServiceImpl transactionService; private RuleService ruleService; - private PatchDaoService patchDaoService; + private AppliedPatchDAO appliedPatchDAO; private List patches; public PatchServiceImpl() @@ -86,9 +86,9 @@ public class PatchServiceImpl implements PatchService this.transactionService = transactionService; } - public void setPatchDaoService(PatchDaoService patchDaoService) + public void setAppliedPatchDAO(AppliedPatchDAO appliedPatchDAO) { - this.patchDaoService = patchDaoService; + this.appliedPatchDAO = appliedPatchDAO; } public void setRuleService(RuleService ruleService) @@ -139,7 +139,7 @@ public class PatchServiceImpl implements PatchService // construct a list of executed patches by ID (also check the date) Map appliedPatchesById = new HashMap(23); - List appliedPatches = patchDaoService.getAppliedPatches(); + List appliedPatches = appliedPatchDAO.getAppliedPatches(); for (final AppliedPatch appliedPatch : appliedPatches) { appliedPatchesById.put(appliedPatch.getId(), appliedPatch); @@ -153,7 +153,8 @@ public class PatchServiceImpl implements PatchService public Date execute() throws Throwable { Date now = new Date(); - patchDaoService.setAppliedOnDate(appliedPatch.getId(), now); + appliedPatch.setAppliedOnDate(now); + appliedPatchDAO.updateAppliedPatch(appliedPatch); return now; } }; @@ -255,7 +256,7 @@ public class PatchServiceImpl implements PatchService " Patch: " + patch); } // get the patch from the DAO - AppliedPatch appliedPatch = patchDaoService.getAppliedPatch(patch.getId()); + AppliedPatch appliedPatch = appliedPatchDAO.getAppliedPatch(patch.getId()); // We bypass the patch if it was executed successfully if (appliedPatch != null && !forcePatch) { @@ -316,9 +317,17 @@ public class PatchServiceImpl implements PatchService String server = (serverDescriptor.getVersion() + " - " + serverDescriptor.getEdition()); // create or update the record of execution + boolean create = true; if (appliedPatch == null) { - appliedPatch = patchDaoService.newAppliedPatch(patch.getId()); + appliedPatch = new AppliedPatch(); + appliedPatch.setId(patch.getId()); + create = true; + } + else + { + // Update it + create = false; } // fill in the record's details String patchDescription = I18NUtil.getMessage(patch.getDescription()); @@ -337,6 +346,15 @@ public class PatchServiceImpl implements PatchService appliedPatch.setSucceeded(success); // whether or not the patch succeeded appliedPatch.setWasExecuted(applies); // whether or not the patch was executed appliedPatch.setReport(report); // additional, human-readable, status + // Update or create the entry + if (create) + { + appliedPatchDAO.createAppliedPatch(appliedPatch); + } + else + { + appliedPatchDAO.updateAppliedPatch(appliedPatch); + } // done if (logger.isDebugEnabled()) @@ -359,7 +377,7 @@ public class PatchServiceImpl implements PatchService for (Patch alternative : alternatives) { // If the patch was executed, then this one was effectively executed - AppliedPatch appliedAlternative = patchDaoService.getAppliedPatch(alternative.getId()); + AppliedPatch appliedAlternative = appliedPatchDAO.getAppliedPatch(alternative.getId()); if (appliedAlternative != null && appliedAlternative.getSucceeded()) { return alternative.getId(); @@ -392,7 +410,7 @@ public class PatchServiceImpl implements PatchService } @SuppressWarnings("unchecked") - public List getPatches(Date fromDate, Date toDate) + public List getPatches(Date fromDate, Date toDate) { if (fromDate == null) { @@ -402,14 +420,9 @@ public class PatchServiceImpl implements PatchService { toDate = INFINITE_DATE; } - List appliedPatches = patchDaoService.getAppliedPatches(fromDate, toDate); - // disconnect each of these - for (PatchInfo appliedPatch : appliedPatches) - { - patchDaoService.detach((AppliedPatch)appliedPatch); - } + List appliedPatches = appliedPatchDAO.getAppliedPatches(fromDate, toDate); // done - return (List) appliedPatches; + return (List) appliedPatches; } /** diff --git a/source/java/org/alfresco/repo/admin/patch/PatchTest.java b/source/java/org/alfresco/repo/admin/patch/PatchTest.java index 1b55bf4805..ddf6917cfc 100644 --- a/source/java/org/alfresco/repo/admin/patch/PatchTest.java +++ b/source/java/org/alfresco/repo/admin/patch/PatchTest.java @@ -1,198 +1,188 @@ -/* - * Copyright (C) 2005-2007 Alfresco Software Limited. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - - * As a special exception to the terms and conditions of version 2.0 of - * the GPL, you may redistribute this Program in connection with Free/Libre - * and Open Source Software ("FLOSS") applications as described in Alfresco's - * FLOSS exception. You should have recieved a copy of the text describing - * the FLOSS exception, and it is also available here: - * http://www.alfresco.com/legal/licensing" - */ -package org.alfresco.repo.admin.patch; - -import java.util.Date; -import java.util.List; - -import junit.framework.TestCase; - -import org.alfresco.error.AlfrescoRuntimeException; -import org.alfresco.repo.domain.AppliedPatch; -import org.alfresco.repo.security.authentication.AuthenticationContext; -import org.alfresco.service.cmr.admin.PatchException; -import org.alfresco.service.cmr.repository.NodeService; -import org.alfresco.service.cmr.search.SearchService; -import org.alfresco.service.namespace.NamespaceService; -import org.alfresco.service.transaction.TransactionService; -import org.alfresco.util.ApplicationContextHelper; -import org.springframework.context.ApplicationContext; - -/** - * @see org.alfresco.repo.admin.patch.Patch - * @see org.alfresco.repo.admin.patch.AbstractPatch - * @see org.alfresco.repo.admin.patch.PatchService - * - * @author Derek Hulley - */ -public class PatchTest extends TestCase -{ - private static final ApplicationContext ctx = ApplicationContextHelper.getApplicationContext(); - - private TransactionService transactionService; - private NamespaceService namespaceService; - private NodeService nodeService; - private SearchService searchService; - private AuthenticationContext authenticationContext; - private PatchService patchService; - private PatchDaoService patchDaoComponent; - - public PatchTest(String name) - { - super(name); - } - - public void setUp() throws Exception - { - transactionService = (TransactionService) ctx.getBean("transactionComponent"); - namespaceService = (NamespaceService) ctx.getBean("namespaceService"); - nodeService = (NodeService) ctx.getBean("nodeService"); - searchService = (SearchService) ctx.getBean("searchService"); - authenticationContext = (AuthenticationContext) ctx.getBean("authenticationContext"); - - patchService = (PatchService) ctx.getBean("PatchService"); - patchDaoComponent = (PatchDaoService) ctx.getBean("patchDaoComponent"); - - // get the patches to play with - patchService.registerPatch((Patch)ctx.getBean("patch.sample.02")); - patchService.registerPatch((Patch)ctx.getBean("patch.sample.01")); - } - - public void testSetup() throws Exception - { - assertNotNull(transactionService); - assertNotNull(patchService); - assertNotNull(patchDaoComponent); - } - - private SamplePatch constructSamplePatch(boolean mustFail) - { - SamplePatch patch = new SamplePatch(mustFail, transactionService); - patch.setNamespaceService(namespaceService); - patch.setNodeService(nodeService); - patch.setSearchService(searchService); - patch.setAuthenticationContext(authenticationContext); - // done - return patch; - } - - public void testSimplePatchSuccess() throws Exception - { - Patch patch = constructSamplePatch(false); - String report = patch.apply(); - // check that the report was generated - assertEquals("Patch report incorrect", SamplePatch.MSG_SUCCESS, report); - } - - public void testPatchReapplication() - { - // successfully apply a patch - Patch patch = constructSamplePatch(false); - patch.apply(); - // check that the patch cannot be reapplied - try - { - patch.apply(); - fail("AbstractPatch failed to prevent reapplication"); - } - catch (AlfrescoRuntimeException e) - { - // expected - } - - // apply an unsuccessful patch - patch = constructSamplePatch(true); - try - { - patch.apply(); - fail("Failed patch didn't throw PatchException"); - } - catch (PatchException e) - { - // expected - } - // repeat - try - { - patch.apply(); - fail("Reapplication of failed patch didn't throw PatchException"); - } - catch (PatchException e) - { - // expected - } - } - - public void testApplyOutstandingPatches() throws Exception - { - // apply outstanding patches - boolean success = patchService.applyOutstandingPatches(); - assertTrue(success); - // get applied patches - List appliedPatches = patchDaoComponent.getAppliedPatches(); - // check that the patch application was recorded - boolean found01 = false; - boolean found02 = false; - for (AppliedPatch appliedPatch : appliedPatches) - { - if (appliedPatch.getId().equals("Sample01")) - { - found01 = true; - assertTrue("Patch info didn't indicate success: " + appliedPatch, appliedPatch.getSucceeded()); - } - else if (appliedPatch.getId().equals("Sample02")) - { - found02 = true; - assertTrue("Patch info didn't indicate success: " + appliedPatch, appliedPatch.getSucceeded()); - } - } - assertTrue("Sample 01 not in list of applied patches", found01); - assertTrue("Sample 02 not in list of applied patches", found02); - } - - public void testGetPatchesByDate() throws Exception - { - // ensure that there are some applied patches - testApplyOutstandingPatches(); - // get the number of applied patches - List appliedPatches = patchDaoComponent.getAppliedPatches(); - assertTrue("Expected at least 2 applied patches", appliedPatches.size() >= 2); - - // now requery using null dates - List appliedPatchesAllDates = patchService.getPatches(null, null); - assertEquals("Applied patches by all dates doesn't match all applied patches", - appliedPatches.size(), appliedPatchesAllDates.size()); - - // make sure that the objects are not connected to the persistence layer - PatchInfo disconnectedObject = appliedPatchesAllDates.get(0); - AppliedPatch persistedObject = patchDaoComponent.getAppliedPatch(disconnectedObject.getId()); - assertNotSame("Instances should not be shared between evicted and cached objects", - disconnectedObject, persistedObject); - - // perform another query with dates that should return no results - List appliedPatchesFutureDates = patchService.getPatches(new Date(), new Date()); - assertEquals("Query returned results for dates when no patches should exist", 0, appliedPatchesFutureDates.size()); - } -} +/* + * Copyright (C) 2005-2007 Alfresco Software Limited. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + * As a special exception to the terms and conditions of version 2.0 of + * the GPL, you may redistribute this Program in connection with Free/Libre + * and Open Source Software ("FLOSS") applications as described in Alfresco's + * FLOSS exception. You should have recieved a copy of the text describing + * the FLOSS exception, and it is also available here: + * http://www.alfresco.com/legal/licensing" + */ +package org.alfresco.repo.admin.patch; + +import java.util.Date; +import java.util.List; + +import junit.framework.TestCase; + +import org.alfresco.error.AlfrescoRuntimeException; +import org.alfresco.repo.security.authentication.AuthenticationContext; +import org.alfresco.service.cmr.admin.PatchException; +import org.alfresco.service.cmr.repository.NodeService; +import org.alfresco.service.cmr.search.SearchService; +import org.alfresco.service.namespace.NamespaceService; +import org.alfresco.service.transaction.TransactionService; +import org.alfresco.util.ApplicationContextHelper; +import org.springframework.context.ApplicationContext; + +/** + * @see org.alfresco.repo.admin.patch.Patch + * @see org.alfresco.repo.admin.patch.AbstractPatch + * @see org.alfresco.repo.admin.patch.PatchService + * + * @author Derek Hulley + */ +public class PatchTest extends TestCase +{ + private static final ApplicationContext ctx = ApplicationContextHelper.getApplicationContext(); + + private TransactionService transactionService; + private NamespaceService namespaceService; + private NodeService nodeService; + private SearchService searchService; + private AuthenticationContext authenticationContext; + private PatchService patchService; + + public PatchTest(String name) + { + super(name); + } + + public void setUp() throws Exception + { + transactionService = (TransactionService) ctx.getBean("transactionComponent"); + namespaceService = (NamespaceService) ctx.getBean("namespaceService"); + nodeService = (NodeService) ctx.getBean("nodeService"); + searchService = (SearchService) ctx.getBean("searchService"); + authenticationContext = (AuthenticationContext) ctx.getBean("authenticationContext"); + + patchService = (PatchService) ctx.getBean("PatchService"); + + // get the patches to play with + patchService.registerPatch((Patch)ctx.getBean("patch.sample.02")); + patchService.registerPatch((Patch)ctx.getBean("patch.sample.01")); + } + + public void testSetup() throws Exception + { + assertNotNull(transactionService); + assertNotNull(patchService); + } + + private SamplePatch constructSamplePatch(boolean mustFail) + { + SamplePatch patch = new SamplePatch(mustFail, transactionService); + patch.setNamespaceService(namespaceService); + patch.setNodeService(nodeService); + patch.setSearchService(searchService); + patch.setAuthenticationContext(authenticationContext); + // done + return patch; + } + + public void testSimplePatchSuccess() throws Exception + { + Patch patch = constructSamplePatch(false); + String report = patch.apply(); + // check that the report was generated + assertEquals("Patch report incorrect", SamplePatch.MSG_SUCCESS, report); + } + + public void testPatchReapplication() + { + // successfully apply a patch + Patch patch = constructSamplePatch(false); + patch.apply(); + // check that the patch cannot be reapplied + try + { + patch.apply(); + fail("AbstractPatch failed to prevent reapplication"); + } + catch (AlfrescoRuntimeException e) + { + // expected + } + + // apply an unsuccessful patch + patch = constructSamplePatch(true); + try + { + patch.apply(); + fail("Failed patch didn't throw PatchException"); + } + catch (PatchException e) + { + // expected + } + // repeat + try + { + patch.apply(); + fail("Reapplication of failed patch didn't throw PatchException"); + } + catch (PatchException e) + { + // expected + } + } + + public void testApplyOutstandingPatches() throws Exception + { + // apply outstanding patches + boolean success = patchService.applyOutstandingPatches(); + assertTrue(success); + // get applied patches + List appliedPatches = patchService.getPatches(null, null); + // check that the patch application was recorded + boolean found01 = false; + boolean found02 = false; + for (AppliedPatch appliedPatch : appliedPatches) + { + if (appliedPatch.getId().equals("Sample01")) + { + found01 = true; + assertTrue("Patch info didn't indicate success: " + appliedPatch, appliedPatch.getSucceeded()); + } + else if (appliedPatch.getId().equals("Sample02")) + { + found02 = true; + assertTrue("Patch info didn't indicate success: " + appliedPatch, appliedPatch.getSucceeded()); + } + } + assertTrue("Sample 01 not in list of applied patches", found01); + assertTrue("Sample 02 not in list of applied patches", found02); + } + + public void testGetPatchesByDate() throws Exception + { + // ensure that there are some applied patches + testApplyOutstandingPatches(); + // get the number of applied patches + List appliedPatches = patchService.getPatches(null, null); + assertTrue("Expected at least 2 applied patches", appliedPatches.size() >= 2); + + // now requery using null dates + List appliedPatchesAllDates = patchService.getPatches(null, null); + assertEquals("Applied patches by all dates doesn't match all applied patches", + appliedPatches.size(), appliedPatchesAllDates.size()); + + // perform another query with dates that should return no results + List appliedPatchesFutureDates = patchService.getPatches(new Date(), new Date()); + assertEquals("Query returned results for dates when no patches should exist", 0, appliedPatchesFutureDates.size()); + } +} diff --git a/source/java/org/alfresco/repo/admin/patch/hibernate/HibernatePatchDaoServiceImpl.java b/source/java/org/alfresco/repo/admin/patch/hibernate/HibernatePatchDaoServiceImpl.java deleted file mode 100644 index f7f603b854..0000000000 --- a/source/java/org/alfresco/repo/admin/patch/hibernate/HibernatePatchDaoServiceImpl.java +++ /dev/null @@ -1,137 +0,0 @@ -/* - * Copyright (C) 2005-2007 Alfresco Software Limited. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - - * As a special exception to the terms and conditions of version 2.0 of - * the GPL, you may redistribute this Program in connection with Free/Libre - * and Open Source Software ("FLOSS") applications as described in Alfresco's - * FLOSS exception. You should have recieved a copy of the text describing - * the FLOSS exception, and it is also available here: - * http://www.alfresco.com/legal/licensing" - */ -package org.alfresco.repo.admin.patch.hibernate; - -import java.util.Date; -import java.util.Iterator; -import java.util.List; - -import org.alfresco.error.AlfrescoRuntimeException; -import org.alfresco.repo.admin.patch.PatchDaoService; -import org.alfresco.repo.domain.AppliedPatch; -import org.alfresco.repo.domain.hibernate.AppliedPatchImpl; -import org.hibernate.Query; -import org.hibernate.Session; -import org.springframework.orm.hibernate3.HibernateCallback; -import org.springframework.orm.hibernate3.support.HibernateDaoSupport; - -/** - * Hibernate-specific implementation for managing patch persistence. - * - * @since 1.2 - * @author Derek Hulley - */ -public class HibernatePatchDaoServiceImpl extends HibernateDaoSupport implements PatchDaoService -{ - public static final String QUERY_GET_ALL_APPLIED_PATCHES = "patch.GetAllAppliedPatches"; - public static final String QUERY_GET_APPLIED_PATCHES_BY_DATE = "patch.GetAppliedPatchesByDate"; - - public AppliedPatch newAppliedPatch(String id) - { - // check for existence - AppliedPatch existing = getAppliedPatch(id); - if (existing != null) - { - throw new AlfrescoRuntimeException("An applied patch already exists: \n" + - " id: " + id); - } - // construct a new one - AppliedPatchImpl patch = new AppliedPatchImpl(); - patch.setId(id); - // save this in hibernate - getHibernateTemplate().save(patch); - // done - return patch; - } - - public AppliedPatch getAppliedPatch(String id) - { - AppliedPatch patch = (AppliedPatch) getHibernateTemplate().get(AppliedPatchImpl.class, id); - // done - return patch; - } - - public void detach(AppliedPatch appliedPatch) - { - getSession().evict(appliedPatch); - } - - /** - * @see #QUERY_GET_ALL_APPLIED_PATCHES - */ - @SuppressWarnings("unchecked") - public List getAppliedPatches() - { - HibernateCallback callback = new HibernateCallback() - { - public Object doInHibernate(Session session) - { - Query query = session.getNamedQuery(HibernatePatchDaoServiceImpl.QUERY_GET_ALL_APPLIED_PATCHES); - return query.list(); - } - }; - List queryResults = (List) getHibernateTemplate().execute(callback); - // done - return queryResults; - } - - /** - * @see #QUERY_GET_APPLIED_PATCHES_BY_DATE - */ - @SuppressWarnings("unchecked") - public List getAppliedPatches(final Date fromDate, final Date toDate) - { - HibernateCallback callback = new HibernateCallback() - { - public Object doInHibernate(Session session) - { - Query query = session.getNamedQuery(HibernatePatchDaoServiceImpl.QUERY_GET_ALL_APPLIED_PATCHES); - return query.list(); - } - }; - List queryResults = (List) getHibernateTemplate().execute(callback); - // eliminate results that are out of range - Iterator iterator = queryResults.iterator(); - while (iterator.hasNext()) - { - AppliedPatch appliedPatch = iterator.next(); - Date appliedOnDate = appliedPatch.getAppliedOnDate(); - if (appliedOnDate != null && - (fromDate.compareTo(appliedOnDate) >= 0 || toDate.compareTo(appliedOnDate) <= 0)) - { - // it is out of range - iterator.remove(); - } - } - // done - return queryResults; - } - - public void setAppliedOnDate(String id, Date appliedOnDate) - { - AppliedPatch patch = (AppliedPatch) getHibernateTemplate().get(AppliedPatchImpl.class, id); - patch.setAppliedOnDate(appliedOnDate); - } -} diff --git a/source/java/org/alfresco/repo/domain/AppliedPatch.java b/source/java/org/alfresco/repo/domain/AppliedPatch.java deleted file mode 100644 index 5f613f945e..0000000000 --- a/source/java/org/alfresco/repo/domain/AppliedPatch.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright (C) 2005-2007 Alfresco Software Limited. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - - * As a special exception to the terms and conditions of version 2.0 of - * the GPL, you may redistribute this Program in connection with Free/Libre - * and Open Source Software ("FLOSS") applications as described in Alfresco's - * FLOSS exception. You should have recieved a copy of the text describing - * the FLOSS exception, and it is also available here: - * http://www.alfresco.com/legal/licensing" - */ -package org.alfresco.repo.domain; - -import java.util.Date; - -import org.alfresco.repo.admin.patch.PatchInfo; - -/** - * Interface for persistent patch application information. - * - * @author Derek Hulley - */ -public interface AppliedPatch extends PatchInfo -{ - public void setId(String id); - - public void setDescription(String description); - - public void setFixesFromSchema(int version); - - public void setFixesToSchema(int version); - - public void setTargetSchema(int version); - - public void setAppliedToSchema(int version); - - public void setAppliedToServer(String server); - - public void setAppliedOnDate(Date date); - - public void setWasExecuted(boolean executed); - - public void setSucceeded(boolean succeeded); - - public void setReport(String report); -} diff --git a/source/java/org/alfresco/repo/domain/DomainTestSuite.java b/source/java/org/alfresco/repo/domain/DomainTestSuite.java index d009a7f73c..e926c59f72 100644 --- a/source/java/org/alfresco/repo/domain/DomainTestSuite.java +++ b/source/java/org/alfresco/repo/domain/DomainTestSuite.java @@ -33,6 +33,7 @@ import org.alfresco.repo.domain.encoding.EncodingDAOTest; import org.alfresco.repo.domain.hibernate.HibernateSessionHelperTest; import org.alfresco.repo.domain.locks.LockDAOTest; import org.alfresco.repo.domain.mimetype.MimetypeDAOTest; +import org.alfresco.repo.domain.patch.AppliedPatchDAOTest; /** * Suite for domain-related tests. @@ -55,6 +56,7 @@ public class DomainTestSuite extends TestSuite suite.addTestSuite(QNameDAOTest.class); suite.addTestSuite(PropertyValueTest.class); suite.addTestSuite(AuditDAOTest.class); + suite.addTestSuite(AppliedPatchDAOTest.class); return suite; } diff --git a/source/java/org/alfresco/repo/domain/patch/AbstractAppliedPatchDAOImpl.java b/source/java/org/alfresco/repo/domain/patch/AbstractAppliedPatchDAOImpl.java new file mode 100644 index 0000000000..8b0e18b25a --- /dev/null +++ b/source/java/org/alfresco/repo/domain/patch/AbstractAppliedPatchDAOImpl.java @@ -0,0 +1,99 @@ +/* + * Copyright (C) 2005-2010 Alfresco Software Limited. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + * As a special exception to the terms and conditions of version 2.0 of + * the GPL, you may redistribute this Program in connection with Free/Libre + * and Open Source Software ("FLOSS") applications as described in Alfresco's + * FLOSS exception. You should have recieved a copy of the text describing + * the FLOSS exception, and it is also available here: + * http://www.alfresco.com/legal/licensing" + */ +package org.alfresco.repo.domain.patch; + +import java.util.ArrayList; +import java.util.Date; +import java.util.Iterator; +import java.util.List; + +import org.alfresco.repo.admin.patch.AppliedPatch; + +/** + * Abstract implementation for DAO alf_applied_patch. + * + * @author Derek Hulley + * @since 3.3 + */ +public abstract class AbstractAppliedPatchDAOImpl implements AppliedPatchDAO +{ + public void createAppliedPatch(AppliedPatch appliedPatch) + { + AppliedPatchEntity entity = new AppliedPatchEntity(appliedPatch); + createAppliedPatchEntity(entity); + } + + public void updateAppliedPatch(AppliedPatch appliedPatch) + { + AppliedPatchEntity entity = new AppliedPatchEntity(appliedPatch); + updateAppliedPatchEntity(entity); + } + + public AppliedPatch getAppliedPatch(String id) + { + return getAppliedPatchEntity(id); + } + + public List getAppliedPatches() + { + List entities = getAppliedPatchEntities(); + List results = new ArrayList(); + results.addAll(entities); + return results; + } + + public List getAppliedPatches(Date from, Date to) + { + // Manual filter (no performance required) + List results = getAppliedPatches(); + Iterator iterator = results.iterator(); + while (iterator.hasNext()) + { + AppliedPatch next = iterator.next(); + Date appliedOn = next.getAppliedOnDate(); + if (from != null && appliedOn != null && from.compareTo(appliedOn) >= 0) + { + iterator.remove(); + continue; + } + if (to != null && appliedOn != null && to.compareTo(appliedOn) <= 0) + { + iterator.remove(); + continue; + } + } + return results; + } + + public void setAppliedOnDate(String id, Date appliedOnDate) + { + throw new UnsupportedOperationException(); + } + + protected abstract void createAppliedPatchEntity(AppliedPatchEntity entity); + protected abstract void updateAppliedPatchEntity(AppliedPatchEntity appliedPatch); + protected abstract AppliedPatchEntity getAppliedPatchEntity(String id); + protected abstract List getAppliedPatchEntities(); +} diff --git a/source/java/org/alfresco/repo/admin/patch/PatchDaoService.java b/source/java/org/alfresco/repo/domain/patch/AppliedPatchDAO.java similarity index 68% rename from source/java/org/alfresco/repo/admin/patch/PatchDaoService.java rename to source/java/org/alfresco/repo/domain/patch/AppliedPatchDAO.java index 9773431a69..35944fc1c2 100644 --- a/source/java/org/alfresco/repo/admin/patch/PatchDaoService.java +++ b/source/java/org/alfresco/repo/domain/patch/AppliedPatchDAO.java @@ -22,48 +22,38 @@ * the FLOSS exception, and it is also available here: * http://www.alfresco.com/legal/licensing" */ -package org.alfresco.repo.admin.patch; +package org.alfresco.repo.domain.patch; import java.util.Date; import java.util.List; -import org.alfresco.repo.domain.AppliedPatch; +import org.alfresco.repo.admin.patch.AppliedPatch; /** - * Provides data access support for patch persistence. + * Provides data access support for patch persistence in alf_applied_patch. * - * @since 1.2 + * @since 3.3 * @author Derek Hulley */ -public interface PatchDaoService +public interface AppliedPatchDAO { /** - * Creates and saves a new instance of the patch. This will not have all the mandatory - * properties set - only the ID. + * Creates and saves a new instance of the patch. * - * @param id the unique key - * @return Returns a new instance that can be manipulated + * @param patchInfo the patch ID and details */ - public AppliedPatch newAppliedPatch(String id); + public void createAppliedPatch(AppliedPatch appliedPatch); + + public void updateAppliedPatch(AppliedPatch appliedPatch); /** * Retrieve an existing patch * * @param id the patch unique ID - * @return Returns the patch instance or null if one has not been persisted + * @return Returns the patch instance or null if one has not been persisted */ public AppliedPatch getAppliedPatch(String id); - /** - * Detaches the given instance from the persistence engine. This will - * ensure that any changes made to the java object do not get persisted, - * allowing the objects to be passed out to external clients without any - * concern of their lifecycle. - * - * @param appliedPatch the object to detach from persistence - */ - public void detach(AppliedPatch appliedPatch); - /** * Get a list of all applied patches * diff --git a/source/java/org/alfresco/repo/domain/patch/AppliedPatchDAOTest.java b/source/java/org/alfresco/repo/domain/patch/AppliedPatchDAOTest.java new file mode 100644 index 0000000000..ceb8ef410e --- /dev/null +++ b/source/java/org/alfresco/repo/domain/patch/AppliedPatchDAOTest.java @@ -0,0 +1,153 @@ +/* + * Copyright (C) 2005-2010 Alfresco Software Limited. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + * As a special exception to the terms and conditions of version 2.0 of + * the GPL, you may redistribute this Program in connection with Free/Libre + * and Open Source Software ("FLOSS") applications as described in Alfresco's + * FLOSS exception. You should have recieved a copy of the text describing + * the FLOSS exception, and it is also available here: + * http://www.alfresco.com/legal/licensing" + */ +package org.alfresco.repo.domain.patch; + +import java.util.Date; + +import junit.framework.TestCase; + +import org.alfresco.repo.admin.patch.AppliedPatch; +import org.alfresco.repo.transaction.RetryingTransactionHelper; +import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback; +import org.alfresco.service.ServiceRegistry; +import org.alfresco.service.transaction.TransactionService; +import org.alfresco.util.ApplicationContextHelper; +import org.springframework.context.ApplicationContext; + +/** + * @see AppliedPatchDAO + * + * @author Derek Hulley + * @since 3.3 + */ +public class AppliedPatchDAOTest extends TestCase +{ + private ApplicationContext ctx = ApplicationContextHelper.getApplicationContext(); + + private TransactionService transactionService; + private RetryingTransactionHelper txnHelper; + private AppliedPatchDAO appliedPatchDAO; + + @Override + public void setUp() throws Exception + { + ServiceRegistry serviceRegistry = (ServiceRegistry) ctx.getBean(ServiceRegistry.SERVICE_REGISTRY); + transactionService = serviceRegistry.getTransactionService(); + txnHelper = transactionService.getRetryingTransactionHelper(); + + appliedPatchDAO = (AppliedPatchDAO) ctx.getBean("appliedPatchDAO"); + } + + private AppliedPatch create(String id, boolean allNull) throws Exception + { + final AppliedPatch appliedPatch = new AppliedPatchEntity(); + appliedPatch.setId(id); + if (!allNull) + { + appliedPatch.setDescription(id); + appliedPatch.setFixesFromSchema(0); + appliedPatch.setFixesToSchema(1); + appliedPatch.setTargetSchema(2); + appliedPatch.setAppliedOnDate(new Date()); + appliedPatch.setAppliedToSchema(1); + appliedPatch.setAppliedToServer("blah"); + appliedPatch.setWasExecuted(true); + appliedPatch.setSucceeded(true); + appliedPatch.setReport("All good in test " + getName()); + } + RetryingTransactionCallback callback = new RetryingTransactionCallback() + { + public Void execute() throws Throwable + { + appliedPatchDAO.createAppliedPatch(appliedPatch); + return null; + } + }; + txnHelper.doInTransaction(callback); + return appliedPatch; + } + + private AppliedPatch get(final String id) throws Exception + { + RetryingTransactionCallback callback = new RetryingTransactionCallback() + { + public AppliedPatch execute() throws Throwable + { + return appliedPatchDAO.getAppliedPatch(id); + } + }; + return txnHelper.doInTransaction(callback); + } + + public void testCreateEmpty() throws Exception + { + final String id = getName() + "-" + System.currentTimeMillis(); + create(id, true); + } + + public void testCreatePopulated() throws Exception + { + final String id = getName() + "-" + System.currentTimeMillis(); + create(id, false); + } + + public void testCreateWithRollback() throws Exception + { + final String id = getName() + "-" + System.currentTimeMillis(); + // Create an encoding + RetryingTransactionCallback callback = new RetryingTransactionCallback() + { + public Void execute() throws Throwable + { + create(id, false); + // Now force a rollback + throw new RuntimeException("Forced"); + } + }; + try + { + txnHelper.doInTransaction(callback); + fail("Transaction didn't roll back"); + } + catch (RuntimeException e) + { + // Expected + } + // Check that it doesn't exist + get(id); + } +// +// public void testCaseInsensitivity() throws Exception +// { +// String encoding = "AAA-" + GUID.generate(); +// Pair lowercasePair = get(encoding.toLowerCase(), true, true); +// // Check that the same pair is retrievable using uppercase +// Pair uppercasePair = get(encoding.toUpperCase(), true, true); +// assertNotNull(uppercasePair); +// assertEquals( +// "Upper and lowercase encoding instance IDs were not the same", +// lowercasePair.getFirst(), uppercasePair.getFirst()); +// } +} diff --git a/source/java/org/alfresco/repo/admin/patch/PatchInfo.java b/source/java/org/alfresco/repo/domain/patch/AppliedPatchEntity.java similarity index 64% rename from source/java/org/alfresco/repo/admin/patch/PatchInfo.java rename to source/java/org/alfresco/repo/domain/patch/AppliedPatchEntity.java index 3fe415c408..386dd95a14 100644 --- a/source/java/org/alfresco/repo/admin/patch/PatchInfo.java +++ b/source/java/org/alfresco/repo/domain/patch/AppliedPatchEntity.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2005-2007 Alfresco Software Limited. + * Copyright (C) 2005-2010 Alfresco Software Limited. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -22,36 +22,25 @@ * the FLOSS exception, and it is also available here: * http://www.alfresco.com/legal/licensing" */ -package org.alfresco.repo.admin.patch; +package org.alfresco.repo.domain.patch; -import java.util.Date; +import org.alfresco.repo.admin.patch.AppliedPatch; /** - * Data on applied patches + * Entity for alf_applied_patch persistence. * * @author Derek Hulley + * @since 3.3 */ -public interface PatchInfo +public class AppliedPatchEntity extends AppliedPatch { - public String getId(); - - public String getDescription(); + public AppliedPatchEntity() + { + super(); + } - public int getFixesFromSchema(); - - public int getFixesToSchema(); - - public int getTargetSchema(); - - public int getAppliedToSchema(); - - public String getAppliedToServer(); - - public Date getAppliedOnDate(); - - public boolean getWasExecuted(); - - public boolean getSucceeded(); - - public String getReport(); + public AppliedPatchEntity(AppliedPatch appliedPatch) + { + super(appliedPatch); + } } diff --git a/source/java/org/alfresco/repo/domain/patch/ibatis/AppliedPatchDAOImpl.java b/source/java/org/alfresco/repo/domain/patch/ibatis/AppliedPatchDAOImpl.java new file mode 100644 index 0000000000..b368efdb54 --- /dev/null +++ b/source/java/org/alfresco/repo/domain/patch/ibatis/AppliedPatchDAOImpl.java @@ -0,0 +1,114 @@ +/* + * Copyright (C) 2005-2010 Alfresco Software Limited. + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + * As a special exception to the terms and conditions of version 2.0 of + * the GPL, you may redistribute this Program in connection with Free/Libre + * and Open Source Software ("FLOSS") applications as described in Alfresco's + * FLOSS exception. You should have recieved a copy of the text describing + * the FLOSS exception, and it is also available here: + * http://www.alfresco.com/legal/licensing" + */ +package org.alfresco.repo.domain.patch.ibatis; + +import java.util.List; + +import org.alfresco.repo.domain.patch.AbstractAppliedPatchDAOImpl; +import org.alfresco.repo.domain.patch.AppliedPatchEntity; +import org.springframework.orm.ibatis.SqlMapClientTemplate; + +/** + * iBatis-specific implementation of the AppliedPatch DAO. + * + * @author Derek Hulley + * @since 3.3 + */ +public class AppliedPatchDAOImpl extends AbstractAppliedPatchDAOImpl +{ + private static final String INSERT_APPLIED_PATCH = "alfresco.appliedpatch.insert_AppliedPatch"; + private static final String UPDATE_APPLIED_PATCH = "alfresco.appliedpatch.update_AppliedPatch"; + private static final String SELECT_APPLIED_PATCH_BY_ID = "alfresco.appliedpatch.select_AppliedPatchById"; + private static final String SELECT_ALL_APPLIED_PATCH = "alfresco.appliedpatch.select_AllAppliedPatches"; + + private SqlMapClientTemplate template; + + public void setSqlMapClientTemplate(SqlMapClientTemplate sqlMapClientTemplate) + { + this.template = sqlMapClientTemplate; + } + + @Override + protected void createAppliedPatchEntity(AppliedPatchEntity entity) + { + template.insert(INSERT_APPLIED_PATCH, entity); + } + + public void updateAppliedPatchEntity(AppliedPatchEntity appliedPatch) + { + template.update(UPDATE_APPLIED_PATCH, appliedPatch); + } + + @Override + protected AppliedPatchEntity getAppliedPatchEntity(String id) + { + AppliedPatchEntity entity = new AppliedPatchEntity(); + entity.setId(id); + entity = (AppliedPatchEntity) template.queryForObject(SELECT_APPLIED_PATCH_BY_ID, entity); + // Could be null + return entity; + } + + @SuppressWarnings("unchecked") + @Override + protected List getAppliedPatchEntities() + { + return (List) template.queryForList(SELECT_ALL_APPLIED_PATCH); + } + + +// +// @Override +// protected EncodingEntity getEncodingEntity(Long id) +// { +// EncodingEntity encodingEntity = new EncodingEntity(); +// encodingEntity.setId(id); +// encodingEntity = (EncodingEntity) template.queryForObject(SELECT_ENCODING_BY_ID, encodingEntity); +// // Done +// return encodingEntity; +// } +// +// @Override +// protected EncodingEntity getEncodingEntity(String encoding) +// { +// EncodingEntity encodingEntity = new EncodingEntity(); +// encodingEntity.setEncoding(encoding == null ? null : encoding.toLowerCase()); +// encodingEntity = (EncodingEntity) template.queryForObject(SELECT_ENCODING_BY_KEY, encodingEntity); +// // Could be null +// return encodingEntity; +// } +// +// @Override +// protected EncodingEntity createEncodingEntity(String encoding) +// { +// EncodingEntity encodingEntity = new EncodingEntity(); +// encodingEntity.setVersion(MimetypeEntity.CONST_LONG_ZERO); +// encodingEntity.setEncoding(encoding == null ? null : encoding.toLowerCase()); +// Long id = (Long) template.insert(INSERT_ENCODING, encodingEntity); +// encodingEntity.setId(id); +// // Done +// return encodingEntity; +// } +} diff --git a/source/java/org/alfresco/repo/domain/patch/ibatis/PatchDAOImpl.java b/source/java/org/alfresco/repo/domain/patch/ibatis/PatchDAOImpl.java index 49d65ab53f..5eaade653e 100644 --- a/source/java/org/alfresco/repo/domain/patch/ibatis/PatchDAOImpl.java +++ b/source/java/org/alfresco/repo/domain/patch/ibatis/PatchDAOImpl.java @@ -43,37 +43,37 @@ public class PatchDAOImpl extends AbstractPatchDAOImpl private static final String SELECT_AVM_LD_NODE_ENTITIES_NULL_VERSION = "alfresco.avm.select_AVMNodes_nullVersionLayeredDirectories"; private static final String SELECT_AVM_LF_NODE_ENTITIES_NULL_VERSION = "alfresco.avm.select_AVMNodes_nullVersionLayeredFiles"; - private SqlMapClientTemplate avmTemplate; + private SqlMapClientTemplate template; - public void setAvmSqlMapClientTemplate(SqlMapClientTemplate avmSqlMapClientTemplate) + public void setSqlMapClientTemplate(SqlMapClientTemplate sqlMapClientTemplate) { - this.avmTemplate = avmSqlMapClientTemplate; + this.template = sqlMapClientTemplate; } - + @Override protected Long getAVMNodeEntitiesCountWhereNewInStore() { - return (Long) avmTemplate.queryForObject(SELECT_AVM_NODE_ENTITIES_COUNT_WHERE_NEW_IN_STORE); + return (Long) template.queryForObject(SELECT_AVM_NODE_ENTITIES_COUNT_WHERE_NEW_IN_STORE); } @SuppressWarnings("unchecked") @Override protected List getAVMNodeEntitiesWithEmptyGUID() { - return (List) avmTemplate.queryForList(SELECT_AVM_NODE_ENTITIES_WITH_EMPTY_GUID); + return (List) template.queryForList(SELECT_AVM_NODE_ENTITIES_WITH_EMPTY_GUID); } @SuppressWarnings("unchecked") @Override protected List getNullVersionLayeredDirectoryNodeEntities() { - return (List) avmTemplate.queryForList(SELECT_AVM_LD_NODE_ENTITIES_NULL_VERSION); + return (List) template.queryForList(SELECT_AVM_LD_NODE_ENTITIES_NULL_VERSION); } @SuppressWarnings("unchecked") @Override protected List getNullVersionLayeredFileNodeEntities() { - return (List) avmTemplate.queryForList(SELECT_AVM_LF_NODE_ENTITIES_NULL_VERSION); + return (List) template.queryForList(SELECT_AVM_LF_NODE_ENTITIES_NULL_VERSION); } } diff --git a/source/java/org/alfresco/repo/importer/system/SystemExporterImporter.java b/source/java/org/alfresco/repo/importer/system/SystemExporterImporter.java index 575ca243ca..fcbb59161c 100644 --- a/source/java/org/alfresco/repo/importer/system/SystemExporterImporter.java +++ b/source/java/org/alfresco/repo/importer/system/SystemExporterImporter.java @@ -28,8 +28,8 @@ import java.io.InputStream; import java.io.OutputStream; import java.util.List; -import org.alfresco.repo.admin.patch.PatchDaoService; -import org.alfresco.repo.domain.AppliedPatch; +import org.alfresco.repo.admin.patch.AppliedPatch; +import org.alfresco.repo.domain.patch.AppliedPatchDAO; import org.alfresco.repo.version.common.counter.VersionCounterService; import org.alfresco.service.cmr.repository.NodeService; import org.alfresco.service.cmr.repository.StoreRef; @@ -44,7 +44,7 @@ public class SystemExporterImporter { // dependencies private NodeService nodeService; - private PatchDaoService patchDao; + private AppliedPatchDAO appliedPatchDAO; private VersionCounterService versionCounterService; @@ -53,9 +53,9 @@ public class SystemExporterImporter this.nodeService = nodeService; } - public void setPatchDao(PatchDaoService patchDaoService) + public void setAppliedPatchDAO(AppliedPatchDAO appliedPatchDAO) { - this.patchDao = patchDaoService; + this.appliedPatchDAO = appliedPatchDAO; } public void setVersionCounterService(VersionCounterService versionCounterService) @@ -74,7 +74,7 @@ public class SystemExporterImporter SystemInfo systemInfo = new SystemInfo(); // capture applied patches - List patches = patchDao.getAppliedPatches(); + List patches = appliedPatchDAO.getAppliedPatches(); for (AppliedPatch patch : patches) { PatchInfo patchInfo = new PatchInfo(); @@ -119,7 +119,8 @@ public class SystemExporterImporter // apply patch info for (PatchInfo patchInfo : systemInfo.patches) { - AppliedPatch patch = patchDao.newAppliedPatch(patchInfo.id); + AppliedPatch patch = new AppliedPatch(); + patch.setId(patchInfo.id); patch.setAppliedOnDate(patchInfo.appliedOnDate); patch.setAppliedToSchema(patchInfo.appliedToSchema); patch.setAppliedToServer(patchInfo.appliedToServer); @@ -130,6 +131,7 @@ public class SystemExporterImporter patch.setSucceeded(patchInfo.succeeded); patch.setTargetSchema(patchInfo.targetSchema); patch.setWasExecuted(patchInfo.wasExecuted); + appliedPatchDAO.createAppliedPatch(patch); } // apply version counters