132 lines
No EOL
4.2 KiB
Text
132 lines
No EOL
4.2 KiB
Text
//***************************************************************************//
|
|
// Legenerálja a DA-hoz a zárolási műveletet. //
|
|
//***************************************************************************//
|
|
template GenerateNoWaitForLock(ENTITYNAME)
|
|
#region No wait for lock
|
|
|
|
private string GetNoWaitForLockCommandText()
|
|
{
|
|
string result = null;
|
|
switch (SDAServer.Instance.Configuration.DataBaseType)
|
|
{
|
|
case DataBaseType.MSSQL:
|
|
{
|
|
result = "select SERIAL from [ConvertNameToSQLTableName([ENTITYNAME])] with(updlock) where ID = :[ConvertNameToCommandParameterName("ID")] {0} ";
|
|
break;
|
|
}
|
|
case DataBaseType.ORACLE:
|
|
case DataBaseType.NATIVEORACLE:
|
|
{
|
|
result = "select SERIAL from [ConvertNameToSQLTableName([ENTITYNAME])] where ID = :[ConvertNameToCommandParameterName("ID")] {0} for update nowait ";
|
|
break;
|
|
}
|
|
default:
|
|
{
|
|
throw new NotSupportedException(SDAServer.Instance.Configuration.DataBaseType.ToString());
|
|
}
|
|
}
|
|
|
|
result = String.Format(result, "");
|
|
return result;
|
|
}
|
|
|
|
public int NoWaitForLock([ENTITYNAME] entity)
|
|
{
|
|
//Console.WriteLine("*** NoWaitForLock 35");
|
|
using ([GetCSharpSQLCommandType()] command = DataAccessor.CreateCommand(this.GetNoWaitForLockCommandText()))
|
|
{
|
|
command.Parameters.Add("[ConvertNameToCommandParameterName("ID")]", [GetCSharpSQLIDType()]).Value = entity.ID;
|
|
int result = -1;
|
|
using ([GetCSharpSQLDataReaderType()] reader = command.ExecuteReader())
|
|
{
|
|
if (reader.Read())
|
|
{
|
|
result = Convert.ToInt32(reader.GetValue(0));
|
|
if (reader.Read())
|
|
{
|
|
throw new Kreta.Framework.DataIntegrityException("Egyediség megsértése: [ENTITYNAME].");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
throw new Kreta.Framework.Exceptions.EntityNotFoundException("[ENTITYNAME]", entity.ID);
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
end template
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* REFACTOR
|
|
template GenerateNoWaitForLock(classname)
|
|
#region No wait for lock
|
|
[GenerateCommandGetterProperty("NoWaitForLock")]
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
/// <returns>A műveletet elvégző SQL parancs.</returns>
|
|
private [GetCSharpSQLCommandType()] [GenerateCommandCreatorName("NoWaitForLock")]()
|
|
{
|
|
[GetCSharpSQLCommandType()] result = new [GetCSharpSQLCommandType()]();
|
|
result.CommandType = CommandType.Text;
|
|
result.Parameters.Add("[ConvertNameToCommandParameterName("ID")]", [GetCSharpSQLIDType()]);
|
|
switch (SDAServer.Instance.Configuration.DataBaseType)
|
|
{
|
|
case DataBaseType.MSSQL:
|
|
{
|
|
result.CommandText = "select SERIAL from [ConvertNameToSQLTableName([classname])] with(updlock) where ID = :[ConvertNameToCommandParameterName("ID")] ";
|
|
break;
|
|
}
|
|
case DataBaseType.ORACLE:
|
|
case DataBaseType.NATIVEORACLE:
|
|
{
|
|
result.CommandText = "select SERIAL from [ConvertNameToSQLTableName([classname])] where ID = :[ConvertNameToCommandParameterName("ID")] ";
|
|
result.CommandText += " for update nowait";
|
|
break;
|
|
}
|
|
default:
|
|
{
|
|
throw new NotSupportedException(SDAServer.Instance.Configuration.DataBaseType.ToString());
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
///
|
|
/// </summary>
|
|
public int NoWaitForLock([classname] entity)
|
|
{
|
|
[GetCSharpSQLDataReaderType()] reader = null;
|
|
[GetCSharpSQLCommandType()] command = this.[ConvertNameToCommandName("NoWaitForLock")];
|
|
[GenerateCommandInit("command")]
|
|
command.Parameters\["[ConvertNameToCommandParameterName("ID")]"\].Value = entity.ID;
|
|
|
|
int result = -1;
|
|
using (reader = command.ExecuteReader())
|
|
{
|
|
if (reader.Read())
|
|
{
|
|
result = Convert.ToInt32(reader.GetValue(0));
|
|
System.Diagnostics.Debug.Assert(reader.Read() == false, "Több ilyen entitást találtam az adatbázisban..."); // XXX
|
|
}
|
|
else
|
|
{
|
|
throw new Kreta.Framework.Exceptions.EntityNotFoundException("[classname]", entity.ID);
|
|
}
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
#endregion
|
|
end template
|
|
*/ |