git-svn-id: https://192.168.0.254/svn/Componentes.Terceros.RemObjects@68 b6239004-a887-0f4b-9937-50029ccdca16
140 lines
4.8 KiB
ObjectPascal
140 lines
4.8 KiB
ObjectPascal
unit uDALocalCommand;
|
|
{----------------------------------------------------------------------------}
|
|
{ Data Abstract Library - Core Library }
|
|
{ }
|
|
{ compiler: Delphi 6 and up, Lazarus/FPC }
|
|
{ platform: Win32, Unux, Mac }
|
|
{ }
|
|
{ (c)opyright RemObjects Software. all rights reserved. }
|
|
{ }
|
|
{ Using this code requires a valid license of the Data Abstract }
|
|
{ which can be obtained at http://www.remobjects.com. }
|
|
{----------------------------------------------------------------------------}
|
|
|
|
{$I DataAbstract.inc}
|
|
|
|
interface
|
|
uses
|
|
Classes,
|
|
uROClient,
|
|
DataAbstract4_Intf, uDALocalHelpers;
|
|
type
|
|
{ TDARemoteCommand }
|
|
TDALocalCommand = class(TROComponent)
|
|
private
|
|
fServiceInstance: IDataAbstractLocalServiceAccess;
|
|
fServiceName: string;
|
|
fServiceInstanceNeedsRelease: Boolean;
|
|
FSessionID: TGuid;
|
|
function GetServiceInstance: IDataAbstractLocalServiceAccess;
|
|
procedure SetServiceInstance(const Value: IDataAbstractLocalServiceAccess);
|
|
procedure SetServiceName(const Value: String);
|
|
public
|
|
destructor Destroy; override;
|
|
procedure Assign(Source: TPersistent); override;
|
|
function Execute(aCommandName: string): integer; overload;
|
|
function Execute(aCommandName: string; aInputParameters: DataParameterArray): integer; overload;
|
|
function Execute(aCommandName: string; aInputParameters: DataParameterArray; out aOutputParameters: DataParameterArray): integer; overload;
|
|
function Execute(aCommandName: string; aParamNames: array of string; aParamValues: array of variant): integer; overload;
|
|
|
|
property ServiceInstance: IDataAbstractLocalServiceAccess read GetServiceInstance write SetServiceInstance;
|
|
property SessionID: TGuid read FSessionID write fSessionID;
|
|
published
|
|
property ServiceName: String read fServiceName write SetServiceName;
|
|
end;
|
|
|
|
implementation
|
|
uses
|
|
uDAEngine;
|
|
{ TDALocalCommand }
|
|
|
|
procedure TDALocalCommand.Assign(Source: TPersistent);
|
|
var
|
|
lSource: TDALocalCommand;
|
|
begin
|
|
inherited;
|
|
if Source is TDALocalCommand then begin
|
|
lSource := TDALocalCommand(Source);
|
|
|
|
ServiceName := lSource.ServiceName;
|
|
end;
|
|
end;
|
|
|
|
destructor TDALocalCommand.Destroy;
|
|
begin
|
|
ServiceInstance := nil;
|
|
inherited;
|
|
end;
|
|
|
|
function TDALocalCommand.Execute(aCommandName: string;
|
|
aInputParameters: DataParameterArray): integer;
|
|
var
|
|
lOutputParameters: DataParameterArray;
|
|
begin
|
|
Result := Self.Execute(aCommandName, aInputParameters, lOutputParameters);
|
|
lOutputParameters.Free;
|
|
end;
|
|
|
|
function TDALocalCommand.Execute(aCommandName: string;
|
|
aParamNames: array of string; aParamValues: array of variant): integer;
|
|
var
|
|
i, idx: Integer;
|
|
lInputParameters: DataParameterArray;
|
|
begin
|
|
lInputParameters := DataParameterArray.Create();
|
|
if (High(aParamNames) <> High(aParamValues)) then
|
|
raise EDAException.Create(Self.Name+': Error in parameters. Count of parameter values doesn''t correspond to count of parameters');
|
|
|
|
for i := Low(aParamNames) to High(aParamNames) do begin
|
|
idx := lInputParameters.Add(DataParameter.Create());
|
|
lInputParameters[idx].Name := UTF8Encode(aParamNames[i]);
|
|
lInputParameters[idx].Value := aParamValues[i];
|
|
end;
|
|
try
|
|
result := Self.Execute(aCommandName, lInputParameters);
|
|
finally
|
|
lInputParameters.Free;
|
|
end;
|
|
end;
|
|
|
|
function TDALocalCommand.Execute(aCommandName: string): integer;
|
|
begin
|
|
Result := Execute(aCommandName,[],[]);
|
|
end;
|
|
|
|
function TDALocalCommand.Execute(aCommandName: string;
|
|
aInputParameters: DataParameterArray;
|
|
out aOutputParameters: DataParameterArray): integer;
|
|
begin
|
|
Result := ServiceInstance.ExecuteCommandEx(aCommandName, aInputParameters, aOutputParameters);
|
|
end;
|
|
|
|
function TDALocalCommand.GetServiceInstance: IDataAbstractLocalServiceAccess;
|
|
begin
|
|
if fServiceInstance <> nil then begin
|
|
Result := fServiceInstance;
|
|
Exit;
|
|
end;
|
|
result:= LocalServiceAccessHelper_Acquire(SessionID, ServiceName);
|
|
fServiceInstanceNeedsRelease := true;
|
|
end;
|
|
|
|
procedure TDALocalCommand.SetServiceInstance(
|
|
const Value: IDataAbstractLocalServiceAccess);
|
|
begin
|
|
if Value <> fServiceInstance then begin
|
|
if (fServiceInstanceNeedsRelease) and (fServiceInstance <> nil) then begin
|
|
LocalServiceAccessHelper_Release(SessionID, ServiceName, fServiceInstance);
|
|
end;
|
|
fServiceInstance := value;
|
|
fServiceInstanceNeedsRelease := false;
|
|
end;
|
|
end;
|
|
|
|
procedure TDALocalCommand.SetServiceName(const Value: String);
|
|
begin
|
|
fServiceName := Value;
|
|
end;
|
|
|
|
end.
|