MOB-448: Better patch for JDBC3 generated keys

- Fixes bug with different column types not matching generated key target type
 - Submitted to  https://issues.apache.org/jira/browse/IBATIS-142
 - MySQL and SQLServer use generated keys
 - Other tidy ups

git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@13732 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
Derek Hulley
2009-03-24 06:21:00 +00:00
parent cc6116e682
commit 33902c69e2
11 changed files with 16 additions and 63 deletions

View File

@@ -37,7 +37,7 @@
</property> </property>
</bean> </bean>
<bean id="activitiesSqlMapClient" class="org.alfresco.repo.domain.ibatis.AlfrescoSqlMapClientFactoryBean" singleton="true"> <bean id="activitiesSqlMapClient" class="org.alfresco.ibatis.HierarchicalSqlMapClientFactoryBean" singleton="true">
<property name="dataSource" ref="iBatisDataSource"/> <property name="dataSource" ref="iBatisDataSource"/>
<property name="resourceLoader" ref="dialectResourceLoader" /> <property name="resourceLoader" ref="dialectResourceLoader" />
<property name="configLocation"> <property name="configLocation">

View File

@@ -9,7 +9,7 @@
<typeAlias alias="ActivityFeed" type="org.alfresco.repo.activities.feed.ActivityFeedDAO"/> <typeAlias alias="ActivityFeed" type="org.alfresco.repo.activities.feed.ActivityFeedDAO"/>
<resultMap id="ActivityFeedResult" class="ActivityFeed"> <resultMap id="ActivityFeedResult" class="ActivityFeed">
<result property="id" column="id"/> <result property="id" column="id" jdbcType="BIGINT" javaType="java.lang.Long"/>
<result property="feedUserId" column="feed_user_id"/> <result property="feedUserId" column="feed_user_id"/>
<result property="postUserId" column="post_user_id"/> <result property="postUserId" column="post_user_id"/>
<result property="postDate" column="post_date"/> <result property="postDate" column="post_date"/>

View File

@@ -9,7 +9,7 @@
<typeAlias alias="FeedControl" type="org.alfresco.repo.activities.feed.control.FeedControlDAO"/> <typeAlias alias="FeedControl" type="org.alfresco.repo.activities.feed.control.FeedControlDAO"/>
<resultMap id="FeedControlResult" class="FeedControl"> <resultMap id="FeedControlResult" class="FeedControl">
<result property="id" column="id"/> <result property="id" column="id" jdbcType="BIGINT" javaType="java.lang.Long"/>
<result property="feedUserId" column="feed_user_id"/> <result property="feedUserId" column="feed_user_id"/>
<result property="siteNetwork" column="site_network"/> <result property="siteNetwork" column="site_network"/>
<result property="appTool" column="app_tool"/> <result property="appTool" column="app_tool"/>

View File

@@ -9,7 +9,7 @@
<typeAlias alias="ActivityPost" type="org.alfresco.repo.activities.post.ActivityPostDAO"/> <typeAlias alias="ActivityPost" type="org.alfresco.repo.activities.post.ActivityPostDAO"/>
<resultMap id="ActivityPostResult" class="ActivityPost"> <resultMap id="ActivityPostResult" class="ActivityPost">
<result property="id" column="sequence_id"/> <result property="id" column="sequence_id" jdbcType="BIGINT" javaType="java.lang.Long"/>
<result property="activityData" column="activity_data"/> <result property="activityData" column="activity_data"/>
<result property="activityType" column="activity_type"/> <result property="activityType" column="activity_type"/>
<result property="userId" column="post_user_id"/> <result property="userId" column="post_user_id"/>

View File

