ClusterInfo.java
3.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
/*
* @(#)ClusterInfo.java 1.4.4,26 custom 26/05/2010
*
* Built automatically by REVERSER
*/
package it.softecspa.fileproxy.db;
import it.softecspa.database.dbconnect.ConnectionManager;
import it.softecspa.database.dbconnect.DatabaseStatement;
import it.softecspa.database.dbconnect.NoRecordFoundException;
import it.softecspa.database.dbconnect.Query;
import it.softecspa.fileproxy.db.criterias.ClusterInfoCriteria;
import it.softecspa.kahuna.sql.SqlWriter;
import java.sql.SQLException;
/**
* Customizable manager for table T005_CLUSTER_INFO
* Class auto generated by REVERSER, version 1.4.4,26 custom
*
* @author il Vera
*/
public class ClusterInfo extends it.softecspa.fileproxy.db.skins.ClusterInfoSkin {
private static final UpdateType START = new UpdateType();
private static final UpdateType HEARTBEAT = new UpdateType();
private static final UpdateType STOP = new UpdateType();
private int beatCount;
public ClusterInfo() {
super();
this.doNotUse = false;
}
/**
* Extract bean using key
*/
public ClusterInfo(ConnectionManager cm, String context, String hostname) throws NoRecordFoundException, SQLException {
super(cm, context, hostname);
}
/**
* Execute select * with criteria
* @throws SQLException if there is an error in your query
*/
public static ClusterInfo[] select(ClusterInfoCriteria criteria) throws SQLException {
SqlWriter sql = criteria.getSelect();
return (ClusterInfo[])(new ClusterInfo()).getRows(criteria.getConnectionManager(), sql.costruisciSelect());
}
/**
* Customizable update method
* @param updateType operation to execute
* @param dbs DatabaseStatement that perform operation
* @return number of update rows or new autoincrement id
* @throws SQLException if there is an error in your query
*/
public int updateRecord(UpdateType updateType, DatabaseStatement dbs) throws SQLException {
// Custom UPDATE
if (updateType == START) {
this.lifeStop = null;
if (super.updateRecord(UPDATE, dbs)==0) {
super.updateRecord(INSERT, dbs);
return -1;
}
return 1;
} else if (updateType == HEARTBEAT) {
dbs.hideQueryLog();
SqlWriter sql = new SqlWriter();
sql.setTables(NAME);
sql.addColumnSET("d_last_beat" , Query.toSQLDateTime(this.lastBeat));
sql.addColumnSET("d_record" , Query.toSQL(Query.getFunCurrentDateTime(dbs.getDBMS())));
sql.addWhere("v_hostname = " + sql.fStr(this.hostname));
sql.addWhere("v_context = " + sql.fStr(this.context));
return dbs.execute(sql.costruisciUpdate());
} else if (updateType == STOP) {
SqlWriter sql = new SqlWriter();
sql.setTables(NAME);
sql.addColumnSET("d_life_stop" , Query.toSQLDateTime(this.lifeStop));
sql.addColumnSET("d_record" , Query.toSQL(Query.getFunCurrentDateTime(dbs.getDBMS())));
sql.addWhere("v_hostname = " +sql.fStr(this.hostname));
sql.addWhere("v_context = " + sql.fStr(this.context));
return dbs.execute(sql.costruisciUpdate());
}
// Insert here your custom code
return super.updateRecord(updateType, dbs);
}
public final int lifeStart(ConnectionManager cm) throws SQLException {
int ret = updateRecord(cm, START);
if (ret<0) {
// Ricarico i dati dopo l'inserimento per recuperare tutti i valori
ClusterInfoCriteria filter = new ClusterInfoCriteria(cm);
filter.setContext(context);
filter.setHostname(hostname);
readRow(cm, filter.getSelect().costruisciSelect());
ret = 1;
}
//
return ret;
}
public final int heartBeat(ConnectionManager cm) throws SQLException {
return updateRecord(cm, HEARTBEAT);
}
public final int lifeStop(ConnectionManager cm) throws SQLException {
return updateRecord(cm, STOP);
}
public int getBeatCount() {
return beatCount;
}
public void resetBeatCount() {
this.beatCount = 0;
}
public int addBeatCount() {
return ++beatCount;
}
}