本文整理汇总了Java中com.espertech.esper.epl.db.DatabasePollingViewableFactory类的典型用法代码示例。如果您正苦于以下问题:Java DatabasePollingViewableFactory类的具体用法?Java DatabasePollingViewableFactory怎么用?Java DatabasePollingViewableFactory使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DatabasePollingViewableFactory类属于com.espertech.esper.epl.db包,在下文中一共展示了DatabasePollingViewableFactory类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testDBStatementViewFactory
import com.espertech.esper.epl.db.DatabasePollingViewableFactory; //导入依赖的package包/类
public void testDBStatementViewFactory() throws Exception
{
DBStatementStreamSpec spec = new DBStatementStreamSpec("s0", new LinkedList<ViewSpec>(),
"mydb_part", "select * from mytesttable where mybigint=${idnum}", null);
EventCollection eventCollection = DatabasePollingViewableFactory.createDBStatementView("id", 1, spec,
SupportDatabaseService.makeService(),
SupportEventAdapterService.getService(), null, null, null, true);
assertEquals(Long.class, eventCollection.getEventType().getPropertyType("mybigint"));
assertEquals(String.class, eventCollection.getEventType().getPropertyType("myvarchar"));
assertEquals(Boolean.class, eventCollection.getEventType().getPropertyType("mybool"));
assertEquals(BigDecimal.class, eventCollection.getEventType().getPropertyType("mynumeric"));
assertEquals(BigDecimal.class, eventCollection.getEventType().getPropertyType("mydecimal"));
}
示例2: testLexSampleSQL
import com.espertech.esper.epl.db.DatabasePollingViewableFactory; //导入依赖的package包/类
public void testLexSampleSQL() throws ExprValidationException
{
String[][] testcases = new String[][] {
{"select * from A where a=b and c=d", "select * from A where 1=0 and a=b and c=d"},
{"select * from A where 1=0", "select * from A where 1=0 and 1=0"},
{"select * from A", "select * from A where 1=0"},
{"select * from A group by x", "select * from A where 1=0 group by x"},
{"select * from A having a>b", "select * from A where 1=0 having a>b"},
{"select * from A order by d", "select * from A where 1=0 order by d"},
{"select * from A group by a having b>c order by d", "select * from A where 1=0 group by a having b>c order by d"},
{"select * from A where (7<4) group by a having b>c order by d", "select * from A where 1=0 and (7<4) group by a having b>c order by d"},
{"select * from A union select * from B", "select * from A where 1=0 union select * from B where 1=0"},
{"select * from A where a=2 union select * from B where 2=3", "select * from A where 1=0 and a=2 union select * from B where 1=0 and 2=3"},
{"select * from A union select * from B union select * from C", "select * from A where 1=0 union select * from B where 1=0 union select * from C where 1=0"},
};
for (int i = 0; i < testcases.length; i++)
{
String result = null;
try
{
result = DatabasePollingViewableFactory.lexSampleSQL(testcases[i][0]).trim();
}
catch (Exception ex)
{
fail("failed case with exception:" + testcases[i][0]);
}
String expected = testcases[i][1].trim();
assertEquals("failed case " + i + " :" + testcases[i][0], expected, result);
}
}
示例3: mapSQLParameters
import com.espertech.esper.epl.db.DatabasePollingViewableFactory; //导入依赖的package包/类
private static void mapSQLParameters(FromClause fromClause, StatementSpecRaw raw, StatementSpecMapContext mapContext) {
if ((fromClause == null) || (fromClause.getStreams() == null)) {
return;
}
int streamNum = -1;
for (Stream stream : fromClause.getStreams()) {
streamNum++;
if (!(stream instanceof SQLStream)) {
continue;
}
SQLStream sqlStream = (SQLStream) stream;
List<PlaceholderParser.Fragment> sqlFragments = null;
try {
sqlFragments = PlaceholderParser.parsePlaceholder(sqlStream.getSqlWithSubsParams());
} catch (PlaceholderParseException e) {
throw new RuntimeException("Error parsing SQL placeholder expression '" + sqlStream.getSqlWithSubsParams() + "': ");
}
for (PlaceholderParser.Fragment fragment : sqlFragments) {
if (!(fragment instanceof PlaceholderParser.ParameterFragment)) {
continue;
}
// Parse expression, store for substitution parameters
String expression = fragment.getValue();
if (expression.toUpperCase(Locale.ENGLISH).equals(DatabasePollingViewableFactory.SAMPLE_WHERECLAUSE_PLACEHOLDER)) {
continue;
}
if (expression.trim().length() == 0) {
throw ASTWalkException.from("Missing expression within ${...} in SQL statement");
}
String toCompile = "select * from java.lang.Object where " + expression;
StatementSpecRaw rawSqlExpr = EPAdministratorHelper.compileEPL(toCompile, expression, false, null, SelectClauseStreamSelectorEnum.ISTREAM_ONLY,
mapContext.getEngineImportService(), mapContext.getVariableService(), mapContext.getEngineURI(), mapContext.getConfiguration(), mapContext.getPatternNodeFactory(), mapContext.getContextManagementService(), mapContext.getExprDeclaredService(), mapContext.getTableService());
if ((rawSqlExpr.getSubstitutionParameters() != null) && (rawSqlExpr.getSubstitutionParameters().size() > 0)) {
throw ASTWalkException.from("EPL substitution parameters are not allowed in SQL ${...} expressions, consider using a variable instead");
}
if (rawSqlExpr.isHasVariables()) {
mapContext.setHasVariables(true);
}
// add expression
if (raw.getSqlParameters() == null) {
raw.setSqlParameters(new HashMap<Integer, List<ExprNode>>());
}
List<ExprNode> listExp = raw.getSqlParameters().get(streamNum);
if (listExp == null) {
listExp = new ArrayList<ExprNode>();
raw.getSqlParameters().put(streamNum, listExp);
}
listExp.add(rawSqlExpr.getFilterRootNode());
}
}
}
示例4: mapSQLParameters
import com.espertech.esper.epl.db.DatabasePollingViewableFactory; //导入依赖的package包/类
private static void mapSQLParameters(FromClause fromClause, StatementSpecRaw raw, StatementSpecMapContext mapContext)
{
if ((fromClause == null) || (fromClause.getStreams() == null)) {
return;
}
int streamNum = -1;
for (Stream stream : fromClause.getStreams()) {
streamNum++;
if (!(stream instanceof SQLStream)) {
continue;
}
SQLStream sqlStream = (SQLStream) stream;
List<PlaceholderParser.Fragment> sqlFragments = null;
try
{
sqlFragments = PlaceholderParser.parsePlaceholder(sqlStream.getSqlWithSubsParams());
}
catch (PlaceholderParseException e)
{
throw new RuntimeException("Error parsing SQL placeholder expression '" + sqlStream.getSqlWithSubsParams() + "': ");
}
for (PlaceholderParser.Fragment fragment : sqlFragments)
{
if (!(fragment instanceof PlaceholderParser.ParameterFragment)) {
continue;
}
// Parse expression, store for substitution parameters
String expression = fragment.getValue();
if (expression.toUpperCase().equals(DatabasePollingViewableFactory.SAMPLE_WHERECLAUSE_PLACEHOLDER)) {
continue;
}
if (expression.trim().length() == 0) {
throw new ASTWalkException("Missing expression within ${...} in SQL statement");
}
String toCompile = "select * from java.lang.Object where " + expression;
StatementSpecRaw rawSqlExpr = EPAdministratorHelper.compileEPL(toCompile, expression, false, null, SelectClauseStreamSelectorEnum.ISTREAM_ONLY,
mapContext.getEngineImportService(), mapContext.getVariableService(), mapContext.getSchedulingService(), mapContext.getEngineURI(), mapContext.getConfiguration(), mapContext.getPatternNodeFactory(), mapContext.getContextManagementService(), mapContext.getExprDeclaredService());
if ((rawSqlExpr.getSubstitutionParameters() != null) && (rawSqlExpr.getSubstitutionParameters().size() > 0)) {
throw new ASTWalkException("EPL substitution parameters are not allowed in SQL ${...} expressions, consider using a variable instead");
}
if (rawSqlExpr.isHasVariables()) {
mapContext.setHasVariables(true);
}
// add expression
if (raw.getSqlParameters() == null) {
raw.setSqlParameters(new HashMap<Integer, List<ExprNode>>());
}
List<ExprNode> listExp = raw.getSqlParameters().get(streamNum);
if (listExp == null) {
listExp = new ArrayList<ExprNode>();
raw.getSqlParameters().put(streamNum, listExp);
}
listExp.add(rawSqlExpr.getFilterRootNode());
}
}
}