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-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-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-Indexes.sql</value>
<value>classpath:alfresco/dbscripts/create/3.2/${db.script.dialect}/AlfrescoPostCreate-3.2-JBPM-Extra.sql</value>
</list> </list>
</property> </property>
<property name="validateUpdateScriptPatches"> <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"/> <parameter property="qnameId" jdbcType="BIGINT" javaType="java.lang.Long"/>
</parameterMap> </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 Snippets -->
<!-- --> <!-- -->
<sql id="insert_Mimetype_AutoIncrement"> <sql id="insert_Mimetype_AutoIncrement">
insert into alf_mimetype (version, mimetype_str) insert into alf_mimetype (version, mimetype_str)
values (#version#, lower(#mimetype#)) values (#version#, #mimetype#)
</sql> </sql>
<sql id="insert_Encoding_AutoIncrement"> <sql id="insert_Encoding_AutoIncrement">
insert into alf_encoding (version, encoding_str) insert into alf_encoding (version, encoding_str)
values (#version#, lower(#encoding#)) values (#version#, #encoding#)
</sql> </sql>
<sql id="insert_ContentUrl_AutoIncrement"> <sql id="insert_ContentUrl_AutoIncrement">
@@ -86,7 +94,7 @@
<sql id="insert_ContentData_AutoIncrement"> <sql id="insert_ContentData_AutoIncrement">
insert into alf_content_data (version, content_url_id, content_mimetype_id, content_encoding_id, content_locale_id) 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> </sql>
<!-- --> <!-- -->
@@ -100,7 +108,7 @@
from from
alf_mimetype alf_mimetype
where where
mimetype_str = lower(#mimetype#) mimetype_str = #mimetype#
</select> </select>
<!-- Get a mimetype based on the ID --> <!-- Get a mimetype based on the ID -->
@@ -120,7 +128,7 @@
from from
alf_encoding alf_encoding
where where
encoding_str = lower(#encoding#) encoding_str = #encoding#
</select> </select>
<!-- Get a encoding based on the ID --> <!-- Get a encoding based on the ID -->
@@ -150,7 +158,7 @@
from from
alf_content_url alf_content_url
where where
content_url_short = lower(#contentUrlShort#) and content_url_short = #contentUrlShort# and
content_url_crc = #contentUrlCrc# content_url_crc = #contentUrlCrc#
</select> </select>
@@ -162,7 +170,7 @@
alf_content_url cu alf_content_url cu
left outer join alf_content_data cd on (cd.content_url_id = cu.id) left outer join alf_content_data cd on (cd.content_url_id = cu.id)
where where
content_url_short = lower(#contentUrlShort#) and content_url_short = #contentUrlShort# and
content_url_crc = #contentUrlCrc# and content_url_crc = #contentUrlCrc# and
cd.id is null cd.id is null
</select> </select>
@@ -226,7 +234,7 @@
<!-- Insert a Content Clean URL --> <!-- Insert a Content Clean URL -->
<insert id="insert_ContentCleanUrl" parameterClass="ContentClean" > <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> </insert>
<!-- Select all content clean URLs --> <!-- Select all content clean URLs -->
@@ -243,7 +251,7 @@
from from
alf_content_clean alf_content_clean
where where
content_url = lower(#contentUrl#) content_url = #contentUrl#
</delete> </delete>
<!-- Remove all Content Clean URLs --> <!-- Remove all Content Clean URLs -->

View File

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

View File

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

View File

@@ -1,254 +1,254 @@
/* /*
* Copyright (C) 2005-2009 Alfresco Software Limited. * Copyright (C) 2005-2009 Alfresco Software Limited.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2 * as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version. * of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * 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 * 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 * the GPL, you may redistribute this Program in connection with Free/Libre
* and Open Source Software ("FLOSS") applications as described in Alfresco's * and Open Source Software ("FLOSS") applications as described in Alfresco's
* FLOSS exception. You should have recieved a copy of the text describing * FLOSS exception. You should have recieved a copy of the text describing
* the FLOSS exception, and it is also available here: * the FLOSS exception, and it is also available here:
* http://www.alfresco.com/legal/licensing" * http://www.alfresco.com/legal/licensing"
*/ */
package org.alfresco.repo.domain.contentclean.ibatis; package org.alfresco.repo.domain.contentclean.ibatis;
import java.sql.SQLException; import java.sql.SQLException;
import org.alfresco.error.AlfrescoRuntimeException; import org.alfresco.error.AlfrescoRuntimeException;
import org.alfresco.repo.domain.contentclean.ContentCleanDAO; import org.alfresco.repo.domain.contentclean.ContentCleanDAO;
import org.alfresco.repo.domain.contentclean.ContentCleanEntity; import org.alfresco.repo.domain.contentclean.ContentCleanEntity;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.springframework.orm.ibatis.SqlMapClientTemplate; import org.springframework.orm.ibatis.SqlMapClientTemplate;
import com.ibatis.sqlmap.client.SqlMapClient; import com.ibatis.sqlmap.client.SqlMapClient;
import com.ibatis.sqlmap.client.event.RowHandler; import com.ibatis.sqlmap.client.event.RowHandler;
/** /**
* iBatis-specific implementation of the Content Cleaner DAO. * iBatis-specific implementation of the Content Cleaner DAO.
* *
* @author Derek Hulley * @author Derek Hulley
* @since 3.2 * @since 3.2
*/ */
public class ContentCleanDAOImpl implements ContentCleanDAO public class ContentCleanDAOImpl implements ContentCleanDAO
{ {
private static Log logger = LogFactory.getLog(ContentCleanDAOImpl.class); private static Log logger = LogFactory.getLog(ContentCleanDAOImpl.class);
private static final int DEFAULT_BATCH_SIZE = 50; private static final int DEFAULT_BATCH_SIZE = 50;
private static final String INSERT_CONTENT_CLEAN = "alfresco.content.insert_ContentCleanUrl"; 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 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_BY_URL = "alfresco.content.delete_ContentCleanUrl";
private static final String DELETE_CONTENT_CLEAN = "alfresco.content.delete_ContentCleanUrls"; private static final String DELETE_CONTENT_CLEAN = "alfresco.content.delete_ContentCleanUrls";
private SqlMapClientTemplate template; private SqlMapClientTemplate template;
public void setSqlMapClientTemplate(SqlMapClientTemplate sqlMapClientTemplate) public void setSqlMapClientTemplate(SqlMapClientTemplate sqlMapClientTemplate)
{ {
this.template = sqlMapClientTemplate; this.template = sqlMapClientTemplate;
} }
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
public ContentUrlBatchProcessor getUrlInserter() public ContentUrlBatchProcessor getUrlInserter()
{ {
final SqlMapClient sqlMapClient = template.getSqlMapClient(); final SqlMapClient sqlMapClient = template.getSqlMapClient();
ContentUrlBatchProcessor processor = new ContentUrlBatchProcessor() ContentUrlBatchProcessor processor = new ContentUrlBatchProcessor()
{ {
private int count = 0; private int count = 0;
private int total = 0; private int total = 0;
public void start() public void start()
{ {
try try
{ {
sqlMapClient.startBatch(); sqlMapClient.startBatch();
count = 0; count = 0;
} }
catch (SQLException e) catch (SQLException e)
{ {
// Batches not supported, so don't do batching // Batches not supported, so don't do batching
count = -1; count = -1;
} }
} }
public void processContentUrl(String contentUrl) public void processContentUrl(String contentUrl)
{ {
ContentCleanEntity contentCleanEntity = new ContentCleanEntity(); ContentCleanEntity contentCleanEntity = new ContentCleanEntity();
contentCleanEntity.setContentUrl(contentUrl); contentCleanEntity.setContentUrl(contentUrl == null ? null : contentUrl.toLowerCase());
template.insert(INSERT_CONTENT_CLEAN, contentCleanEntity); template.insert(INSERT_CONTENT_CLEAN, contentCleanEntity);
// Write the batch // Write the batch
executeBatch(); executeBatch();
total++; total++;
} }
public void end() public void end()
{ {
// Write the batch // Write the batch
executeBatch(); executeBatch();
if (logger.isDebugEnabled()) if (logger.isDebugEnabled())
{ {
logger.debug(" Inserted " + total + " content URLs (FINISHED)"); logger.debug(" Inserted " + total + " content URLs (FINISHED)");
} }
} }
private void executeBatch() private void executeBatch()
{ {
// Are we batching? // Are we batching?
if (count > -1) if (count > -1)
{ {
// Write the batch, if required // Write the batch, if required
if (++count >= DEFAULT_BATCH_SIZE) if (++count >= DEFAULT_BATCH_SIZE)
{ {
try try
{ {
sqlMapClient.executeBatch(); sqlMapClient.executeBatch();
sqlMapClient.startBatch(); sqlMapClient.startBatch();
} }
catch (SQLException e) catch (SQLException e)
{ {
throw new AlfrescoRuntimeException("Failed to execute batch", e); throw new AlfrescoRuntimeException("Failed to execute batch", e);
} }
count = 0; count = 0;
} }
} }
if (logger.isDebugEnabled() && (total == 0 || (total % 1000 == 0) )) if (logger.isDebugEnabled() && (total == 0 || (total % 1000 == 0) ))
{ {
logger.debug(" Inserted " + total + " content URLs"); logger.debug(" Inserted " + total + " content URLs");
} }
} }
}; };
// Done // Done
return processor; return processor;
} }
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
public ContentUrlBatchProcessor getUrlRemover() public ContentUrlBatchProcessor getUrlRemover()
{ {
final SqlMapClient sqlMapClient = template.getSqlMapClient(); final SqlMapClient sqlMapClient = template.getSqlMapClient();
ContentUrlBatchProcessor processor = new ContentUrlBatchProcessor() ContentUrlBatchProcessor processor = new ContentUrlBatchProcessor()
{ {
private int count = 0; private int count = 0;
private int total = 0; private int total = 0;
public void start() public void start()
{ {
try try
{ {
sqlMapClient.startBatch(); sqlMapClient.startBatch();
count = 0; count = 0;
} }
catch (SQLException e) catch (SQLException e)
{ {
// Batches not supported, so don't do batching // Batches not supported, so don't do batching
count = -1; count = -1;
} }
} }
public void processContentUrl(String contentUrl) public void processContentUrl(String contentUrl)
{ {
ContentCleanEntity contentCleanEntity = new ContentCleanEntity(); ContentCleanEntity contentCleanEntity = new ContentCleanEntity();
contentCleanEntity.setContentUrl(contentUrl); contentCleanEntity.setContentUrl(contentUrl);
template.delete(DELETE_CONTENT_CLEAN_BY_URL, contentCleanEntity); template.delete(DELETE_CONTENT_CLEAN_BY_URL, contentCleanEntity);
// Write the batch // Write the batch
executeBatch(); executeBatch();
total++; total++;
} }
public void end() public void end()
{ {
// Write the batch // Write the batch
executeBatch(); executeBatch();
if (logger.isDebugEnabled()) if (logger.isDebugEnabled())
{ {
logger.debug(" Removed " + total + " content URLs (FINISHED)"); logger.debug(" Removed " + total + " content URLs (FINISHED)");
} }
} }
private void executeBatch() private void executeBatch()
{ {
// Are we batching? // Are we batching?
if (count > -1) if (count > -1)
{ {
// Write the batch, if required // Write the batch, if required
if (++count >= DEFAULT_BATCH_SIZE) if (++count >= DEFAULT_BATCH_SIZE)
{ {
try try
{ {
sqlMapClient.executeBatch(); sqlMapClient.executeBatch();
sqlMapClient.startBatch(); sqlMapClient.startBatch();
} }
catch (SQLException e) catch (SQLException e)
{ {
throw new AlfrescoRuntimeException("Failed to execute batch", e); throw new AlfrescoRuntimeException("Failed to execute batch", e);
} }
count = 0; count = 0;
} }
} }
if (logger.isDebugEnabled() && (total == 0 || (total % 1000 == 0) )) if (logger.isDebugEnabled() && (total == 0 || (total % 1000 == 0) ))
{ {
logger.debug(" Removed " + total + " content URLs"); logger.debug(" Removed " + total + " content URLs");
} }
} }
}; };
// Done // Done
return processor; return processor;
} }
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
public void listAllUrls(ContentUrlBatchProcessor batchProcessor) public void listAllUrls(ContentUrlBatchProcessor batchProcessor)
{ {
ListAllRowHandler rowHandler = new ListAllRowHandler(batchProcessor); ListAllRowHandler rowHandler = new ListAllRowHandler(batchProcessor);
batchProcessor.start(); batchProcessor.start();
template.queryWithRowHandler(SELECT_CONTENT_CLEAN_URLS, rowHandler); template.queryWithRowHandler(SELECT_CONTENT_CLEAN_URLS, rowHandler);
batchProcessor.end(); batchProcessor.end();
if (logger.isDebugEnabled()) if (logger.isDebugEnabled())
{ {
logger.debug(" Listed " + rowHandler.total + " content URLs"); logger.debug(" Listed " + rowHandler.total + " content URLs");
} }
} }
/** /**
* Row handler for listing all content clean URLs * Row handler for listing all content clean URLs
* @author Derek Hulley * @author Derek Hulley
* @since 3.2 * @since 3.2
*/ */
private static class ListAllRowHandler implements RowHandler private static class ListAllRowHandler implements RowHandler
{ {
private final ContentUrlBatchProcessor batchProcessor; private final ContentUrlBatchProcessor batchProcessor;
private int total = 0; private int total = 0;
private ListAllRowHandler(ContentUrlBatchProcessor batchProcessor) private ListAllRowHandler(ContentUrlBatchProcessor batchProcessor)
{ {
this.batchProcessor = batchProcessor; this.batchProcessor = batchProcessor;
} }
public void handleRow(Object valueObject) public void handleRow(Object valueObject)
{ {
batchProcessor.processContentUrl((String)valueObject); batchProcessor.processContentUrl((String)valueObject);
total++; total++;
if (logger.isDebugEnabled() && (total == 0 || (total % 1000 == 0) )) if (logger.isDebugEnabled() && (total == 0 || (total % 1000 == 0) ))
{ {
logger.debug(" Listed " + total + " content URLs"); logger.debug(" Listed " + total + " content URLs");
} }
} }
} }
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
public void cleanUp() public void cleanUp()
{ {
template.delete(DELETE_CONTENT_CLEAN); template.delete(DELETE_CONTENT_CLEAN);
} }
} }

View File

@@ -1,202 +1,210 @@
/* /*
* Copyright (C) 2005-2009 Alfresco Software Limited. * Copyright (C) 2005-2009 Alfresco Software Limited.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2 * as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version. * of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * 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 * 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 * the GPL, you may redistribute this Program in connection with Free/Libre
* and Open Source Software ("FLOSS") applications as described in Alfresco's * and Open Source Software ("FLOSS") applications as described in Alfresco's
* FLOSS exception. You should have recieved a copy of the text describing * FLOSS exception. You should have recieved a copy of the text describing
* the FLOSS exception, and it is also available here: * the FLOSS exception, and it is also available here:
* http://www.alfresco.com/legal/licensing" * http://www.alfresco.com/legal/licensing"
*/ */
package org.alfresco.repo.domain.contentdata.ibatis; package org.alfresco.repo.domain.contentdata.ibatis;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import org.alfresco.repo.domain.contentdata.AbstractContentDataDAOImpl; import org.alfresco.repo.domain.contentdata.AbstractContentDataDAOImpl;
import org.alfresco.repo.domain.contentdata.ContentDataEntity; import org.alfresco.repo.domain.contentdata.ContentDataEntity;
import org.alfresco.repo.domain.contentdata.ContentUrlEntity; import org.alfresco.repo.domain.contentdata.ContentUrlEntity;
import org.springframework.orm.ibatis.SqlMapClientTemplate; import org.springframework.orm.ibatis.SqlMapClientTemplate;
import com.ibatis.sqlmap.client.event.RowHandler; import com.ibatis.sqlmap.client.event.RowHandler;
/** /**
* iBatis-specific implementation of the ContentData DAO. * iBatis-specific implementation of the ContentData DAO.
* *
* @author Derek Hulley * @author Derek Hulley
* @since 3.2 * @since 3.2
*/ */
public class ContentDataDAOImpl extends AbstractContentDataDAOImpl 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_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 = "alfresco.content.select_ContentUrlByKey";
private static final String SELECT_CONTENT_URL_BY_KEY_UNREFERENCED = "alfresco.content.select_ContentUrlByKeyUnreferenced"; 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_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_ID = "alfresco.content.select_ContentDataById";
private static final String SELECT_CONTENT_DATA_BY_NODE_AND_QNAME = "alfresco.content.select_ContentDataByNodeAndQName"; 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_URL = "alfresco.content.insert_ContentUrl";
private static final String INSERT_CONTENT_DATA = "alfresco.content.insert_ContentData"; 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_DATA = "alfresco.content.delete_ContentData";
private static final String DELETE_CONTENT_URL = "alfresco.content.delete_ContentUrl"; private static final String DELETE_CONTENT_URL = "alfresco.content.delete_ContentUrl";
private SqlMapClientTemplate template; private SqlMapClientTemplate template;
public void setSqlMapClientTemplate(SqlMapClientTemplate sqlMapClientTemplate) public void setSqlMapClientTemplate(SqlMapClientTemplate sqlMapClientTemplate)
{ {
this.template = sqlMapClientTemplate; this.template = sqlMapClientTemplate;
} }
@Override @Override
protected ContentUrlEntity createContentUrlEntity(String contentUrl, long size) protected ContentUrlEntity createContentUrlEntity(String contentUrl, long size)
{ {
ContentUrlEntity contentUrlEntity = new ContentUrlEntity(); ContentUrlEntity contentUrlEntity = new ContentUrlEntity();
contentUrlEntity.setVersion(ContentUrlEntity.CONST_LONG_ZERO); contentUrlEntity.setVersion(ContentUrlEntity.CONST_LONG_ZERO);
contentUrlEntity.setContentUrl(contentUrl); contentUrlEntity.setContentUrl(contentUrl);
contentUrlEntity.setSize(size); contentUrlEntity.setSize(size);
/* Long id = (Long) */ template.insert(INSERT_CONTENT_URL, contentUrlEntity); /* Long id = (Long) */ template.insert(INSERT_CONTENT_URL, contentUrlEntity);
/*contentUrlEntity.setId(id);*/ /*contentUrlEntity.setId(id);*/
// Register the url as new // Register the url as new
registerNewContentUrl(contentUrl); registerNewContentUrl(contentUrl);
// Done // Done
return contentUrlEntity; return contentUrlEntity;
} }
@Override @Override
protected ContentUrlEntity getContentUrlEntity(Long id) protected ContentUrlEntity getContentUrlEntity(Long id)
{ {
ContentUrlEntity contentUrlEntity = new ContentUrlEntity(); ContentUrlEntity contentUrlEntity = new ContentUrlEntity();
contentUrlEntity.setId(id); contentUrlEntity.setId(id);
contentUrlEntity = (ContentUrlEntity) template.queryForObject(SELECT_CONTENT_URL_BY_ID, contentUrlEntity); contentUrlEntity = (ContentUrlEntity) template.queryForObject(SELECT_CONTENT_URL_BY_ID, contentUrlEntity);
// Done // Done
return contentUrlEntity; return contentUrlEntity;
} }
@Override @Override
protected ContentUrlEntity getContentUrlEntity(String contentUrl) protected ContentUrlEntity getContentUrlEntity(String contentUrl)
{ {
ContentUrlEntity contentUrlEntity = new ContentUrlEntity(); ContentUrlEntity contentUrlEntity = new ContentUrlEntity();
contentUrlEntity.setContentUrl(contentUrl); contentUrlEntity.setContentUrl(contentUrl);
contentUrlEntity = (ContentUrlEntity) template.queryForObject(SELECT_CONTENT_URL_BY_KEY, contentUrlEntity); if (contentUrlEntity.getContentUrlShort() != null)
// Done {
return contentUrlEntity; contentUrlEntity.setContentUrlShort(contentUrlEntity.getContentUrlShort().toLowerCase());
} }
contentUrlEntity = (ContentUrlEntity) template.queryForObject(SELECT_CONTENT_URL_BY_KEY, contentUrlEntity);
@Override // Done
protected int deleteContentUrlEntity(Long id) return contentUrlEntity;
{ }
Map<String, Object> params = new HashMap<String, Object>(11);
params.put("id", id); @Override
return template.delete(DELETE_CONTENT_URL, params); protected int deleteContentUrlEntity(Long id)
} {
Map<String, Object> params = new HashMap<String, Object>(11);
@Override params.put("id", id);
protected ContentUrlEntity getContentUrlEntityUnreferenced(String contentUrl) return template.delete(DELETE_CONTENT_URL, params);
{ }
ContentUrlEntity contentUrlEntity = new ContentUrlEntity();
contentUrlEntity.setContentUrl(contentUrl); @Override
contentUrlEntity = (ContentUrlEntity) template.queryForObject(SELECT_CONTENT_URL_BY_KEY_UNREFERENCED, contentUrlEntity); protected ContentUrlEntity getContentUrlEntityUnreferenced(String contentUrl)
// Done {
return contentUrlEntity; ContentUrlEntity contentUrlEntity = new ContentUrlEntity();
} contentUrlEntity.setContentUrl(contentUrl);
if (contentUrlEntity.getContentUrlShort() != null)
@Override {
protected ContentDataEntity createContentDataEntity( contentUrlEntity.setContentUrlShort(contentUrlEntity.getContentUrlShort().toLowerCase());
Long contentUrlId, }
Long mimetypeId, contentUrlEntity = (ContentUrlEntity) template.queryForObject(SELECT_CONTENT_URL_BY_KEY_UNREFERENCED, contentUrlEntity);
Long encodingId, // Done
Long localeId) return contentUrlEntity;
{ }
ContentDataEntity contentDataEntity = new ContentDataEntity();
contentDataEntity.setVersion(ContentDataEntity.CONST_LONG_ZERO); @Override
contentDataEntity.setContentUrlId(contentUrlId); protected ContentDataEntity createContentDataEntity(
contentDataEntity.setMimetypeId(mimetypeId); Long contentUrlId,
contentDataEntity.setEncodingId(encodingId); Long mimetypeId,
contentDataEntity.setLocaleId(localeId); Long encodingId,
template.insert(INSERT_CONTENT_DATA, contentDataEntity); Long localeId)
// Done {
return contentDataEntity; ContentDataEntity contentDataEntity = new ContentDataEntity();
} contentDataEntity.setVersion(ContentDataEntity.CONST_LONG_ZERO);
contentDataEntity.setContentUrlId(contentUrlId);
@Override contentDataEntity.setMimetypeId(mimetypeId);
protected ContentDataEntity getContentDataEntity(Long id) contentDataEntity.setEncodingId(encodingId);
{ contentDataEntity.setLocaleId(localeId);
Map<String, Object> params = new HashMap<String, Object>(11); template.insert(INSERT_CONTENT_DATA, contentDataEntity);
params.put("id", id); // Done
ContentDataEntity contentDataEntity = (ContentDataEntity) template.queryForObject(SELECT_CONTENT_DATA_BY_ID, params); return contentDataEntity;
// Done }
return contentDataEntity;
} @Override
protected ContentDataEntity getContentDataEntity(Long id)
@Override {
protected int deleteContentDataEntity(Long id) Map<String, Object> params = new HashMap<String, Object>(11);
{ params.put("id", id);
Map<String, Object> params = new HashMap<String, Object>(11); ContentDataEntity contentDataEntity = (ContentDataEntity) template.queryForObject(SELECT_CONTENT_DATA_BY_ID, params);
params.put("id", id); // Done
return template.delete(DELETE_CONTENT_DATA, params); return contentDataEntity;
} }
public void deleteContentDataForNode(Long nodeId, Set<Long> qnameIds) @Override
{ protected int deleteContentDataEntity(Long id)
/* {
* TODO: use IN clause in parameters Map<String, Object> params = new HashMap<String, Object>(11);
*/ params.put("id", id);
for (Long qnameId : qnameIds) return template.delete(DELETE_CONTENT_DATA, params);
{ }
// Get the ContentData that matches (may be multiple due to collection properties)
Map<String, Object> params = new HashMap<String, Object>(11); public void deleteContentDataForNode(Long nodeId, Set<Long> qnameIds)
params.put("nodeId", nodeId); {
params.put("qnameId", qnameId); /*
@SuppressWarnings("unchecked") * TODO: use IN clause in parameters
List<Long> ids = (List<Long>) template.queryForList(SELECT_CONTENT_DATA_BY_NODE_AND_QNAME, params); */
// Delete each one for (Long qnameId : qnameIds)
for (Long id : ids) {
{ // Get the ContentData that matches (may be multiple due to collection properties)
// Get the content urls Map<String, Object> params = new HashMap<String, Object>(11);
ContentDataEntity contentDataEntity = getContentDataEntity(id); params.put("nodeId", nodeId);
// This might be null as there is no constraint ensuring that the node points to a valid ContentData entity params.put("qnameId", qnameId);
if (contentDataEntity == null) @SuppressWarnings("unchecked")
{ List<Long> ids = (List<Long>) template.queryForList(SELECT_CONTENT_DATA_BY_NODE_AND_QNAME, params);
continue; // Delete each one
} for (Long id : ids)
// Only check the content URLs if one is present {
String contentUrl = contentDataEntity.getContentUrl(); // Get the content urls
// Delete the ContentData entity ContentDataEntity contentDataEntity = getContentDataEntity(id);
deleteContentData(id); // This might be null as there is no constraint ensuring that the node points to a valid ContentData entity
// Check if the content URL was orphaned if (contentDataEntity == null)
if (contentUrl != null) {
{ continue;
// It has been dereferenced and may be orphaned - we'll check later }
registerDereferenceContentUrl(contentUrl); // 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)
public void getAllContentUrls(final ContentUrlHandler contentUrlHandler) {
{ // It has been dereferenced and may be orphaned - we'll check later
RowHandler rowHandler = new RowHandler() registerDereferenceContentUrl(contentUrl);
{ }
public void handleRow(Object valueObject) }
{ }
contentUrlHandler.handle((String)valueObject); }
}
}; public void getAllContentUrls(final ContentUrlHandler contentUrlHandler)
template.queryWithRowHandler(SELECT_CONTENT_URLS, rowHandler); {
} 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. * Copyright (C) 2005-2009 Alfresco Software Limited.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2 * as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version. * of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * 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 * 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 * the GPL, you may redistribute this Program in connection with Free/Libre
* and Open Source Software ("FLOSS") applications as described in Alfresco's * and Open Source Software ("FLOSS") applications as described in Alfresco's
* FLOSS exception. You should have recieved a copy of the text describing * FLOSS exception. You should have recieved a copy of the text describing
* the FLOSS exception, and it is also available here: * the FLOSS exception, and it is also available here:
* http://www.alfresco.com/legal/licensing" * http://www.alfresco.com/legal/licensing"
*/ */
package org.alfresco.repo.domain.encoding.ibatis; package org.alfresco.repo.domain.encoding.ibatis;
import org.alfresco.repo.domain.encoding.AbstractEncodingDAOImpl; import org.alfresco.repo.domain.encoding.AbstractEncodingDAOImpl;
import org.alfresco.repo.domain.encoding.EncodingEntity; import org.alfresco.repo.domain.encoding.EncodingEntity;
import org.alfresco.repo.domain.mimetype.MimetypeEntity; import org.alfresco.repo.domain.mimetype.MimetypeEntity;
import org.springframework.orm.ibatis.SqlMapClientTemplate; import org.springframework.orm.ibatis.SqlMapClientTemplate;
/** /**
* iBatis-specific implementation of the Mimetype DAO. * iBatis-specific implementation of the Mimetype DAO.
* *
* @author Derek Hulley * @author Derek Hulley
* @since 3.2 * @since 3.2
*/ */
public class EncodingDAOImpl extends AbstractEncodingDAOImpl public class EncodingDAOImpl extends AbstractEncodingDAOImpl
{ {
private static final String SELECT_ENCODING_BY_ID = "alfresco.content.select_EncodingById"; 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 SELECT_ENCODING_BY_KEY = "alfresco.content.select_EncodingByKey";
private static final String INSERT_ENCODING = "alfresco.content.insert_Encoding"; private static final String INSERT_ENCODING = "alfresco.content.insert_Encoding";
private SqlMapClientTemplate template; private SqlMapClientTemplate template;
public void setSqlMapClientTemplate(SqlMapClientTemplate sqlMapClientTemplate) public void setSqlMapClientTemplate(SqlMapClientTemplate sqlMapClientTemplate)
{ {
this.template = sqlMapClientTemplate; this.template = sqlMapClientTemplate;
} }
@Override @Override
protected EncodingEntity getEncodingEntity(Long id) protected EncodingEntity getEncodingEntity(Long id)
{ {
EncodingEntity encodingEntity = new EncodingEntity(); EncodingEntity encodingEntity = new EncodingEntity();
encodingEntity.setId(id); encodingEntity.setId(id);
encodingEntity = (EncodingEntity) template.queryForObject(SELECT_ENCODING_BY_ID, encodingEntity); encodingEntity = (EncodingEntity) template.queryForObject(SELECT_ENCODING_BY_ID, encodingEntity);
// Done // Done
return encodingEntity; return encodingEntity;
} }
@Override @Override
protected EncodingEntity getEncodingEntity(String encoding) protected EncodingEntity getEncodingEntity(String encoding)
{ {
EncodingEntity encodingEntity = new EncodingEntity(); EncodingEntity encodingEntity = new EncodingEntity();
encodingEntity.setEncoding(encoding); encodingEntity.setEncoding(encoding == null ? null : encoding.toLowerCase());
encodingEntity = (EncodingEntity) template.queryForObject(SELECT_ENCODING_BY_KEY, encodingEntity); encodingEntity = (EncodingEntity) template.queryForObject(SELECT_ENCODING_BY_KEY, encodingEntity);
// Could be null // Could be null
return encodingEntity; return encodingEntity;
} }
@Override @Override
protected EncodingEntity createEncodingEntity(String encoding) protected EncodingEntity createEncodingEntity(String encoding)
{ {
EncodingEntity encodingEntity = new EncodingEntity(); EncodingEntity encodingEntity = new EncodingEntity();
encodingEntity.setVersion(MimetypeEntity.CONST_LONG_ZERO); encodingEntity.setVersion(MimetypeEntity.CONST_LONG_ZERO);
encodingEntity.setEncoding(encoding); encodingEntity.setEncoding(encoding == null ? null : encoding.toLowerCase());
Long id = (Long) template.insert(INSERT_ENCODING, encodingEntity); Long id = (Long) template.insert(INSERT_ENCODING, encodingEntity);
encodingEntity.setId(id); encodingEntity.setId(id);
// Done // Done
return encodingEntity; return encodingEntity;
} }
} }

View File

@@ -1,174 +1,174 @@
/* /*
* Copyright (C) 2005-2009 Alfresco Software Limited. * Copyright (C) 2005-2009 Alfresco Software Limited.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2 * as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version. * of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * 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 * 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 * the GPL, you may redistribute this Program in connection with Free/Libre
* and Open Source Software ("FLOSS") applications as described in Alfresco's * and Open Source Software ("FLOSS") applications as described in Alfresco's
* FLOSS exception. You should have recieved a copy of the text describing * FLOSS exception. You should have recieved a copy of the text describing
* the FLOSS exception, and it is also available here: * the FLOSS exception, and it is also available here:
* http://www.alfresco.com/legal/licensing" * http://www.alfresco.com/legal/licensing"
*/ */
package org.alfresco.repo.domain.locks.ibatis; package org.alfresco.repo.domain.locks.ibatis;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import org.alfresco.repo.domain.locks.AbstractLockDAOImpl; import org.alfresco.repo.domain.locks.AbstractLockDAOImpl;
import org.alfresco.repo.domain.locks.LockEntity; import org.alfresco.repo.domain.locks.LockEntity;
import org.alfresco.repo.domain.locks.LockResourceEntity; import org.alfresco.repo.domain.locks.LockResourceEntity;
import org.springframework.orm.ibatis.SqlMapClientTemplate; import org.springframework.orm.ibatis.SqlMapClientTemplate;
/** /**
* iBatis-specific implementation of the Locks DAO. * iBatis-specific implementation of the Locks DAO.
* *
* @author Derek Hulley * @author Derek Hulley
* @since 3.2 * @since 3.2
*/ */
public class LockDAOImpl extends AbstractLockDAOImpl public class LockDAOImpl extends AbstractLockDAOImpl
{ {
private static final String SELECT_LOCKRESOURCE_BY_QNAME = "alfresco.lock.select_LockResourceByQName"; 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_ID = "alfresco.lock.select_LockByID";
private static final String SELECT_LOCK_BY_KEY = "alfresco.lock.select_LockByKey"; 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 SELECT_LOCK_BY_SHARED_IDS = "alfresco.lock.select_LockBySharedIds";
private static final String INSERT_LOCKRESOURCE = "alfresco.lock.insert_LockResource"; private static final String INSERT_LOCKRESOURCE = "alfresco.lock.insert_LockResource";
private static final String INSERT_LOCK = "alfresco.lock.insert_Lock"; 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_LOCK = "alfresco.lock.update_Lock";
private static final String UPDATE_EXCLUSIVE_LOCK = "alfresco.lock.update_ExclusiveLock"; private static final String UPDATE_EXCLUSIVE_LOCK = "alfresco.lock.update_ExclusiveLock";
private SqlMapClientTemplate template; private SqlMapClientTemplate template;
public void setSqlMapClientTemplate(SqlMapClientTemplate sqlMapClientTemplate) public void setSqlMapClientTemplate(SqlMapClientTemplate sqlMapClientTemplate)
{ {
this.template = sqlMapClientTemplate; this.template = sqlMapClientTemplate;
} }
@Override @Override
protected LockResourceEntity getLockResource(Long qnameNamespaceId, String qnameLocalName) protected LockResourceEntity getLockResource(Long qnameNamespaceId, String qnameLocalName)
{ {
LockResourceEntity lockResource = new LockResourceEntity(); LockResourceEntity lockResource = new LockResourceEntity();
lockResource.setQnameNamespaceId(qnameNamespaceId); lockResource.setQnameNamespaceId(qnameNamespaceId);
lockResource.setQnameLocalName(qnameLocalName); lockResource.setQnameLocalName(qnameLocalName == null ? null : qnameLocalName.toLowerCase());
lockResource = (LockResourceEntity) template.queryForObject(SELECT_LOCKRESOURCE_BY_QNAME, lockResource); lockResource = (LockResourceEntity) template.queryForObject(SELECT_LOCKRESOURCE_BY_QNAME, lockResource);
// Could be null // Could be null
return lockResource; return lockResource;
} }
@Override @Override
protected LockResourceEntity createLockResource(Long qnameNamespaceId, String qnameLocalName) protected LockResourceEntity createLockResource(Long qnameNamespaceId, String qnameLocalName)
{ {
LockResourceEntity lockResource = new LockResourceEntity(); LockResourceEntity lockResource = new LockResourceEntity();
lockResource.setVersion(LockEntity.CONST_LONG_ZERO); lockResource.setVersion(LockEntity.CONST_LONG_ZERO);
lockResource.setQnameNamespaceId(qnameNamespaceId); lockResource.setQnameNamespaceId(qnameNamespaceId);
lockResource.setQnameLocalName(qnameLocalName); lockResource.setQnameLocalName(qnameLocalName == null ? null : qnameLocalName.toLowerCase());
Long id = (Long) template.insert(INSERT_LOCKRESOURCE, lockResource); Long id = (Long) template.insert(INSERT_LOCKRESOURCE, lockResource);
lockResource.setId(id); lockResource.setId(id);
// Done // Done
return lockResource; return lockResource;
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Override @Override
protected List<LockEntity> getLocksBySharedResourceIds(List<Long> sharedLockResourceIds) protected List<LockEntity> getLocksBySharedResourceIds(List<Long> sharedLockResourceIds)
{ {
List<LockEntity> locks = template.queryForList(SELECT_LOCK_BY_SHARED_IDS, sharedLockResourceIds); List<LockEntity> locks = template.queryForList(SELECT_LOCK_BY_SHARED_IDS, sharedLockResourceIds);
// Done // Done
return locks; return locks;
} }
@Override @Override
protected LockEntity getLock(Long id) protected LockEntity getLock(Long id)
{ {
LockEntity lock = new LockEntity(); LockEntity lock = new LockEntity();
lock.setId(id); lock.setId(id);
lock = (LockEntity) template.queryForObject(SELECT_LOCK_BY_ID, lock); lock = (LockEntity) template.queryForObject(SELECT_LOCK_BY_ID, lock);
// Done // Done
return lock; return lock;
} }
@Override @Override
protected LockEntity getLock(Long sharedResourceId, Long exclusiveResourceId) protected LockEntity getLock(Long sharedResourceId, Long exclusiveResourceId)
{ {
LockEntity lock = new LockEntity(); LockEntity lock = new LockEntity();
lock.setSharedResourceId(sharedResourceId); lock.setSharedResourceId(sharedResourceId);
lock.setExclusiveResourceId(exclusiveResourceId); lock.setExclusiveResourceId(exclusiveResourceId);
lock = (LockEntity) template.queryForObject(SELECT_LOCK_BY_KEY, lock); lock = (LockEntity) template.queryForObject(SELECT_LOCK_BY_KEY, lock);
// Done // Done
return lock; return lock;
} }
@Override @Override
protected LockEntity createLock( protected LockEntity createLock(
Long sharedResourceId, Long sharedResourceId,
Long exclusiveResourceId, Long exclusiveResourceId,
String lockToken, String lockToken,
long timeToLive) long timeToLive)
{ {
LockEntity lock = new LockEntity(); LockEntity lock = new LockEntity();
lock.setVersion(LockEntity.CONST_LONG_ZERO); lock.setVersion(LockEntity.CONST_LONG_ZERO);
lock.setSharedResourceId(sharedResourceId); lock.setSharedResourceId(sharedResourceId);
lock.setExclusiveResourceId(exclusiveResourceId); lock.setExclusiveResourceId(exclusiveResourceId);
lock.setLockToken(lockToken); lock.setLockToken(lockToken == null ? null : lockToken.toLowerCase());
long now = System.currentTimeMillis(); long now = System.currentTimeMillis();
long exp = now + timeToLive; long exp = now + timeToLive;
lock.setStartTime(now); lock.setStartTime(now);
lock.setExpiryTime(exp); lock.setExpiryTime(exp);
Long id = (Long) template.insert(INSERT_LOCK, lock); Long id = (Long) template.insert(INSERT_LOCK, lock);
lock.setId(id); lock.setId(id);
// Done // Done
return lock; return lock;
} }
@Override @Override
protected LockEntity updateLock(LockEntity lockEntity, String lockToken, long timeToLive) protected LockEntity updateLock(LockEntity lockEntity, String lockToken, long timeToLive)
{ {
LockEntity updateLockEntity = new LockEntity(); LockEntity updateLockEntity = new LockEntity();
updateLockEntity.setId(lockEntity.getId()); updateLockEntity.setId(lockEntity.getId());
updateLockEntity.setVersion(lockEntity.getVersion()); updateLockEntity.setVersion(lockEntity.getVersion());
updateLockEntity.incrementVersion(); // Increment the version number updateLockEntity.incrementVersion(); // Increment the version number
updateLockEntity.setSharedResourceId(lockEntity.getSharedResourceId()); updateLockEntity.setSharedResourceId(lockEntity.getSharedResourceId());
updateLockEntity.setExclusiveResourceId(lockEntity.getExclusiveResourceId()); updateLockEntity.setExclusiveResourceId(lockEntity.getExclusiveResourceId());
updateLockEntity.setLockToken(lockToken); updateLockEntity.setLockToken(lockToken == null ? null : lockToken.toLowerCase());
long now = (timeToLive > 0) ? System.currentTimeMillis() : 0L; long now = (timeToLive > 0) ? System.currentTimeMillis() : 0L;
long exp = (timeToLive > 0) ? (now + timeToLive) : 0L; long exp = (timeToLive > 0) ? (now + timeToLive) : 0L;
updateLockEntity.setStartTime(new Long(now)); updateLockEntity.setStartTime(new Long(now));
updateLockEntity.setExpiryTime(new Long(exp)); updateLockEntity.setExpiryTime(new Long(exp));
template.update(UPDATE_LOCK, updateLockEntity, 1); template.update(UPDATE_LOCK, updateLockEntity, 1);
// Done // Done
return updateLockEntity; return updateLockEntity;
} }
@Override @Override
protected int updateLocks( protected int updateLocks(
Long exclusiveLockResourceId, Long exclusiveLockResourceId,
String oldLockToken, String oldLockToken,
String newLockToken, String newLockToken,
long timeToLive) long timeToLive)
{ {
Map<String, Object> params = new HashMap<String, Object>(11); Map<String, Object> params = new HashMap<String, Object>(11);
params.put("exclusiveLockResourceId", exclusiveLockResourceId); params.put("exclusiveLockResourceId", exclusiveLockResourceId);
params.put("oldLockToken", oldLockToken); params.put("oldLockToken", oldLockToken);
params.put("newLockToken", newLockToken); params.put("newLockToken", newLockToken == null ? null : newLockToken.toLowerCase());
long now = (timeToLive > 0) ? System.currentTimeMillis() : 0L; long now = (timeToLive > 0) ? System.currentTimeMillis() : 0L;
long exp = (timeToLive > 0) ? (now + timeToLive) : 0L; long exp = (timeToLive > 0) ? (now + timeToLive) : 0L;
params.put("newStartTime", new Long(now)); params.put("newStartTime", new Long(now));
params.put("newExpiryTime", new Long(exp)); params.put("newExpiryTime", new Long(exp));
int updateCount = template.update(UPDATE_EXCLUSIVE_LOCK, params); int updateCount = template.update(UPDATE_EXCLUSIVE_LOCK, params);
// Done // Done
return updateCount; return updateCount;
} }
} }

View File

@@ -1,81 +1,81 @@
/* /*
* Copyright (C) 2005-2009 Alfresco Software Limited. * Copyright (C) 2005-2009 Alfresco Software Limited.
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License * modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2 * as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version. * of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software * along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * 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 * 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 * the GPL, you may redistribute this Program in connection with Free/Libre
* and Open Source Software ("FLOSS") applications as described in Alfresco's * and Open Source Software ("FLOSS") applications as described in Alfresco's
* FLOSS exception. You should have recieved a copy of the text describing * FLOSS exception. You should have recieved a copy of the text describing
* the FLOSS exception, and it is also available here: * the FLOSS exception, and it is also available here:
* http://www.alfresco.com/legal/licensing" * http://www.alfresco.com/legal/licensing"
*/ */
package org.alfresco.repo.domain.mimetype.ibatis; package org.alfresco.repo.domain.mimetype.ibatis;
import org.alfresco.repo.domain.mimetype.AbstractMimetypeDAOImpl; import org.alfresco.repo.domain.mimetype.AbstractMimetypeDAOImpl;
import org.alfresco.repo.domain.mimetype.MimetypeEntity; import org.alfresco.repo.domain.mimetype.MimetypeEntity;
import org.springframework.orm.ibatis.SqlMapClientTemplate; import org.springframework.orm.ibatis.SqlMapClientTemplate;
/** /**
* iBatis-specific implementation of the Mimetype DAO. * iBatis-specific implementation of the Mimetype DAO.
* *
* @author Derek Hulley * @author Derek Hulley
* @since 3.2 * @since 3.2
*/ */
public class MimetypeDAOImpl extends AbstractMimetypeDAOImpl public class MimetypeDAOImpl extends AbstractMimetypeDAOImpl
{ {
private static final String SELECT_MIMETYPE_BY_ID = "alfresco.content.select_MimetypeById"; 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 SELECT_MIMETYPE_BY_KEY = "alfresco.content.select_MimetypeByKey";
private static final String INSERT_MIMETYPE = "alfresco.content.insert_Mimetype"; private static final String INSERT_MIMETYPE = "alfresco.content.insert_Mimetype";
private SqlMapClientTemplate template; private SqlMapClientTemplate template;
public void setSqlMapClientTemplate(SqlMapClientTemplate sqlMapClientTemplate) public void setSqlMapClientTemplate(SqlMapClientTemplate sqlMapClientTemplate)
{ {
this.template = sqlMapClientTemplate; this.template = sqlMapClientTemplate;
} }
@Override @Override
protected MimetypeEntity getMimetypeEntity(Long id) protected MimetypeEntity getMimetypeEntity(Long id)
{ {
MimetypeEntity mimetypeEntity = new MimetypeEntity(); MimetypeEntity mimetypeEntity = new MimetypeEntity();
mimetypeEntity.setId(id); mimetypeEntity.setId(id);
mimetypeEntity = (MimetypeEntity) template.queryForObject(SELECT_MIMETYPE_BY_ID, mimetypeEntity); mimetypeEntity = (MimetypeEntity) template.queryForObject(SELECT_MIMETYPE_BY_ID, mimetypeEntity);
// Done // Done
return mimetypeEntity; return mimetypeEntity;
} }
@Override @Override
protected MimetypeEntity getMimetypeEntity(String mimetype) protected MimetypeEntity getMimetypeEntity(String mimetype)
{ {
MimetypeEntity mimetypeEntity = new MimetypeEntity(); MimetypeEntity mimetypeEntity = new MimetypeEntity();
mimetypeEntity.setMimetype(mimetype); mimetypeEntity.setMimetype(mimetype == null ? null : mimetype.toLowerCase());
mimetypeEntity = (MimetypeEntity) template.queryForObject(SELECT_MIMETYPE_BY_KEY, mimetypeEntity); mimetypeEntity = (MimetypeEntity) template.queryForObject(SELECT_MIMETYPE_BY_KEY, mimetypeEntity);
// Could be null // Could be null
return mimetypeEntity; return mimetypeEntity;
} }
@Override @Override
protected MimetypeEntity createMimetypeEntity(String mimetype) protected MimetypeEntity createMimetypeEntity(String mimetype)
{ {
MimetypeEntity mimetypeEntity = new MimetypeEntity(); MimetypeEntity mimetypeEntity = new MimetypeEntity();
mimetypeEntity.setVersion(MimetypeEntity.CONST_LONG_ZERO); mimetypeEntity.setVersion(MimetypeEntity.CONST_LONG_ZERO);
mimetypeEntity.setMimetype(mimetype); mimetypeEntity.setMimetype(mimetype == null ? null : mimetype.toLowerCase());
Long id = (Long) template.insert(INSERT_MIMETYPE, mimetypeEntity); Long id = (Long) template.insert(INSERT_MIMETYPE, mimetypeEntity);
mimetypeEntity.setId(id); mimetypeEntity.setId(id);
// Done // Done
return mimetypeEntity; return mimetypeEntity;
} }
} }