1 /***
2 * Copyright 2003, 2004, 2005. CodeStreet LLC.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
7 *
8 * Unless required by applicable law or agreed to in writing, software
9 * distributed under the License is distributed on an "AS IS" BASIS,
10 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 * See the License for the specific language governing permissions and
12 * limitations under the License.
13 */
14
15 package com.codestreet.selector;
16
17 import com.codestreet.selector.parser.Result;
18 import com.codestreet.selector.rv.ValueProvider;
19 import com.codestreet.selector.parser.NumericValue;
20
21 // import com.codestreet.selector.jms.ValueProvider;
22 import com.tibco.tibrv.*;
23 import java.math.BigDecimal;
24 import java.util.Hashtable;
25
26 /*
27 * import com.tibco.tibjms.*; import javax.jms.*;
28 */
29
30 /***
31 * Created by IntelliJ IDEA. User: jawaid.hakim Date: Mar 26, 2003 Time:
32 * 11:00:08 AM To change this template use Options | File Templates.
33 */
34 public class Main
35 {
36 public Main()
37 {
38 }
39
40 public static void main(String[] args)
41 {
42 try
43 {
44 {
45 /*
46 * com.tibco.tibjms.TibjmsConnectionFactory connFact = new
47 * com.tibco.tibjms.TibjmsConnectionFactory("tcp://localhost:7222");
48 * Connection conn = connFact.createConnection(); Session sess =
49 * conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
50 *
51 * MapMessage mapMsg = sess.createMapMessage();
52 * mapMsg.setStringProperty("MessageName", "CreateOrder");
53 * mapMsg.setDoubleProperty("Quantity", 101.0);
54 * mapMsg.setDoubleProperty("Price", 100.0);
55 * mapMsg.setDoubleProperty("MinLot", 50);
56 * mapMsg.setBooleanProperty("JMS_TIBCO_MSG_EXT", true);
57 * MapMessage nestedMapMsg = sess.createMapMessage();
58 * nestedMapMsg.setStringProperty("MessageName", "CreateOrder");
59 * mapMsg.setObject("Nested", nestedMapMsg);
60 *
61 * ValueProvider ext = new ValueProvider(mapMsg);
62 *
63 * //String selector = "Quantity > 100 AND Price < 100 OR MinLot >=
64 * 50 AND MessageName in ('foo', 'goo', 'too', 'CreateOrder',
65 * 'last')"; //String selector = "MessageName in ('foo', 'goo',
66 * 'too', 'CreateOrder', 'last', '1', '2', '3', '4', '5', 'a',
67 * 'b', 'c', 'd')"; String selector = "JMSPriority >= 0 AND
68 * Quantity > 100 AND MessageName in ('foo', 'goo', 'too',
69 * 'CreateOrder', 'last', '1', '2', '3', '4', '5', 'a', 'b',
70 * 'c', 'd')"; //String selector = "Quantity > 100 AND Price <
71 * 100 OR MinLot >= 50"; // String selector = "MessageName LIKE
72 * 'Create_r%#%' ESCAPE '#' AND Price <= 100 OR Quantity > 100
73 * AND MinLot >= 50"; //String selector = "MessageName LIKE
74 * 'Create_r//_%' ESCAPE '//'"; Selector csselector =
75 * Selector.getInstance(selector);
76 *
77 * //System.out.println(csselector.toString());
78 * // Get the list of identifiers that the parser found. For
79 * each identifier - set the // value appropriately. //Map idMap =
80 * csselector.getIdentifiers();
81 * // Evaluate the selector many times and print out the time.
82 * long start = System.currentTimeMillis(); long upper =
83 * 2000000; for (long i = 0; i < upper; ++i) { /* // Set
84 * identifier values Map idValues = new java.util.HashMap(); for
85 * (java.util.Iterator iter = idMap.keySet().iterator();
86 * iter.hasNext(); ) { String id = (String)iter.next(); if
87 * (id.equals("Quantity")) idValues.put(id, new Double(101));
88 * else if (id.equals("MessageName")) idValues.put(id,
89 * "CreateOrder"); else if (id.equals("Price")) idValues.put(id,
90 * new Double(100)); else if (id.equals("MinLot"))
91 * idValues.put(id, new Double(50)); }
92 */
93
94 /*
95 * // Evaluate selector csselector.eval(ext, null); } long end =
96 * System.currentTimeMillis(); System.out.println(upper + "
97 * evaluations of '" + selector + "' in " + ((end - start) /
98 * 1000) + " seconds");
99 */
100 }
101
102 {
103 java.util.Map map = new java.util.HashMap();
104 map.put("SecurityID", "TIBX");
105 map.put("Quantity", new NumericValue(new Integer(101)));
106 map.put("Volume", new NumericValue(new Double(25.5)));
107
108 String selector = "Quantity > 100 AND Volume <= 50.5";
109 //String selector = "SecurityID = 'TIBX' AND Quantity > 100 AND Volume <= 50.5";
110 Selector csselector = Selector.getInstance(selector);
111
112 /*
113 * TibrvMsg rvMsg = new TibrvMsg(); rvMsg.add("Quantity", new
114 * Double(101)); rvMsg.add("Price", new Double(100));
115 * rvMsg.add("MinLot", new Double(50)); rvMsg.add("MessageName",
116 * "CreateOrder"); rvMsg.add("JMSPriority", new Integer(0));
117 * TibrvMsg nested = new TibrvMsg(); nested.add("MessageName",
118 * "CreateOrder%"); rvMsg.add("Nested", nested);
119 *
120 * ValueProvider ext = ValueProvider.valueOf(rvMsg);
121 *
122 */
123
124 // String selector = "MessageName in ('foo', 'goo', 'too',
125 // 'CreateOrder', 'last', '1', '2', '3', '4', '5', 'a', 'b',
126 // 'c', 'd')";
127 // String selector = "MessageName in ('foo', 'goo', 'too',
128 // 'CreateOrder', 'last', '1', '2', '3', '4', '5', 'a', 'b',
129 // 'c', 'd')";
130 // String selector = "JMSPriority >= 0 AND Quantity > 100 AND
131 // MessageName in ('foo', 'goo', 'too', 'CreateOrder', 'last',
132 // '1', '2', '3', '4', '5', 'a', 'b', 'c', 'd')";
133 // String selector = "Quantity > 100 AND Price < 100 OR MinLot
134 // >= 50";
135 // String selector = "MessageName LIKE 'CreateOr%' ESCAPE '#'
136 // AND Price <= 100 OR Quantity > 100 AND MinLot >= 50";
137 // String selector = "MessageName LIKE 'Create_r//_%' ESCAPE
138 // '//'";
139 // System.out.println(csselector.toString());
140 // Get the list of identifiers that the parser found. For each
141 // identifier - set the
142 // value appropriately.
143 // Map idMap = csselector.getIdentifiers();
144 // Evaluate the selector many times and print out the time.
145 long start = System.currentTimeMillis();
146 long upper = 2000000;
147 for (long i = 0; i < upper; ++i)
148 {
149 /*
150 * // Set identifier values Map idValues = new
151 * java.util.HashMap(); for (java.util.Iterator iter =
152 * idMap.keySet().iterator(); iter.hasNext(); ) { String id =
153 * (String)iter.next(); if (id.equals("Quantity"))
154 * idValues.put(id, new Double(101)); else if
155 * (id.equals("MessageName")) idValues.put(id,
156 * "CreateOrder"); else if (id.equals("Price"))
157 * idValues.put(id, new Double(100)); else if
158 * (id.equals("MinLot")) idValues.put(id, new Double(50)); }
159 */
160
161 // Evaluate selector
162 Result result = csselector.eval(map);
163 System.out.println(result.toString());
164 }
165 long end = System.currentTimeMillis();
166 System.out.println(upper + " evaluations of '" + selector
167 + "' in " + ((end - start) / 1000) + " seconds");
168 }
169
170 }
171 catch (Exception ex)
172 {
173 ex.printStackTrace();
174 }
175 }
176 }
This page was automatically generated by Maven