EJBQLCpublic class EJBQLC extends Object This class is the driver of the EJBQL compiler. It controls the compiler
passes: syntax analysis, semantic analysis and generation of the JDOQL query.
A EJBQLC instance is able to compile multiple EJBQL queries as long as they
come from the same deployement descriptor. The class uses the model instance
passed to the constructor to access any meta data from the deployement
descriptor. Method {@link #compile} compiles a single EJBQL query string
together with the java.lang.reflect.Method instance of the corresponding
finder/selector method. The result is a JDOQLElements instance, that can be
used to construct a JDOQL query instance. |
Fields Summary |
---|
protected com.sun.jdo.api.persistence.model.Model | modelMeta data access. | protected com.sun.jdo.spi.persistence.support.ejb.model.util.NameMapper | nameMapperName mapping EJB <-> JDO. | protected EJBQLAST | astThe intermediate form of the EJBQL query string. | private static com.sun.jdo.spi.persistence.utility.logging.Logger | loggerThe logger | protected static final ResourceBundle | msgsI18N support. | public static final String | SIGNATURESignature with CVS keyword substitution for identifying the generated code |
Methods Summary |
---|
public JDOQLElements | compile(java.lang.String ejbqlQuery, java.lang.reflect.Method method, int resultTypeMapping, boolean finderNotSelector, java.lang.String ejbName)Compiles the specified query string for the specified
finder/selector method.
boolean finer = logger.isLoggable(Logger.FINER);
boolean finest = logger.isLoggable(Logger.FINEST);
if (method == null)
ErrorMsg.fatal(I18NHelper.getMessage(msgs,
"ERR_MissingMethodInstance")); //NOI18N
if ((ejbqlQuery == null) || ejbqlQuery.trim().length() == 0)
ErrorMsg.error(I18NHelper.getMessage(msgs,
"EXC_MissingEjbqlQueryText", ejbName, //NOI18N
getMethodSignature(method)));
if (finer)
logger.finer("LOG_EJBQLCCompile", ejbName, //NOI18N
getMethodSignature(method), ejbqlQuery);
JDOQLElements result = null;
TypeSupport typeSupport = new TypeSupport(model, nameMapper);
ParameterSupport paramSupport = new ParameterSupport(method);
String pass = null;
try
{
// syntax analysis
pass = "syntax analysis"; //NOI18N
if (finer) logger.finer("LOG_EJBQLCStartPass", pass); //NOI18N
EJBQLParser parser = createStringParser(ejbqlQuery);
parser.query();
ast = (EJBQLAST)parser.getAST();
if (finest) logger.finest("LOG_EJBQLCDumpTree", ast.getTreeRepr("(AST)")); //NOI18N
// semantic analysis
pass = "semantic analysis"; //NOI18N
if (finer) logger.finer("LOG_EJBQLCStartPass", pass); //NOI18N
Semantic semantic = new Semantic();
semantic.init(typeSupport, paramSupport, method, resultTypeMapping,
finderNotSelector, ejbName);
semantic.setASTFactory(EJBQLASTFactory.getInstance());
semantic.query(ast);
ast = (EJBQLAST)semantic.getAST();
if (finest) logger.finest("LOG_EJBQLCDumpTree", ast.getTreeRepr("(typed AST)")); //NOI18N
// JDOQL code generation
pass = "code generation"; //NOI18N
if (finer) logger.finer("LOG_EJBQLCStartPass", pass); //NOI18N
JDOQLCodeGeneration codeGen = new JDOQLCodeGeneration();
codeGen.init(typeSupport, paramSupport);
codeGen.setASTFactory(EJBQLASTFactory.getInstance());
codeGen.query(ast);
result = codeGen.getJDOQLElements();
if (finer) logger.finer("LOG_EJBQLCResult", result.toString()); //NOI18N
}
catch (EJBQLException ex) {
// add EJB name, finder/selector, EJBQL to error message.
Object[] msgArgs = { ejbName, getMethodSignature(method),
ejbqlQuery, ex.getMessage() };
ErrorMsg.error(I18NHelper.getMessage(msgs,
"EXC_InvalidEJBQLQuery", msgArgs)); //NOI18N
}
catch (Throwable t) {
Object[] msgArgs = { ejbName, getMethodSignature(method),
ejbqlQuery, t.toString() };
// log a SEVERE message with nested exception
ErrorMsg.log(Logger.SEVERE, I18NHelper.getMessage(msgs,
"EXC_EJBQLQueryInternalError", msgArgs), t); //NOI18N
}
// return the JDOQLElements instance representing the elements
// of the JDOQL query.
return result;
| private EJBQLParser | createStringParser(java.lang.String text)Creates an ANTLR EJBQL parser reading a string.
Reader in = new StringReader(text);
EJBQLLexer lexer = new EJBQLLexer(in);
TokenBuffer buffer = new TokenBuffer(lexer);
EJBQLParser parser = new EJBQLParser(buffer);
parser.setASTFactory(EJBQLASTFactory.getInstance());
return parser;
| private java.lang.String | getMethodSignature(java.lang.reflect.Method m)Returns the signature of a method w/o exceptions and modifiers
as a string.
if (m == null)
return ""; //NOI18N
return m.getReturnType().getName() + ' " + m.getName() +
JavaClassWriterHelper.parenleft_ +
JavaClassWriterHelper.getParameterTypesList(m) +
JavaClassWriterHelper.parenright_ ;
|
|