@@ -12,7 +12,7 @@
values (#activityType#, #activitySummary#, #activitySummaryFormat#, #feedUserId#, #postUserId#, #postDate#, #postId#, #siteNetwork#, #appTool#, #feedDate#) values (#activityType#, #activitySummary#, #activitySummaryFormat#, #feedUserId#, #postUserId#, #postDate#, #postId#, #siteNetwork#, #appTool#, #feedDate#)
<selectKey resultClass="long" keyProperty="id" type="post"> <selectKey resultClass="long" keyProperty="id" type="post">
KEY_COLUMN:id KEY_COLUMN:GENERATED_KEY
</selectKey> </selectKey>
</insert> </insert>

View File

@@ -12,7 +12,7 @@
values (#feedUserId#, #siteNetwork#, #appTool#, #lastModified#) values (#feedUserId#, #siteNetwork#, #appTool#, #lastModified#)
<selectKey resultClass="long" keyProperty="id" type="post"> <selectKey resultClass="long" keyProperty="id" type="post">
KEY_COLUMN:id KEY_COLUMN:GENERATED_KEY
</selectKey> </selectKey>
</insert> </insert>

View File

@@ -12,7 +12,7 @@
values (#status#, #activityData#, #userId#, #postDate#, #activityType#, #siteNetwork#, #appTool#, #jobTaskNode#, #lastModified#) values (#status#, #activityData#, #userId#, #postDate#, #activityType#, #siteNetwork#, #appTool#, #jobTaskNode#, #lastModified#)
<selectKey resultClass="long" keyProperty="id" type="post"> <selectKey resultClass="long" keyProperty="id" type="post">
KEY_COLUMN:sequence_id KEY_COLUMN:GENERATED_KEY
</selectKey> </selectKey>
</insert> </insert>

View File

@@ -35,7 +35,7 @@ import org.json.JSONObject;
*/ */
public class ActivityFeedDAO public class ActivityFeedDAO
{ {
private long id; // internal DB-generated id private Long id; // internal DB-generated id
private String activityType; private String activityType;
private String activitySummary; private String activitySummary;
private String activitySummaryFormat; private String activitySummaryFormat;
@@ -48,12 +48,12 @@ public class ActivityFeedDAO
private long postId; // for debug - not an explicit FK constraint, could be used to implement re-generate private long postId; // for debug - not an explicit FK constraint, could be used to implement re-generate
public long getId() public Long getId()
{ {
return id; return id;
} }
public void setId(long id) public void setId(Long id)
{ {
this.id = id; this.id = id;
} }

View File

@@ -33,7 +33,7 @@ import org.alfresco.service.cmr.activities.FeedControl;
*/ */
public class FeedControlDAO public class FeedControlDAO
{ {
private long id; // internal DB-generated id private Long id; // internal DB-generated id
private String feedUserId; private String feedUserId;
private String siteNetwork; private String siteNetwork;
private String appTool; private String appTool;
@@ -66,12 +66,12 @@ public class FeedControlDAO
return new FeedControl(this.siteNetwork, this.appTool); return new FeedControl(this.siteNetwork, this.appTool);
} }
public long getId() public Long getId()
{ {
return id; return id;
} }
public void setId(long id) public void setId(Long id)
{ {
this.id = id; this.id = id;
} }

View File

@@ -33,7 +33,7 @@ public class ActivityPostDAO
{ {
public enum STATUS { POSTED, PENDING, PROCESSED, ERROR }; public enum STATUS { POSTED, PENDING, PROCESSED, ERROR };
private long id; // internal DB-generated sequence id private Long id; // internal DB-generated sequence id
private String activityData; private String activityData;
private String activityType; private String activityType;
private String userId; private String userId;
@@ -48,11 +48,11 @@ public class ActivityPostDAO
private long minId = -1; private long minId = -1;
private long maxId = -1; private long maxId = -1;
public long getId() public Long getId()
{ {
return id; return id;
} }
public void setId(long id) public void setId(Long id)
{ {
this.id = id; this.id = id;
} }

View File

@@ -1,47 +0,0 @@
package org.alfresco.repo.domain.ibatis;
import java.io.IOException;
import java.util.Properties;
import org.alfresco.ibatis.HierarchicalSqlMapClientFactoryBean;
import org.hibernate.cfg.Environment;
import org.springframework.core.io.Resource;
import com.ibatis.sqlmap.client.SqlMapClient;
/**
* Extension to the SQLMap factory to produce <tt>SqlMapClient</tt> instances that
* cater for Alfresco extensions.
* <p>
* Currently, this is just a hack to find the Hibernate dialect and provide that as
* a property to the factory code. This will go away if we move over to iBatis; to be
* replaced with something similar to the schema script loading that uses a hierarchy
* of databases.
*
* @author Derek Hulley
* @since 3.1
*/
public class AlfrescoSqlMapClientFactoryBean extends HierarchicalSqlMapClientFactoryBean
{
@Override
protected SqlMapClient buildSqlMapClient(Resource configLocation, Properties properties) throws IOException
{
// Get the Hibernate dialect from the system properties
String hibernateDialect = System.getProperty(Environment.DIALECT);
if (hibernateDialect == null)
{
return super.buildSqlMapClient(configLocation, properties);
}
else
{
if (properties == null)
{
properties = new Properties();
}
properties.put("hibernate.dialect", hibernateDialect);
return super.buildSqlMapClient(configLocation, properties);
}
}
}