Skip to content

Commit d634e45

Browse files
committed
added sample spatialindex.test
initial dummy/demo versions of custom index and custom find
1 parent 6daebed commit d634e45

File tree

4 files changed

+247
-2
lines changed

4 files changed

+247
-2
lines changed

SpatialIndex_DataParser.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<Export generator="Cache" version="25" zv="Cache for Windows (x86-64) 2015.3 (Build 215U)" ts="2015-09-18 03:21:40">
2+
<Export generator="Cache" version="25">
33
<Class name="SpatialIndex.DataParser">
44
<Super>%RegisteredObject</Super>
5-
<TimeChanged>63813,11950.513682</TimeChanged>
65
<TimeCreated>63813,11943.491744</TimeCreated>
76

87
<Parameter name="fileName">

SpatialIndex_Index.xml

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Export generator="Cache" version="25">
3+
<Class name="SpatialIndex.Index">
4+
<Super>%Library.FunctionalIndex</Super>
5+
<TimeCreated>63812,71450.004249</TimeCreated>
6+
7+
<Method name="DeleteIndex">
8+
<Description>
9+
This method is invoked when an existing instance of a class is deleted.</Description>
10+
<ClassMethod>1</ClassMethod>
11+
<CodeMode>generator</CodeMode>
12+
<FormalSpec>pID:%CacheString,pArg...:%Binary</FormalSpec>
13+
<ServerOnly>1</ServerOnly>
14+
<Implementation><![CDATA[$$$GENERATE($C(9)_"write ""in delete""")
15+
]]></Implementation>
16+
</Method>
17+
18+
<Method name="Find">
19+
<ClassMethod>1</ClassMethod>
20+
<CodeMode>generator</CodeMode>
21+
<FormalSpec>rect:%Binary</FormalSpec>
22+
<ReturnType>%Library.Binary</ReturnType>
23+
<SqlProc>1</SqlProc>
24+
<ServerOnly>1</ServerOnly>
25+
<Implementation><![CDATA[
26+
$$$GENERATE($C(9)_"set result = ##class(SpatialIndex.SQLResult).%New()")
27+
$$$GENERATE($C(9)_"do result.PrepareFind(rect)")
28+
$$$GENERATE($C(9)_"quit result")
29+
]]></Implementation>
30+
</Method>
31+
32+
<Method name="InsertIndex">
33+
<Description>
34+
This method is invoked when a new instance of a class is inserted into the database.</Description>
35+
<ClassMethod>1</ClassMethod>
36+
<CodeMode>generator</CodeMode>
37+
<FormalSpec>pID:%CacheString,pArg...:%Binary</FormalSpec>
38+
<ServerOnly>1</ServerOnly>
39+
<Implementation><![CDATA[
40+
if %mode'="method" {
41+
set IndexGlobal = ..IndexLocation(%class,%property)
42+
$$$GENERATE($C(9)_"set indexer = ##class(SpatialIndex.Indexer).%New($Name("_IndexGlobal_"))")
43+
$$$GENERATE($C(9)_"do indexer.Insert(pArg(1),pArg(2),pID)")
44+
}
45+
]]></Implementation>
46+
</Method>
47+
48+
<Method name="PurgeIndex">
49+
<ClassMethod>1</ClassMethod>
50+
<CodeMode>generator</CodeMode>
51+
<ServerOnly>1</ServerOnly>
52+
<Implementation><![CDATA[
53+
if %mode'="method" {
54+
set IndexGlobal = ..IndexLocation(%class,%property)
55+
$$$GENERATE($C(9)_"kill " _ IndexGlobal)
56+
}
57+
]]></Implementation>
58+
</Method>
59+
60+
<Method name="UpdateIndex">
61+
<Description>
62+
This method is invoked when an existing instance of a class is updated.</Description>
63+
<ClassMethod>1</ClassMethod>
64+
<CodeMode>generator</CodeMode>
65+
<FormalSpec>pID:%CacheString,pArg...:%Binary</FormalSpec>
66+
<ServerOnly>1</ServerOnly>
67+
<Implementation><![CDATA[$$$GENERATE($C(9)_"write ""in UpdateIndex""")
68+
]]></Implementation>
69+
</Method>
70+
71+
<Method name="SortBeginIndex">
72+
<ClassMethod>1</ClassMethod>
73+
<CodeMode>generator</CodeMode>
74+
<ServerOnly>1</ServerOnly>
75+
<Implementation><![CDATA[$$$GENERATE($C(9)_"set a = 0")
76+
]]></Implementation>
77+
</Method>
78+
79+
<Method name="SortEndIndex">
80+
<ClassMethod>1</ClassMethod>
81+
<CodeMode>generator</CodeMode>
82+
<FormalSpec>pCommit:%Integer=1</FormalSpec>
83+
<ServerOnly>1</ServerOnly>
84+
<Implementation><![CDATA[$$$GENERATE($C(9)_"set a = 0")
85+
]]></Implementation>
86+
</Method>
87+
88+
<Method name="IndexLocation">
89+
<ClassMethod>1</ClassMethod>
90+
<FormalSpec>className:%String,indexName:%String</FormalSpec>
91+
<ReturnType>%String</ReturnType>
92+
<Implementation><![CDATA[quit $Name(^TestGlobal(className, indexName))
93+
]]></Implementation>
94+
</Method>
95+
</Class>
96+
</Export>

