📄 cmsdbaccess.java
字号:
} finally {
stmnt = null;
}
try {
con.close();
} catch (Exception e) {
// ignore the exception
} finally {
con = null;
}
}
/**
* Inserts all values to the statement for insert and update.
* @param stmnt the Statement to fill the values to.
* @param cms the CmsObject to get access to cms-ressources.
* @param subId the subid of this module.
* @param dataset the set of data for this contentdefinition.
* @return the actual rowcounter.
*/
protected int sqlFillValues(PreparedStatement stmnt, int subId, CmsMasterDataSet dataset)
throws SQLException {
// columncounter
int i = 1;
//// COREDATA ////
stmnt.setInt(i++,dataset.m_masterId);
stmnt.setInt(i++,subId);
stmnt.setInt(i++,dataset.m_userId);
stmnt.setInt(i++,dataset.m_groupId);
stmnt.setInt(i++,dataset.m_lockedInProject);
stmnt.setInt(i++,dataset.m_accessFlags);
stmnt.setInt(i++,dataset.m_state);
stmnt.setInt(i++,dataset.m_lockedBy);
stmnt.setInt(i++,dataset.m_lastModifiedBy);
stmnt.setTimestamp(i++,new Timestamp(dataset.m_dateCreated));
stmnt.setTimestamp(i++,new Timestamp(dataset.m_dateLastModified));
//// USERDATA ////
stmnt.setTimestamp(i++,new Timestamp(dataset.m_publicationDate));
stmnt.setTimestamp(i++,new Timestamp(dataset.m_purgeDate));
stmnt.setInt(i++,dataset.m_flags);
stmnt.setInt(i++,dataset.m_feedId);
stmnt.setInt(i++,dataset.m_feedReference);
if(dataset.m_feedFilename == null){
stmnt.setNull(i++,Types.VARCHAR);
} else {
stmnt.setString(i++,dataset.m_feedFilename);
}
if(dataset.m_title == null){
stmnt.setNull(i++,Types.VARCHAR);
} else {
stmnt.setString(i++,dataset.m_title);
}
//// GENERIC DATA ////
i = sqlSetTextArray(stmnt, dataset.m_dataBig, i);
i = sqlSetTextArray(stmnt, dataset.m_dataMedium, i);
i = sqlSetTextArray(stmnt, dataset.m_dataSmall, i);
i = sqlSetIntArray(stmnt, dataset.m_dataInt, i);
i = sqlSetIntArray(stmnt, dataset.m_dataReference, i);
i = sqlSetDateArray(stmnt, dataset.m_dataDate, i);
return i;
}
/**
* Inserts all values to the statement for insert and update.
* @param res the Resultset read the values from.
* @param cms the CmsObject to get access to cms-ressources.
* @param content the CmsMasterContent to write to the database.
* @param dataset the set of data for this contentdefinition.
* @return the actual rowcounter.
*/
protected int sqlFillValues(ResultSet res, CmsObject cms, CmsMasterDataSet dataset)
throws SQLException {
// columncounter
int i = 1;
//// COREDATA ////
dataset.m_masterId = res.getInt(i++);
res.getInt(i++); // we don't have to store the sub-id
dataset.m_userId = res.getInt(i++);
dataset.m_groupId = res.getInt(i++);
dataset.m_lockedInProject = res.getInt(i++);
// compute project based on the current project and the channels
dataset.m_projectId = computeProjectId(cms, dataset);
dataset.m_accessFlags = res.getInt(i++);
dataset.m_state = res.getInt(i++);
dataset.m_lockedBy =res.getInt(i++);
dataset.m_lastModifiedBy = res.getInt(i++);
dataset.m_dateCreated = res.getTimestamp(i++).getTime();
dataset.m_dateLastModified = res.getTimestamp(i++).getTime();
//// USERDATA ////
dataset.m_publicationDate = res.getTimestamp(i++).getTime();
dataset.m_purgeDate = res.getTimestamp(i++).getTime();
dataset.m_flags = res.getInt(i++);
dataset.m_feedId = res.getInt(i++);
dataset.m_feedReference = res.getInt(i++);
dataset.m_feedFilename = res.getString(i++);
dataset.m_title = res.getString(i++);;
//// GENERIC DATA ////
i = sqlSetTextArray(res, dataset.m_dataBig, i);
i = sqlSetTextArray(res, dataset.m_dataMedium, i);
i = sqlSetTextArray(res, dataset.m_dataSmall, i);
i = sqlSetIntArray(res, dataset.m_dataInt, i);
i = sqlSetIntArray(res, dataset.m_dataReference, i);
i = sqlSetDateArray(res, dataset.m_dataDate, i);
return i;
}
/**
* Computes the correct project id based on the channels.
*/
protected int computeProjectId(CmsObject cms, CmsMasterDataSet dataset) throws SQLException {
int onlineProjectId = I_CmsConstants.C_UNKNOWN_ID;
int offlineProjectId = I_CmsConstants.C_UNKNOWN_ID;
try {
offlineProjectId = cms.getRequestContext().currentProject().getId();
onlineProjectId = cms.onlineProject().getId();
} catch(CmsException exc) {
// ignore the exception
}
if(!isOnlineProject(cms)) {
// this is a offline project -> compute if we have to return the
// online project id or the offline project id
// the owner and the administrtor has always access
try {
if( (cms.getRequestContext().currentUser().getId() == dataset.m_userId) ||
cms.isAdmin()) {
return offlineProjectId;
}
} catch(CmsException exc) {
// ignore the exception -> we are not admin
}
String statement_key = "read_channel_offline";
String poolToUse = m_poolName;
PreparedStatement stmnt = null;
ResultSet res = null;
Connection con = null;
try {
cms.setContextToCos();
con = DriverManager.getConnection(poolToUse);
stmnt = sqlPrepare(con, statement_key);
stmnt.setInt(1, dataset.m_masterId);
res = stmnt.executeQuery();
while(res.next()) {
// get the channel id
int channeldId = res.getInt(1);
// read the resource by property "channelid"
Vector resources = new Vector();
try {
resources = cms.getResourcesWithProperty(I_CmsConstants.C_PROPERTY_CHANNELID, channeldId+"", I_CmsConstants.C_TYPE_FOLDER);
} catch(CmsException exc) {
// ignore the exception - read the next one
}
if(resources.size() >= 1) {
int resProjectId = ((CmsResource)resources.get(0)).getProjectId();
if(resProjectId == offlineProjectId) {
// yes - we have found a chanel that belongs to
// the current offlineproject -> we can return the
// offline project id as computed project id
return offlineProjectId;
}
}
}
} finally {
cms.setContextToVfs();
sqlClose(con, stmnt, res);
}
}
// no channel found, that belongs to the offlineproject ->
// return the online project id.
return onlineProjectId;
}
/**
* Sets an array of strings into the stmnt.
* @param stmnt the PreparedStatement to set the values into.
* @param array the array of strings to set.
* @param the columnscounter for the stmnt.
* @return the increased columnscounter;
*/
protected int sqlSetTextArray(PreparedStatement stmnt, String[] array, int columnscounter)
throws SQLException {
for(int j = 0; j < array.length; j++) {
if(array[j] == null) {
stmnt.setNull(columnscounter++,Types.LONGVARCHAR);
} else {
stmnt.setString(columnscounter++,array[j]);
}
}
return columnscounter;
}
/**
* Sets an array of strings from the resultset.
* @param res the ResultSet to get the values from.
* @param array the array of strings to set.
* @param the columnscounter for the res.
* @return the increased columnscounter;
*/
protected int sqlSetTextArray(ResultSet res, String[] array, int columnscounter)
throws SQLException {
for(int j = 0; j < array.length; j++) {
array[j] = res.getString(columnscounter++);
}
return columnscounter;
}
/**
* Sets an array of ints into the stmnt.
* @param stmnt the PreparedStatement to set the values into.
* @param array the array of ints to set.
* @param the columnscounter for the stmnt.
* @return the increased columnscounter;
*/
protected int sqlSetIntArray(PreparedStatement stmnt, int[] array, int columnscounter)
throws SQLException {
for(int j = 0; j < array.length; j++) {
stmnt.setInt(columnscounter++,array[j]);
}
return columnscounter;
}
/**
* Sets an array of ints from the resultset.
* @param res the ResultSet to get the values from.
* @param array the array of ints to set.
* @param the columnscounter for the res.
* @return the increased columnscounter;
*/
protected int sqlSetIntArray(ResultSet res, int[] array, int columnscounter)
throws SQLException {
for(int j = 0; j < array.length; j++) {
array[j] = res.getInt(columnscounter++);
}
return columnscounter;
}
/**
* Sets an array of ints into the stmnt.
* @param stmnt the PreparedStatement to set the values into.
* @param array the array of longs to set.
* @param the columnscounter for the stmnt.
* @return the increased columnscounter;
*/
protected int sqlSetDateArray(PreparedStatement stmnt, long[] array, int columnscounter)
throws SQLException {
for(int j = 0; j < array.length; j++) {
stmnt.setTimestamp(columnscounter++,new Timestamp(array[j]));
}
return columnscounter;
}
/**
* Sets an array of ints from the resultset.
* @param res the ResultSet to get the values from.
* @param array the array of longs to set.
* @param the columnscounter for the res.
* @return the increased columnscounter;
*/
protected int sqlSetDateArray(ResultSet res, long[] array, int columnscounter)
throws SQLException {
for(int j = 0; j < array.length; j++) {
array[j] = res.getTimestamp(columnscounter++).getTime();
}
return columnscounter;
}
/**
* Returns a vector of contentdefinitions based on the sql resultset.
* Never mind about the visible flag.
* @param res - the ResultSet to get data-lines from.
* @param contentDefinitionClass - the class of the cd to create new instances.
* @param cms - the CmsObject to get access to cms-ressources.
* @throws SqlException if nothing could be read from the resultset.
*/
protected Vector createVectorOfCd(ResultSet res, Class contentDefinitionClass, CmsObject cms)
throws SQLException {
return createVectorOfCd(res, contentDefinitionClass, cms, false);
}
/**
* Returns a vector of contentdefinitions based on the sql resultset.
* @param res - the ResultSet to get data-lines from.
* @param contentDefinitionClass - the class of the cd to create new instances.
* @param cms - the CmsObject to get access to cms-ressources.
* @param viewonly - decides, if only the ones that are visible should be returned
* @throws SqlException if nothing could be read from the resultset.
*/
protected Vector createVectorOfCd(ResultSet res, Class contentDefinitionClass, CmsObject cms, boolean viewonly)
throws SQLException {
Constructor constructor;
Vector retValue = new Vector();
try { // to get the constructor to create an empty contentDefinition
constructor = contentDefinitionClass.getConstructor(new Class[]{CmsObject.class, CmsMasterDataSet.class});
} catch(NoSuchMethodException exc) {
if(I_CmsLogChannels.C_PREPROCESSOR_IS_LOGGING && CmsBase.isLogging()) {
CmsBase.log(I_CmsLogChannels.C_MODULE_DEBUG, "[CmsDbAccess] Cannot locate constructor: " + exc.getMessage());
}
// canno't fill the vector - missing constructor
return retValue;
}
while(res.next()) { // while there is data in the resultset
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -