📄 cmsworkflowdriver.java
字号:
ResultSet res = null;
Connection conn = null;
PreparedStatement stmt = null;
try {
conn = m_sqlManager.getConnection(dbc);
stmt = m_sqlManager.getPreparedStatement(conn, "C_TASKPAR_TEST");
// test if the parameter already exists for this task
stmt.setInt(1, taskId);
stmt.setString(2, parname);
res = stmt.executeQuery();
if (res.next()) {
//Parameter exisits, so make an update
internalWriteTaskParameter(dbc, res.getInt(m_sqlManager.readQuery("C_PAR_ID")), parvalue);
} else {
//Parameter is not exisiting, so make an insert
internalWriteTaskParameter(dbc, taskId, parname, parvalue);
}
} catch (SQLException e) {
throw new CmsDbSqlException(Messages.get().container(
Messages.ERR_GENERIC_SQL_1,
CmsDbSqlException.getErrorQuery(stmt)), e);
} finally {
// close all db-resources
m_sqlManager.closeAll(dbc, conn, stmt, res);
}
}
/**
* @see org.opencms.db.I_CmsWorkflowDriver#writeTaskType(org.opencms.db.CmsDbContext, int, int, java.lang.String, java.lang.String, java.lang.String, int, int)
*/
public void writeTaskType(
CmsDbContext dbc,
int autofinish,
int escalationtyperef,
String htmllink,
String name,
String permission,
int priorityref,
int roleref) throws CmsDataAccessException {
ResultSet res = null;
PreparedStatement stmt = null;
Connection conn = null;
try {
conn = m_sqlManager.getConnection(dbc);
stmt = m_sqlManager.getPreparedStatement(conn, "C_TASK_GET_TASKTYPE");
// test if the parameter already exists for this task
stmt.setString(1, name);
res = stmt.executeQuery();
if (res.next()) {
//Parameter exists, so make an update
internalWriteTaskType(
dbc,
res.getInt(m_sqlManager.readQuery("C_PAR_ID")),
autofinish,
escalationtyperef,
htmllink,
name,
permission,
priorityref,
roleref);
} else {
//Parameter is not existing, so make an insert
internalWriteTaskType(
dbc,
autofinish,
escalationtyperef,
htmllink,
name,
permission,
priorityref,
roleref);
}
} catch (SQLException e) {
throw new CmsDbSqlException(Messages.get().container(
Messages.ERR_GENERIC_SQL_1,
CmsDbSqlException.getErrorQuery(stmt)), e);
} finally {
// close all db-resources
m_sqlManager.closeAll(dbc, conn, stmt, res);
}
}
/**
* @see java.lang.Object#finalize()
*/
protected void finalize() throws Throwable {
try {
m_sqlManager = null;
m_driverManager = null;
} catch (Throwable t) {
// ignore
}
super.finalize();
}
/**
* Semi-constructor to create a CmsTask instance from a JDBC result set.
*
* @param res the result set from the query
* @return the CmsTash created from the data
* @throws SQLException if something goes wrong
*/
protected CmsTask internalCreateTask(ResultSet res) throws SQLException {
int autofinish = res.getInt(m_sqlManager.readQuery("C_TASK_AUTOFINISH"));
java.sql.Timestamp endtime = CmsDbUtil.getTimestamp(res, m_sqlManager.readQuery("C_TASK_ENDTIME"));
int escalationtype = res.getInt(m_sqlManager.readQuery("C_TASK_ESCALATIONTYPE"));
int id = res.getInt(m_sqlManager.readQuery("C_TASK_ID"));
CmsUUID initiatoruser = new CmsUUID(res.getString(m_sqlManager.readQuery("C_TASK_INITIATORUSER")));
int milestone = res.getInt(m_sqlManager.readQuery("C_TASK_MILESTONE"));
String name = res.getString(m_sqlManager.readQuery("C_TASK_NAME"));
CmsUUID originaluser = new CmsUUID(res.getString(m_sqlManager.readQuery("C_TASK_ORIGINALUSER")));
CmsUUID agentuser = new CmsUUID(res.getString(m_sqlManager.readQuery("C_TASK_AGENTUSER")));
int parent = res.getInt(m_sqlManager.readQuery("C_TASK_PARENT"));
int percentage = res.getInt(m_sqlManager.readQuery("C_TASK_PERCENTAGE"));
String permission = res.getString(m_sqlManager.readQuery("C_TASK_PERMISSION"));
int priority = res.getInt(m_sqlManager.readQuery("C_TASK_PRIORITY"));
CmsUUID role = new CmsUUID(res.getString(m_sqlManager.readQuery("C_TASK_ROLE")));
int root = res.getInt(m_sqlManager.readQuery("C_TASK_ROOT"));
java.sql.Timestamp starttime = CmsDbUtil.getTimestamp(res, m_sqlManager.readQuery("C_TASK_STARTTIME"));
int state = res.getInt(m_sqlManager.readQuery("C_TASK_STATE"));
int tasktype = res.getInt(m_sqlManager.readQuery("C_TASK_TASKTYPE"));
java.sql.Timestamp timeout = CmsDbUtil.getTimestamp(res, m_sqlManager.readQuery("C_TASK_TIMEOUT"));
java.sql.Timestamp wakeuptime = CmsDbUtil.getTimestamp(res, m_sqlManager.readQuery("C_TASK_WAKEUPTIME"));
String htmllink = res.getString(m_sqlManager.readQuery("C_TASK_HTMLLINK"));
return new CmsTask(
id,
name,
state,
tasktype,
root,
parent,
initiatoruser,
role,
agentuser,
originaluser,
starttime,
wakeuptime,
timeout,
endtime,
percentage,
permission,
priority,
escalationtype,
htmllink,
milestone,
autofinish);
}
/**
* Constructs a sql condition for the given task type.<p>
*
* @param first flag to indicate the first condition
* @param tasktype the type to query
* @return the sql condition
*/
protected String internalReadTaskTypeCondition(boolean first, int tasktype) {
String result = "";
// handle the tasktype for the SQL String
if (!first) {
result = result + " AND ";
}
switch (tasktype) {
case CmsTaskService.TASKS_ALL:
result = result + m_sqlManager.readQuery("C_TASK_ROOT") + "<>0";
break;
case CmsTaskService.TASKS_OPEN:
result = result + m_sqlManager.readQuery("C_TASK_STATE") + "=" + CmsTaskService.TASK_STATE_STARTED;
break;
case CmsTaskService.TASKS_ACTIVE:
result = result + m_sqlManager.readQuery("C_TASK_STATE") + "=" + CmsTaskService.TASK_STATE_STARTED;
break;
case CmsTaskService.TASKS_DONE:
result = result + m_sqlManager.readQuery("C_TASK_STATE") + "=" + CmsTaskService.TASK_STATE_ENDED;
break;
case CmsTaskService.TASKS_NEW:
result = result
+ m_sqlManager.readQuery("C_TASK_PERCENTAGE")
+ "='0' AND "
+ m_sqlManager.readQuery("C_TASK_STATE")
+ "="
+ CmsTaskService.TASK_STATE_STARTED;
break;
default:
}
return result;
}
/**
* Updates a task parameter.<p>
*
* @param dbc the current database context
* @param parid the id of the parameter
* @param parvalue the value of the parameter
*
* @throws CmsDataAccessException if something goes wrong
*/
protected void internalWriteTaskParameter(CmsDbContext dbc, int parid, String parvalue)
throws CmsDataAccessException {
PreparedStatement stmt = null;
Connection conn = null;
try {
conn = m_sqlManager.getConnection(dbc);
stmt = m_sqlManager.getPreparedStatement(conn, "C_TASKPAR_UPDATE");
stmt.setString(1, parvalue);
stmt.setInt(2, parid);
stmt.executeUpdate();
} catch (SQLException e) {
throw new CmsDbSqlException(Messages.get().container(
Messages.ERR_GENERIC_SQL_1,
CmsDbSqlException.getErrorQuery(stmt)), e);
} finally {
m_sqlManager.closeAll(dbc, conn, stmt, null);
}
}
/**
* Adds a task parameter to a task.<p>
*
* @param dbc the current database context
* @param taskId the id of the task
* @param parname the name of the parameter
* @param parvalue the value of the parameter
*
* @return the id of the new parameter
* @throws CmsDataAccessException if something goes wrong
*/
protected int internalWriteTaskParameter(CmsDbContext dbc, int taskId, String parname, String parvalue)
throws CmsDataAccessException {
PreparedStatement stmt = null;
Connection conn = null;
int newId = CmsDbUtil.UNKNOWN_ID;
try {
conn = m_sqlManager.getConnection(dbc);
stmt = m_sqlManager.getPreparedStatement(conn, "C_TASKPAR_INSERT");
newId = m_sqlManager.nextId(TABLE_TASKPAR);
stmt.setInt(1, newId);
stmt.setInt(2, taskId);
stmt.setString(3, m_sqlManager.validateEmpty(parname));
stmt.setString(4, m_sqlManager.validateEmpty(parvalue));
stmt.executeUpdate();
} catch (SQLException e) {
throw new CmsDbSqlException(Messages.get().container(
Messages.ERR_GENERIC_SQL_1,
CmsDbSqlException.getErrorQuery(stmt)), e);
} finally {
// close all db-resources
m_sqlManager.closeAll(dbc, conn, stmt, null);
}
return newId;
}
/**
* Updates a task.<p>
*
* @param dbc the current database context
* @param taskId the id of the task
* @param autofinish tbd
* @param escalationtyperef tbd
* @param htmllink tbd
* @param name tbd
* @param permission tbd
* @param priorityref tbd
* @param roleref tbd
*
* @throws CmsDataAccessException if something goes wrong
*/
protected void internalWriteTaskType(
CmsDbContext dbc,
int taskId,
int autofinish,
int escalationtyperef,
String htmllink,
String name,
String permission,
int priorityref,
int roleref) throws CmsDataAccessException {
PreparedStatement stmt = null;
Connection conn = null;
try {
conn = m_sqlManager.getConnection(dbc);
stmt = m_sqlManager.getPreparedStatement(conn, "C_TASKTYPE_UPDATE");
stmt.setInt(1, autofinish);
stmt.setInt(2, escalationtyperef);
stmt.setString(3, htmllink);
stmt.setString(4, name);
stmt.setString(5, permission);
stmt.setInt(6, priorityref);
stmt.setInt(7, roleref);
stmt.setInt(8, taskId);
stmt.executeUpdate();
} catch (SQLException e) {
throw new CmsDbSqlException(Messages.get().container(
Messages.ERR_GENERIC_SQL_1,
CmsDbSqlException.getErrorQuery(stmt)), e);
} finally {
m_sqlManager.closeAll(dbc, conn, stmt, null);
}
}
/**
* Inserts a new task.<p>
*
* @param dbc the current database context
* @param autofinish tbd
* @param escalationtyperef tbd
* @param htmllink tbd
* @param name tbd
* @param permission tbd
* @param priorityref tbd
* @param roleref tbd
*
* @return tbd
* @throws CmsDataAccessException tbd
*/
protected int internalWriteTaskType(
CmsDbContext dbc,
int autofinish,
int escalationtyperef,
String htmllink,
String name,
String permission,
int priorityref,
int roleref) throws CmsDataAccessException {
PreparedStatement stmt = null;
Connection conn = null;
int newId = CmsDbUtil.UNKNOWN_ID;
try {
conn = m_sqlManager.getConnection(dbc);
stmt = m_sqlManager.getPreparedStatement(conn, "C_TASKTYPE_INSERT");
newId = m_sqlManager.nextId(TABLE_TASKPAR);
stmt.setInt(1, autofinish);
stmt.setInt(2, escalationtyperef);
stmt.setString(3, htmllink);
stmt.setInt(4, newId);
stmt.setString(5, name);
stmt.setString(6, permission);
stmt.setInt(7, priorityref);
stmt.setInt(8, roleref);
stmt.executeUpdate();
} catch (SQLException e) {
throw new CmsDbSqlException(Messages.get().container(
Messages.ERR_GENERIC_SQL_1,
CmsDbSqlException.getErrorQuery(stmt)), e);
} finally {
// close all db-resources
m_sqlManager.closeAll(dbc, conn, stmt, null);
}
return newId;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -