http://jira.springframework.org/browse/SPRNET-1017 - Locally managed transactions were not propagated when performing dataset operations in AdoTemplate.
This commit is contained in:
@@ -329,8 +329,8 @@ namespace Spring.Data.Core
|
||||
IDbDataAdapter dataAdapter = null;
|
||||
try
|
||||
{
|
||||
dataAdapter = DbProvider.CreateDataAdapter();
|
||||
//TODO row updated event handling...
|
||||
dataAdapter = DbProvider.CreateDataAdapter();
|
||||
//TODO row updated event handling... (SPRNET-1014)
|
||||
dataAdapter.SelectCommand = DbProvider.CreateCommand();
|
||||
dataAdapter.SelectCommand.Connection = connectionTxPairToUse.Connection;
|
||||
//TODO register for warnings on connection.
|
||||
@@ -1150,7 +1150,8 @@ namespace Spring.Data.Core
|
||||
#endregion
|
||||
|
||||
ITableMappingCollection mappingCollection = DoCreateMappingCollection(null);
|
||||
return (int)Execute(new DataAdapterFillCallback(dataTable,
|
||||
return (int)Execute(new DataAdapterFillCallback(dbProvider,
|
||||
dataTable,
|
||||
commandType, sql,
|
||||
mappingCollection, null, null, null));
|
||||
}
|
||||
@@ -1172,7 +1173,8 @@ namespace Spring.Data.Core
|
||||
tableMappingName = "Table";
|
||||
}
|
||||
ITableMappingCollection mappingCollection = DoCreateMappingCollection(new string[] { tableMappingName });
|
||||
return (int)Execute(new DataAdapterFillCallback(dataTable,
|
||||
return (int)Execute(new DataAdapterFillCallback(dbProvider,
|
||||
dataTable,
|
||||
commandType, sql,
|
||||
mappingCollection, null, null, null));
|
||||
|
||||
@@ -1183,9 +1185,10 @@ namespace Spring.Data.Core
|
||||
{
|
||||
ValidateFillArguments(dataTable, sql, tableMapping);
|
||||
ITableMappingCollection mappingCollection = new DataTableMappingCollection();
|
||||
mappingCollection.Add((object)tableMapping);
|
||||
mappingCollection.Add(tableMapping);
|
||||
|
||||
return (int)Execute(new DataAdapterFillCallback(dataTable,
|
||||
return (int)Execute(new DataAdapterFillCallback(dbProvider,
|
||||
dataTable,
|
||||
commandType, sql,
|
||||
mappingCollection, null, null, null));
|
||||
}
|
||||
@@ -1197,7 +1200,8 @@ namespace Spring.Data.Core
|
||||
ValidateFillArguments(dataTable, sql, tableMapping);
|
||||
ITableMappingCollection mappingCollection = new DataTableMappingCollection();
|
||||
mappingCollection.Add((object)tableMapping);
|
||||
return (int)Execute(new DataAdapterFillCallback(dataTable,
|
||||
return (int)Execute(new DataAdapterFillCallback(dbProvider,
|
||||
dataTable,
|
||||
commandType, sql,
|
||||
mappingCollection, setter, null, null));
|
||||
}
|
||||
@@ -1212,7 +1216,7 @@ namespace Spring.Data.Core
|
||||
{
|
||||
ValidateFillWithParameterArguments(dataTable, sql, parameters);
|
||||
ITableMappingCollection mappingCollection = DoCreateMappingCollection(null);
|
||||
return (int)Execute(new DataAdapterFillCallback(dataTable,
|
||||
return (int)Execute(new DataAdapterFillCallback(dbProvider,dataTable,
|
||||
commandType, sql,
|
||||
mappingCollection, null, null,
|
||||
parameters));
|
||||
@@ -1228,7 +1232,7 @@ namespace Spring.Data.Core
|
||||
tableMappingName = "Table";
|
||||
}
|
||||
ITableMappingCollection mappingCollection = DoCreateMappingCollection(new string[] { tableMappingName });
|
||||
return (int)Execute(new DataAdapterFillCallback(dataTable,
|
||||
return (int)Execute(new DataAdapterFillCallback(dbProvider, dataTable,
|
||||
commandType, sql,
|
||||
mappingCollection, null, null, parameters));
|
||||
}
|
||||
@@ -1240,7 +1244,7 @@ namespace Spring.Data.Core
|
||||
ValidateFillWithParameterArguments(dataTable, sql, parameters, tableMapping);
|
||||
ITableMappingCollection mappingCollection = new DataTableMappingCollection();
|
||||
mappingCollection.Add((object)tableMapping);
|
||||
return (int)Execute(new DataAdapterFillCallback(dataTable,
|
||||
return (int)Execute(new DataAdapterFillCallback(dbProvider, dataTable,
|
||||
commandType, sql,
|
||||
mappingCollection, null, null, parameters));
|
||||
}
|
||||
@@ -1253,7 +1257,7 @@ namespace Spring.Data.Core
|
||||
ValidateFillWithParameterArguments(dataTable, sql, parameters, tableMapping);
|
||||
ITableMappingCollection mappingCollection = new DataTableMappingCollection();
|
||||
mappingCollection.Add((object)tableMapping);
|
||||
return (int)Execute(new DataAdapterFillCallback(dataTable,
|
||||
return (int)Execute(new DataAdapterFillCallback(dbProvider, dataTable,
|
||||
commandType, sql,
|
||||
mappingCollection, dataAdapterSetter, null, parameters));
|
||||
}
|
||||
@@ -1262,7 +1266,7 @@ namespace Spring.Data.Core
|
||||
#endregion
|
||||
|
||||
#region DataTable Update operations
|
||||
//TODO conflict options...
|
||||
|
||||
|
||||
public int DataTableUpdateWithCommandBuilder(DataTable dataTable,
|
||||
CommandType commandType,
|
||||
@@ -1490,7 +1494,7 @@ namespace Spring.Data.Core
|
||||
|
||||
|
||||
ITableMappingCollection mappingCollection = DoCreateMappingCollection(null);
|
||||
return (int)Execute(new DataAdapterFillCallback(dataSet,
|
||||
return (int)Execute(new DataAdapterFillCallback(DbProvider, dataSet,
|
||||
commandType, sql,
|
||||
mappingCollection, null, null, null));
|
||||
}
|
||||
@@ -1513,7 +1517,7 @@ namespace Spring.Data.Core
|
||||
tableNames = new string[] { "Table" };
|
||||
}
|
||||
ITableMappingCollection mappingCollection = DoCreateMappingCollection(tableNames);
|
||||
return (int)Execute(new DataAdapterFillCallback(dataSet,
|
||||
return (int)Execute(new DataAdapterFillCallback(DbProvider, dataSet,
|
||||
commandType, sql,
|
||||
mappingCollection, null, null, null));
|
||||
}
|
||||
@@ -1523,7 +1527,7 @@ namespace Spring.Data.Core
|
||||
ITableMappingCollection tableMapping)
|
||||
{
|
||||
ValidateFillArguments(dataSet, sql, tableMapping);
|
||||
return (int)Execute(new DataAdapterFillCallback(dataSet,
|
||||
return (int)Execute(new DataAdapterFillCallback(DbProvider, dataSet,
|
||||
commandType, sql,
|
||||
tableMapping, null, null, null));
|
||||
|
||||
@@ -1534,7 +1538,7 @@ namespace Spring.Data.Core
|
||||
IDataAdapterSetter setter)
|
||||
{
|
||||
ValidateFillArguments(dataSet, sql, tableMapping);
|
||||
return (int)Execute(new DataAdapterFillCallback(dataSet,
|
||||
return (int)Execute(new DataAdapterFillCallback(DbProvider, dataSet,
|
||||
commandType, sql,
|
||||
tableMapping, setter, null, null));
|
||||
|
||||
@@ -1546,7 +1550,7 @@ namespace Spring.Data.Core
|
||||
IDataSetFillLifecycleProcessor fillLifecycleProcessor)
|
||||
{
|
||||
ValidateFillArguments(dataSet, sql, tableMapping);
|
||||
return (int)Execute(new DataAdapterFillCallback(dataSet,
|
||||
return (int)Execute(new DataAdapterFillCallback(DbProvider, dataSet,
|
||||
commandType, sql,
|
||||
tableMapping, setter, fillLifecycleProcessor, null));
|
||||
|
||||
@@ -1561,7 +1565,7 @@ namespace Spring.Data.Core
|
||||
{
|
||||
ValidateFillWithParameterArguments(dataSet, sql, parameters);
|
||||
ITableMappingCollection mappingCollection = DoCreateMappingCollection(null);
|
||||
return (int)Execute(new DataAdapterFillCallback(dataSet,
|
||||
return (int)Execute(new DataAdapterFillCallback(DbProvider, dataSet,
|
||||
commandType, sql,
|
||||
mappingCollection, null, null,
|
||||
parameters));
|
||||
@@ -1577,7 +1581,7 @@ namespace Spring.Data.Core
|
||||
tableNames = new string[] { "Table" };
|
||||
}
|
||||
ITableMappingCollection tableMapping = DoCreateMappingCollection(tableNames);
|
||||
return (int)Execute(new DataAdapterFillCallback(dataSet,
|
||||
return (int)Execute(new DataAdapterFillCallback(DbProvider, dataSet,
|
||||
commandType, sql,
|
||||
tableMapping, null, null, parameters));
|
||||
|
||||
@@ -1588,7 +1592,7 @@ namespace Spring.Data.Core
|
||||
ITableMappingCollection tableMapping)
|
||||
{
|
||||
ValidateFillWithParameterArguments(dataSet, sql, parameters, tableMapping);
|
||||
return (int)Execute(new DataAdapterFillCallback(dataSet,
|
||||
return (int)Execute(new DataAdapterFillCallback(DbProvider, dataSet,
|
||||
commandType, sql,
|
||||
tableMapping, null, null, parameters));
|
||||
}
|
||||
@@ -1599,7 +1603,7 @@ namespace Spring.Data.Core
|
||||
IDataAdapterSetter dataAdapterSetter)
|
||||
{
|
||||
ValidateFillWithParameterArguments(dataSet, sql, parameters, tableMapping);
|
||||
return (int)Execute(new DataAdapterFillCallback(dataSet,
|
||||
return (int)Execute(new DataAdapterFillCallback(DbProvider, dataSet,
|
||||
commandType, sql,
|
||||
tableMapping, dataAdapterSetter, null, parameters));
|
||||
}
|
||||
@@ -1611,7 +1615,7 @@ namespace Spring.Data.Core
|
||||
IDataSetFillLifecycleProcessor fillLifecycleProcessor)
|
||||
{
|
||||
ValidateFillWithParameterArguments(dataSet, sql, parameters, tableMapping);
|
||||
return (int)Execute(new DataAdapterFillCallback(dataSet,
|
||||
return (int)Execute(new DataAdapterFillCallback(DbProvider, dataSet,
|
||||
commandType, sql,
|
||||
tableMapping, dataAdapterSetter, fillLifecycleProcessor, parameters));
|
||||
}
|
||||
@@ -1681,7 +1685,7 @@ namespace Spring.Data.Core
|
||||
|
||||
ITableMappingCollection mappingCollection = DoCreateMappingCollection(new string[] { tableName });
|
||||
|
||||
return (int)Execute(new DataAdapterUpdateCallback(dataSet,
|
||||
return (int)Execute(new DataAdapterUpdateCallback(DbProvider, dataSet,
|
||||
mappingCollection,
|
||||
insertCommand,
|
||||
updateCommand,
|
||||
@@ -1722,7 +1726,7 @@ namespace Spring.Data.Core
|
||||
}
|
||||
ITableMappingCollection mappingCollection = DoCreateMappingCollection(new string[] { tableName });
|
||||
|
||||
int returnVal = (int)Execute(new DataAdapterUpdateCallback(dataSet, mappingCollection,
|
||||
int returnVal = (int)Execute(new DataAdapterUpdateCallback(DbProvider, dataSet, mappingCollection,
|
||||
insertCommand, updateCommand, deleteCommand, null));
|
||||
|
||||
if (insertSql != null)
|
||||
@@ -1751,7 +1755,7 @@ namespace Spring.Data.Core
|
||||
{
|
||||
ValidateUpdateArguments(dataSet, tableName);
|
||||
ITableMappingCollection tableMapping = DoCreateMappingCollection(new string[] { tableName });
|
||||
return (int)Execute(new DataAdapterUpdateCallback(dataSet,
|
||||
return (int)Execute(new DataAdapterUpdateCallback(DbProvider, dataSet,
|
||||
tableMapping,
|
||||
insertCommand,
|
||||
updateCommand,
|
||||
@@ -1767,7 +1771,7 @@ namespace Spring.Data.Core
|
||||
IDbCommand deleteCommand)
|
||||
{
|
||||
ValidateUpdateArguments(dataSet, tableMapping);
|
||||
return (int)Execute(new DataAdapterUpdateCallback(dataSet,
|
||||
return (int)Execute(new DataAdapterUpdateCallback(DbProvider, dataSet,
|
||||
tableMapping,
|
||||
insertCommand,
|
||||
updateCommand,
|
||||
@@ -1783,7 +1787,7 @@ namespace Spring.Data.Core
|
||||
IDataAdapterSetter dataAdapterSetter)
|
||||
{
|
||||
ValidateUpdateArguments(dataSet, tableMapping);
|
||||
return (int)Execute(new DataAdapterUpdateCallback(dataSet,
|
||||
return (int)Execute(new DataAdapterUpdateCallback(DbProvider, dataSet,
|
||||
tableMapping,
|
||||
insertCommand,
|
||||
updateCommand,
|
||||
@@ -1873,7 +1877,7 @@ namespace Spring.Data.Core
|
||||
ParameterUtils.CopyParameters(deleteCommand, deleteParameters);
|
||||
}
|
||||
|
||||
int returnVal = (int)Execute(new DataAdapterUpdateCallback(dataTable, mappingCollection,
|
||||
int returnVal = (int)Execute(new DataAdapterUpdateCallback(DbProvider, dataTable, mappingCollection,
|
||||
insertCommand, updateCommand, deleteCommand, null));
|
||||
|
||||
if (insertSql != null)
|
||||
@@ -2161,9 +2165,11 @@ namespace Spring.Data.Core
|
||||
private ITableMappingCollection mappingCollection;
|
||||
private IDataAdapterSetter dataAdapterSetter;
|
||||
private IDataSetFillLifecycleProcessor fillLifecycleProcessor;
|
||||
private IDbParameters parameters;
|
||||
private IDbParameters parameters;
|
||||
private IDbProvider dbProvider;
|
||||
|
||||
public DataAdapterFillCallback(DataSet dataSet,
|
||||
public DataAdapterFillCallback(IDbProvider dbProvider,
|
||||
DataSet dataSet,
|
||||
CommandType commandType,
|
||||
string sql,
|
||||
ITableMappingCollection mappingCollection,
|
||||
@@ -2171,7 +2177,8 @@ namespace Spring.Data.Core
|
||||
IDataSetFillLifecycleProcessor fillLifecycleProcessor,
|
||||
IDbParameters parameters)
|
||||
{
|
||||
containsDataSet = true;
|
||||
containsDataSet = true;
|
||||
this.dbProvider = dbProvider;
|
||||
this.dataSet = dataSet;
|
||||
this.commandType = commandType;
|
||||
this.sql = sql;
|
||||
@@ -2179,9 +2186,10 @@ namespace Spring.Data.Core
|
||||
this.dataAdapterSetter = dataAdapterSetter;
|
||||
this.fillLifecycleProcessor = fillLifecycleProcessor;
|
||||
this.parameters = parameters;
|
||||
}
|
||||
|
||||
public DataAdapterFillCallback(DataTable dataTable,
|
||||
}
|
||||
|
||||
public DataAdapterFillCallback(IDbProvider dbProvider,
|
||||
DataTable dataTable,
|
||||
CommandType commandType,
|
||||
string sql,
|
||||
ITableMappingCollection mappingCollection,
|
||||
@@ -2189,7 +2197,8 @@ namespace Spring.Data.Core
|
||||
IDataSetFillLifecycleProcessor fillLifecycleProcessor,
|
||||
IDbParameters parameters)
|
||||
{
|
||||
containsDataSet = false;
|
||||
containsDataSet = false;
|
||||
this.dbProvider = dbProvider;
|
||||
this.dataTable = dataTable;
|
||||
this.commandType = commandType;
|
||||
this.sql = sql;
|
||||
@@ -2202,9 +2211,14 @@ namespace Spring.Data.Core
|
||||
|
||||
|
||||
public object DoInDataAdapter(IDbDataAdapter dataAdapter)
|
||||
{
|
||||
{
|
||||
ConnectionTxPair connectionTxPairToUse = ConnectionUtils.GetConnectionTxPair(dbProvider);
|
||||
dataAdapter.SelectCommand.Connection = connectionTxPairToUse.Connection;
|
||||
dataAdapter.SelectCommand.Transaction = connectionTxPairToUse.Transaction;
|
||||
|
||||
dataAdapter.SelectCommand.CommandType = commandType;
|
||||
dataAdapter.SelectCommand.CommandText = sql;
|
||||
dataAdapter.SelectCommand.CommandText = sql;
|
||||
|
||||
//TODO investigate performance of cloning....would need to change signature to
|
||||
// DataTableMapping[] otherwise...
|
||||
foreach (DataTableMapping dataTableMapping in mappingCollection)
|
||||
@@ -2263,16 +2277,13 @@ namespace Spring.Data.Core
|
||||
private IDbCommand insertCommand;
|
||||
private IDbCommand updateCommand;
|
||||
private IDbCommand deleteCommand;
|
||||
private IDataAdapterSetter dataAdapterSetter;
|
||||
private IDataAdapterSetter dataAdapterSetter;
|
||||
private IDbProvider dbProvider;
|
||||
|
||||
public DataAdapterUpdateCallback(DataSet dataSet,
|
||||
ITableMappingCollection mappingCollection,
|
||||
IDbCommand insertCommand,
|
||||
IDbCommand updateCommand,
|
||||
IDbCommand deleteCommand,
|
||||
IDataAdapterSetter dataAdapterSetter)
|
||||
public DataAdapterUpdateCallback(IDbProvider dbProvider, DataSet dataSet, ITableMappingCollection mappingCollection, IDbCommand insertCommand, IDbCommand updateCommand, IDbCommand deleteCommand, IDataAdapterSetter dataAdapterSetter)
|
||||
{
|
||||
containsDataSet = true;
|
||||
containsDataSet = true;
|
||||
this.dbProvider = dbProvider;
|
||||
this.dataSet = dataSet;
|
||||
this.mappingCollection = mappingCollection;
|
||||
this.insertCommand = insertCommand;
|
||||
@@ -2281,14 +2292,10 @@ namespace Spring.Data.Core
|
||||
this.dataAdapterSetter = dataAdapterSetter;
|
||||
}
|
||||
|
||||
public DataAdapterUpdateCallback(DataTable dataTable,
|
||||
ITableMappingCollection mappingCollection,
|
||||
IDbCommand insertCommand,
|
||||
IDbCommand updateCommand,
|
||||
IDbCommand deleteCommand,
|
||||
IDataAdapterSetter dataAdapterSetter)
|
||||
public DataAdapterUpdateCallback(IDbProvider dbProvider, DataTable dataTable, ITableMappingCollection mappingCollection, IDbCommand insertCommand, IDbCommand updateCommand, IDbCommand deleteCommand, IDataAdapterSetter dataAdapterSetter)
|
||||
{
|
||||
containsDataSet = false;
|
||||
containsDataSet = false;
|
||||
this.dbProvider = dbProvider;
|
||||
this.dataTable = dataTable;
|
||||
this.mappingCollection = mappingCollection;
|
||||
this.insertCommand = insertCommand;
|
||||
@@ -2299,7 +2306,11 @@ namespace Spring.Data.Core
|
||||
#region IDataAdapterCallback Members
|
||||
|
||||
public object DoInDataAdapter(IDbDataAdapter dataAdapter)
|
||||
{
|
||||
{
|
||||
ConnectionTxPair connectionTxPairToUse = ConnectionUtils.GetConnectionTxPair(dbProvider);
|
||||
dataAdapter.SelectCommand.Connection = connectionTxPairToUse.Connection;
|
||||
dataAdapter.SelectCommand.Transaction = connectionTxPairToUse.Transaction;
|
||||
|
||||
//TODO - did not make copies of parameters...
|
||||
if (insertCommand == null && updateCommand == null && deleteCommand == null)
|
||||
{
|
||||
|
||||
@@ -287,27 +287,6 @@ namespace Spring.Data
|
||||
string parameterName, Enum dbType, int size, object parameterValue);
|
||||
|
||||
|
||||
/*
|
||||
/// <summary>
|
||||
/// Execute a query for a result list, given static SQL.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// The results will be mapped to a List (one entry for each row)
|
||||
/// of IDictionaries (one entry for each column using he column
|
||||
/// name as the key). Each element in the list will be of the form
|
||||
/// returned by ths interfaces QueryForMap() methods.
|
||||
/// </remarks>
|
||||
/// <param name="cmdType">The type of the command.</param>
|
||||
/// <param name="sql">The SQL query to execute</param>
|
||||
/// <returns></returns>
|
||||
IList QueryForList(CommandType cmdType, string sql);
|
||||
*/
|
||||
//IDictionary QueryForDictionary(CommandType cmdType, string sql);
|
||||
//TODO -
|
||||
//Object QueryForObject(CommandType cmdType, String sql, Type requiredType) throws DataAccessException;
|
||||
//IDictionary QueryForDictionary
|
||||
//IList QueryForList
|
||||
|
||||
#endregion
|
||||
|
||||
#region Query for ObjectDelegate
|
||||
@@ -402,19 +381,9 @@ namespace Spring.Data
|
||||
// each with either a IRowMapper, IResultSetExtractor, IRowCallback
|
||||
// and multiple output parameters.
|
||||
IDictionary QueryWithCommandCreator(IDbCommandCreator commandCreator, IList resultProcessors);
|
||||
|
||||
//TODO
|
||||
//Object QueryForObject(... Type requiredType)
|
||||
//IDictionary QueryForDictionary
|
||||
//IList QueryForList
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
// ***************************************************************
|
||||
// NB: Complex DataSet/DataTable operations are best handled with
|
||||
// DataSetOperations class in Spring.Data.Objects
|
||||
// ***************************************************************
|
||||
|
||||
|
||||
#region DataTable Create operations without parameters
|
||||
|
||||
DataTable DataTableCreate(CommandType commandType, string sql);
|
||||
@@ -449,11 +418,7 @@ namespace Spring.Data
|
||||
ITableMapping tableMapping,
|
||||
IDataAdapterSetter dataAdapterSetter);
|
||||
|
||||
|
||||
//TODO
|
||||
/*
|
||||
DataTable DataTableCreateWithParams(IDbDataAdapterCreator dataAdapterCreator);
|
||||
*/
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -497,17 +462,10 @@ namespace Spring.Data
|
||||
IDbParameters parameters,
|
||||
ITableMapping tableMapping,
|
||||
IDataAdapterSetter dataAdapterSetter);
|
||||
|
||||
//TODO
|
||||
/*
|
||||
int DataTableFillWithParams(DataTable dataTable,
|
||||
IDbDataAdapterCreator dataAdapterCreator);
|
||||
|
||||
*/
|
||||
|
||||
#endregion
|
||||
|
||||
#region DataTable Update operations
|
||||
//TODO conflict options...
|
||||
|
||||
int DataTableUpdateWithCommandBuilder(DataTable dataTable,
|
||||
CommandType commandType,
|
||||
@@ -665,8 +623,6 @@ namespace Spring.Data
|
||||
#endregion
|
||||
|
||||
#region DataSet Update operations
|
||||
//TODO expose RowUpdate event in a generic manner
|
||||
//TODO any way to integrate Accept/RejectChanges based on tx outcome?
|
||||
|
||||
int DataSetUpdateWithCommandBuilder(DataSet dataSet,
|
||||
CommandType commandType,
|
||||
|
||||
@@ -32,6 +32,8 @@ using Spring.Data.Common;
|
||||
using Spring.Data.Core;
|
||||
using Spring.Data.Support;
|
||||
using Spring.Objects;
|
||||
using Spring.Transaction;
|
||||
using Spring.Transaction.Support;
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -48,6 +50,7 @@ namespace Spring.Data
|
||||
|
||||
IAdoOperations adoOperations;
|
||||
IDbProvider dbProvider;
|
||||
private IPlatformTransactionManager transactionManager;
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -82,13 +85,8 @@ namespace Spring.Data
|
||||
Assert.IsNotNull(ctx);
|
||||
dbProvider = ctx["DbProvider"] as IDbProvider;
|
||||
Assert.IsNotNull(dbProvider);
|
||||
UserCredentialsDbProvider userCredentialsDbProvider = dbProvider as UserCredentialsDbProvider;
|
||||
Assert.IsNotNull(userCredentialsDbProvider);
|
||||
|
||||
//userCredentialsDbProvider.Username = "User ID=springqa";
|
||||
//userCredentialsDbProvider.Password = "Password=springqa";
|
||||
userCredentialsDbProvider.SetCredentialsForCurrentThread("User ID=springqa", "Password=springqa");
|
||||
adoOperations = new AdoTemplate(userCredentialsDbProvider);
|
||||
adoOperations = new AdoTemplate(dbProvider);
|
||||
transactionManager = new AdoPlatformTransactionManager(dbProvider);
|
||||
|
||||
}
|
||||
|
||||
@@ -97,12 +95,10 @@ namespace Spring.Data
|
||||
[Test]
|
||||
public void FillDataSetNoParams()
|
||||
{
|
||||
String sql = "select TestObjectNo, Age, Name from TestObjects";
|
||||
DataSet dataSet = new DataSet();
|
||||
adoOperations.DataSetFill(dataSet, CommandType.Text, sql);
|
||||
Assert.AreEqual(1, dataSet.Tables.Count);
|
||||
Assert.AreEqual(4, dataSet.Tables["Table"].Rows.Count);
|
||||
|
||||
PopulateTestObjectsTable();
|
||||
string sql = ValidateTestObjects(4);
|
||||
DataSet dataSet;
|
||||
|
||||
dataSet = new DataSet();
|
||||
adoOperations.DataSetFill(dataSet, CommandType.Text, sql, new string[] {"TestObjects"});
|
||||
Assert.AreEqual(1, dataSet.Tables.Count);
|
||||
@@ -125,41 +121,92 @@ namespace Spring.Data
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void UpdateDataSet()
|
||||
|
||||
[Test]
|
||||
public void UpdateDataSet()
|
||||
{
|
||||
PopulateTestObjectsTable();
|
||||
ValidateTestObjects(4);
|
||||
DoUpdateDataSet();
|
||||
ValidateTestObjects(5);
|
||||
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void UpdateDataSetTxRollback()
|
||||
{
|
||||
|
||||
PopulateTestObjectsTable();
|
||||
ValidateTestObjects(4);
|
||||
TransactionTemplate tt = new TransactionTemplate(transactionManager);
|
||||
try
|
||||
{
|
||||
object result = tt.Execute(new DataSetUpdateTransactionCallback(this, true));
|
||||
Assert.Fail("Should have thrown exception to rollback transaction.");
|
||||
} catch (Exception e)
|
||||
{
|
||||
ValidateTestObjects(4);
|
||||
}
|
||||
}
|
||||
|
||||
private void PopulateTestObjectsTable()
|
||||
{
|
||||
adoOperations.ExecuteNonQuery(CommandType.Text, "truncate table TestObjects");
|
||||
int age = 18;
|
||||
int counter = 0;
|
||||
for (int i=0;i<4;i++)
|
||||
{
|
||||
String sql =
|
||||
String.Format("insert into TestObjects(Age, Name) VALUES ({0}, '{1}')", age++, "George" + counter++);
|
||||
adoOperations.ExecuteNonQuery(CommandType.Text, sql);
|
||||
}
|
||||
}
|
||||
|
||||
private string ValidateTestObjects(int count)
|
||||
{
|
||||
String sql = "select TestObjectNo, Age, Name from TestObjects";
|
||||
DataSet dataSet = new DataSet();
|
||||
adoOperations.DataSetFill(dataSet, CommandType.Text, sql, new string[] {"TestObjects"});
|
||||
|
||||
//Create and add new row.
|
||||
adoOperations.DataSetFill(dataSet, CommandType.Text, sql);
|
||||
Assert.AreEqual(1, dataSet.Tables.Count);
|
||||
Assert.AreEqual(count, dataSet.Tables["Table"].Rows.Count);
|
||||
return sql;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void DoUpdateDataSet()
|
||||
{
|
||||
String sql = "select TestObjectNo, Age, Name from TestObjects";
|
||||
DataSet dataSet = new DataSet();
|
||||
adoOperations.DataSetFill(dataSet, CommandType.Text, sql, new string[] { "TestObjects" });
|
||||
|
||||
//Create and add new row.
|
||||
DataRow myDataRow = dataSet.Tables["TestObjects"].NewRow();
|
||||
myDataRow["Age"] = 101;
|
||||
myDataRow["Name"] = "OldManWinter";
|
||||
myDataRow["Name"] = "OldManWinter";
|
||||
dataSet.Tables["TestObjects"].Rows.Add(myDataRow);
|
||||
|
||||
//TODO - think about api...
|
||||
IDbCommand insertCommand = dbProvider.CreateCommand();
|
||||
insertCommand.CommandText = "insert into TestObjects(Age,Name) values (@Age,@Name)";
|
||||
|
||||
//TODO - think about api...
|
||||
IDbCommand insertCommand = dbProvider.CreateCommand();
|
||||
insertCommand.CommandText = "insert into TestObjects(Age,Name) values (@Age,@Name)";
|
||||
IDbParameters parameters = adoOperations.CreateDbParameters();
|
||||
parameters.Add("Name", DbType.String, 12, "Name");
|
||||
//TODO - remembering the -1 isn't all that natural... add string name, dbtype, string sourceCol)
|
||||
//or AddSourceCol("Age", SqlDbType.Int); would copy into source col?
|
||||
//TODO - remembering the -1 isn't all that natural... add string name, dbtype, string sourceCol)
|
||||
//or AddSourceCol("Age", SqlDbType.Int); would copy into source col?
|
||||
parameters.Add("Age", SqlDbType.Int, -1, "Age");
|
||||
|
||||
//TODO - this isn't all that natural...
|
||||
ParameterUtils.CopyParameters(insertCommand, parameters);
|
||||
|
||||
//insertCommand.Parameters.Add()
|
||||
|
||||
adoOperations.DataSetUpdate(dataSet, "TestObjects",
|
||||
insertCommand,
|
||||
null,
|
||||
null);
|
||||
|
||||
//TODO avoid param Utils copy by adding argument...
|
||||
|
||||
//TODO - this isn't all that natural...
|
||||
ParameterUtils.CopyParameters(insertCommand, parameters);
|
||||
|
||||
//insertCommand.Parameters.Add()
|
||||
|
||||
adoOperations.DataSetUpdate(dataSet, "TestObjects",
|
||||
insertCommand,
|
||||
null,
|
||||
null);
|
||||
|
||||
//TODO avoid param Utils copy by adding argument...
|
||||
|
||||
//adoOperations.DataSetUpdate(dataSet, "TestObjects",
|
||||
// insertCommand, parameters,
|
||||
// null, null,
|
||||
@@ -169,11 +216,10 @@ namespace Spring.Data
|
||||
// CommandType type, string sql, parameters,
|
||||
// null, null,
|
||||
// null, null);
|
||||
|
||||
//TODO how about breaking up the operations...
|
||||
|
||||
}
|
||||
|
||||
//TODO how about breaking up the operations...
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ExecuteQueryWithResultSetExtractor()
|
||||
{
|
||||
@@ -284,4 +330,32 @@ namespace Spring.Data
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
internal class DataSetUpdateTransactionCallback : ITransactionCallback
|
||||
{
|
||||
private bool throwException;
|
||||
private AdoTemplateTests adoTemplateTests;
|
||||
|
||||
public DataSetUpdateTransactionCallback(AdoTemplateTests adoTemplateTests, bool throwException)
|
||||
{
|
||||
this.throwException = throwException;
|
||||
this.adoTemplateTests = adoTemplateTests;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets called by TransactionTemplate.Execute within a
|
||||
/// transaction context.
|
||||
/// </summary>
|
||||
/// <param name="status">The associated transaction status.</param>
|
||||
/// <returns>A result object or <c>null</c>.</returns>
|
||||
public object DoInTransaction(ITransactionStatus status)
|
||||
{
|
||||
if (throwException)
|
||||
{
|
||||
throw new ArgumentException("Explicitly thrown exception");
|
||||
}
|
||||
adoTemplateTests.DoUpdateDataSet();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,33 +1,14 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<objects xmlns="http://www.springframework.net"
|
||||
xmlns:d="http://www.springframework.net/database">
|
||||
xmlns:db="http://www.springframework.net/database">
|
||||
|
||||
<!-- ;User ID=springqa;Password=springqa; -->
|
||||
|
||||
|
||||
<d:provider id="DbProvider"
|
||||
<db:provider id="DbProvider"
|
||||
provider="SqlServer-2.0"
|
||||
connectionString="Data Source=MARKT60\SQL2005;Initial Catalog=Spring;Persist Security Info=True;User ID=springqa;Password=springqa"/>
|
||||
<!-- Data Source=MARKT60\SQL2005;Initial Catalog=Spring;Persist Security Info=True;User ID=springqa -->
|
||||
<!--
|
||||
|
||||
<d:provider id="DbProvider"
|
||||
provider="SqlServer-1.1"
|
||||
connectionString="Data Source=(local);Database=Spring;User ID=springqa;Password=springqa;Trusted_Connection=False"/>
|
||||
-->
|
||||
<!--
|
||||
<object id="DbProvider" type="Spring.Data.Common.DbProviderFactoryObject, Spring.Data">
|
||||
<property name="ProviderName" value="SqlServer-1.1"/>
|
||||
<property name="ConnectionString"
|
||||
value="Data Source=(local);Database=Spring;User ID=springqa;Password=springqa;Trusted_Connection=False"/>
|
||||
|
||||
</object>
|
||||
-->
|
||||
|
||||
|
||||
<object id="adoTemplate"
|
||||
type="Spring.Data.Core.AdoTemplate, Spring.Data">
|
||||
|
||||
<object id="adoTemplate" type="Spring.Data.Core.AdoTemplate, Spring.Data">
|
||||
<property name="DbProvider" ref="DbProvider"/>
|
||||
</object>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user