From 528df9ef5ff39ead244fdc4b51510db5215c4df0 Mon Sep 17 00:00:00 2001 From: Derek Hulley Date: Wed, 19 Aug 2009 02:30:42 +0000 Subject: [PATCH] Audit DAO - Audit config (alf_audit_cfg) now uses CRC check and persists via ContentService and alf_content_data - Reverted 3.3 references back to 3.2 git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@15805 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261 --- config/alfresco/dao/dao-context.xml | 6 + .../AlfrescoPostCreate-3.2-AuditTables.sql | 30 ++++ ...scoPostCreate-3.2-PropertyValueTables.sql} | 18 +-- config/alfresco/ibatis/audit-SqlMapConfig.xml | 12 ++ config/alfresco/ibatis/ibatis-context.xml | 12 ++ .../audit-common-SqlMap.xml | 56 +++++++ .../audit-insert-SqlMap.xml | 16 ++ .../alfresco/patch/patch-services-context.xml | 18 ++- config/alfresco/version.properties | 4 +- .../org/alfresco/repo/domain/CrcHelper.java | 2 +- .../domain/audit/AbstractAuditDAOImpl.java | 150 ++++++++++++++++++ .../repo/domain/audit/AuditConfigEntity.java | 110 +++++++++++++ .../alfresco/repo/domain/audit/AuditDAO.java | 48 ++++++ .../repo/domain/audit/AuditDAOTest.java | 87 ++++++++++ .../domain/audit/ibatis/AuditDAOImpl.java | 71 +++++++++ .../propval/AbstractPropertyValueDAOImpl.java | 2 +- .../propval/DefaultPropertyTypeConverter.java | 2 +- .../domain/propval/PropertyClassEntity.java | 2 +- .../propval/PropertyDateValueEntity.java | 2 +- .../propval/PropertyDoubleValueEntity.java | 2 +- .../domain/propval/PropertyIdSearchRow.java | 2 +- .../domain/propval/PropertyLinkEntity.java | 2 +- .../propval/PropertyStringValueEntity.java | 2 +- .../domain/propval/PropertyTypeConverter.java | 2 +- .../repo/domain/propval/PropertyValueDAO.java | 2 +- .../domain/propval/PropertyValueDAOTest.java | 2 +- .../domain/propval/PropertyValueEntity.java | 4 +- .../propval/ibatis/PropertyValueDAOImpl.java | 2 +- 28 files changed, 639 insertions(+), 29 deletions(-) create mode 100644 config/alfresco/dbscripts/create/3.2/org.hibernate.dialect.MySQLInnoDBDialect/AlfrescoPostCreate-3.2-AuditTables.sql rename config/alfresco/dbscripts/create/{3.3/org.hibernate.dialect.MySQLInnoDBDialect/AlfrescoPostCreate-3.3-PropertyValueTables.sql => 3.2/org.hibernate.dialect.MySQLInnoDBDialect/AlfrescoPostCreate-3.2-PropertyValueTables.sql} (79%) create mode 100644 config/alfresco/ibatis/audit-SqlMapConfig.xml create mode 100644 config/alfresco/ibatis/org.hibernate.dialect.Dialect/audit-common-SqlMap.xml create mode 100644 config/alfresco/ibatis/org.hibernate.dialect.MySQLInnoDBDialect/audit-insert-SqlMap.xml create mode 100644 source/java/org/alfresco/repo/domain/audit/AbstractAuditDAOImpl.java create mode 100644 source/java/org/alfresco/repo/domain/audit/AuditConfigEntity.java create mode 100644 source/java/org/alfresco/repo/domain/audit/AuditDAO.java create mode 100644 source/java/org/alfresco/repo/domain/audit/AuditDAOTest.java create mode 100644 source/java/org/alfresco/repo/domain/audit/ibatis/AuditDAOImpl.java diff --git a/config/alfresco/dao/dao-context.xml b/config/alfresco/dao/dao-context.xml index a5f927e7e1..d9ce5ae336 100644 --- a/config/alfresco/dao/dao-context.xml +++ b/config/alfresco/dao/dao-context.xml @@ -55,4 +55,10 @@ + + + + + + diff --git a/config/alfresco/dbscripts/create/3.2/org.hibernate.dialect.MySQLInnoDBDialect/AlfrescoPostCreate-3.2-AuditTables.sql b/config/alfresco/dbscripts/create/3.2/org.hibernate.dialect.MySQLInnoDBDialect/AlfrescoPostCreate-3.2-AuditTables.sql new file mode 100644 index 0000000000..a85996943e --- /dev/null +++ b/config/alfresco/dbscripts/create/3.2/org.hibernate.dialect.MySQLInnoDBDialect/AlfrescoPostCreate-3.2-AuditTables.sql @@ -0,0 +1,30 @@ +-- +-- Title: Audit tables +-- Database: MySQL InnoDB +-- Since: V3.2 Schema 3002 +-- Author: Derek Hulley +-- +-- Please contact support@alfresco.com if you need assistance with the upgrade. +-- + +CREATE TABLE alf_audit_cfg +( + id BIGINT NOT NULL AUTO_INCREMENT, + content_data_id BIGINT NOT NULL, + content_crc BIGINT NOT NULL, + UNIQUE INDEX idx_alf_audit_cfg_crc (content_crc), + CONSTRAINT fk_alf_audit_cfg_cd FOREIGN KEY (content_data_id) REFERENCES alf_content_data (id), + PRIMARY KEY (id) +) ENGINE=InnoDB; + +-- +-- Record script finish +-- +DELETE FROM alf_applied_patch WHERE id = 'patch.db-V3.2-AuditTables'; +INSERT INTO alf_applied_patch + (id, description, fixes_from_schema, fixes_to_schema, applied_to_schema, target_schema, applied_on_date, applied_to_server, was_executed, succeeded, report) + VALUES + ( + 'patch.db-V3.2-AuditTables', 'Manually executed script upgrade V3.2: Audit Tables', + 0, 3001, -1, 3002, null, 'UNKOWN', 1, 1, 'Script completed' + ); \ No newline at end of file diff --git a/config/alfresco/dbscripts/create/3.3/org.hibernate.dialect.MySQLInnoDBDialect/AlfrescoPostCreate-3.3-PropertyValueTables.sql b/config/alfresco/dbscripts/create/3.2/org.hibernate.dialect.MySQLInnoDBDialect/AlfrescoPostCreate-3.2-PropertyValueTables.sql similarity index 79% rename from config/alfresco/dbscripts/create/3.3/org.hibernate.dialect.MySQLInnoDBDialect/AlfrescoPostCreate-3.3-PropertyValueTables.sql rename to config/alfresco/dbscripts/create/3.2/org.hibernate.dialect.MySQLInnoDBDialect/AlfrescoPostCreate-3.2-PropertyValueTables.sql index f3aada207b..4fd6c58260 100644 --- a/config/alfresco/dbscripts/create/3.3/org.hibernate.dialect.MySQLInnoDBDialect/AlfrescoPostCreate-3.3-PropertyValueTables.sql +++ b/config/alfresco/dbscripts/create/3.2/org.hibernate.dialect.MySQLInnoDBDialect/AlfrescoPostCreate-3.2-PropertyValueTables.sql @@ -1,7 +1,7 @@ -- -- Title: Property Value tables -- Database: MySQL InnoDB --- Since: V3.3 Schema 3001 +-- Since: V3.2 Schema 3001 -- Author: Derek Hulley -- -- Please contact support@alfresco.com if you need assistance with the upgrade. @@ -81,11 +81,11 @@ CREATE TABLE alf_prop_link -- -- Record script finish -- --- DELETE FROM alf_applied_patch WHERE id = 'patch.db-V3.3-PropertyValueTables'; --- INSERT INTO alf_applied_patch --- (id, description, fixes_from_schema, fixes_to_schema, applied_to_schema, target_schema, applied_on_date, applied_to_server, was_executed, succeeded, report) --- VALUES --- ( --- 'patch.db-V3.3-PropertyValueTables', 'Manually executed script upgrade V3.3: PropertyValue Tables', --- 0, 3000, -1, 3001, null, 'UNKOWN', 1, 1, 'Script completed' --- ); \ No newline at end of file +DELETE FROM alf_applied_patch WHERE id = 'patch.db-V3.2-PropertyValueTables'; +INSERT INTO alf_applied_patch + (id, description, fixes_from_schema, fixes_to_schema, applied_to_schema, target_schema, applied_on_date, applied_to_server, was_executed, succeeded, report) + VALUES + ( + 'patch.db-V3.2-PropertyValueTables', 'Manually executed script upgrade V3.2: PropertyValue Tables', + 0, 3000, -1, 3001, null, 'UNKOWN', 1, 1, 'Script completed' + ); \ No newline at end of file diff --git a/config/alfresco/ibatis/audit-SqlMapConfig.xml b/config/alfresco/ibatis/audit-SqlMapConfig.xml new file mode 100644 index 0000000000..75420b9d2c --- /dev/null +++ b/config/alfresco/ibatis/audit-SqlMapConfig.xml @@ -0,0 +1,12 @@ + + + + + + + + + + diff --git a/config/alfresco/ibatis/ibatis-context.xml b/config/alfresco/ibatis/ibatis-context.xml index 90bdc8ac60..12d34beeec 100644 --- a/config/alfresco/ibatis/ibatis-context.xml +++ b/config/alfresco/ibatis/ibatis-context.xml @@ -86,4 +86,16 @@ + + + + + + classpath:alfresco/ibatis/audit-SqlMapConfig.xml + + + + + + diff --git a/config/alfresco/ibatis/org.hibernate.dialect.Dialect/audit-common-SqlMap.xml b/config/alfresco/ibatis/org.hibernate.dialect.Dialect/audit-common-SqlMap.xml new file mode 100644 index 0000000000..1be605727c --- /dev/null +++ b/config/alfresco/ibatis/org.hibernate.dialect.Dialect/audit-common-SqlMap.xml @@ -0,0 +1,56 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + insert into alf_audit_cfg (content_data_id, content_crc) + values (#contentDataId#, #contentCrc#) + + + + + + + + + + \ No newline at end of file diff --git a/config/alfresco/ibatis/org.hibernate.dialect.MySQLInnoDBDialect/audit-insert-SqlMap.xml b/config/alfresco/ibatis/org.hibernate.dialect.MySQLInnoDBDialect/audit-insert-SqlMap.xml new file mode 100644 index 0000000000..44a704f579 --- /dev/null +++ b/config/alfresco/ibatis/org.hibernate.dialect.MySQLInnoDBDialect/audit-insert-SqlMap.xml @@ -0,0 +1,16 @@ + + + + + + + + + + KEY_COLUMN:GENERATED_KEY + + + + \ No newline at end of file diff --git a/config/alfresco/patch/patch-services-context.xml b/config/alfresco/patch/patch-services-context.xml index efb2ebde60..1015ae3200 100644 --- a/config/alfresco/patch/patch-services-context.xml +++ b/config/alfresco/patch/patch-services-context.xml @@ -1969,15 +1969,27 @@ alfresco/templates/imap/command_processor_scripts.acp - - patch.db-V3.3-PropertyValueTables + + patch.db-V3.2-PropertyValueTables patch.schemaUpgradeScript.description 0 3000 3001 - classpath:alfresco/dbscripts/create/3.3/${db.script.dialect}/AlfrescoPostCreate-3.3-PropertyValueTables.sql + classpath:alfresco/dbscripts/create/3.2/${db.script.dialect}/AlfrescoPostCreate-3.2-PropertyValueTables.sql + + + + + patch.db-V3.2-AuditTables + patch.schemaUpgradeScript.description + 0 + 3001 + 3002 + + + classpath:alfresco/dbscripts/create/3.2/${db.script.dialect}/AlfrescoPostCreate-3.2-AuditTables.sql diff --git a/config/alfresco/version.properties b/config/alfresco/version.properties index 72bbc71928..640cf8e2d7 100644 --- a/config/alfresco/version.properties +++ b/config/alfresco/version.properties @@ -5,7 +5,7 @@ # Version label version.major=3 -version.minor=3 +version.minor=2 version.revision=0 version.label= @@ -19,4 +19,4 @@ version.build=@build-number@ # Schema number -version.schema=3001 +version.schema=3002 diff --git a/source/java/org/alfresco/repo/domain/CrcHelper.java b/source/java/org/alfresco/repo/domain/CrcHelper.java index 0404202747..162227660a 100644 --- a/source/java/org/alfresco/repo/domain/CrcHelper.java +++ b/source/java/org/alfresco/repo/domain/CrcHelper.java @@ -32,7 +32,7 @@ import org.alfresco.util.Pair; * Helper class to calculate CRC values for string persistence. * * @author Derek Hulley - * @since 3.3 + * @since 3.2 */ public class CrcHelper { diff --git a/source/java/org/alfresco/repo/domain/audit/AbstractAuditDAOImpl.java b/source/java/org/alfresco/repo/domain/audit/AbstractAuditDAOImpl.java new file mode 100644 index 0000000000..fb4b9e2f7b --- /dev/null +++ b/source/java/org/alfresco/repo/domain/audit/AbstractAuditDAOImpl.java @@ -0,0 +1,150 @@ +/* + * Copyright (C) 2005-2009 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.audit; + +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; +import java.util.zip.CRC32; + +import org.alfresco.error.AlfrescoRuntimeException; +import org.alfresco.repo.content.MimetypeMap; +import org.alfresco.repo.domain.contentdata.ContentDataDAO; +import org.alfresco.service.cmr.repository.ContentData; +import org.alfresco.service.cmr.repository.ContentService; +import org.alfresco.service.cmr.repository.ContentWriter; +import org.alfresco.util.Pair; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +/** + * Abstract helper DAO for alf_audit_XXX tables. + * + * @author Derek Hulley + * @since 3.2 + */ +public abstract class AbstractAuditDAOImpl implements AuditDAO +{ + private static final Log logger = LogFactory.getLog(AbstractAuditDAOImpl.class); + + private ContentService contentService; + private ContentDataDAO contentDataDAO; + + public void setContentService(ContentService contentService) + { + this.contentService = contentService; + } + + public void setContentDataDAO(ContentDataDAO contentDataDAO) + { + this.contentDataDAO = contentDataDAO; + } + + /** + * {@inheritDoc} + */ + public Pair getOrCreateAuditConfig(URL url) + { + InputStream is = null; + try + { + is = url.openStream(); + // Calculate the CRC and find an entry that matches + CRC32 crcCalc = new CRC32(); + byte[] buffer = new byte[1024]; + int read = -1; + do + { + read = is.read(buffer); + if (read < 0) + { + break; + } + crcCalc.update(buffer, 0, read); + } + while (true); + long crc = crcCalc.getValue(); + // Find an existing entry + AuditConfigEntity existingEntity = getAuditConfigByCrc(crc); + if (existingEntity != null) + { + Long existingEntityId = existingEntity.getId(); + // Locate the content + ContentData existingContentData = contentDataDAO.getContentData( + existingEntity.getContentDataId() + ).getSecond(); + Pair result = new Pair(existingEntityId, existingContentData); + // Done + if (logger.isDebugEnabled()) + { + logger.debug( + "Found existing configuration with same CRC: \n" + + " URL: " + url + "\n" + + " CRC: " + crc + "\n" + + " Result: " + result); + } + return result; + } + else + { + // Upload the content afresh + is.close(); + is = url.openStream(); + ContentWriter writer = contentService.getWriter(null, null, false); + writer.setEncoding("UTF-8"); + writer.setMimetype(MimetypeMap.MIMETYPE_XML); + writer.putContent(is); + ContentData newContentData = writer.getContentData(); + Long newContentDataId = contentDataDAO.createContentData(newContentData).getFirst(); + AuditConfigEntity newEntity = createAuditConfig(newContentDataId, crc); + Pair result = new Pair(newEntity.getId(), newContentData); + // Done + if (logger.isDebugEnabled()) + { + logger.debug( + "Created new audit config: \n" + + " URL: " + url + "\n" + + " CRC: " + crc + "\n" + + " Result: " + result); + } + return result; + } + } + catch (IOException e) + { + throw new AlfrescoRuntimeException("Failed to read Audit configuration: " + url); + } + finally + { + if (is != null) + { + try { is.close(); } catch (Throwable e) {} + } + } + } + + protected abstract AuditConfigEntity getAuditConfigByCrc(long crc); + protected abstract AuditConfigEntity createAuditConfig(Long contentDataId, long crc); +} diff --git a/source/java/org/alfresco/repo/domain/audit/AuditConfigEntity.java b/source/java/org/alfresco/repo/domain/audit/AuditConfigEntity.java new file mode 100644 index 0000000000..0df2a6dad0 --- /dev/null +++ b/source/java/org/alfresco/repo/domain/audit/AuditConfigEntity.java @@ -0,0 +1,110 @@ +/* + * Copyright (C) 2005-2009 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.audit; + +import org.alfresco.util.EqualsHelper; + +/** + * Entity bean for alf_audit_cfg table. + * + * @author Derek Hulley + * @since 3.2 + */ +public class AuditConfigEntity +{ + private Long id; + private Long contentDataId; + private long contentCrc; + + public AuditConfigEntity() + { + } + + @Override + public int hashCode() + { + return (int) contentCrc; + } + + @Override + public boolean equals(Object obj) + { + if (this == obj) + { + return true; + } + else if (obj instanceof AuditConfigEntity) + { + AuditConfigEntity that = (AuditConfigEntity) obj; + return EqualsHelper.nullSafeEquals(this.id, that.id); + } + else + { + return false; + } + } + + @Override + public String toString() + { + StringBuilder sb = new StringBuilder(512); + sb.append("AuditConfigEntity") + .append("[ ID=").append(id) + .append(", contentDataId=").append(contentDataId) + .append(", contentCrc=").append(contentCrc) + .append("]"); + return sb.toString(); + } + + public Long getId() + { + return id; + } + + public void setId(Long id) + { + this.id = id; + } + + public Long getContentDataId() + { + return contentDataId; + } + + public void setContentDataId(Long contentDataId) + { + this.contentDataId = contentDataId; + } + + public long getContentCrc() + { + return contentCrc; + } + + public void setContentCrc(long contentCrc) + { + this.contentCrc = contentCrc; + } +} diff --git a/source/java/org/alfresco/repo/domain/audit/AuditDAO.java b/source/java/org/alfresco/repo/domain/audit/AuditDAO.java new file mode 100644 index 0000000000..9bfd0bf020 --- /dev/null +++ b/source/java/org/alfresco/repo/domain/audit/AuditDAO.java @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2005-2009 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.audit; + +import java.net.URL; + +import org.alfresco.service.cmr.repository.ContentData; +import org.alfresco.util.Pair; + +/** + * DAO services for alf_audit_XXX tables. + * + * @author Derek Hulley + * @since 3.2 + */ +public interface AuditDAO +{ + /** + * Creates a new audit config entry or finds an existing one + * + * @param the URL of the configuration + * @return Returns the ID of the config matching the input stream and the + * content storage details + */ + Pair getOrCreateAuditConfig(URL url); +} diff --git a/source/java/org/alfresco/repo/domain/audit/AuditDAOTest.java b/source/java/org/alfresco/repo/domain/audit/AuditDAOTest.java new file mode 100644 index 0000000000..b6c3556dda --- /dev/null +++ b/source/java/org/alfresco/repo/domain/audit/AuditDAOTest.java @@ -0,0 +1,87 @@ +/* + * Copyright (C) 2005-2009 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.audit; + +import java.io.File; +import java.net.URL; + +import junit.framework.TestCase; + +import org.alfresco.repo.content.transform.AbstractContentTransformerTest; +import org.alfresco.repo.domain.contentdata.ContentDataDAO; +import org.alfresco.repo.transaction.RetryingTransactionHelper; +import org.alfresco.repo.transaction.RetryingTransactionHelper.RetryingTransactionCallback; +import org.alfresco.service.ServiceRegistry; +import org.alfresco.service.cmr.repository.ContentData; +import org.alfresco.service.transaction.TransactionService; +import org.alfresco.util.ApplicationContextHelper; +import org.alfresco.util.Pair; +import org.springframework.context.ConfigurableApplicationContext; + +/** + * @see ContentDataDAO + * + * @author Derek Hulley + * @since 3.2 + */ +public class AuditDAOTest extends TestCase +{ + private ConfigurableApplicationContext ctx = (ConfigurableApplicationContext) ApplicationContextHelper.getApplicationContext(); + + private TransactionService transactionService; + private RetryingTransactionHelper txnHelper; + private AuditDAO auditDAO; + + @Override + public void setUp() throws Exception + { + ServiceRegistry serviceRegistry = (ServiceRegistry) ctx.getBean(ServiceRegistry.SERVICE_REGISTRY); + transactionService = serviceRegistry.getTransactionService(); + txnHelper = transactionService.getRetryingTransactionHelper(); + + auditDAO = (AuditDAO) ctx.getBean("auditDAO"); + } + + public void testAuditConfig() throws Exception + { + final File file = AbstractContentTransformerTest.loadQuickTestFile("pdf"); + assertNotNull(file); + final URL url = new URL("file:" + file.getAbsolutePath()); + RetryingTransactionCallback> callback = new RetryingTransactionCallback>() + { + public Pair execute() throws Throwable + { + Pair contentDataPair = auditDAO.getOrCreateAuditConfig(url); + return contentDataPair; + } + }; + Pair configPair = txnHelper.doInTransaction(callback); + assertNotNull(configPair); + // Now repeat. The results should be exactly the same. + Pair configPairCheck = txnHelper.doInTransaction(callback); + assertNotNull(configPairCheck); + assertEquals(configPair, configPairCheck); + } +} diff --git a/source/java/org/alfresco/repo/domain/audit/ibatis/AuditDAOImpl.java b/source/java/org/alfresco/repo/domain/audit/ibatis/AuditDAOImpl.java new file mode 100644 index 0000000000..da147c2130 --- /dev/null +++ b/source/java/org/alfresco/repo/domain/audit/ibatis/AuditDAOImpl.java @@ -0,0 +1,71 @@ +/* + * Copyright (C) 2005-2009 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.audit.ibatis; + +import org.alfresco.repo.domain.audit.AbstractAuditDAOImpl; +import org.alfresco.repo.domain.audit.AuditConfigEntity; +import org.springframework.orm.ibatis.SqlMapClientTemplate; + +/** + * iBatis-specific implementation of the DAO for alf_audit_XXX tables. + * + * @author Derek Hulley + * @since 3.2 + */ +public class AuditDAOImpl extends AbstractAuditDAOImpl +{ + private static final String SELECT_CONFIG_BY_CRC = "select.AuditConfigByCrc"; + private static final String INSERT_CONFIG = "insert.AuditConfig"; + + private SqlMapClientTemplate template; + + public void setSqlMapClientTemplate(SqlMapClientTemplate sqlMapClientTemplate) + { + this.template = sqlMapClientTemplate; + } + + @Override + protected AuditConfigEntity getAuditConfigByCrc(long crc) + { + AuditConfigEntity entity = new AuditConfigEntity(); + entity.setContentCrc(crc); + entity = (AuditConfigEntity) template.queryForObject( + SELECT_CONFIG_BY_CRC, + entity); + // Done + return entity; + } + + @Override + protected AuditConfigEntity createAuditConfig(Long contentDataId, long crc) + { + AuditConfigEntity entity = new AuditConfigEntity(); + entity.setContentDataId(contentDataId); + entity.setContentCrc(crc); + Long id = (Long) template.insert(INSERT_CONFIG, entity); + entity.setId(id); + return entity; + } +} diff --git a/source/java/org/alfresco/repo/domain/propval/AbstractPropertyValueDAOImpl.java b/source/java/org/alfresco/repo/domain/propval/AbstractPropertyValueDAOImpl.java index 101e963358..5ded453e98 100644 --- a/source/java/org/alfresco/repo/domain/propval/AbstractPropertyValueDAOImpl.java +++ b/source/java/org/alfresco/repo/domain/propval/AbstractPropertyValueDAOImpl.java @@ -52,7 +52,7 @@ import org.apache.commons.logging.LogFactory; * for CRUD operations. * * @author Derek Hulley - * @since 3.3 + * @since 3.2 */ public abstract class AbstractPropertyValueDAOImpl implements PropertyValueDAO { diff --git a/source/java/org/alfresco/repo/domain/propval/DefaultPropertyTypeConverter.java b/source/java/org/alfresco/repo/domain/propval/DefaultPropertyTypeConverter.java index 5c946314b0..e4ad789241 100644 --- a/source/java/org/alfresco/repo/domain/propval/DefaultPropertyTypeConverter.java +++ b/source/java/org/alfresco/repo/domain/propval/DefaultPropertyTypeConverter.java @@ -33,7 +33,7 @@ import org.alfresco.service.cmr.repository.datatype.DefaultTypeConverter; * the {@link DefaultTypeConverter} is used. * * @author Derek Hulley - * @since 3.3 + * @since 3.2 */ public class DefaultPropertyTypeConverter implements PropertyTypeConverter { diff --git a/source/java/org/alfresco/repo/domain/propval/PropertyClassEntity.java b/source/java/org/alfresco/repo/domain/propval/PropertyClassEntity.java index 35c5a77260..81a996dda3 100644 --- a/source/java/org/alfresco/repo/domain/propval/PropertyClassEntity.java +++ b/source/java/org/alfresco/repo/domain/propval/PropertyClassEntity.java @@ -33,7 +33,7 @@ import org.alfresco.util.Pair; * Entity bean for alf_prop_class table. * * @author Derek Hulley - * @since 3.3 + * @since 3.2 */ public class PropertyClassEntity { diff --git a/source/java/org/alfresco/repo/domain/propval/PropertyDateValueEntity.java b/source/java/org/alfresco/repo/domain/propval/PropertyDateValueEntity.java index 4fcafd6e18..7f5dc48a6c 100644 --- a/source/java/org/alfresco/repo/domain/propval/PropertyDateValueEntity.java +++ b/source/java/org/alfresco/repo/domain/propval/PropertyDateValueEntity.java @@ -36,7 +36,7 @@ import org.alfresco.util.Pair; * Entity bean for alf_prop_date_value table. * * @author Derek Hulley - * @since 3.3 + * @since 3.2 */ public class PropertyDateValueEntity { diff --git a/source/java/org/alfresco/repo/domain/propval/PropertyDoubleValueEntity.java b/source/java/org/alfresco/repo/domain/propval/PropertyDoubleValueEntity.java index 0f70fdb4f6..bd7d8c88c2 100644 --- a/source/java/org/alfresco/repo/domain/propval/PropertyDoubleValueEntity.java +++ b/source/java/org/alfresco/repo/domain/propval/PropertyDoubleValueEntity.java @@ -31,7 +31,7 @@ import org.alfresco.util.Pair; * Entity bean for alf_prop_numeric_value table. * * @author Derek Hulley - * @since 3.3 + * @since 3.2 */ public class PropertyDoubleValueEntity { diff --git a/source/java/org/alfresco/repo/domain/propval/PropertyIdSearchRow.java b/source/java/org/alfresco/repo/domain/propval/PropertyIdSearchRow.java index 3f3f8df4aa..44c06c2253 100644 --- a/source/java/org/alfresco/repo/domain/propval/PropertyIdSearchRow.java +++ b/source/java/org/alfresco/repo/domain/propval/PropertyIdSearchRow.java @@ -30,7 +30,7 @@ import java.io.Serializable; * Entity bean search results from alf_prop_collections_link and alf_prop_value tables. * * @author Derek Hulley - * @since 3.3 + * @since 3.2 */ public class PropertyIdSearchRow { diff --git a/source/java/org/alfresco/repo/domain/propval/PropertyLinkEntity.java b/source/java/org/alfresco/repo/domain/propval/PropertyLinkEntity.java index 8b3ded7335..542655f009 100644 --- a/source/java/org/alfresco/repo/domain/propval/PropertyLinkEntity.java +++ b/source/java/org/alfresco/repo/domain/propval/PropertyLinkEntity.java @@ -28,7 +28,7 @@ package org.alfresco.repo.domain.propval; * Entity bean for alf_prop_link table. * * @author Derek Hulley - * @since 3.3 + * @since 3.2 */ public class PropertyLinkEntity { diff --git a/source/java/org/alfresco/repo/domain/propval/PropertyStringValueEntity.java b/source/java/org/alfresco/repo/domain/propval/PropertyStringValueEntity.java index f1ba4afb99..d8e12c72e6 100644 --- a/source/java/org/alfresco/repo/domain/propval/PropertyStringValueEntity.java +++ b/source/java/org/alfresco/repo/domain/propval/PropertyStringValueEntity.java @@ -31,7 +31,7 @@ import org.alfresco.util.Pair; * Entity bean for alf_prop_string_value table. * * @author Derek Hulley - * @since 3.3 + * @since 3.2 */ public class PropertyStringValueEntity { diff --git a/source/java/org/alfresco/repo/domain/propval/PropertyTypeConverter.java b/source/java/org/alfresco/repo/domain/propval/PropertyTypeConverter.java index 3c48ead8ad..71f34159fd 100644 --- a/source/java/org/alfresco/repo/domain/propval/PropertyTypeConverter.java +++ b/source/java/org/alfresco/repo/domain/propval/PropertyTypeConverter.java @@ -31,7 +31,7 @@ package org.alfresco.repo.domain.propval; * and back again. * * @author Derek Hulley - * @since 3.3 + * @since 3.2 */ public interface PropertyTypeConverter { diff --git a/source/java/org/alfresco/repo/domain/propval/PropertyValueDAO.java b/source/java/org/alfresco/repo/domain/propval/PropertyValueDAO.java index 8b01cb928f..e0c64cc24b 100644 --- a/source/java/org/alfresco/repo/domain/propval/PropertyValueDAO.java +++ b/source/java/org/alfresco/repo/domain/propval/PropertyValueDAO.java @@ -33,7 +33,7 @@ import org.alfresco.util.Pair; * DAO services for alf_prop_XXX tables. * * @author Derek Hulley - * @since 3.3 + * @since 3.2 */ public interface PropertyValueDAO { diff --git a/source/java/org/alfresco/repo/domain/propval/PropertyValueDAOTest.java b/source/java/org/alfresco/repo/domain/propval/PropertyValueDAOTest.java index 3a2672f48f..52aa84beed 100644 --- a/source/java/org/alfresco/repo/domain/propval/PropertyValueDAOTest.java +++ b/source/java/org/alfresco/repo/domain/propval/PropertyValueDAOTest.java @@ -46,7 +46,7 @@ import org.springframework.context.ApplicationContext; * @see PropertyValueDAO * * @author Derek Hulley - * @since 3.3 + * @since 3.2 */ public class PropertyValueDAOTest extends TestCase { diff --git a/source/java/org/alfresco/repo/domain/propval/PropertyValueEntity.java b/source/java/org/alfresco/repo/domain/propval/PropertyValueEntity.java index 6376c81564..bc04f9a14a 100644 --- a/source/java/org/alfresco/repo/domain/propval/PropertyValueEntity.java +++ b/source/java/org/alfresco/repo/domain/propval/PropertyValueEntity.java @@ -44,7 +44,7 @@ import org.apache.commons.logging.LogFactory; * or will be references to data in other tables. * * @author Derek Hulley - * @since 3.3 + * @since 3.2 */ public class PropertyValueEntity { @@ -65,7 +65,7 @@ public class PropertyValueEntity * and should not be used in public interfaces. * * @author Derek Hulley - * @since 3.3 + * @since 3.2 */ public static enum PersistedType { diff --git a/source/java/org/alfresco/repo/domain/propval/ibatis/PropertyValueDAOImpl.java b/source/java/org/alfresco/repo/domain/propval/ibatis/PropertyValueDAOImpl.java index 7e665f8592..76050a4c73 100644 --- a/source/java/org/alfresco/repo/domain/propval/ibatis/PropertyValueDAOImpl.java +++ b/source/java/org/alfresco/repo/domain/propval/ibatis/PropertyValueDAOImpl.java @@ -44,7 +44,7 @@ import org.springframework.orm.ibatis.SqlMapClientTemplate; * iBatis-specific implementation of the PropertyValue DAO. * * @author Derek Hulley - * @since 3.3 + * @since 3.2 */ public class PropertyValueDAOImpl extends AbstractPropertyValueDAOImpl {