Forum: Building VoltDB Applications

Post: Sharing code between stored procedures

Sharing code between stored procedures
theschmitzer
Feb 8, 2013
I have a java class ProcFoo and another one ProcFar.

I would like to share some code between them. So I created ProcCommon

public class ProcCommon extends VoltProcedure {
public void commonLogic() {
// Access volt db using query
}
};

public class ProcFoo extends ProcCommon {
public VoltTable[] run(...) {
commonLogic();
}
};

public class ProcBar extends procCommon {
public VoltTable[] run(...) {
commonLogic();
}
};

If I don't reference procCommon in the DDL, it does not get included in the catalog, causing a runtime error. If I do, though

CREATE PROCEDURE FROM CLASS ProcFoo;
CREATE PROCEDURE FROM CLASS ProcBar;
CREATE PROCEDURE FROM CLASS ProcCommon;

This fails b/c ProcCommon does not have a run()

What's the best practice?
pmartel
Feb 8, 2013
This is a known weakness in the current catalog compiler. It is designated ENG-4061 in the issues database.

The future method for specifying additional library classes for use by stored procedures is still under discussion.

IMO, the best workaround for this particular example until this issue is resolved in the product is to add an unused "run" method to the common base class.

--paul
theschmitzer
Feb 11, 2013
Thanks I did that, and added to Schema

CREATE PROCEDURE FROM CLASS ProcCommon;

Seems to work.