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
This commit is contained in:
Derek Hulley
2010-01-18 16:39:18 +00:00
parent 7f24c8c4e7
commit b96d174e1f
26 changed files with 941 additions and 696 deletions

View File

@@ -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 <b>alf_applied_patch</b>.
*
* @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<AppliedPatch> getAppliedPatches()
{
List<AppliedPatchEntity> entities = getAppliedPatchEntities();
List<AppliedPatch> results = new ArrayList<AppliedPatch>();
results.addAll(entities);
return results;
}
public List<AppliedPatch> getAppliedPatches(Date from, Date to)
{
// Manual filter (no performance required)
List<AppliedPatch> results = getAppliedPatches();
Iterator<AppliedPatch> 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<AppliedPatchEntity> getAppliedPatchEntities();
}

View File

@@ -0,0 +1,81 @@
/*
* 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.patch;
import java.util.Date;
import java.util.List;
import org.alfresco.repo.admin.patch.AppliedPatch;
/**
* Provides data access support for patch persistence in <b>alf_applied_patch</b>.
*
* @since 3.3
* @author Derek Hulley
*/
public interface AppliedPatchDAO
{
/**
* Creates and saves a new instance of the patch.
*
* @param patchInfo the patch ID and details
*/
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 <tt>null</tt> if one has not been persisted
*/
public AppliedPatch getAppliedPatch(String id);
/**
* Get a list of all applied patches
*
* @return Returns a list of all applied patches
*/
public List<AppliedPatch> getAppliedPatches();
/**
* Get a list of all patches applied between the given dates.
*
* @param from the lower date limit or null to ignore
* @param to the upper date limit or null to ignore
* @return Returns applied patches for the date range, but also patches without
* a date
*/
public List<AppliedPatch> getAppliedPatches(Date from, Date to);
/**
* Update the patch <i>applied on</i> date.
*
* @param id the patch ID
* @param appliedOnDate the date applied
*/
public void setAppliedOnDate(String id, Date appliedOnDate);
}

View File

@@ -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<Void> callback = new RetryingTransactionCallback<Void>()
{
public Void execute() throws Throwable
{
appliedPatchDAO.createAppliedPatch(appliedPatch);
return null;
}
};
txnHelper.doInTransaction(callback);
return appliedPatch;
}
private AppliedPatch get(final String id) throws Exception
{
RetryingTransactionCallback<AppliedPatch> callback = new RetryingTransactionCallback<AppliedPatch>()
{
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<Void> callback = new RetryingTransactionCallback<Void>()
{
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<Long, String> lowercasePair = get(encoding.toLowerCase(), true, true);
// // Check that the same pair is retrievable using uppercase
// Pair<Long, String> uppercasePair = get(encoding.toUpperCase(), true, true);
// assertNotNull(uppercasePair);
// assertEquals(
// "Upper and lowercase encoding instance IDs were not the same",
// lowercasePair.getFirst(), uppercasePair.getFirst());
// }
}

View File

@@ -0,0 +1,46 @@
/*
* 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 org.alfresco.repo.admin.patch.AppliedPatch;
/**
* Entity for <b>alf_applied_patch</b> persistence.
*
* @author Derek Hulley
* @since 3.3
*/
public class AppliedPatchEntity extends AppliedPatch
{
public AppliedPatchEntity()
{
super();
}
public AppliedPatchEntity(AppliedPatch appliedPatch)
{
super(appliedPatch);
}
}

View File

@@ -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<AppliedPatchEntity> getAppliedPatchEntities()
{
return (List<AppliedPatchEntity>) 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;
// }
}

View File

@@ -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<AVMNodeEntity> getAVMNodeEntitiesWithEmptyGUID()
{
return (List<AVMNodeEntity>) avmTemplate.queryForList(SELECT_AVM_NODE_ENTITIES_WITH_EMPTY_GUID);
return (List<AVMNodeEntity>) template.queryForList(SELECT_AVM_NODE_ENTITIES_WITH_EMPTY_GUID);
}
@SuppressWarnings("unchecked")
@Override
protected List<AVMNodeEntity> getNullVersionLayeredDirectoryNodeEntities()
{
return (List<AVMNodeEntity>) avmTemplate.queryForList(SELECT_AVM_LD_NODE_ENTITIES_NULL_VERSION);
return (List<AVMNodeEntity>) template.queryForList(SELECT_AVM_LD_NODE_ENTITIES_NULL_VERSION);
}
@SuppressWarnings("unchecked")
@Override
protected List<AVMNodeEntity> getNullVersionLayeredFileNodeEntities()
{
return (List<AVMNodeEntity>) avmTemplate.queryForList(SELECT_AVM_LF_NODE_ENTITIES_NULL_VERSION);
return (List<AVMNodeEntity>) template.queryForList(SELECT_AVM_LF_NODE_ENTITIES_NULL_VERSION);
}
}