|
1 | 1 | <?xml version="1.0" encoding="UTF-8"?>
|
2 | 2 | <Export generator="Cache" version="25">
|
3 | 3 | <Class name="SQLKPI.Generator">
|
| 4 | +<Description> |
| 5 | +Generates kpi class</Description> |
4 | 6 | <Abstract>1</Abstract>
|
5 | 7 | <TimeCreated>64244,40301.291978</TimeCreated>
|
| 8 | + |
| 9 | +<XData name="kpi"> |
| 10 | +<Description> |
| 11 | +This XData definition defines the kpi.</Description> |
| 12 | +<Data><![CDATA[ |
| 13 | +<kpi |
| 14 | +xmlns="http://www.intersystems.com/deepsee/kpi" |
| 15 | + name="!!!1!!!" sourceType="sql" |
| 16 | + sql="!!!2!!!"> |
| 17 | +]]></Data> |
| 18 | +</XData> |
| 19 | + |
| 20 | +<Method name="generateKPIClass"> |
| 21 | +<Description> |
| 22 | +do ##class(SQLKPI.Generator).generateKPIClass("SELECT name, type FROM Sample.Per", "KPIName", "try.kpi") </Description> |
| 23 | +<ClassMethod>1</ClassMethod> |
| 24 | +<FormalSpec>sql:%String,name:%String,class:%String</FormalSpec> |
| 25 | +<Implementation><![CDATA[ |
| 26 | + #dim sc As %Status = $$$OK |
| 27 | + |
| 28 | + if '##class(%Dictionary.ClassDefinition).%ExistsId(class) { |
| 29 | + set classObj = ##class(%Dictionary.ClassDefinition).%New(class) |
| 30 | + set classObj.GeneratedBy = "SQLKPI.Generator" |
| 31 | + set classObj.Super = "%DeepSee.KPI" |
| 32 | + set classObj.Description = "This kpi class was automatically generated by SQLkpi utility." |
| 33 | + } else { |
| 34 | + set classObj = ##class(%Dictionary.ClassDefinition).%OpenId(class) |
| 35 | + do classObj.XDatas.Clear() |
| 36 | + } |
| 37 | + |
| 38 | + set kpi = ##class(%Dictionary.XDataDefinition).%New(class _ ":kpi") |
| 39 | + set kpi.XMLNamespace = "http://www.intersystems.com/deepsee/kpi" |
| 40 | + |
| 41 | + set header = ##class(%Dictionary.XDataDefinition).IDKEYOpen($classname(), "kpi").Data.Read(10000) |
| 42 | + do ..ReplaceRegexp(.header, "!!!1!!!", name) |
| 43 | + do ..ReplaceRegexp(.header, "!!!2!!!", sql) |
| 44 | + do kpi.Data.WriteLine(header) |
| 45 | + |
| 46 | + set st = ##class(%SQL.Statement).%New() |
| 47 | + set sc = st.%Prepare(sql) |
| 48 | + quit:$$$ISERR(sc) sc |
| 49 | + |
| 50 | + #dim result As %SQL.StatementResult |
| 51 | + set result = st.%Execute() |
| 52 | + |
| 53 | + #dim metadata As SQL.StatementMetadata |
| 54 | + set metadata = result.%GetMetadata() |
| 55 | + set columnCount = metadata.columns.Count() |
| 56 | + for i=1:1:columnCount { |
| 57 | + #dim column As %SQL.StatementColumn |
| 58 | + set column = metadata.columns.GetAt(i) |
| 59 | + do kpi.Data.WriteLine("<property name=""" _ column.colName _ """/>") |
| 60 | + } |
| 61 | + do kpi.Data.Write("</kpi>") |
| 62 | + |
| 63 | + do classObj.XDatas.Insert(kpi) |
| 64 | + |
| 65 | + set sc = classObj.%Save() |
| 66 | + return:$$$ISERR(sc) sc |
| 67 | + return $System.OBJ.Compile(class, "cuks /displaylog=0 /displayerror=0") |
| 68 | +]]></Implementation> |
| 69 | +</Method> |
| 70 | + |
| 71 | +<Method name="ReplaceRegexp"> |
| 72 | +<Description> |
| 73 | +Replaces all occurances of Pattern with ReplacePattern. |
| 74 | +w $System.Status.GetErrorText(##class(SQLKPI.Generator).ReplaceRegexp(.Text))</Description> |
| 75 | +<ClassMethod>1</ClassMethod> |
| 76 | +<FormalSpec><![CDATA[&Text,Pattern:%String="",ReplacePattern:%String=""]]></FormalSpec> |
| 77 | +<ReturnType>%Status</ReturnType> |
| 78 | +<Implementation><![CDATA[ |
| 79 | + #Dim Matcher As %Regex.Matcher = ##class(%Regex.Matcher).%New(Pattern, Text) |
| 80 | + Set Text = Matcher.ReplaceAll(ReplacePattern) |
| 81 | + Quit Matcher.Status |
| 82 | +]]></Implementation> |
| 83 | +</Method> |
6 | 84 | </Class>
|
7 | 85 | </Export>
|
0 commit comments