protected String membersQuery = null;
public void init() throws MessagingException {
if (getInitParameter("data_source") == null) {
throw new MailetException("data_source not specified for JDBCListserv");
}
if (getInitParameter("listserv_id") == null) {
throw new MailetException("listserv_id not specified for JDBCListserv");
}
if (getInitParameter("listserv_table") == null) {
throw new MailetException("listserv_table not specified for JDBCListserv");
}
if (getInitParameter("members_table") == null) {
throw new MailetException("members_table not specified for JDBCListserv");
}
String datasourceName = getInitParameter("data_source");
listservID = getInitParameter("listserv_id");
listservTable = getInitParameter("listserv_table");
membersTable = getInitParameter("members_table");
if (getInitParameter("cache_settings") != null) {
try {
cacheSettings = new Boolean(getInitParameter("cache_settings")).booleanValue();
} catch (Exception e) {
//ignore error
}
}
Connection conn = null;
try {
ComponentManager componentManager = (ComponentManager)getMailetContext().getAttribute(Constants.AVALON_COMPONENT_MANAGER);
// Get the DataSourceSelector block
DataSourceSelector datasources = (DataSourceSelector)componentManager.lookup(DataSourceSelector.ROLE);
// Get the data-source required.
datasource = (DataSourceComponent)datasources.select(datasourceName);
conn = datasource.getConnection();
// Check if the required listserv table exists. If not, complain.
DatabaseMetaData dbMetaData = conn.getMetaData();
// Need to ask in the case that identifiers are stored, ask the DatabaseMetaInfo.
// Try UPPER, lower, and MixedCase, to see if the table is there.
if (! ( tableExists(dbMetaData, listservTable) ||
tableExists(dbMetaData, listservTable.toUpperCase()) ||
tableExists(dbMetaData, listservTable.toLowerCase()) )) {
throw new MailetException("Could not find table '" + listservTable + "' in datasource '" + datasourceName + "'");
}
// Check if the required members table exists. If not, complain.
// Need to ask in the case that identifiers are stored, ask the DatabaseMetaInfo.
// Try UPPER, lower, and MixedCase, to see if the table is there.
if (! ( tableExists(dbMetaData, membersTable) ||
tableExists(dbMetaData, membersTable.toUpperCase()) ||
tableExists(dbMetaData, membersTable.toLowerCase()) )) {
throw new MailetException("Could not find table '" + membersTable + "' in datasource '" + datasourceName + "'");
}
listservQuery = "SELECT members_only, attachments_allowed, reply_to_list, subject_prefix, list_address FROM "
+ listservTable + " WHERE listserv_id = ?";
membersQuery = "SELECT member FROM " + membersTable + " WHERE listserv_id = ?";