how to get java to capture printing from sybase stored proc

In my experience on Wall St, Sybase store proc can get very complex. A basic technique is the lowly “print”. It beats “select” because under error condition all selects into a log table are rolled back.

Sometimes Sybase print output doesn’t get returned to java. For jdbc I had a simple reusable method to while-loop through a series of warnings. Here’s my technique for spring jdbcTempalte. Note the documented “logging all warnings” may not work. If you don’t override handleWarnings() like I did, then all warnings become exceptions so super.query() return value is lost — real show stopper.

public class GenericProcedureCaller extends JdbcTemplate {
@Override
protected void handleWarnings(Statement stmt) {
try {
super.handleWarnings(stmt);
} catch (SQLWarningException e) {
log.info("\t\t v v v output from database server v v v v ");
SQLWarning warn = e.SQLWarning();
while (warn != null) {
log.info(warn);
warn = warn.getNextWarning();
}
log.info("\t\t ^ ^ ^ output from database server ^ ^ ^ ^ ");
} catch (SQLException e) {
e.printStackTrace();
}
}
@Override
public List query(String sql, RowMapper rowMapper) throws DataAccessException {
boolean oldSetting = isIgnoreWarnings();
// setting to false to capture "prints" from the proc, but there's side effect.
setIgnoreWarnings(false);
try {
return super.query(sql, rowMapper);
} finally {
setIgnoreWarnings(oldSetting);
}
}

factory-method vs FactoryBean.java in Spring

I feel there’s deeper and richer support for FactoryBean.java. Notes from spring doc —

— “factory bean” vs FactoryBean —
When the Spring documentation makes mention of a ‘factory bean’, this will be a reference to a bean that is configured in the Spring container that will create objects via an instance or static factory method. When the documentation mentions a FactoryBean (notice the capitalization) this is a reference to a Spring-specific FactoryBean.

— getting the FactoryBean object itself —
Finally, there is sometimes a need to ask a container for an actual FactoryBean instance itself, not the bean it produces. This may be achieved by prepending the bean id with ‘&’ when calling the getBean method of the BeanFactory (such as the ApplicationContext bean factory).

So for a given FactoryBean with an id of myBean, invoking getBean(“myBean”) on the container will return the product of the FactoryBean, but invoking getBean(“&myBean”) will return the FactoryBean instance itself.

FactoryBean to avoid hardcoded classnames in spring xml

Without this, you need to hard code the class name in a windows-specific xml, and a different classname in the linux-specific xml

public class CalcLibFactoryBean implements FactoryBean {
@Override
public CalcLibWrapper getObject() throws Exception {
if (System.getProperty("os.name").toLowerCase().startsWith("win")) {
return new PxYldCalcWrapperStub();
}else {
return new PxYldCalcWrapper();
}
}

convenient spring jdbc methods

1a) Query for map – if your query/proc returns just a single row and you
don’t want to create a new bean class.
* Column names had better be distinct, which is usually easy.
* Similar to boost tuple.
2) Query for object (of your custom class) – if your proc/query returns
a single row, and you already have a bean class to hold all attributes.
3) queryForObject (String sql, String.class) – if you are sure to get
only one row and combine all columns into a single string
4a) Query for int – if your query/proc returns nothing but an integer
4b) Query for object – if your proc/query returns a single Date
5) Row mapper – if your query/proc returns a result set

simplest spring-jmx setup to configure a trading server

Without any annotation or source code change, any public (static or non-static) methods will be accessible on jconsole.
                xmlns:context=”http://www.springframework.org/schema/context”
                xsi:schemaLocation=”http://www.springframework.org/schema/beans
                           http://www.springframework.org/schema/beans/spring-beans.xsd
                           http://www.springframework.org/schema/context
                           http://www.springframework.org/schema/context/spring-context.xsd”>