-
Notifications
You must be signed in to change notification settings - Fork 4
/
projection.cls
82 lines (64 loc) · 2.27 KB
/
projection.cls
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/// This class is internal to %pkg.isc.rest; consumers should not use or reference it directly.
Class %pkg.isc.rest.model.action.projection Extends %Projection.AbstractProjection [ System = 3 ]
{
/// Ensure this projection is applied in the main thread to prevent race conditions/deadlock when REST dispatch
/// classes and resources are being compiled at the same time.
Parameter DisableMulticompile As BOOLEAN = 1;
ClassMethod CreateProjection(classname As %String, ByRef parameters As %String, modified As %String, qstruct) As %Status
{
Set sc = $$$OK
Set initTransLevel = $TLevel
Try {
Set actions = ##class(%pkg.isc.rest.model.action.generator).GetActionMetadata(classname)
If (actions.actions.Count() = 0) {
Quit
}
TSTART
// Create action handler class
Set targetClass = classname_".Actions"
Set classDefinition = ##class(%Dictionary.ClassDefinition).%New()
Set classDefinition.Name = targetClass
Set classDefinition.Super = "%pkg.isc.rest.model.action.handler"
Set classDefinition.ProcedureBlock = 1
Set param = ##class(%Dictionary.ParameterDefinition).%New()
Set param.Name = "SOURCECLASS"
Set param.Default = classname
Do classDefinition.Parameters.Insert(param)
Set dependencies = ##class(%pkg.isc.rest.model.action.generator).GetClassDependencies(classname)
Set classDefinition.CompileAfter = $ListToString(dependencies)
Set classDefinition.DependsOn = $ListToString(dependencies)
$$$ThrowOnError(classDefinition.%Save())
Do ..QueueClass(targetClass)
TCOMMIT
} Catch e {
Set sc = e.AsStatus()
}
While ($TLevel > initTransLevel) {
TROLLBACK 1
}
Quit sc
}
ClassMethod RemoveProjection(classname As %String, ByRef parameters As %String, recompile As %Boolean, modified As %String, qstruct) As %Status
{
Set sc = $$$OK
Set initTransLevel = $TLevel
Try {
TSTART
Set targetClass = classname_".Actions"
If ##class(%Dictionary.ClassDefinition).%ExistsId(targetClass) {
$$$ThrowOnError($System.OBJ.Delete(targetClass,.qstruct))
}
&sql(delete from %pkg_isc_rest.actionMap where ResourceClass = :classname)
If (SQLCODE < 0) {
Throw ##class(%Exception.SQL).CreateFromSQLCODE(SQLCODE,%msg)
}
TCOMMIT
} Catch e {
Set sc = e.AsStatus()
}
While ($TLevel > initTransLevel) {
TROLLBACK 1
}
Quit sc
}
}