自定义velocity的DataSourceResourceLoader?

时间:2013-10-11 10:42:55

标签: java spring java-ee velocity

我使用apache velocity模板格式化内容然后发送邮件。但模板内容将在database table中提供。为此,我们可以使用DataSourceResourceLoader。 但它适用于预定义的数据库表格式,只有templateContent。但是我希望使用相同的DataSourceResourceLoader从同一个表中获得更多列。 我怎么能这样做?

请在DataSourceResourceLoader中找到以下代码,其中只有一列。

public synchronized InputStream getResourceStream(final String name)
        throws ResourceNotFoundException
    {
        if (org.apache.commons.lang.StringUtils.isEmpty(name))
        {
            throw new ResourceNotFoundException("DataSourceResourceLoader: Template name was empty or null");
        }

        Connection conn = null;
        ResultSet rs = null;
        PreparedStatement ps = null;
        try
        {
            conn = openDbConnection();
            ps = getStatement(conn, templateColumn, tableName, keyColumn, name);
            rs = ps.executeQuery();

            if (rs.next())
            {
                InputStream stream = rs.getBinaryStream(templateColumn);
                if (stream == null)
                {
                    throw new ResourceNotFoundException("DataSourceResourceLoader: "
                                                        + "template column for '"
                                                        + name + "' is null");
                }

                return new BufferedInputStream(stream);
            }
            else
            {
                throw new ResourceNotFoundException("DataSourceResourceLoader: "
                                                    + "could not find resource '"
                                                    + name + "'");

            }
        }
        catch (SQLException sqle)
        {
            String msg = "DataSourceResourceLoader: database problem while getting resource '"
                         + name + "': ";

            log.error(msg, sqle);
            throw new ResourceNotFoundException(msg);
        }
        catch (NamingException ne)
        {
            String msg = "DataSourceResourceLoader: database problem while getting resource '"
                         + name + "': ";

            log.error(msg, ne);
            throw new ResourceNotFoundException(msg);
        }
        finally
        {
            closeResultSet(rs);
            closeStatement(ps);
            closeDbConnection(conn);
        }
    }

在上面的代码中InputStream stream = rs.getBinaryStream(templateColumn);被检索并返回。现在我需要更多的专栏。我怎么能这样做?

谢谢!

0 个答案:

没有答案