Subversion Repositories SmartDukaan

Rev

Rev 5536 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
5519 amar.kumar 1
<?xml version="1.0" encoding="UTF-8"?>
2
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" 
3
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
4
 
5
<mapper namespace="in.shop2020.alert.persistence.EntityMapper">
6
<resultMap type="monitored_entity" id="monitored_entityResult">
7
		<id property="id" column="id"/>
8
	</resultMap>
9
 
10
<select id="isEntityMonitorable" parameterType="int" resultType="boolean">
11
	SELECT isActive
12
	FROM entity_monitoring_status
13
	<where>
14
        entityType = #{entityType}
15
	</where>
16
</select>
17
 
18
<insert id="insertEntity" parameterType="monitored_entity" useGeneratedKeys="true" keyProperty="id">
19
	INSERT INTO monitored_entity
20
		(entityType, eventType, entityIdentifier, warnExpiryTime, criticalExpiryTime, entityProperties, entityProcessedState)
21
    VALUES
22
      (#{entityType}, #{eventType}, #{entityIdentifier}, #{warnExpiryTime}, #{criticalExpiryTime}, #{entityProperties}, 1)
23
</insert>
24
 
25
<update id="updateEntity" parameterType="monitored_entity">
26
	UPDATE monitored_entity
27
      SET eventType=#{eventType}, warnExpiryTime=#{warnExpiryTime}, 
28
      	criticalExpiryTime=#{criticalExpiryTime}, 
29
      	entityProperties=#{entityProperties} 
30
	<where>
31
  		id = #{id}
32
  	</where>   	
33
</update>
34
 
35
<!--  select id="isEntityMonitorable" parameterType="int" resultType="int">
36
	SELECT ISNULL((SELECT 1 FROM entity_monitoring_status WHERE entityType = entityType AND isActive = true), 0)
37
</select-->
38
 
39
<select id="getEntity" parameterType="map" resultType="monitored_entity">
40
	SELECT * 
41
	FROM monitored_entity
42
	<where>
43
  		 entityType = #{entityType}
44
  		 AND entityIdentifier = #{entityIdentifier}
45
  	</where>
46
</select>
47
 
48
<insert id="insertAlertedEntity" parameterType="map" useGeneratedKeys="true" keyProperty="id">
49
	INSERT INTO alerted_entity
50
      (entityType, eventType, entityIdentifier, lastAlertedTime, entityProperties, entityProcessedState)
51
    VALUES
52
      (#{entityType}, #{eventType}, #{entityIdentifier}, #{lastAlertedTime}, #{entityProperties}, #{entityProcessedState})
53
</insert>
54
 
55
<delete id="removeMonitoredEntity" parameterType="map">
56
	DELETE FROM monitored_entity
57
	<where>
58
  		 entityType = #{entityType}
59
  		 AND entityIdentifier = #{entityIdentifier}
60
  	</where>
61
</delete>
62
 
63
<select id="getEntitiesToBeAlerted" resultType="monitored_entity">
64
	SELECT * 
65
	FROM monitored_entity
66
	<where>
67
  		 (warnExpiryTime &lt;= NOW()
68
  		 AND entityProcessedState &lt; 1)
69
  		 OR (criticalExpiryTime &lt;= NOW()
70
  		 AND entityProcessedState &lt; 2)
71
  	</where>
72
</select>
73
 
74
<update id="updateEntityProcessedState" parameterType="map">
75
	UPDATE monitored_entity
76
      SET entityProcessedState=#{state}
77
	<where>
78
  		id = #{id}
79
  	</where>   	
80
</update>
81
 
82
<select id="getEntities" parameterType="searchFilter" resultType="monitored_entity">
83
	SELECT * from monitored_entity
84
	<where>
85
    <if test="entityType != 0">
86
        AND entityType = #{entityType}
87
    </if>
88
    <if test="eventType != null">
89
        AND eventType = #{eventType}
90
    </if>
91
    <if test="entityIdentifier != null">
92
        AND entityIdentifier = #{entityIdentifier}
93
    </if>
94
    <if test="entityProcessedState != null">
95
        AND entityProcessedState = #{entityProcessedState}
96
    </if>
97
    </where>
98
</select>
99
 
100
<select id="getAlertedEntities" parameterType="searchFilter" resultType="alerted_entity">
101
	SELECT * from alerted_entity
102
	<where>
103
    <if test="entityType != null">
104
        AND entityType = #{entityType}
105
    </if>
106
    <if test="eventType != null">
107
        AND eventType = #{eventType}
108
    </if>
109
    <if test="entityIdentifier != null">
110
        AND entityIdentifier = #{entityIdentifier}
111
    </if>
112
    <if test="entityProcessedState != null">
113
        AND entityProcessedState = #{entityProcessedState}
114
    </if>
115
    </where>
116
</select>
117
 
118
<select id="getAlertMapper" parameterType="map" resultType="alert_mapper">
119
	SELECT * 
120
	FROM alert_mapper
121
	<where>
122
  		 entityType = #{entityType}
123
  		 AND eventType = #{eventType}
124
  	</where>
125
  	LIMIT 1
126
</select>
127
 
128
<update id="activateEntityMonitoring" parameterType="map">
129
	UPDATE entity_monitoring_status 
130
	SET isActive = true
131
	AND defaultAlertGroup = #{userIds}
132
	<where>
133
  		 entityType = #{entityType}
134
  	</where>
135
</update>
136
 
137
<update id="deActivateEntityMonitoring" parameterType="map">
138
	UPDATE entity_monitoring_status 
139
	SET isActive = 0
140
	<where>
141
  		 entityType = #{entityType}
142
  	</where>
143
</update>
144
 
145
<insert id="registerEventType" parameterType="alert_mapper">
146
	INSERT INTO alert_mapper
147
      (entityType, eventType, eventDescription, userIds, alertType)
148
    VALUES
149
      (#{entityType}, #{eventType}, #{eventDescription}, #{userIds}, #{alertType})
150
</insert>
151
 
152
</mapper>