Merged V3.2 to HEAD

17271: Merged DEV/BELARUS/V3.2-2009_10_27 to V3.2
      17224: ETHREEOH-2321: Upgrade scripts for Ent DBs (V3.2 branch)


git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@18042 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Derek Hulley
2010-01-14 16:41:29 +00:00
parent 58dd1c6228
commit 354faccbc3
10 changed files with 847 additions and 808 deletions

View File

@@ -82,6 +82,7 @@
<value>classpath:alfresco/dbscripts/create/3.2/${db.script.dialect}/AlfrescoPostCreate-3.2-AuditTables.sql</value>
<value>classpath:alfresco/dbscripts/create/3.2/${db.script.dialect}/AlfrescoPostCreate-3.2-AvmTables.sql</value>
<value>classpath:alfresco/dbscripts/create/3.2/${db.script.dialect}/AlfrescoPostCreate-3.2-Indexes.sql</value>
<value>classpath:alfresco/dbscripts/create/3.2/${db.script.dialect}/AlfrescoPostCreate-3.2-JBPM-Extra.sql</value>
</list>
</property>
<property name="validateUpdateScriptPatches">

View File

@@ -0,0 +1,22 @@
--
-- Title: Fix jbpm tables
-- Database: Generic
-- Since: V3.2 schema 2013
-- Author: Pavel Yurkevich
--
-- Please contact support@alfresco.com if you need assistance with the upgrade.
--
-- This patch is only required to fix the 'configuration_' column in JBPM on DB2.
--
--
-- Record script finish
--
DELETE FROM alf_applied_patch WHERE id = 'patch.db-V3.2-JBPM-Extra';
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-JBPM-Extra', 'Manually executed script upgrade V3.2 fix problems in jbpm tables.',
0, 2012, -1, 2013, null, 'UNKOWN', ${TRUE}, ${TRUE}, 'Script completed'
);

View File

