I'm interested in importing data into Derby databases from other sources, and the ability in Derby to have Java classes return ResultSets that can be used as dynamic tables seemed promising:

INSERT INTO sometable
SELECT *
FROM new somejavaclass(constructorParameters) t;

The class "somejavaclass" must implement java.sql.ResultSet.

I've gotten it to work, but only by having my class be in some subpackage of org.apache.derby.diag. There is code in the parser source that implements a special check if the java class is not in one of a few special packages (sqlgrammer.jj line 1644):

if (!javaClassName.startsWith("org.apache.derby.diag.") && !javaClassName.startsWith("org.apache.derby.catalog.") && !javaClassName.startsWith("com.ibm.db2j."))
{
    checkInternalFeature(javaClassName);
}

I don't like the fact that I must have my class in some special package, but I haven't been able to find out how to turn off the check for "foreign" Java classes. (It seems to be hard-coded in CompilerContext, checking for the bit INTERNAL_SQL_ILLEGAL in the flag set by setReliability().)

Does anyone know how to turn off this test so my class doesn't have to live in the Derby tree?

BTW, I realize you can do something similar with "CREATE PROCEDURE", but it seems you lose the ability to choose which columns you want--or have to implement the selection yourself in Java--, and you can't join with other tables, etc., so I'd prefer to use the "FROM new javaclass()" form, if possible.

Thanks,
Mark
--
Mark Rose
QSS Group, Inc. / NASA Ames Research Center
650.604.3627

Reply via email to