001: /*
002: * Created on May 2, 2003
003: *
004: * Dbmjui is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU General Public License version 2 as
006: * published by the Free Software Foundation.
007: *
008: * Dbmjui is distributed in the hope that it will be useful,
009: * but WITHOUT ANY WARRANTY; without even the implied warranty of
010: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
011: * General Public License for more details.
012: *
013: * You should have received a copy of the GNU General Public
014: * License along with dbmjui; see the file COPYING. If not,
015: * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
016: * Boston, MA 02111-1307, USA.
017: *
018: */
019: package fr.aliacom.dbmjui.components.instance;
020:
021: import org.apache.log4j.Logger;
022:
023: import com.sap.dbtech.powertoys.DBM;
024:
025: import fr.aliacom.dbmjui.DbInstance;
026: import fr.aliacom.dbmjui.DbState;
027: import fr.aliacom.dbmjui.beans.InstanceInformations;
028: import fr.aliacom.dbmjui.driver.IInstanceHelper;
029:
030: /**
031: * @author tom
032: *
033: * (c) 2001, 2003 Thomas Cataldo
034: */
035: public class InstanceHelper implements IInstanceHelper {
036:
037: private Logger logger;
038:
039: public InstanceHelper() {
040: logger = Logger.getLogger(InstanceHelper.class);
041: }
042:
043: public InstanceInformations updateInformations(DbInstance dbi) {
044: InstanceInformations ii = dbi.getInformations();
045: if (ii == null) {
046: ii = new InstanceInformations();
047: ii.setDbi(dbi);
048: }
049: int oldState = ii.getState();
050: int newState = oldState;
051: DBM aDbm = null;
052: try {
053: logger.debug("Reloading dbi state...");
054: aDbm = dbi.getPlainDbmConnection();
055: String[] lines = aDbm.cmd("db_state").split("\n");
056: logger.debug("lines[1]='" + lines[1] + "'");
057: if (lines[1].equals("WARM") || lines[1].equals("ONLINE")) {
058: newState = DbState.WARM_STATE;
059: } else if (lines[1].equals("COLD")
060: || lines[1].equals("ADMIN")) {
061: newState = DbState.COLD_STATE;
062: } else {
063: newState = DbState.STOP_STATE;
064: }
065: ii.setState(newState);
066: if (newState == DbState.WARM_STATE) {
067: aDbm.cmd("sql_connect");
068: lines = aDbm.cmd("info state").split("\n");
069: ii.setDataMax(parseIntLine(lines[19]));
070: ii.setData(parseIntLine(lines[3]));
071:
072: ii.setLogMax(parseIntLine(lines[20]));
073: ii.setLog(parseIntLine(lines[12]));
074:
075: ii.setSessionMax(parseIntLine(lines[23]));
076: ii.setSession(parseIntLine(lines[15]));
077: } else {
078: ii.setDataMax(0);
079: ii.setLogMax(0);
080: ii.setSessionMax(0);
081: ii.setData(0);
082: ii.setLog(0);
083: ii.setSession(0);
084: }
085: aDbm.release();
086: } catch (Exception e) {
087: logger.fatal(e);
088: }
089: return ii;
090: }
091:
092: private final int parseIntLine(String line) {
093: String values[] = line.split("=");
094: int ret = Integer.parseInt(values[1].trim());
095: return ret;
096: }
097:
098: /**
099: * Method isAutologEnabled.
100: * @return boolean
101: */
102: public boolean isAutologEnabled(DbInstance dbi) {
103: boolean ret = false;
104: try {
105: DBM dbm = dbi.getPlainDbmConnection();
106: String aLog = dbm.cmd("autolog_show");
107: dbm.release();
108: if (aLog.endsWith("ON")) {
109: ret = true;
110: }
111: } catch (Exception e) {
112: }
113: return ret;
114: }
115:
116: public void changeState(DbInstance dbi, int newState) {
117: try {
118: String cmd = "db_warm";
119: switch (newState) {
120: case DbState.COLD_STATE:
121: cmd = "db_cold -f";
122: break;
123: case DbState.WARM_STATE:
124: cmd = "db_warm -f";
125: break;
126: case DbState.STOP_STATE:
127: cmd = "db_stop";
128: break;
129: }
130: DBM dbm = dbi.getDbmConnection();
131: dbm.cmd(cmd);
132: dbm.release();
133: dbi.getInformations().setState(newState);
134: updateInformations(dbi);
135: } catch (Exception e) {
136: logger.fatal(e);
137: }
138: }
139:
140: }
|