using SD.LLBLGen.Pro.ORMSupportClasses;
using SD.LLBLGen.Pro.DQE.MySql;
namespace YourRootNamespace.DatabaseSpecific
{
public partial class DataAccessAdapter
{
#region Class Member Declarations
// sorter to use on a batch update query (for MySql queries)
private ISortExpression _updateEntitiesDirectlySorter;
// the limit of the batch update query (for MySql queries)
private int _updateEntitiesDirectlyLimit;
// sorter to use on a batch delete query (for MySql queries)
private ISortExpression _deleteEntitiesDirectlySorter;
// the limit of the batch delete query (for MySql queries)
private int _deleteEntitiesDirectlyLimit;
#endregion
#region Extend the UpdateEntitiesDirectly method for MySql specific clauses
///
/// Called right before the actual update query is executed
///
/// The ActionQuery to execute
protected override void OnUpdateEntitiesDirectly(IActionQuery updateQuery)
{
// call the base method
base.OnUpdateEntitiesDirectly(updateQuery);
int i = 0;
// add the ORDER BY clause (if applicable)
if (_updateEntitiesDirectlySorter != null)
{
// prepare the sortExpression object
MySqlSpecificCreator dqe = new MySqlSpecificCreator();
_updateEntitiesDirectlySorter.DatabaseSpecificCreator = dqe;
InsertPersistenceInfoObjects(_updateEntitiesDirectlySorter);
// add the ORDER BY clause
updateQuery.Command.CommandText +=
string.Format(" ORDER BY {0}", _updateEntitiesDirectlySorter.ToQueryText(ref i));
}
// add the LIMIT clause (if applicable)
if (_updateEntitiesDirectlyLimit > 0)
{
updateQuery.Command.CommandText +=
string.Format(" LIMIT {0}", _updateEntitiesDirectlyLimit);
}
}
///
/// Updates all entities of the same type or subtype of the entity entityWithNewValues directly in the persistent storage if they match the filter
/// supplied in filterBucket. Only the fields changed in entityWithNewValues are updated for these fields. Entities of a subtype of the type
/// of entityWithNewValues which are affected by the filterBucket's filter will thus also be updated.
///
/// Entity object which contains the new values for the entities of the same type and which match the filter
/// in filterBucket. Only fields which are changed are updated.
/// filter information to filter out the entities to update.
/// The sorter to use on the update query.
/// The limti of the update query. Only available for MySql queries
/// the number of physically updated entities. Use this number only to test if the update succeeded (so value is > 0).
public int UpdateEntitiesDirectly(IEntity2 entityWithNewValues,
IRelationPredicateBucket filterBucket, ISortExpression sorter, int limit)
{
// update the parameters for the query
_updateEntitiesDirectlySorter = sorter;
_updateEntitiesDirectlyLimit = limit;
int rc = 0;
try
{
// persist the batch update query
rc = UpdateEntitiesDirectly(entityWithNewValues, filterBucket);
}
finally
{
// reset the private custom variables
_updateEntitiesDirectlySorter = null;
_updateEntitiesDirectlyLimit = 0;
}
return rc;
}
#endregion
#region Extend the DeleteEntitiesDirectly method for MySql specific clauses
///
/// Called right before the actual update query is executed
///
/// The ActionQuery to execute
protected override void OnDeleteEntitiesDirectly(IActionQuery deleteQuery)
{
// call the base method
base.OnDeleteEntitiesDirectly(deleteQuery);
int i = 0;
// add the ORDER BY clause (if applicable)
if (_deleteEntitiesDirectlySorter != null)
{
// prepare the sortExpression object
MySqlSpecificCreator dqe = new MySqlSpecificCreator();
_deleteEntitiesDirectlySorter.DatabaseSpecificCreator = dqe;
InsertPersistenceInfoObjects(_deleteEntitiesDirectlySorter);
// add the ORDER BY clause
deleteQuery.Command.CommandText +=
string.Format(" ORDER BY {0}", _deleteEntitiesDirectlySorter.ToQueryText(ref i));
}
// add the LIMIT clause (if applicable)
if (_deleteEntitiesDirectlyLimit > 0)
{
deleteQuery.Command.CommandText +=
string.Format(" LIMIT {0}", _deleteEntitiesDirectlyLimit);
}
}
///
/// Updates all entities of the same type or subtype of the entity entityWithNewValues directly in the persistent storage if they match the filter
/// supplied in filterBucket. Only the fields changed in entityWithNewValues are updated for these fields. Entities of a subtype of the type
/// of entityWithNewValues which are affected by the filterBucket's filter will thus also be updated.
///
/// Entity object which contains the new values for the entities of the same type and which match the filter
/// in filterBucket. Only fields which are changed are updated.
/// filter information to filter out the entities to update.
/// The sorter to use on the update query.
/// The limti of the update query. Only available for MySql queries
/// the number of physically updated entities. Use this number only to test if the update succeeded (so value is > 0).
public int DeleteEntitiesDirectly(string entityName, IRelationPredicateBucket filterBucket,
ISortExpression sorter, int limit)
{
// update the parameters for the query
_deleteEntitiesDirectlySorter = sorter;
_deleteEntitiesDirectlyLimit = limit;
int rc = 0;
try
{
// persist the batch delte query
rc = DeleteEntitiesDirectly(entityName, filterBucket);
}
finally
{
// reset the private custom variables
_deleteEntitiesDirectlySorter = null;
_deleteEntitiesDirectlyLimit = 0;
}
return rc;
}
#endregion
}
}