All Downloads are FREE. Search and download functionalities are using the official Maven repository.

mybatis.uudb-pool-common.xml Maven / Gradle / Ivy

There is a newer version: 2.10.3
Show newest version
<?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="eu.unicore.xuudb.server.db.UudbPoolMapper">

	<select id="getAliveMapping" resultType="eu.unicore.xuudb.server.db.MappingBean">
		select id, entry from UUDB_POOL_ENTRIES 
		where pool = #{pool} AND poolKey = #{key} AND freezeTime IS NULL
	</select>
	
	<select id="getFrozenMappings" resultType="eu.unicore.xuudb.server.db.MappingBean">
		select id, entry from UUDB_POOL_ENTRIES 
		where pool = #{pool} AND poolKey = #{key} AND freezeTime IS NOT NULL
	</select>
	
	<update id="updateAccessTime">
		UPDATE UUDB_POOL_ENTRIES SET lastAccess = NOW() 
		WHERE id = #{id}
	</update>
 
	<select id="getFreeMapping" resultType="eu.unicore.xuudb.server.db.MappingBean">
		select id, entry from UUDB_POOL_ENTRIES 
		WHERE pool = #{pool} AND poolKey IS NULL 
		LIMIT 1 
	</select>

	<update id="addMapping">
		UPDATE UUDB_POOL_ENTRIES SET poolKey = #{key}, lastAccess = NOW()
		WHERE id = #{id}
	</update>

	<select id="getInactiveMappings" resultType="eu.unicore.xuudb.server.db.MappingBean">
		SELECT id, entry, lastAccess FROM UUDB_POOL_ENTRIES 
		WHERE freezeTime IS NULL AND pool= #{pool} AND lastAccess &lt; #{since} AND poolKey IS NOT NULL
	</select>

	<update id="freezeMapping">
		UPDATE UUDB_POOL_ENTRIES SET freezeTime = NOW() 
		WHERE id = #{id}
	</update>

	<select id="getOldMappings" resultType="eu.unicore.xuudb.server.db.MappingBean">
		SELECT id, entry, freezeTime FROM UUDB_POOL_ENTRIES 
		WHERE freezeTime IS NOT NULL AND pool= #{pool} AND freezeTime &lt; #{since} AND poolKey IS NOT NULL
	</select>

	<update id="removeMapping">
		UPDATE UUDB_POOL_ENTRIES SET freezeTime = NULL, lastAccess = NULL, poolKey = NULL  
		WHERE id = #{id}
	</update>

	<select id="countOccupiedMappings" resultType="long">
		SELECT COUNT(*) FROM UUDB_POOL_ENTRIES 
		WHERE pool = #{pool} and poolKey IS NOT NULL
	</select>

	<select id="getMappings" resultType="eu.unicore.xuudb.server.db.MappingBean">
		<include refid="getMappingsSelect"/> 
		<where>
			<if test="status != null &amp;&amp; status == 'live'"> 	UUDB_POOL_ENTRIES.freezeTime IS NULL </if> 
			<if test="status != null &amp;&amp; status == 'frozen'"> 	UUDB_POOL_ENTRIES.freezeTime IS NOT NULL </if>
			<if test="pool != null"> 						AND UUDB_POOL_ENTRIES.pool = #{pool} </if>
			AND UUDB_POOL_ENTRIES.pool = UUDB_POOLS.id
			AND UUDB_POOL_ENTRIES.poolKey IS NOT NULL
		</where>
	</select>

	<select id="findMappingsByValue" resultType="eu.unicore.xuudb.server.db.MappingBean">
		<include refid="getMappingsSelect"/> 
		WHERE 
			UUDB_POOL_ENTRIES.entry = #{value} AND
			UUDB_POOL_ENTRIES.pool = UUDB_POOLS.id AND
			UUDB_POOLS.valueType = #{valueType}
	</select>

	<select id="findMappingsByKey" resultType="eu.unicore.xuudb.server.db.MappingBean">
		<include refid="getMappingsSelect"/> 
		WHERE 
			UUDB_POOLS.keyType = #{keyType} AND
			UUDB_POOL_ENTRIES.poolKey = #{key} AND
			UUDB_POOL_ENTRIES.pool = UUDB_POOLS.id
	</select>

	<insert id="populatePool" useGeneratedKeys="true">
		INSERT INTO UUDB_POOL_ENTRIES (pool, entry, lastAccess) 
		VALUES (#{pool}, #{entry}, NOW())
	</insert>

	<insert id="createPool" parameterType="eu.unicore.xuudb.server.db.MappingBean" 
						useGeneratedKeys="true" keyProperty="id">
		INSERT INTO UUDB_POOLS (name, keyType, valueType) 
		VALUES (#{poolName}, #{mappingKeyType}, #{mappingValueType})
	</insert>

	<delete id="removePool">
		DELETE FROM UUDB_POOLS WHERE name = #{poolName}
	</delete>
	
	<select id="checkPoolExistence" resultType="eu.unicore.xuudb.server.db.MappingBean">
		select id, keyType AS mappingKeyType, valueType AS mappingValueType from UUDB_POOLS where name = #{pool}
	</select>
	
	<select id="listPools" resultType="eu.unicore.xuudb.server.db.PoolInfoBean">
		SELECT a.NAME AS poolName, a.keyType AS poolKeyType, a.valueType AS poolType, ALIVEMAPPINGS, FROZENMAPPINGS, FREESLOTS
 			FROM UUDB_POOLS a 
 			LEFT OUTER JOIN 
 				(SELECT POOL, COUNT(*) AS ALIVEMAPPINGS FROM UUDB_POOL_ENTRIES WHERE FREEZETIME IS NULL AND POOLKEY IS NOT NULL GROUP BY POOL) b 
 				ON b.pool = a.id
 			LEFT OUTER JOIN 
 				(SELECT POOL, COUNT(*) AS FROZENMAPPINGS FROM UUDB_POOL_ENTRIES WHERE FREEZETIME IS NOT NULL GROUP BY POOL) c 
 				ON c.pool = a.id
 			LEFT OUTER JOIN 
 				(SELECT POOL, COUNT(*) AS FREESLOTS FROM UUDB_POOL_ENTRIES WHERE POOLKEY IS NULL GROUP BY POOL) d 
 				ON d.pool = a.id
	</select>

	<!-- reusable -->
	<sql id="getMappingsSelect">
		SELECT UUDB_POOL_ENTRIES.id, UUDB_POOL_ENTRIES.entry, UUDB_POOL_ENTRIES.freezeTime, 
			UUDB_POOL_ENTRIES.lastAccess, UUDB_POOL_ENTRIES.poolKey AS mappingKey, 
			UUDB_POOLS.name AS poolName, UUDB_POOLS.keyType AS mappingKeyType
		FROM UUDB_POOL_ENTRIES, UUDB_POOLS
	</sql>
</mapper>




© 2015 - 2024 Weber Informatics LLC | Privacy Policy