Changeset 1202
- Timestamp:
- 12/04/11 23:04:48 (18 months ago)
- Location:
- raptor-client/trunk
- Files:
-
- 13 edited
-
src/main/java/uk/ac/cardiff/raptor/event/expansion/ResourceCategoryAttributeAssociationDefinition.java (modified) (1 diff)
-
src/main/java/uk/ac/cardiff/raptor/event/expansion/connector/DataConnector.java (modified) (1 diff)
-
src/main/java/uk/ac/cardiff/raptor/event/expansion/connector/RDBMSColumnDescriptor.java (modified) (1 diff)
-
src/main/java/uk/ac/cardiff/raptor/event/expansion/connector/RDBMSDataConnector.java (modified) (11 diffs)
-
src/main/java/uk/ac/cardiff/raptor/runtimeutils/ReflectionHelper.java (modified) (1 diff)
-
src/main/java/uk/ac/cardiff/raptor/store/impl/PersistantEventHandler.java (modified) (1 diff)
-
src/test/java/uk/ac/cardiff/raptor/event/expansion/RDBMSDataConnectorTest.java (modified) (2 diffs)
-
test-output/Default suite/Default test.html (modified) (1 diff)
-
test-output/Default suite/Default test.xml (modified) (1 diff)
-
test-output/Default suite/methods-alphabetical.html (modified) (1 diff)
-
test-output/Default suite/methods.html (modified) (1 diff)
-
test-output/junitreports/TEST-uk.ac.cardiff.raptor.event.expansion.RDBMSDataConnectorTest.xml (modified) (1 diff)
-
test-output/testng-results.xml (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/event/expansion/ResourceCategoryAttributeAssociationDefinition.java
r1176 r1202 51 51 52 52 ResourceMetadata resourceMetadata = null; 53 Object result = 54 dataConnection.runQueryUnique("from ResourceMetadata where resourceId=?", 55 new Object[] {event.getResourceId()}); 53 Object result = null; 54 if (event.getResourceId() != null) { 55 result = 56 dataConnection.runQueryUnique("from ResourceMetadata where resourceId=?", 57 new Object[] {event.getResourceId()}); 58 } 56 59 if (result != null && result instanceof ResourceMetadata) { 57 60 resourceMetadata = (ResourceMetadata) result; -
raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/event/expansion/connector/DataConnector.java
r1201 r1202 22 22 import java.util.Map; 23 23 24 /**25 * @author philsmart26 *27 */28 24 public interface DataConnector { 29 25 -
raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/event/expansion/connector/RDBMSColumnDescriptor.java
r1201 r1202 1 /** 2 * Copyright (C) 2010 Cardiff University, Wales <smartp@cf.ac.uk> 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 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 1 16 2 17 package uk.ac.cardiff.raptor.event.expansion.connector; -
raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/event/expansion/connector/RDBMSDataConnector.java
r1201 r1202 1 /* 2 * Licensed to the University Corporation for Advanced Internet Development, 3 * Inc. (UCAID) under one or more contributor license agreements. See the 4 * NOTICE file distributed with this work for additional information regarding 5 * copyright ownership. The UCAID licenses this file to You under the Apache 6 * License, Version 2.0 (the "License"); you may not use this file except in 7 * compliance with the License. You may obtain a copy of the License at 1 /** 2 * Copyright (C) 2010 Cardiff University, Wales <smartp@cf.ac.uk> 8 3 * 9 * http://www.apache.org/licenses/LICENSE-2.0 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 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 10 9 * 11 10 * Unless required by applicable law or agreed to in writing, software … … 15 14 * limitations under the License. 16 15 */ 17 18 16 package uk.ac.cardiff.raptor.event.expansion.connector; 19 17 … … 90 88 * Constructor. 91 89 * 92 * @param source data source used to retrieve connections 93 */ 94 public RDBMSDataConnector(DataSource source) { 90 */ 91 public RDBMSDataConnector() { 95 92 super(); 96 97 dataSource = source;98 99 readOnlyConnection = true;100 usesStoredProcedure = false;101 noResultIsError = false;102 103 columnDescriptors = new HashMap<String, RDBMSColumnDescriptor>();104 93 } 105 94 … … 123 112 initialized = true; 124 113 initializeCache(); 114 readOnlyConnection = true; 115 usesStoredProcedure = false; 116 noResultIsError = false; 117 columnDescriptors = new HashMap<String, RDBMSColumnDescriptor>(); 125 118 } 126 119 } … … 206 199 public Map<String, RDBMSColumnDescriptor> getColumnDescriptor() { 207 200 return columnDescriptors; 201 } 202 203 /** 204 * This removes all entries from the cache. {@link #initialize()} must be called first or this method does nothing. 205 */ 206 protected void clearCache() { 207 if (cacheResults && initialized) { 208 cache.clear(); 209 cacheResetTimeMs = System.currentTimeMillis(); 210 } 211 } 212 213 private void checkCacheValidity() { 214 if (cacheTimeoutMs == 0 || !cacheResults) { 215 return; 216 } 217 long currentTimeMillis = System.currentTimeMillis(); 218 boolean shouldReset = (currentTimeMillis - cacheResetTimeMs) > cacheTimeoutMs; 219 log.trace("Should reset cache?{} - time left {}", shouldReset, (currentTimeMillis - cacheResetTimeMs)); 220 if (shouldReset) { 221 log.info("Ldap cache was cleared, timeout reached"); 222 clearCache(); 223 } 208 224 } 209 225 … … 258 274 query = query.trim(); 259 275 276 checkCacheValidity(); 277 260 278 Map<String, String> resolvedAttributes = null; 261 279 if (cacheResults) { … … 292 310 Map<String, Map<String, String>> results = cache.get(principal); 293 311 attributes = results.get(query); 294 log. debug("RDBMS data connector - Fetched attributes from cache for principal {}", principal);312 log.trace("RDBMS data connector - Fetched attributes from cache for principal {}", principal); 295 313 } 296 314 } … … 299 317 } 300 318 319 /** 320 * Attributes returned from the database connector are defined by the SELECT statement in the SQL query, not through 321 * the <code>attributes</code> array. This is a no-op method. 322 */ 301 323 public void setReturnAttributes(String[] attributes) { 302 324 … … 323 345 connection.setReadOnly(true); 324 346 } 325 log. debug("RDBMS data connector - Querying database for attributes with query {}", query);347 log.trace("RDBMS data connector - Querying database for attributes with query {}", query); 326 348 Statement stmt = connection.createStatement(); 327 349 stmt.setQueryTimeout(queryTimeout); … … 502 524 results.put(query, attributes); 503 525 504 log. debug("RDBMS data connector - Caching attributes for principal {}", principal);526 log.trace("RDBMS data connector - Caching attributes for principal {}", principal); 505 527 506 528 } … … 562 584 } 563 585 586 /** 587 * @param dataSource the dataSource to set 588 */ 589 public void setDataSource(DataSource dataSource) { 590 this.dataSource = dataSource; 591 } 592 564 593 } -
raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/runtimeutils/ReflectionHelper.java
r1176 r1202 122 122 123 123 /** 124 * Uses reflection to get all the classes that are in the <code>EVENT_PACKAGE_NAME</code package. 125 * 126 * @return a list of simple names of found classes; 127 */ 128 public static List<String> getAllEventClasses() { 129 List<String> allClasses = new ArrayList<String>(); 130 String forPckgName = EVENT_PACKAGE_NAME; 131 String jarFile = getJARFilePath(forPckgName); 132 jarFile = jarFile.replace("file:", ""); 133 log.debug("jar {}", jarFile); 134 List<String> classes = getClassNamesInJarOrFolder(jarFile, forPckgName); 135 136 for (String classname : classes) { 137 try { 138 Object o = Class.forName(classname.replace(".class", "")).newInstance(); 139 if (o != null) 140 if (o instanceof uk.ac.cardiff.model.event.Event) { 141 allClasses.add(o.getClass().getSimpleName()); 142 } 143 } catch (ClassNotFoundException cnfex) { 144 log.error("error getting subclasses of Entry, {}", cnfex); 145 } catch (InstantiationException iex) { 146 // log.error("{}", iex); 147 } catch (IllegalAccessException iaex) { 148 // The class is not public 149 } 150 } 151 return allClasses; 152 } 153 154 /** 124 155 * This is terrible code. Finds all fieldnames of all classes that are subclasses of the 125 * <code>uk.ac.cardiff.model.event.Event</code>class.156 * {@link uk.ac.cardiff.model.event.Event} class. 126 157 * 127 158 * @return -
raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/store/impl/PersistantEventHandler.java
r1188 r1202 93 93 94 94 public List query(String query, Object[] parameters) { 95 log.trace("SQL query to entry handler [{}], with parameters [{}]", query, Arrays.asList(parameters)); 95 if (parameters != null) { 96 log.trace("SQL query to entry handler [{}], with parameters [{}]", query, Arrays.asList(parameters)); 97 } else { 98 log.trace("SQL query to entry handler [{}], with no parameters", query); 99 } 96 100 return dataConnection.runQuery(query, parameters); 97 101 } -
raptor-client/trunk/src/test/java/uk/ac/cardiff/raptor/event/expansion/RDBMSDataConnectorTest.java
r1201 r1202 1 /** 2 * Copyright (C) 2010 Cardiff University, Wales <smartp@cf.ac.uk> 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 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 1 16 2 17 package uk.ac.cardiff.raptor.event.expansion; … … 24 39 bds.setPassword(""); 25 40 26 dataConnector = new RDBMSDataConnector(bds); 41 dataConnector = new RDBMSDataConnector(); 42 dataConnector.setDataSource(bds); 27 43 dataConnector.setNoResultIsError(false); 28 44 dataConnector.setCacheResults(true); 45 dataConnector.setCacheTimeoutMs(1000); 29 46 dataConnector.initialise(); 30 47 } -
raptor-client/trunk/test-output/Default suite/Default test.html
r1201 r1202 58 58 <td>Tests passed/Failed/Skipped:</td><td>2/0/0</td> 59 59 </tr><tr> 60 <td>Started on:</td><td> Mon Nov 28 22:44:42 GMT 2011</td>60 <td>Started on:</td><td>Tue Nov 29 10:53:12 GMT 2011</td> 61 61 </tr> 62 <tr><td>Total time:</td><td>0 seconds (22 2ms)</td>62 <tr><td>Total time:</td><td>0 seconds (227 ms)</td> 63 63 </tr><tr> 64 64 <td>Included groups:</td><td></td> -
raptor-client/trunk/test-output/Default suite/Default test.xml
r1201 r1202 1 1 <?xml version="1.0" encoding="UTF-8"?> 2 <testsuite hostname="testkwshibb1.nerc.ac.uk" name="uk.ac.cardiff.raptor.event.expansion.RDBMSDataConnectorTest" tests="2" failures="0" timestamp="2 8 Nov 2011 22:44:42 GMT" time="0.222" errors="0">2 <testsuite hostname="testkwshibb1.nerc.ac.uk" name="uk.ac.cardiff.raptor.event.expansion.RDBMSDataConnectorTest" tests="2" failures="0" timestamp="29 Nov 2011 10:53:12 GMT" time="0.227" errors="0"> 3 3 <testcase name="cacheTest" time="0.092" classname="uk.ac.cardiff.raptor.event.expansion.RDBMSDataConnectorTest"/> 4 4 <testcase name="getAttributesTest" time="0.0050" classname="uk.ac.cardiff.raptor.event.expansion.RDBMSDataConnectorTest"/> -
raptor-client/trunk/test-output/Default suite/methods-alphabetical.html
r1201 r1202 2 2 <table border="1"> 3 3 <tr><th>Time</th><th>Delta (ms)</th><th>Suite<br>configuration</th><th>Test<br>configuration</th><th>Class<br>configuration</th><th>Groups<br>configuration</th><th>Method<br>configuration</th><th>Test<br>method</th><th>Thread</th><th>Instances</th></tr> 4 <tr bgcolor="cd6888"> <td>11/11/2 8 22:44:42</td> <td>0</td> <td> </td><td> </td><td> </td><td> </td><td> </td><td title="uk.ac.cardiff.raptor.event.expansion.RDBMSDataConnectorTest.cacheTest()">cacheTest</td>4 <tr bgcolor="cd6888"> <td>11/11/29 10:53:12</td> <td>0</td> <td> </td><td> </td><td> </td><td> </td><td> </td><td title="uk.ac.cardiff.raptor.event.expansion.RDBMSDataConnectorTest.cacheTest()">cacheTest</td> 5 5 <td>main@1211753909</td> <td></td> </tr> 6 <tr bgcolor="cd6888"> <td>11/11/2 8 22:44:42</td> <td>93</td> <td> </td><td> </td><td> </td><td> </td><td> </td><td title="uk.ac.cardiff.raptor.event.expansion.RDBMSDataConnectorTest.getAttributesTest()">getAttributesTest</td>6 <tr bgcolor="cd6888"> <td>11/11/29 10:53:12</td> <td>94</td> <td> </td><td> </td><td> </td><td> </td><td> </td><td title="uk.ac.cardiff.raptor.event.expansion.RDBMSDataConnectorTest.getAttributesTest()">getAttributesTest</td> 7 7 <td>main@1211753909</td> <td></td> </tr> 8 <tr bgcolor="cd6888"> <td>11/11/2 8 22:44:42</td> <td>-115</td> <td> </td><td> </td><td title=">>uk.ac.cardiff.raptor.event.expansion.RDBMSDataConnectorTest.setup()">>>setup</td>8 <tr bgcolor="cd6888"> <td>11/11/29 10:53:12</td> <td>-119</td> <td> </td><td> </td><td title=">>uk.ac.cardiff.raptor.event.expansion.RDBMSDataConnectorTest.setup()">>>setup</td> 9 9 <td> </td><td> </td><td> </td> <td>main@1211753909</td> <td></td> </tr> 10 10 </table> -
raptor-client/trunk/test-output/Default suite/methods.html
r1201 r1202 2 2 <table border="1"> 3 3 <tr><th>Time</th><th>Delta (ms)</th><th>Suite<br>configuration</th><th>Test<br>configuration</th><th>Class<br>configuration</th><th>Groups<br>configuration</th><th>Method<br>configuration</th><th>Test<br>method</th><th>Thread</th><th>Instances</th></tr> 4 <tr bgcolor="cd6888"> <td>11/11/2 8 22:44:42</td> <td>0</td> <td> </td><td> </td><td title=">>uk.ac.cardiff.raptor.event.expansion.RDBMSDataConnectorTest.setup()">>>setup</td>4 <tr bgcolor="cd6888"> <td>11/11/29 10:53:12</td> <td>0</td> <td> </td><td> </td><td title=">>uk.ac.cardiff.raptor.event.expansion.RDBMSDataConnectorTest.setup()">>>setup</td> 5 5 <td> </td><td> </td><td> </td> <td>main@1211753909</td> <td></td> </tr> 6 <tr bgcolor="cd6888"> <td>11/11/2 8 22:44:42</td> <td>115</td> <td> </td><td> </td><td> </td><td> </td><td> </td><td title="uk.ac.cardiff.raptor.event.expansion.RDBMSDataConnectorTest.cacheTest()">cacheTest</td>6 <tr bgcolor="cd6888"> <td>11/11/29 10:53:12</td> <td>119</td> <td> </td><td> </td><td> </td><td> </td><td> </td><td title="uk.ac.cardiff.raptor.event.expansion.RDBMSDataConnectorTest.cacheTest()">cacheTest</td> 7 7 <td>main@1211753909</td> <td></td> </tr> 8 <tr bgcolor="cd6888"> <td>11/11/2 8 22:44:42</td> <td>208</td> <td> </td><td> </td><td> </td><td> </td><td> </td><td title="uk.ac.cardiff.raptor.event.expansion.RDBMSDataConnectorTest.getAttributesTest()">getAttributesTest</td>8 <tr bgcolor="cd6888"> <td>11/11/29 10:53:12</td> <td>213</td> <td> </td><td> </td><td> </td><td> </td><td> </td><td title="uk.ac.cardiff.raptor.event.expansion.RDBMSDataConnectorTest.getAttributesTest()">getAttributesTest</td> 9 9 <td>main@1211753909</td> <td></td> </tr> 10 10 </table> -
raptor-client/trunk/test-output/junitreports/TEST-uk.ac.cardiff.raptor.event.expansion.RDBMSDataConnectorTest.xml
r1201 r1202 1 1 <?xml version="1.0" encoding="UTF-8"?> 2 2 <!-- Generated by org.testng.reporters.JUnitReportReporter --> 3 <testsuite hostname="testkwshibb1.nerc.ac.uk" name="uk.ac.cardiff.raptor.event.expansion.RDBMSDataConnectorTest" tests="2" failures="0" timestamp="28 Nov 2011 22:44:42 GMT" time="0.097" errors="0"> 3 <testsuite hostname="testkwshibb1.nerc.ac.uk" name="uk.ac.cardiff.raptor.event.expansion.RDBMSDataConnectorTest" tests="2" failures="0" timestamp="29 Nov 2011 10:53:12 GMT" time="0.097" errors="0"> 4 <testcase name="getAttributesTest" time="0.005" classname="uk.ac.cardiff.raptor.event.expansion.RDBMSDataConnectorTest"/> 4 5 <testcase name="cacheTest" time="0.092" classname="uk.ac.cardiff.raptor.event.expansion.RDBMSDataConnectorTest"/> 5 <testcase name="getAttributesTest" time="0.005" classname="uk.ac.cardiff.raptor.event.expansion.RDBMSDataConnectorTest"/>6 6 </testsuite> -
raptor-client/trunk/test-output/testng-results.xml
r1201 r1202 3 3 <reporter-output> 4 4 </reporter-output> 5 <suite name="Default suite" duration-ms="22 2" started-at="2011-11-28T22:44:42Z" finished-at="2011-11-28T22:44:42Z">5 <suite name="Default suite" duration-ms="227" started-at="2011-11-29T10:53:12Z" finished-at="2011-11-29T10:53:12Z"> 6 6 <groups> 7 7 </groups> 8 <test name="Default test" duration-ms="22 2" started-at="2011-11-28T22:44:42Z" finished-at="2011-11-28T22:44:42Z">8 <test name="Default test" duration-ms="227" started-at="2011-11-29T10:53:12Z" finished-at="2011-11-29T10:53:12Z"> 9 9 <class name="uk.ac.cardiff.raptor.event.expansion.RDBMSDataConnectorTest"> 10 <test-method status="PASS" signature="setup()" name="setup" is-config="true" duration-ms="11 6" started-at="2011-11-28T22:44:42Z" finished-at="2011-11-28T22:44:42Z">10 <test-method status="PASS" signature="setup()" name="setup" is-config="true" duration-ms="119" started-at="2011-11-29T10:53:12Z" finished-at="2011-11-29T10:53:12Z"> 11 11 </test-method> 12 <test-method status="PASS" signature="cacheTest()" name="cacheTest" duration-ms="92" started-at="2011-11-2 8T22:44:42Z" finished-at="2011-11-28T22:44:42Z">12 <test-method status="PASS" signature="cacheTest()" name="cacheTest" duration-ms="92" started-at="2011-11-29T10:53:12Z" finished-at="2011-11-29T10:53:12Z"> 13 13 </test-method> 14 <test-method status="PASS" signature="getAttributesTest()" name="getAttributesTest" duration-ms="5" started-at="2011-11-2 8T22:44:42Z" finished-at="2011-11-28T22:44:42Z">14 <test-method status="PASS" signature="getAttributesTest()" name="getAttributesTest" duration-ms="5" started-at="2011-11-29T10:53:12Z" finished-at="2011-11-29T10:53:12Z"> 15 15 </test-method> 16 16 </class>
Note: See TracChangeset
for help on using the changeset viewer.
