-
Notifications
You must be signed in to change notification settings - Fork 14
/
navigate.xml
executable file
·159 lines (150 loc) · 6.88 KB
/
navigate.xml
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="navigate">
<select id="navigate" resultType="java.util.LinkedHashMap" >
select nhdplus_navigation.navigate_cached(
pnavigationtype := <choose><when test="navigationMode != null">#{navigationMode,jdbcType=VARCHAR}</when><otherwise>null</otherwise></choose>
,pstartcomid := <choose><when test="comid != null">#{comid,jdbcType=NUMERIC}</when><otherwise>null</otherwise></choose>
,pstartpermanentidentifier := null
,pstartreachcode := null
,pstartmeasure := null
,pstopcomid := <choose><when test="stopComid != null">#{stopComid,jdbcType=NUMERIC}</when><otherwise>null</otherwise></choose>
,pstoppermanentidentifier := null
,pstopreachcode := null
,pstopmeasure := null
,pmaxdistancekm := <choose><when test="distance != null">#{distance,jdbcType=NUMERIC}</when><otherwise>null</otherwise></choose>
,pmaxflowtimehour := null
,pdebug := 'FALSE'
,paddflowlineattributes := 'FALSE'
,paddflowlinegeometry := 'FALSE'
);
</select>
<select id="getCache" resultType="String">
select min(session_id) session_id
from nhdplus_navigation.navigation_cache_status
where return_code = 0 and
start_comid = #{comid} and
navigation_mode = #{navigationMode}
<choose>
<when test="null != distance">
and max_distance = #{distance}
</when>
<otherwise>
and max_distance is null
</otherwise>
</choose>
<choose>
<when test="null != stopComid">
and stop_comid = #{stopComid}
</when>
<otherwise>
and stop_comid is null
</otherwise>
</choose>
</select>
<sql id="core">
<choose>
<when test="navigationMode == 'DM'">
<include refid="navigate.DM"/>
</when>
<when test="navigationMode == 'DD'">
<include refid="navigate.DD"/>
</when>
<when test="navigationMode == 'UM'">
<include refid="navigate.UM"/>
</when>
<when test="navigationMode == 'UT'">
<include refid="navigate.UT"/>
</when>
</choose>
</sql>
<sql id="DM">
with
recursive nav(comid, terminalpathid, dnhydroseq, stoplength)
as (select comid, terminalpathid, dnhydroseq,
pathlength + lengthkm <if test="null != distance">- #{distance}</if> stoplength
from nhdplus.plusflowlinevaa_np21
where comid = #{comid,jdbcType=NUMERIC}
union
select x.comid, x.terminalpathid, x.dnhydroseq, nav.stoplength
from nhdplus.plusflowlinevaa_np21 x,
nav
where x.hydroseq = nav.dnhydroseq and
x.terminalpathid = nav.terminalpathid
<if test="null != distance">
and x.pathlength + x.lengthkm >= nav.stoplength
</if>
),
navigation_results
as (select comid
from nav
)
</sql>
<sql id="DD">
with
recursive nav(comid, dnhydroseq, dnminorhyd, stoplength, terminalflag)
as (select comid, dnhydroseq, dnminorhyd,
pathlength + lengthkm <if test="null != distance">- #{distance}</if> stoplength,
terminalflag
from nhdplus.plusflowlinevaa_np21
where comid = #{comid,jdbcType=NUMERIC}
union
select x.comid, x.dnhydroseq, x.dnminorhyd, nav.stoplength, x.terminalflag
from nhdplus.plusflowlinevaa_np21 x,
nav
where (x.hydroseq = nav.dnhydroseq or
(nav.dnminorhyd != 0 and
x.hydroseq = nav.dnminorhyd)) and
nav.terminalflag != 1
<if test="null != distance">
and x.pathlength + x.lengthkm >= nav.stoplength
</if>
),
navigation_results
as (select comid
from nav
)
</sql>
<sql id="UM">
with
recursive nav(comid, levelpathid, uphydroseq, stoplength)
as (select comid, levelpathid, uphydroseq,
pathlength + 0 <if test="null != distance">+ #{distance}</if> stoplength
from nhdplus.plusflowlinevaa_np21
where comid = #{comid,jdbcType=NUMERIC}
union all
select x.comid, x.levelpathid, x.uphydroseq, nav.stoplength
from nhdplus.plusflowlinevaa_np21 x,
nav
where x.hydroseq = nav.uphydroseq and
x.levelpathid = nav.levelpathid
<if test="null != distance">
and x.pathlength <= nav.stoplength
</if>
),
navigation_results
as (select comid
from nav
)
</sql>
<sql id="UT">
with
recursive navigation_results(comid, hydroseq, startflag, stoplength)
as (select comid, hydroseq, startflag,
pathlength + 0 <if test="null != distance">+ #{distance}</if> stoplength
from nhdplus.plusflowlinevaa_np21
where comid = #{comid,jdbcType=NUMERIC}
union
select x.comid, x.hydroseq, x.startflag, navigation_results.stoplength
from nhdplus.plusflowlinevaa_np21 x,
navigation_results
where navigation_results.startflag != 1 and
(x.dnhydroseq = navigation_results.hydroseq or
(x.dnminorhyd != 0 and
x.dnminorhyd = navigation_results.hydroseq))
<if test="null != distance">
and x.pathlength <= navigation_results.stoplength
</if>
)
</sql>
</mapper>