File D:\maven-qcr-plugin-testsunitaires\qcr4java\h2-1.3.170-sources\target\site\qc\lecode\engine\SessionWithState.java.html

1 /*
2 * Copyright 2004-2011 H2 Group. Multiple-Licensed under the H2 License,
3 * Version 1.0, and under the Eclipse Public License, Version 1.0
4 * (http://h2database.com/html/license.html).
5 * Initial Developer: H2 Group
6 */
7 package org.h2.engine;
8
9 import java.util.ArrayList;
10 import org.h2.command.CommandInterface;
11 import org.h2.result.ResultInterface;
12 import org.h2.util.New;
13 import org.h2.value.Value;
14
15 /**
16 * The base class for both remote and embedded sessions.
17 */
18 abstract class SessionWithState implements SessionInterface {
19
20 protected ArrayList<String> sessionState;
21 protected boolean sessionStateChanged;
22 private boolean sessionStateUpdating;
23
24 /**
25 * Re-create the session state using the stored sessionState list.
26 */
27 protected void recreateSessionState() {
28 if (sessionState != null && sessionState.size() > 0) {
29 sessionStateUpdating = true;
30 try {
31 for (String sql : sessionState) {
32 CommandInterface ci = prepareCommand(sql, Integer.MAX_VALUE);
33 ci.executeUpdate();
34 }
35 } finally {
36 sessionStateUpdating = false;
37 sessionStateChanged = false;
38 }
39 }
40 }
41
42 /**
43 * Read the session state if necessary.
44 */
45 public void readSessionState() {
46 if (!sessionStateChanged || sessionStateUpdating) {
47 return;
48 }
49 sessionStateChanged = false;
50 sessionState = New.arrayList();
51 CommandInterface ci = prepareCommand("SELECT * FROM INFORMATION_SCHEMA.SESSION_STATE", Integer.MAX_VALUE);
52 ResultInterface result = ci.executeQuery(0, false);
53 while (result.next()) {
54 Value[] row = result.currentRow();
55 sessionState.add(row[1].getString());
56 }
57 }
58
59 }
60