@@ -65,18 +65,26 @@
<parameter property="qnameId" jdbcType="BIGINT" javaType="java.lang.Long"/>
</parameterMap>
<parameterMap id="parameter_ContentData" class="ContentData">
<parameter property="version" jdbcType="BIGINT" javaType="java.lang.Long"/>
<parameter property="contentUrlId" jdbcType="BIGINT" javaType="java.lang.Long"/>
<parameter property="mimetypeId" jdbcType="BIGINT" javaType="java.lang.Long"/>
<parameter property="encodingId" jdbcType="BIGINT" javaType="java.lang.Long"/>
<parameter property="localeId" jdbcType="BIGINT" javaType="java.lang.Long"/>
</parameterMap>
<!-- -->
<!-- SQL Snippets -->
<!-- -->
<sql id="insert_Mimetype_AutoIncrement">
insert into alf_mimetype (version, mimetype_str)
values (#version#, lower(#mimetype#))
values (#version#, #mimetype#)
</sql>
<sql id="insert_Encoding_AutoIncrement">
insert into alf_encoding (version, encoding_str)
values (#version#, lower(#encoding#))
values (#version#, #encoding#)
</sql>
<sql id="insert_ContentUrl_AutoIncrement">
@@ -86,7 +94,7 @@
<sql id="insert_ContentData_AutoIncrement">
insert into alf_content_data (version, content_url_id, content_mimetype_id, content_encoding_id, content_locale_id)
values (#version#, #contentUrlId#, #mimetypeId#, #encodingId#, #localeId#)
values (?, ?, ?, ?, ?)
</sql>
<!-- -->
@@ -100,7 +108,7 @@
from
alf_mimetype
where
mimetype_str = lower(#mimetype#)
mimetype_str = #mimetype#
</select>
<!-- Get a mimetype based on the ID -->
@@ -120,7 +128,7 @@
from
alf_encoding
where
encoding_str = lower(#encoding#)
encoding_str = #encoding#
</select>
<!-- Get a encoding based on the ID -->
@@ -150,7 +158,7 @@
from
alf_content_url
where
content_url_short = lower(#contentUrlShort#) and
content_url_short = #contentUrlShort# and
content_url_crc = #contentUrlCrc#
</select>
@@ -162,7 +170,7 @@
alf_content_url cu
left outer join alf_content_data cd on (cd.content_url_id = cu.id)
where
content_url_short = lower(#contentUrlShort#) and
content_url_short = #contentUrlShort# and
content_url_crc = #contentUrlCrc# and
cd.id is null
</select>
@@ -226,7 +234,7 @@
<!-- Insert a Content Clean URL -->
<insert id="insert_ContentCleanUrl" parameterClass="ContentClean" >
insert into alf_content_clean (content_url) values (lower(#contentUrl#))
insert into alf_content_clean (content_url) values (#contentUrl#)
</insert>
<!-- Select all content clean URLs -->
@@ -243,7 +251,7 @@
from
alf_content_clean
where
content_url = lower(#contentUrl#)
content_url = #contentUrl#
</delete>
<!-- Remove all Content Clean URLs -->

View File

@@ -52,12 +52,12 @@
<sql id="insert_LockResource_AutoIncrement">
insert into alf_lock_resource (version, qname_ns_id, qname_localname)
values (#version#, #qnameNamespaceId#, lower(#qnameLocalName#))
values (#version#, #qnameNamespaceId#, #qnameLocalName#)
</sql>
<sql id="insert_Lock_AutoIncrement">
insert into alf_lock (version, shared_resource_id, excl_resource_id, lock_token, start_time, expiry_time)
values (#version#, #sharedResourceId#, #exclusiveResourceId#, lower(#lockToken#), #startTime#, #expiryTime#)
values (#version#, #sharedResourceId#, #exclusiveResourceId#, #lockToken#, #startTime#, #expiryTime#)
</sql>
<!-- -->
@@ -72,7 +72,7 @@
alf_lock_resource
where
qname_ns_id = #qnameNamespaceId# and
qname_localname = lower(#qnameLocalName#)
qname_localname = #qnameLocalName#
</select>
<!-- Get a lock based on the ID -->
@@ -117,7 +117,7 @@
alf_lock
set
version = #version#,
lock_token = lower(#lockToken#),
lock_token = #lockToken#,
start_time = #startTime#,
expiry_time = #expiryTime#
where
@@ -131,7 +131,7 @@
alf_lock
set
version = version + 1,
lock_token = lower(?),
lock_token = ?,
start_time = ?,
expiry_time = ?
where

View File

@@ -27,7 +27,7 @@
</selectKey>
</insert>
<insert id="insert_ContentData" parameterClass="ContentData" >
<insert id="insert_ContentData" parameterMap="parameter_ContentData" >
<include refid="alfresco.content.insert_ContentData_AutoIncrement"/>
<selectKey resultClass="long" keyProperty="id" type="post">
KEY_COLUMN:GENERATED_KEY

View File

@@ -1,254 +1,254 @@
/*
* 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.contentclean.ibatis;
import java.sql.SQLException;
import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.repo.domain.contentclean.ContentCleanDAO;
import org.alfresco.repo.domain.contentclean.ContentCleanEntity;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.orm.ibatis.SqlMapClientTemplate;
import com.ibatis.sqlmap.client.SqlMapClient;
import com.ibatis.sqlmap.client.event.RowHandler;
/**
* iBatis-specific implementation of the Content Cleaner DAO.
*
* @author Derek Hulley
* @since 3.2
*/
public class ContentCleanDAOImpl implements ContentCleanDAO
{
private static Log logger = LogFactory.getLog(ContentCleanDAOImpl.class);
private static final int DEFAULT_BATCH_SIZE = 50;
private static final String INSERT_CONTENT_CLEAN = "alfresco.content.insert_ContentCleanUrl";
private static final String SELECT_CONTENT_CLEAN_URLS = "alfresco.content.select_ContentCleanUrls";
private static final String DELETE_CONTENT_CLEAN_BY_URL = "alfresco.content.delete_ContentCleanUrl";
private static final String DELETE_CONTENT_CLEAN = "alfresco.content.delete_ContentCleanUrls";
private SqlMapClientTemplate template;
public void setSqlMapClientTemplate(SqlMapClientTemplate sqlMapClientTemplate)
{
this.template = sqlMapClientTemplate;
}
/**
* {@inheritDoc}
*/
public ContentUrlBatchProcessor getUrlInserter()
{
final SqlMapClient sqlMapClient = template.getSqlMapClient();
ContentUrlBatchProcessor processor = new ContentUrlBatchProcessor()
{
private int count = 0;
private int total = 0;
public void start()
{
try
{
sqlMapClient.startBatch();
count = 0;
}
catch (SQLException e)
{
// Batches not supported, so don't do batching
count = -1;
}
}
public void processContentUrl(String contentUrl)
{
ContentCleanEntity contentCleanEntity = new ContentCleanEntity();
contentCleanEntity.setContentUrl(contentUrl);
template.insert(INSERT_CONTENT_CLEAN, contentCleanEntity);
// Write the batch
executeBatch();
total++;
}
public void end()
{
// Write the batch
executeBatch();
if (logger.isDebugEnabled())
{
logger.debug(" Inserted " + total + " content URLs (FINISHED)");
}
}
private void executeBatch()
{
// Are we batching?
if (count > -1)
{
// Write the batch, if required
if (++count >= DEFAULT_BATCH_SIZE)
{
try
{
sqlMapClient.executeBatch();
sqlMapClient.startBatch();
}
catch (SQLException e)
{
throw new AlfrescoRuntimeException("Failed to execute batch", e);
}
count = 0;
}
}
if (logger.isDebugEnabled() && (total == 0 || (total % 1000 == 0) ))
{
logger.debug(" Inserted " + total + " content URLs");
}
}
};
// Done
return processor;
}
/**
* {@inheritDoc}
*/
public ContentUrlBatchProcessor getUrlRemover()
{
final SqlMapClient sqlMapClient = template.getSqlMapClient();
ContentUrlBatchProcessor processor = new ContentUrlBatchProcessor()
{
private int count = 0;
private int total = 0;
public void start()
{
try
{
sqlMapClient.startBatch();
count = 0;
}
catch (SQLException e)
{
// Batches not supported, so don't do batching
count = -1;
}
}
public void processContentUrl(String contentUrl)
{
ContentCleanEntity contentCleanEntity = new ContentCleanEntity();
contentCleanEntity.setContentUrl(contentUrl);
template.delete(DELETE_CONTENT_CLEAN_BY_URL, contentCleanEntity);
// Write the batch
executeBatch();
total++;
}
public void end()
{
// Write the batch
executeBatch();
if (logger.isDebugEnabled())
{
logger.debug(" Removed " + total + " content URLs (FINISHED)");
}
}
private void executeBatch()
{
// Are we batching?
if (count > -1)
{
// Write the batch, if required
if (++count >= DEFAULT_BATCH_SIZE)
{
try
{
sqlMapClient.executeBatch();
sqlMapClient.startBatch();
}
catch (SQLException e)
{
throw new AlfrescoRuntimeException("Failed to execute batch", e);
}
count = 0;
}
}
if (logger.isDebugEnabled() && (total == 0 || (total % 1000 == 0) ))
{
logger.debug(" Removed " + total + " content URLs");
}
}
};
// Done
return processor;
}
/**
* {@inheritDoc}
*/
public void listAllUrls(ContentUrlBatchProcessor batchProcessor)
{
ListAllRowHandler rowHandler = new ListAllRowHandler(batchProcessor);
batchProcessor.start();
template.queryWithRowHandler(SELECT_CONTENT_CLEAN_URLS, rowHandler);
batchProcessor.end();
if (logger.isDebugEnabled())
{
logger.debug(" Listed " + rowHandler.total + " content URLs");
}
}
/**
* Row handler for listing all content clean URLs
* @author Derek Hulley
* @since 3.2
*/
private static class ListAllRowHandler implements RowHandler
{
private final ContentUrlBatchProcessor batchProcessor;
private int total = 0;
private ListAllRowHandler(ContentUrlBatchProcessor batchProcessor)
{
this.batchProcessor = batchProcessor;
}
public void handleRow(Object valueObject)
{
batchProcessor.processContentUrl((String)valueObject);
total++;
if (logger.isDebugEnabled() && (total == 0 || (total % 1000 == 0) ))
{
logger.debug(" Listed " + total + " content URLs");
}
}
}
/**
* {@inheritDoc}
*/
public void cleanUp()
{
template.delete(DELETE_CONTENT_CLEAN);
}
}
/*
* 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.contentclean.ibatis;
import java.sql.SQLException;
import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.repo.domain.contentclean.ContentCleanDAO;
import org.alfresco.repo.domain.contentclean.ContentCleanEntity;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.orm.ibatis.SqlMapClientTemplate;
import com.ibatis.sqlmap.client.SqlMapClient;
import com.ibatis.sqlmap.client.event.RowHandler;
/**
* iBatis-specific implementation of the Content Cleaner DAO.
*
* @author Derek Hulley
* @since 3.2
*/
public class ContentCleanDAOImpl implements ContentCleanDAO
{
private static Log logger = LogFactory.getLog(ContentCleanDAOImpl.class);
private static final int DEFAULT_BATCH_SIZE = 50;
private static final String INSERT_CONTENT_CLEAN = "alfresco.content.insert_ContentCleanUrl";
private static final String SELECT_CONTENT_CLEAN_URLS = "alfresco.content.select_ContentCleanUrls";
private static final String DELETE_CONTENT_CLEAN_BY_URL = "alfresco.content.delete_ContentCleanUrl";
private static final String DELETE_CONTENT_CLEAN = "alfresco.content.delete_ContentCleanUrls";
private SqlMapClientTemplate template;
public void setSqlMapClientTemplate(SqlMapClientTemplate sqlMapClientTemplate)
{
this.template = sqlMapClientTemplate;
}
/**
* {@inheritDoc}
*/
public ContentUrlBatchProcessor getUrlInserter()
{
final SqlMapClient sqlMapClient = template.getSqlMapClient();
ContentUrlBatchProcessor processor = new ContentUrlBatchProcessor()
{
private int count = 0;
private int total = 0;
public void start()
{
try
{
sqlMapClient.startBatch();
count = 0;
}
catch (SQLException e)
{
// Batches not supported, so don't do batching
count = -1;
}
}
public void processContentUrl(String contentUrl)
{
ContentCleanEntity contentCleanEntity = new ContentCleanEntity();
contentCleanEntity.setContentUrl(contentUrl == null ? null : contentUrl.toLowerCase());
template.insert(INSERT_CONTENT_CLEAN, contentCleanEntity);
// Write the batch
executeBatch();
total++;
}
public void end()
{
// Write the batch
executeBatch();
if (logger.isDebugEnabled())
{
logger.debug(" Inserted " + total + " content URLs (FINISHED)");
}
}
private void executeBatch()
{
// Are we batching?
if (count > -1)
{
// Write the batch, if required
if (++count >= DEFAULT_BATCH_SIZE)
{
try
{
sqlMapClient.executeBatch();
sqlMapClient.startBatch();
}
catch (SQLException e)
{
throw new AlfrescoRuntimeException("Failed to execute batch", e);
}
count = 0;
}
}
if (logger.isDebugEnabled() && (total == 0 || (total % 1000 == 0) ))
{
logger.debug(" Inserted " + total + " content URLs");
}
}
};
// Done
return processor;
}
/**
* {@inheritDoc}
*/
public ContentUrlBatchProcessor getUrlRemover()
{
final SqlMapClient sqlMapClient = template.getSqlMapClient();
ContentUrlBatchProcessor processor = new ContentUrlBatchProcessor()
{
private int count = 0;
private int total = 0;
public void start()
{
try
{
sqlMapClient.startBatch();
count = 0;
}
catch (SQLException e)
{
// Batches not supported, so don't do batching
count = -1;
}
}
public void processContentUrl(String contentUrl)
{
ContentCleanEntity contentCleanEntity = new ContentCleanEntity();
contentCleanEntity.setContentUrl(contentUrl);
template.delete(DELETE_CONTENT_CLEAN_BY_URL, contentCleanEntity);
// Write the batch
executeBatch();
total++;
}
public void end()
{
// Write the batch
executeBatch();
if (logger.isDebugEnabled())
{
logger.debug(" Removed " + total + " content URLs (FINISHED)");
}
}
private void executeBatch()
{
// Are we batching?
if (count > -1)
{
// Write the batch, if required
if (++count >= DEFAULT_BATCH_SIZE)
{
try
{
sqlMapClient.executeBatch();
sqlMapClient.startBatch();
}
catch (SQLException e)
{
throw new AlfrescoRuntimeException("Failed to execute batch", e);
}
count = 0;
}
}
if (logger.isDebugEnabled() && (total == 0 || (total % 1000 == 0) ))
{
logger.debug(" Removed " + total + " content URLs");
}
}
};
// Done
return processor;
}
/**
* {@inheritDoc}
*/
public void listAllUrls(ContentUrlBatchProcessor batchProcessor)
{
ListAllRowHandler rowHandler = new ListAllRowHandler(batchProcessor);
batchProcessor.start();
template.queryWithRowHandler(SELECT_CONTENT_CLEAN_URLS, rowHandler);
batchProcessor.end();
if (logger.isDebugEnabled())
{
logger.debug(" Listed " + rowHandler.total + " content URLs");
}
}
/**
* Row handler for listing all content clean URLs
* @author Derek Hulley
* @since 3.2
*/
private static class ListAllRowHandler implements RowHandler
{
private final ContentUrlBatchProcessor batchProcessor;
private int total = 0;
private ListAllRowHandler(ContentUrlBatchProcessor batchProcessor)
{
this.batchProcessor = batchProcessor;
}
public void handleRow(Object valueObject)
{
batchProcessor.processContentUrl((String)valueObject);
total++;
if (logger.isDebugEnabled() && (total == 0 || (total % 1000 == 0) ))
{
logger.debug(" Listed " + total + " content URLs");
}
}
}
/**
* {@inheritDoc}
*/
public void cleanUp()
{
template.delete(DELETE_CONTENT_CLEAN);
}
}

View File

@@ -1,202 +1,210 @@
/*
* 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.contentdata.ibatis;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.alfresco.repo.domain.contentdata.AbstractContentDataDAOImpl;
import org.alfresco.repo.domain.contentdata.ContentDataEntity;
import org.alfresco.repo.domain.contentdata.ContentUrlEntity;
import org.springframework.orm.ibatis.SqlMapClientTemplate;
import com.ibatis.sqlmap.client.event.RowHandler;
/**
* iBatis-specific implementation of the ContentData DAO.
*
* @author Derek Hulley
* @since 3.2
*/
public class ContentDataDAOImpl extends AbstractContentDataDAOImpl
{
private static final String SELECT_CONTENT_URL_BY_ID = "alfresco.content.select_ContentUrlById";
private static final String SELECT_CONTENT_URL_BY_KEY = "alfresco.content.select_ContentUrlByKey";
private static final String SELECT_CONTENT_URL_BY_KEY_UNREFERENCED = "alfresco.content.select_ContentUrlByKeyUnreferenced";
private static final String SELECT_CONTENT_URLS = "alfresco.content.select_ContentUrls";
private static final String SELECT_CONTENT_DATA_BY_ID = "alfresco.content.select_ContentDataById";
private static final String SELECT_CONTENT_DATA_BY_NODE_AND_QNAME = "alfresco.content.select_ContentDataByNodeAndQName";
private static final String INSERT_CONTENT_URL = "alfresco.content.insert_ContentUrl";
private static final String INSERT_CONTENT_DATA = "alfresco.content.insert_ContentData";
private static final String DELETE_CONTENT_DATA = "alfresco.content.delete_ContentData";
private static final String DELETE_CONTENT_URL = "alfresco.content.delete_ContentUrl";
private SqlMapClientTemplate template;
public void setSqlMapClientTemplate(SqlMapClientTemplate sqlMapClientTemplate)
{
this.template = sqlMapClientTemplate;
}
@Override
protected ContentUrlEntity createContentUrlEntity(String contentUrl, long size)
{
ContentUrlEntity contentUrlEntity = new ContentUrlEntity();
contentUrlEntity.setVersion(ContentUrlEntity.CONST_LONG_ZERO);
contentUrlEntity.setContentUrl(contentUrl);
contentUrlEntity.setSize(size);
/* Long id = (Long) */ template.insert(INSERT_CONTENT_URL, contentUrlEntity);
/*contentUrlEntity.setId(id);*/
// Register the url as new
registerNewContentUrl(contentUrl);
// Done
return contentUrlEntity;
}
@Override
protected ContentUrlEntity getContentUrlEntity(Long id)
{
ContentUrlEntity contentUrlEntity = new ContentUrlEntity();
contentUrlEntity.setId(id);
contentUrlEntity = (ContentUrlEntity) template.queryForObject(SELECT_CONTENT_URL_BY_ID, contentUrlEntity);
// Done
return contentUrlEntity;
}
@Override
protected ContentUrlEntity getContentUrlEntity(String contentUrl)
{
ContentUrlEntity contentUrlEntity = new ContentUrlEntity();
contentUrlEntity.setContentUrl(contentUrl);
contentUrlEntity = (ContentUrlEntity) template.queryForObject(SELECT_CONTENT_URL_BY_KEY, contentUrlEntity);
// Done
return contentUrlEntity;
}
@Override
protected int deleteContentUrlEntity(Long id)
{
Map<String, Object> params = new HashMap<String, Object>(11);
params.put("id", id);
return template.delete(DELETE_CONTENT_URL, params);
}
@Override
protected ContentUrlEntity getContentUrlEntityUnreferenced(String contentUrl)
{
ContentUrlEntity contentUrlEntity = new ContentUrlEntity();
contentUrlEntity.setContentUrl(contentUrl);
contentUrlEntity = (ContentUrlEntity) template.queryForObject(SELECT_CONTENT_URL_BY_KEY_UNREFERENCED, contentUrlEntity);
// Done
return contentUrlEntity;
}
@Override
protected ContentDataEntity createContentDataEntity(
Long contentUrlId,
Long mimetypeId,
Long encodingId,
Long localeId)
{
ContentDataEntity contentDataEntity = new ContentDataEntity();
contentDataEntity.setVersion(ContentDataEntity.CONST_LONG_ZERO);
contentDataEntity.setContentUrlId(contentUrlId);
contentDataEntity.setMimetypeId(mimetypeId);
contentDataEntity.setEncodingId(encodingId);
contentDataEntity.setLocaleId(localeId);
template.insert(INSERT_CONTENT_DATA, contentDataEntity);
// Done
return contentDataEntity;
}
@Override
protected ContentDataEntity getContentDataEntity(Long id)
{
Map<String, Object> params = new HashMap<String, Object>(11);
params.put("id", id);
ContentDataEntity contentDataEntity = (ContentDataEntity) template.queryForObject(SELECT_CONTENT_DATA_BY_ID, params);
// Done
return contentDataEntity;
}
@Override
protected int deleteContentDataEntity(Long id)
{
Map<String, Object> params = new HashMap<String, Object>(11);
params.put("id", id);
return template.delete(DELETE_CONTENT_DATA, params);
}
public void deleteContentDataForNode(Long nodeId, Set<Long> qnameIds)
{
/*
* TODO: use IN clause in parameters
*/
for (Long qnameId : qnameIds)
{
// Get the ContentData that matches (may be multiple due to collection properties)
Map<String, Object> params = new HashMap<String, Object>(11);
params.put("nodeId", nodeId);
params.put("qnameId", qnameId);
@SuppressWarnings("unchecked")
List<Long> ids = (List<Long>) template.queryForList(SELECT_CONTENT_DATA_BY_NODE_AND_QNAME, params);
// Delete each one
for (Long id : ids)
{
// Get the content urls
ContentDataEntity contentDataEntity = getContentDataEntity(id);
// This might be null as there is no constraint ensuring that the node points to a valid ContentData entity
if (contentDataEntity == null)
{
continue;
}
// Only check the content URLs if one is present
String contentUrl = contentDataEntity.getContentUrl();
// Delete the ContentData entity
deleteContentData(id);
// Check if the content URL was orphaned
if (contentUrl != null)
{
// It has been dereferenced and may be orphaned - we'll check later
registerDereferenceContentUrl(contentUrl);
}
}
}
}
public void getAllContentUrls(final ContentUrlHandler contentUrlHandler)
{
RowHandler rowHandler = new RowHandler()
{
public void handleRow(Object valueObject)
{
contentUrlHandler.handle((String)valueObject);
}
};
template.queryWithRowHandler(SELECT_CONTENT_URLS, rowHandler);
}
}
/*
* 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.contentdata.ibatis;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.alfresco.repo.domain.contentdata.AbstractContentDataDAOImpl;
import org.alfresco.repo.domain.contentdata.ContentDataEntity;
import org.alfresco.repo.domain.contentdata.ContentUrlEntity;
import org.springframework.orm.ibatis.SqlMapClientTemplate;
import com.ibatis.sqlmap.client.event.RowHandler;
/**
* iBatis-specific implementation of the ContentData DAO.
*
* @author Derek Hulley
* @since 3.2
*/
public class ContentDataDAOImpl extends AbstractContentDataDAOImpl
{
private static final String SELECT_CONTENT_URL_BY_ID = "alfresco.content.select_ContentUrlById";
private static final String SELECT_CONTENT_URL_BY_KEY = "alfresco.content.select_ContentUrlByKey";
private static final String SELECT_CONTENT_URL_BY_KEY_UNREFERENCED = "alfresco.content.select_ContentUrlByKeyUnreferenced";
private static final String SELECT_CONTENT_URLS = "alfresco.content.select_ContentUrls";
private static final String SELECT_CONTENT_DATA_BY_ID = "alfresco.content.select_ContentDataById";
private static final String SELECT_CONTENT_DATA_BY_NODE_AND_QNAME = "alfresco.content.select_ContentDataByNodeAndQName";
private static final String INSERT_CONTENT_URL = "alfresco.content.insert_ContentUrl";
private static final String INSERT_CONTENT_DATA = "alfresco.content.insert_ContentData";
private static final String DELETE_CONTENT_DATA = "alfresco.content.delete_ContentData";
private static final String DELETE_CONTENT_URL = "alfresco.content.delete_ContentUrl";
private SqlMapClientTemplate template;
public void setSqlMapClientTemplate(SqlMapClientTemplate sqlMapClientTemplate)
{
this.template = sqlMapClientTemplate;
}
@Override
protected ContentUrlEntity createContentUrlEntity(String contentUrl, long size)
{
ContentUrlEntity contentUrlEntity = new ContentUrlEntity();
contentUrlEntity.setVersion(ContentUrlEntity.CONST_LONG_ZERO);
contentUrlEntity.setContentUrl(contentUrl);
contentUrlEntity.setSize(size);
/* Long id = (Long) */ template.insert(INSERT_CONTENT_URL, contentUrlEntity);
/*contentUrlEntity.setId(id);*/
// Register the url as new
registerNewContentUrl(contentUrl);
// Done
return contentUrlEntity;
}
@Override
protected ContentUrlEntity getContentUrlEntity(Long id)
{
ContentUrlEntity contentUrlEntity = new ContentUrlEntity();
contentUrlEntity.setId(id);
contentUrlEntity = (ContentUrlEntity) template.queryForObject(SELECT_CONTENT_URL_BY_ID, contentUrlEntity);
// Done
return contentUrlEntity;
}
@Override
protected ContentUrlEntity getContentUrlEntity(String contentUrl)
{
ContentUrlEntity contentUrlEntity = new ContentUrlEntity();
contentUrlEntity.setContentUrl(contentUrl);
if (contentUrlEntity.getContentUrlShort() != null)
{
contentUrlEntity.setContentUrlShort(contentUrlEntity.getContentUrlShort().toLowerCase());
}
contentUrlEntity = (ContentUrlEntity) template.queryForObject(SELECT_CONTENT_URL_BY_KEY, contentUrlEntity);
// Done
return contentUrlEntity;
}
@Override
protected int deleteContentUrlEntity(Long id)
{
Map<String, Object> params = new HashMap<String, Object>(11);
params.put("id", id);
return template.delete(DELETE_CONTENT_URL, params);
}
@Override
protected ContentUrlEntity getContentUrlEntityUnreferenced(String contentUrl)
{
ContentUrlEntity contentUrlEntity = new ContentUrlEntity();
contentUrlEntity.setContentUrl(contentUrl);
if (contentUrlEntity.getContentUrlShort() != null)
{
contentUrlEntity.setContentUrlShort(contentUrlEntity.getContentUrlShort().toLowerCase());
}
contentUrlEntity = (ContentUrlEntity) template.queryForObject(SELECT_CONTENT_URL_BY_KEY_UNREFERENCED, contentUrlEntity);
// Done
return contentUrlEntity;
}
@Override
protected ContentDataEntity createContentDataEntity(
Long contentUrlId,
Long mimetypeId,
Long encodingId,
Long localeId)
{
ContentDataEntity contentDataEntity = new ContentDataEntity();
contentDataEntity.setVersion(ContentDataEntity.CONST_LONG_ZERO);
contentDataEntity.setContentUrlId(contentUrlId);
contentDataEntity.setMimetypeId(mimetypeId);
contentDataEntity.setEncodingId(encodingId);
contentDataEntity.setLocaleId(localeId);
template.insert(INSERT_CONTENT_DATA, contentDataEntity);
// Done
return contentDataEntity;
}
@Override
protected ContentDataEntity getContentDataEntity(Long id)
{
Map<String, Object> params = new HashMap<String, Object>(11);
params.put("id", id);
ContentDataEntity contentDataEntity = (ContentDataEntity) template.queryForObject(SELECT_CONTENT_DATA_BY_ID, params);
// Done
return contentDataEntity;
}
@Override
protected int deleteContentDataEntity(Long id)
{
Map<String, Object> params = new HashMap<String, Object>(11);
params.put("id", id);
return template.delete(DELETE_CONTENT_DATA, params);
}
public void deleteContentDataForNode(Long nodeId, Set<Long> qnameIds)
{
/*
* TODO: use IN clause in parameters
*/
for (Long qnameId : qnameIds)
{
// Get the ContentData that matches (may be multiple due to collection properties)
Map<String, Object> params = new HashMap<String, Object>(11);
params.put("nodeId", nodeId);
params.put("qnameId", qnameId);
@SuppressWarnings("unchecked")
List<Long> ids = (List<Long>) template.queryForList(SELECT_CONTENT_DATA_BY_NODE_AND_QNAME, params);
// Delete each one
for (Long id : ids)
{
// Get the content urls
ContentDataEntity contentDataEntity = getContentDataEntity(id);
// This might be null as there is no constraint ensuring that the node points to a valid ContentData entity
if (contentDataEntity == null)
{
continue;
}
// Only check the content URLs if one is present
String contentUrl = contentDataEntity.getContentUrl();
// Delete the ContentData entity
deleteContentData(id);
// Check if the content URL was orphaned
if (contentUrl != null)
{
// It has been dereferenced and may be orphaned - we'll check later
registerDereferenceContentUrl(contentUrl);
}
}
}
}
public void getAllContentUrls(final ContentUrlHandler contentUrlHandler)
{
RowHandler rowHandler = new RowHandler()
{
public void handleRow(Object valueObject)
{
contentUrlHandler.handle((String)valueObject);
}
};
template.queryWithRowHandler(SELECT_CONTENT_URLS, rowHandler);
}
}

View File

@@ -1,82 +1,82 @@
/*
* 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.encoding.ibatis;
import org.alfresco.repo.domain.encoding.AbstractEncodingDAOImpl;
import org.alfresco.repo.domain.encoding.EncodingEntity;
import org.alfresco.repo.domain.mimetype.MimetypeEntity;
import org.springframework.orm.ibatis.SqlMapClientTemplate;
/**
* iBatis-specific implementation of the Mimetype DAO.
*
* @author Derek Hulley
* @since 3.2
*/
public class EncodingDAOImpl extends AbstractEncodingDAOImpl
{
private static final String SELECT_ENCODING_BY_ID = "alfresco.content.select_EncodingById";
private static final String SELECT_ENCODING_BY_KEY = "alfresco.content.select_EncodingByKey";
private static final String INSERT_ENCODING = "alfresco.content.insert_Encoding";
private SqlMapClientTemplate template;
public void setSqlMapClientTemplate(SqlMapClientTemplate sqlMapClientTemplate)
{
this.template = sqlMapClientTemplate;
}
@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);
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);
Long id = (Long) template.insert(INSERT_ENCODING, encodingEntity);
encodingEntity.setId(id);
// Done
return encodingEntity;
}
}
/*
* 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.encoding.ibatis;
import org.alfresco.repo.domain.encoding.AbstractEncodingDAOImpl;
import org.alfresco.repo.domain.encoding.EncodingEntity;
import org.alfresco.repo.domain.mimetype.MimetypeEntity;
import org.springframework.orm.ibatis.SqlMapClientTemplate;
/**
* iBatis-specific implementation of the Mimetype DAO.
*
* @author Derek Hulley
* @since 3.2
*/
public class EncodingDAOImpl extends AbstractEncodingDAOImpl
{
private static final String SELECT_ENCODING_BY_ID = "alfresco.content.select_EncodingById";
private static final String SELECT_ENCODING_BY_KEY = "alfresco.content.select_EncodingByKey";
private static final String INSERT_ENCODING = "alfresco.content.insert_Encoding";
private SqlMapClientTemplate template;
public void setSqlMapClientTemplate(SqlMapClientTemplate sqlMapClientTemplate)
{
this.template = sqlMapClientTemplate;
}
@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

@@ -1,174 +1,174 @@
/*
* 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.locks.ibatis;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.alfresco.repo.domain.locks.AbstractLockDAOImpl;
import org.alfresco.repo.domain.locks.LockEntity;
import org.alfresco.repo.domain.locks.LockResourceEntity;
import org.springframework.orm.ibatis.SqlMapClientTemplate;
/**
* iBatis-specific implementation of the Locks DAO.
*
* @author Derek Hulley
* @since 3.2
*/
public class LockDAOImpl extends AbstractLockDAOImpl
{
private static final String SELECT_LOCKRESOURCE_BY_QNAME = "alfresco.lock.select_LockResourceByQName";
private static final String SELECT_LOCK_BY_ID = "alfresco.lock.select_LockByID";
private static final String SELECT_LOCK_BY_KEY = "alfresco.lock.select_LockByKey";
private static final String SELECT_LOCK_BY_SHARED_IDS = "alfresco.lock.select_LockBySharedIds";
private static final String INSERT_LOCKRESOURCE = "alfresco.lock.insert_LockResource";
private static final String INSERT_LOCK = "alfresco.lock.insert_Lock";
private static final String UPDATE_LOCK = "alfresco.lock.update_Lock";
private static final String UPDATE_EXCLUSIVE_LOCK = "alfresco.lock.update_ExclusiveLock";
private SqlMapClientTemplate template;
public void setSqlMapClientTemplate(SqlMapClientTemplate sqlMapClientTemplate)
{
this.template = sqlMapClientTemplate;
}
@Override
protected LockResourceEntity getLockResource(Long qnameNamespaceId, String qnameLocalName)
{
LockResourceEntity lockResource = new LockResourceEntity();
lockResource.setQnameNamespaceId(qnameNamespaceId);
lockResource.setQnameLocalName(qnameLocalName);
lockResource = (LockResourceEntity) template.queryForObject(SELECT_LOCKRESOURCE_BY_QNAME, lockResource);
// Could be null
return lockResource;
}
@Override
protected LockResourceEntity createLockResource(Long qnameNamespaceId, String qnameLocalName)
{
LockResourceEntity lockResource = new LockResourceEntity();
lockResource.setVersion(LockEntity.CONST_LONG_ZERO);
lockResource.setQnameNamespaceId(qnameNamespaceId);
lockResource.setQnameLocalName(qnameLocalName);
Long id = (Long) template.insert(INSERT_LOCKRESOURCE, lockResource);
lockResource.setId(id);
// Done
return lockResource;
}
@SuppressWarnings("unchecked")
@Override
protected List<LockEntity> getLocksBySharedResourceIds(List<Long> sharedLockResourceIds)
{
List<LockEntity> locks = template.queryForList(SELECT_LOCK_BY_SHARED_IDS, sharedLockResourceIds);
// Done
return locks;
}
@Override
protected LockEntity getLock(Long id)
{
LockEntity lock = new LockEntity();
lock.setId(id);
lock = (LockEntity) template.queryForObject(SELECT_LOCK_BY_ID, lock);
// Done
return lock;
}
@Override
protected LockEntity getLock(Long sharedResourceId, Long exclusiveResourceId)
{
LockEntity lock = new LockEntity();
lock.setSharedResourceId(sharedResourceId);
lock.setExclusiveResourceId(exclusiveResourceId);
lock = (LockEntity) template.queryForObject(SELECT_LOCK_BY_KEY, lock);
// Done
return lock;
}
@Override
protected LockEntity createLock(
Long sharedResourceId,
Long exclusiveResourceId,
String lockToken,
long timeToLive)
{
LockEntity lock = new LockEntity();
lock.setVersion(LockEntity.CONST_LONG_ZERO);
lock.setSharedResourceId(sharedResourceId);
lock.setExclusiveResourceId(exclusiveResourceId);
lock.setLockToken(lockToken);
long now = System.currentTimeMillis();
long exp = now + timeToLive;
lock.setStartTime(now);
lock.setExpiryTime(exp);
Long id = (Long) template.insert(INSERT_LOCK, lock);
lock.setId(id);
// Done
return lock;
}
@Override
protected LockEntity updateLock(LockEntity lockEntity, String lockToken, long timeToLive)
{
LockEntity updateLockEntity = new LockEntity();
updateLockEntity.setId(lockEntity.getId());
updateLockEntity.setVersion(lockEntity.getVersion());
updateLockEntity.incrementVersion(); // Increment the version number
updateLockEntity.setSharedResourceId(lockEntity.getSharedResourceId());
updateLockEntity.setExclusiveResourceId(lockEntity.getExclusiveResourceId());
updateLockEntity.setLockToken(lockToken);
long now = (timeToLive > 0) ? System.currentTimeMillis() : 0L;
long exp = (timeToLive > 0) ? (now + timeToLive) : 0L;
updateLockEntity.setStartTime(new Long(now));
updateLockEntity.setExpiryTime(new Long(exp));
template.update(UPDATE_LOCK, updateLockEntity, 1);
// Done
return updateLockEntity;
}
@Override
protected int updateLocks(
Long exclusiveLockResourceId,
String oldLockToken,
String newLockToken,
long timeToLive)
{
Map<String, Object> params = new HashMap<String, Object>(11);
params.put("exclusiveLockResourceId", exclusiveLockResourceId);
params.put("oldLockToken", oldLockToken);
params.put("newLockToken", newLockToken);
long now = (timeToLive > 0) ? System.currentTimeMillis() : 0L;
long exp = (timeToLive > 0) ? (now + timeToLive) : 0L;
params.put("newStartTime", new Long(now));
params.put("newExpiryTime", new Long(exp));
int updateCount = template.update(UPDATE_EXCLUSIVE_LOCK, params);
// Done
return updateCount;
}
}
/*
* 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.locks.ibatis;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.alfresco.repo.domain.locks.AbstractLockDAOImpl;
import org.alfresco.repo.domain.locks.LockEntity;
import org.alfresco.repo.domain.locks.LockResourceEntity;
import org.springframework.orm.ibatis.SqlMapClientTemplate;
/**
* iBatis-specific implementation of the Locks DAO.
*
* @author Derek Hulley
* @since 3.2
*/
public class LockDAOImpl extends AbstractLockDAOImpl
{
private static final String SELECT_LOCKRESOURCE_BY_QNAME = "alfresco.lock.select_LockResourceByQName";
private static final String SELECT_LOCK_BY_ID = "alfresco.lock.select_LockByID";
private static final String SELECT_LOCK_BY_KEY = "alfresco.lock.select_LockByKey";
private static final String SELECT_LOCK_BY_SHARED_IDS = "alfresco.lock.select_LockBySharedIds";
private static final String INSERT_LOCKRESOURCE = "alfresco.lock.insert_LockResource";
private static final String INSERT_LOCK = "alfresco.lock.insert_Lock";
private static final String UPDATE_LOCK = "alfresco.lock.update_Lock";
private static final String UPDATE_EXCLUSIVE_LOCK = "alfresco.lock.update_ExclusiveLock";
private SqlMapClientTemplate template;
public void setSqlMapClientTemplate(SqlMapClientTemplate sqlMapClientTemplate)
{
this.template = sqlMapClientTemplate;
}
@Override
protected LockResourceEntity getLockResource(Long qnameNamespaceId, String qnameLocalName)
{
LockResourceEntity lockResource = new LockResourceEntity();
lockResource.setQnameNamespaceId(qnameNamespaceId);
lockResource.setQnameLocalName(qnameLocalName == null ? null : qnameLocalName.toLowerCase());
lockResource = (LockResourceEntity) template.queryForObject(SELECT_LOCKRESOURCE_BY_QNAME, lockResource);
// Could be null
return lockResource;
}
@Override
protected LockResourceEntity createLockResource(Long qnameNamespaceId, String qnameLocalName)
{
LockResourceEntity lockResource = new LockResourceEntity();
lockResource.setVersion(LockEntity.CONST_LONG_ZERO);
lockResource.setQnameNamespaceId(qnameNamespaceId);
lockResource.setQnameLocalName(qnameLocalName == null ? null : qnameLocalName.toLowerCase());
Long id = (Long) template.insert(INSERT_LOCKRESOURCE, lockResource);
lockResource.setId(id);
// Done
return lockResource;
}
@SuppressWarnings("unchecked")
@Override
protected List<LockEntity> getLocksBySharedResourceIds(List<Long> sharedLockResourceIds)
{
List<LockEntity> locks = template.queryForList(SELECT_LOCK_BY_SHARED_IDS, sharedLockResourceIds);
// Done
return locks;
}
@Override
protected LockEntity getLock(Long id)
{
LockEntity lock = new LockEntity();
lock.setId(id);
lock = (LockEntity) template.queryForObject(SELECT_LOCK_BY_ID, lock);
// Done
return lock;
}
@Override
protected LockEntity getLock(Long sharedResourceId, Long exclusiveResourceId)
{
LockEntity lock = new LockEntity();
lock.setSharedResourceId(sharedResourceId);
lock.setExclusiveResourceId(exclusiveResourceId);
lock = (LockEntity) template.queryForObject(SELECT_LOCK_BY_KEY, lock);
// Done
return lock;
}
@Override
protected LockEntity createLock(
Long sharedResourceId,
Long exclusiveResourceId,
String lockToken,
long timeToLive)
{
LockEntity lock = new LockEntity();
lock.setVersion(LockEntity.CONST_LONG_ZERO);
lock.setSharedResourceId(sharedResourceId);
lock.setExclusiveResourceId(exclusiveResourceId);
lock.setLockToken(lockToken == null ? null : lockToken.toLowerCase());
long now = System.currentTimeMillis();
long exp = now + timeToLive;
lock.setStartTime(now);
lock.setExpiryTime(exp);
Long id = (Long) template.insert(INSERT_LOCK, lock);
lock.setId(id);
// Done
return lock;
}
@Override
protected LockEntity updateLock(LockEntity lockEntity, String lockToken, long timeToLive)
{
LockEntity updateLockEntity = new LockEntity();
updateLockEntity.setId(lockEntity.getId());
updateLockEntity.setVersion(lockEntity.getVersion());
updateLockEntity.incrementVersion(); // Increment the version number
updateLockEntity.setSharedResourceId(lockEntity.getSharedResourceId());
updateLockEntity.setExclusiveResourceId(lockEntity.getExclusiveResourceId());
updateLockEntity.setLockToken(lockToken == null ? null : lockToken.toLowerCase());
long now = (timeToLive > 0) ? System.currentTimeMillis() : 0L;
long exp = (timeToLive > 0) ? (now + timeToLive) : 0L;
updateLockEntity.setStartTime(new Long(now));
updateLockEntity.setExpiryTime(new Long(exp));
template.update(UPDATE_LOCK, updateLockEntity, 1);
// Done
return updateLockEntity;
}
@Override
protected int updateLocks(
Long exclusiveLockResourceId,
String oldLockToken,
String newLockToken,
long timeToLive)
{
Map<String, Object> params = new HashMap<String, Object>(11);
params.put("exclusiveLockResourceId", exclusiveLockResourceId);
params.put("oldLockToken", oldLockToken);
params.put("newLockToken", newLockToken == null ? null : newLockToken.toLowerCase());
long now = (timeToLive > 0) ? System.currentTimeMillis() : 0L;
long exp = (timeToLive > 0) ? (now + timeToLive) : 0L;
params.put("newStartTime", new Long(now));
params.put("newExpiryTime", new Long(exp));
int updateCount = template.update(UPDATE_EXCLUSIVE_LOCK, params);
// Done
return updateCount;
}
}

View File

@@ -1,81 +1,81 @@
/*
* 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.mimetype.ibatis;
import org.alfresco.repo.domain.mimetype.AbstractMimetypeDAOImpl;
import org.alfresco.repo.domain.mimetype.MimetypeEntity;
import org.springframework.orm.ibatis.SqlMapClientTemplate;
/**
* iBatis-specific implementation of the Mimetype DAO.
*
* @author Derek Hulley
* @since 3.2
*/
public class MimetypeDAOImpl extends AbstractMimetypeDAOImpl
{
private static final String SELECT_MIMETYPE_BY_ID = "alfresco.content.select_MimetypeById";
private static final String SELECT_MIMETYPE_BY_KEY = "alfresco.content.select_MimetypeByKey";
private static final String INSERT_MIMETYPE = "alfresco.content.insert_Mimetype";
private SqlMapClientTemplate template;
public void setSqlMapClientTemplate(SqlMapClientTemplate sqlMapClientTemplate)
{
this.template = sqlMapClientTemplate;
}
@Override
protected MimetypeEntity getMimetypeEntity(Long id)
{
MimetypeEntity mimetypeEntity = new MimetypeEntity();
mimetypeEntity.setId(id);
mimetypeEntity = (MimetypeEntity) template.queryForObject(SELECT_MIMETYPE_BY_ID, mimetypeEntity);
// Done
return mimetypeEntity;
}
@Override
protected MimetypeEntity getMimetypeEntity(String mimetype)
{
MimetypeEntity mimetypeEntity = new MimetypeEntity();
mimetypeEntity.setMimetype(mimetype);
mimetypeEntity = (MimetypeEntity) template.queryForObject(SELECT_MIMETYPE_BY_KEY, mimetypeEntity);
// Could be null
return mimetypeEntity;
}
@Override
protected MimetypeEntity createMimetypeEntity(String mimetype)
{
MimetypeEntity mimetypeEntity = new MimetypeEntity();
mimetypeEntity.setVersion(MimetypeEntity.CONST_LONG_ZERO);
mimetypeEntity.setMimetype(mimetype);
Long id = (Long) template.insert(INSERT_MIMETYPE, mimetypeEntity);
mimetypeEntity.setId(id);
// Done
return mimetypeEntity;
}
}
/*
* 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.mimetype.ibatis;
import org.alfresco.repo.domain.mimetype.AbstractMimetypeDAOImpl;
import org.alfresco.repo.domain.mimetype.MimetypeEntity;
import org.springframework.orm.ibatis.SqlMapClientTemplate;
/**
* iBatis-specific implementation of the Mimetype DAO.
*
* @author Derek Hulley
* @since 3.2
*/
public class MimetypeDAOImpl extends AbstractMimetypeDAOImpl
{
private static final String SELECT_MIMETYPE_BY_ID = "alfresco.content.select_MimetypeById";
private static final String SELECT_MIMETYPE_BY_KEY = "alfresco.content.select_MimetypeByKey";
private static final String INSERT_MIMETYPE = "alfresco.content.insert_Mimetype";
private SqlMapClientTemplate template;
public void setSqlMapClientTemplate(SqlMapClientTemplate sqlMapClientTemplate)
{
this.template = sqlMapClientTemplate;
}
@Override
protected MimetypeEntity getMimetypeEntity(Long id)
{
MimetypeEntity mimetypeEntity = new MimetypeEntity();
mimetypeEntity.setId(id);
mimetypeEntity = (MimetypeEntity) template.queryForObject(SELECT_MIMETYPE_BY_ID, mimetypeEntity);
// Done
return mimetypeEntity;
}
@Override
protected MimetypeEntity getMimetypeEntity(String mimetype)
{
MimetypeEntity mimetypeEntity = new MimetypeEntity();
mimetypeEntity.setMimetype(mimetype == null ? null : mimetype.toLowerCase());
mimetypeEntity = (MimetypeEntity) template.queryForObject(SELECT_MIMETYPE_BY_KEY, mimetypeEntity);
// Could be null
return mimetypeEntity;
}
@Override
protected MimetypeEntity createMimetypeEntity(String mimetype)
{
MimetypeEntity mimetypeEntity = new MimetypeEntity();
mimetypeEntity.setVersion(MimetypeEntity.CONST_LONG_ZERO);
mimetypeEntity.setMimetype(mimetype == null ? null : mimetype.toLowerCase());
Long id = (Long) template.insert(INSERT_MIMETYPE, mimetypeEntity);
mimetypeEntity.setId(id);
// Done
return mimetypeEntity;
}
}