365日アプリケーションブログ

一日一アプリケーションを構築することを目指すブログです。アプリケーションの種類は基本的に気まぐれです。

【20140422】【jQuery】ORA-01555体験アプリ

お題

ORA-01555を体験するためのアプリ

プログラム概要

UNDO領域内が0.5秒ごとに更新される。

0領域のデータに対してselectを投げ、(ボタンを押すだけ)

それから1秒以内に0領域が更新されれば、ORA-01555が発生する。

(selectは1秒かかる前提)

ソース

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
<title>ORA-01555体験アプリ</title>
<script src="http://code.jquery.com/jquery-1.8.2.min.js"></script>
<style>
img {
  width: 100px;
  height: 100px;
  margin: 0px;
}
body {
	background-color: yellow;
}
td {
	width: 50px;
	height: 50px;
	background-color: red;
}
</style>
</head>
<body background="">
<h3>UNDO領域</h3>
<table border="1">
<tr><td id="td0" align="center">0</td><td id="td1" align="center">1</td></tr>
<tr><td id="td3" align="center">3</td><td id="td2" align="center">2</td></tr>
</table>
<br>
<input type="button" id="button" value="0の領域のデータにselect">
<p>※UNDO内の各領域が0.5秒ごとに更新される前提です。<br> selectは1秒かかる前提です。<br> 従って、0領域が更新される1.0秒前までにselectを行う必要があります<br> でないとORA-01555が発生します。</p>
<script>
$(function() {
	var td0Color = "blue";
	undo();
	function undo(){
		var i = 0;
		var td;
		var $color = "blue";
		timerId1 = setInterval(function(){
			if(i == 4){
				i = 0;
				if($color == "blue") {
					$color = "red";
					//alert(i);
				} else {
					$color = "blue";
				}
			}
			td = "#td" + i;
			$(td).css("background-color", $color);
			if(i == 0) {
				td0Color = $color;
			}
			i++;
			//alert(i);
		},500);
	}
	
	$('#button').click(function() {
		var startColor = td0Color;
		var endColor;
		timerId2 = setInterval(function(){
			endColor = td0Color;
			if(startColor == endColor) {
				alert('成功');
				clearInterval(timerId2);
			} else {
				alert('ORA-01555: スナップショットが古すぎます');
				clearInterval(timerId2);
			}
		},1000);
	});
});
</script>
</body>
</html>

URL

ORA-01555体験アプリ