package de.webman.content.workflow.db;
import com.teamkonzept.db.*;
import com.teamkonzept.lib.*;
import de.webman.content.workflow.*;
import java.util.*;
import java.sql.*;
/**
haelt die Daten einer Transition, Implementierung von TKDBData
* @author $Author: doehling $
* @version $Revision: 1.2 $
*/
public class VersionStatusTransitionDBData extends TKDBData implements TKHashable
{
/** Der Event String (prefix) */
private static final String EVENT_STRING = "CE_SWITCH_EVENT";
/** Ausgangsstatus */
public int status_id;
/** Zielstatus */
public int new_status_id;
/** Attribute der transition */
public String transition_attributes;
/** Ausgangsstatus als String */
public String status;
/** Zielstatus als String */
public String new_status;
private String event;
/** +,-, ? */
public String mode;
/** steht fuer das l */
public boolean delete;
TKHashtable hashed;
/** Klasse des Ausgangsstatus */
public VersionStatus fromStatus;
/** Klasse des Zielstatus */
public VersionStatus toStatus;
public void init () {
status_id = -1;
new_status_id = -1;
transition_attributes = null;
status = null;
new_status = null;
mode = null;
delete = false;
hashed = null;
fromStatus = null;
toStatus = null;
event = null;
}
/**
liefert den Event zurueck, der diese
Transition ausloest
*/
public String getEvent()
{
if (event == null)
{
if (mode != null && mode.equals("+"))
event = EVENT_STRING + "_" + status_id + "_" + new_status_id;
else
event = "";
}
return event;
}
public boolean isTransition()
{
return mode.equals("+");
}
public VersionStatusTransitionDBData () {
this.init();
}
public VersionStatusTransitionDBData(
int status_id, int new_status_id, String transition_attributes)
{
this.init();
this.status_id = status_id;
this.new_status_id = new_status_id;
this.transition_attributes = transition_attributes;
this.scanAttributes();
}
public VersionStatusTransitionDBData(
VersionStatics statics,
int status_id, String status,
int new_status_id, String new_status,
String transition_attributes)
{
this.status_id = status_id;
this.new_status_id = new_status_id;
this.transition_attributes = transition_attributes;
this.status = status;
this.new_status = new_status;
resolveStatus (statics);
this.scanAttributes();
}
public VersionStatusTransitionDBData (VersionStatics statics, ResultSet r)
{
try { this.fill (statics, r); } catch (Exception ex) { this.init(); }
}
public VersionStatusTransitionDBData (ResultSet r) {
this (null,r);
}
public void insertPrimaryIntoQuery (TKQuery query) throws SQLException {
query.setQueryParams("STATUS_ID", new Integer(status_id));
query.setQueryParams("NEW_STATUS_ID", new Integer(new_status_id));
}
public void insertInitialIntoQuery (TKQuery query) throws SQLException {
query.setQueryParams("TRANSITION_ATTRIBUTES", transition_attributes);
}
public void insertIntoQuery (TKQuery query) throws SQLException
{
insertPrimaryIntoQuery (query);
insertInitialIntoQuery (query);
}
public void fill (VersionStatics statics, ResultSet r) throws SQLException
{
this.status_id = r.getInt("STATUS_ID");
this.new_status_id = r.getInt("NEW_STATUS_ID");
this.transition_attributes = r.getString("TRANSITION_ATTRIBUTES");
this.status = r.getString("STATUS");
this.new_status = r.getString("NEW_STATUS");
resolveStatus (statics);
this.scanAttributes();
}
public void fill (ResultSet r) throws SQLException
{
fill (null,r);
}
public void assembleAttributes ()
{
this.transition_attributes =
(this.mode == null ? "?" : this.mode) + ";" +
(this.delete ? "delete;" : "");
}
public void scanAttributes () {
mode = "?";
delete = false;
event = null;
if (transition_attributes == null) return;
StringTokenizer tokenizer = new StringTokenizer(transition_attributes,";");
while (tokenizer.hasMoreTokens())
{
String attr = tokenizer.nextToken();
if (attr == null)
continue;
if (attr.equalsIgnoreCase ("?")) mode = attr;
else if (attr.equalsIgnoreCase ("+")) mode = attr;
else if (attr.equalsIgnoreCase ("-")) mode = attr;
else if (attr.equalsIgnoreCase ("delete")) delete = true;
}
makeHashed();
}
public void resolveStatus (VersionStatics statics) {
if (statics == null)
return;
fromStatus = (VersionStatus) statics.getStatusPool().get(new Integer(this.status_id));
toStatus = (VersionStatus) statics.getStatusPool().get(new Integer(this.new_status_id));
rehashStatus();
}
public void rehashStatus ()
{
if (hashed == null)
{
makeHashed();
return;
}
if (fromStatus != null) hashed.put ("FROM",fromStatus.toHashtable());
if (toStatus != null) hashed.put ("TO",toStatus.toHashtable());
}
public void makeHashed () {
hashed = new TKHashtable();
hashed.put ("STATUS_ID",new Integer (status_id));
hashed.put ("NEW_STATUS_ID",new Integer (new_status_id));
if (status != null) hashed.put ("STATUS",status);
if (new_status != null) hashed.put ("NEW_STATUS",new_status);
hashed.put ("THIS_MODE",mode == null ? "?" : mode);
hashed.put ("ATTR.L",delete ? "ON" : "OFF");
hashed.put("EVENT", getEvent());
rehashStatus();
}
public TKHashtable toHashtable ()
{
if (hashed == null)
makeHashed();
// TKHashtable hash = new TKHashtable(); alex
return hashed;
}
public String toString()
{
return "( TRANSITION := "
+ "(STATUS_ID = " + String.valueOf( status_id )
+ ", NEW_STATUS_ID = " + String.valueOf( new_status_id )
+ ", TRANSITION_ATTRIBUTES = " + transition_attributes
+ ", STATUS = " + status
+ ", NEW_STATUS = " + new_status
+ ", MODE = " + mode
+ ", ATTR.l = " + delete
+ ")<BR>"
+ ")<BR>";
}
public String toSql ()
{
return "INSERT INTO VERSION_STATUS_TRANSITION (STATUS_ID, NEW_STATUS_ID, TRANSITION_ATTRIBUTES) "+
"VALUES ("+status_id+","+new_status_id+",\""+transition_attributes+"\") ";
}
}
|