SpatialIndex_SQLResult.xml

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Export generator="Cache" version="25">
3+
<Class name="SpatialIndex.SQLResult">
4+
<Super>%SQL.AbstractFind</Super>
5+
<TimeCreated>63812,80595.195041</TimeCreated>
6+
7+
<Property name="ResultBits">
8+
<MultiDimensional>1</MultiDimensional>
9+
<Private>1</Private>
10+
</Property>
11+
12+
<Method name="%OnNew">
13+
<Private>1</Private>
14+
<ReturnType>%Status</ReturnType>
15+
<ServerOnly>1</ServerOnly>
16+
<Implementation><![CDATA[
17+
kill i%ResultBits
18+
quit $$$OK
19+
]]></Implementation>
20+
</Method>
21+
22+
<Method name="PrepareFind">
23+
<FormalSpec>rect:%Binary</FormalSpec>
24+
<ReturnType>%Status</ReturnType>
25+
<Implementation><![CDATA[
26+
set str = ""
27+
set $BIT(str,10 + 1) = 1
28+
set $BIT(str,15 + 1) = 1
29+
set $BIT(str,17 + 1) = 1
30+
set i%ResultBits = 1
31+
set i%ResultBits(1) = str
32+
quit $$$OK
33+
]]></Implementation>
34+
</Method>
35+
36+
<Method name="ContainsItem">
37+
<FormalSpec>pItem:%String</FormalSpec>
38+
<ReturnType>%Boolean</ReturnType>
39+
<Implementation><![CDATA[
40+
set tChunk = (pItem\64000)+1, tPos=(pItem#64000)+1
41+
quit $bit($g(i%ResultBits(tChunk)),tPos)
42+
]]></Implementation>
43+
</Method>
44+
45+
<Method name="GetChunk">
46+
<FormalSpec>pChunk:%Integer</FormalSpec>
47+
<ReturnType>%Binary</ReturnType>
48+
<Implementation><![CDATA[quit $g(i%ResultBits(pChunk))
49+
]]></Implementation>
50+
</Method>
51+
52+
<Method name="NextChunk">
53+
<FormalSpec><![CDATA[&pChunk:%Integer=""]]></FormalSpec>
54+
<ReturnType>%Binary</ReturnType>
55+
<Implementation><![CDATA[
56+
set pChunk = $order(i%ResultBits(pChunk),1,tBits)
57+
quit:pChunk="" ""
58+
quit tBits
59+
]]></Implementation>
60+
</Method>
61+
62+
<Method name="PreviousChunk">
63+
<FormalSpec><![CDATA[&pChunk:%Integer=""]]></FormalSpec>
64+
<ReturnType>%Binary</ReturnType>
65+
<Implementation><![CDATA[
66+
set pChunk = $order(i%ResultBits(pChunk),-1,tBits)
67+
quit:pChunk="" ""
68+
quit tBits
69+
]]></Implementation>
70+
</Method>
71+
</Class>
72+
</Export>

SpatialIndex_Test.xml

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Export generator="Cache" version="25">
3+
<Class name="SpatialIndex.Test">
4+
<Super>%Persistent</Super>
5+
<TimeCreated>63812,70763.114831</TimeCreated>
6+
7+
<Property name="Name">
8+
<Type>%String</Type>
9+
<Parameter name="MAXLEN" value="300"/>
10+
</Property>
11+
12+
<Property name="Latitude">
13+
<Type>%String</Type>
14+
</Property>
15+
16+
<Property name="Longitude">
17+
<Type>%String</Type>
18+
</Property>
19+
20+
<Index name="x1F">
21+
<Properties>Latitude,Longitude</Properties>
22+
<TypeClass>SpatialIndex.Index</TypeClass>
23+
</Index>
24+
25+
<Method name="load">
26+
<ClassMethod>1</ClassMethod>
27+
<FormalSpec>filename:%String="c:\temp\RUcut.txt"</FormalSpec>
28+
<Implementation><![CDATA[
29+
do ..%KillExtent()
30+
do $system.Process.SetZEOF(1)
31+
open filename:"R"
32+
for {
33+
use filename read line
34+
quit:$ZEOF=-1
35+
set columnList = $ListFromString(line," ")
36+
set p = ..%New()
37+
set p.Name = $List(columnList, 2)
38+
set p.Latitude=$List(columnList,5)
39+
set p.Longitude=$List(columnList,6)
40+
set ec = p.%Save()
41+
if 'ec {
42+
use $Principal zw ec
43+
}
44+
}
45+
close filename
46+
]]></Implementation>
47+
</Method>
48+
49+
<Storage name="Default">
50+
<Type>%Library.CacheStorage</Type>
51+
<DataLocation>^SpatialIndex.TestD</DataLocation>
52+
<DefaultData>TestDefaultData</DefaultData>
53+
<IdLocation>^SpatialIndex.TestD</IdLocation>
54+
<IndexLocation>^SpatialIndex.TestI</IndexLocation>
55+
<StreamLocation>^SpatialIndex.TestS</StreamLocation>
56+
<Data name="TestDefaultData">
57+
<Value name="1">
58+
<Value>%%CLASSNAME</Value>
59+
</Value>
60+
<Value name="2">
61+
<Value>Name</Value>
62+
</Value>
63+
<Value name="3">
64+
<Value>X</Value>
65+
</Value>
66+
<Value name="4">
67+
<Value>Y</Value>
68+
</Value>
69+
<Value name="5">
70+
<Value>Latitude</Value>
71+
</Value>
72+
<Value name="6">
73+
<Value>Longitude</Value>
74+
</Value>
75+
</Data>
76+
</Storage>
77+
</Class>
78+
</Export>

0 commit comments

Comments
 (0)