Changeset 1202 for raptor-client


Ignore:
Timestamp:
12/04/11 23:04:48 (9 years ago)
Author:
philsmart
Message:
 
Location:
raptor-client/trunk
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/event/expansion/ResourceCategoryAttributeAssociationDefinition.java

    r1176 r1202  
    5151 
    5252        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        } 
    5659        if (result != null && result instanceof ResourceMetadata) { 
    5760            resourceMetadata = (ResourceMetadata) result; 
  • raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/event/expansion/connector/DataConnector.java

    r1201 r1202  
    2222import java.util.Map; 
    2323 
    24 /** 
    25  * @author philsmart 
    26  *  
    27  */ 
    2824public interface DataConnector { 
    2925 
  • 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 */ 
    116 
    217package 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> 
    83 * 
    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 
    109 * 
    1110 * Unless required by applicable law or agreed to in writing, software 
     
    1514 * limitations under the License. 
    1615 */ 
    17  
    1816package uk.ac.cardiff.raptor.event.expansion.connector; 
    1917 
     
    9088     * Constructor. 
    9189     *  
    92      * @param source data source used to retrieve connections 
    93      */ 
    94     public RDBMSDataConnector(DataSource source) { 
     90     */ 
     91    public RDBMSDataConnector() { 
    9592        super(); 
    96  
    97         dataSource = source; 
    98  
    99         readOnlyConnection = true; 
    100         usesStoredProcedure = false; 
    101         noResultIsError = false; 
    102  
    103         columnDescriptors = new HashMap<String, RDBMSColumnDescriptor>(); 
    10493    } 
    10594 
     
    123112            initialized = true; 
    124113            initializeCache(); 
     114            readOnlyConnection = true; 
     115            usesStoredProcedure = false; 
     116            noResultIsError = false; 
     117            columnDescriptors = new HashMap<String, RDBMSColumnDescriptor>(); 
    125118        } 
    126119    } 
     
    206199    public Map<String, RDBMSColumnDescriptor> getColumnDescriptor() { 
    207200        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        } 
    208224    } 
    209225 
     
    258274        query = query.trim(); 
    259275 
     276        checkCacheValidity(); 
     277 
    260278        Map<String, String> resolvedAttributes = null; 
    261279        if (cacheResults) { 
     
    292310                Map<String, Map<String, String>> results = cache.get(principal); 
    293311                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); 
    295313            } 
    296314        } 
     
    299317    } 
    300318 
     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     */ 
    301323    public void setReturnAttributes(String[] attributes) { 
    302324 
     
    323345                connection.setReadOnly(true); 
    324346            } 
    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); 
    326348            Statement stmt = connection.createStatement(); 
    327349            stmt.setQueryTimeout(queryTimeout); 
     
    502524        results.put(query, attributes); 
    503525 
    504         log.debug("RDBMS data connector - Caching attributes for principal {}", principal); 
     526        log.trace("RDBMS data connector - Caching attributes for principal {}", principal); 
    505527 
    506528    } 
     
    562584    } 
    563585 
     586    /** 
     587     * @param dataSource the dataSource to set 
     588     */ 
     589    public void setDataSource(DataSource dataSource) { 
     590        this.dataSource = dataSource; 
     591    } 
     592 
    564593} 
  • raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/runtimeutils/ReflectionHelper.java

    r1176 r1202  
    122122 
    123123    /** 
     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    /** 
    124155     * 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. 
    126157     *  
    127158     * @return 
  • raptor-client/trunk/src/main/java/uk/ac/cardiff/raptor/store/impl/PersistantEventHandler.java

    r1188 r1202  
    9393 
    9494    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        } 
    96100        return dataConnection.runQuery(query, parameters); 
    97101    } 
  • 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 */ 
    116 
    217package uk.ac.cardiff.raptor.event.expansion; 
     
    2439        bds.setPassword(""); 
    2540 
    26         dataConnector = new RDBMSDataConnector(bds); 
     41        dataConnector = new RDBMSDataConnector(); 
     42        dataConnector.setDataSource(bds); 
    2743        dataConnector.setNoResultIsError(false); 
    2844        dataConnector.setCacheResults(true); 
     45        dataConnector.setCacheTimeoutMs(1000); 
    2946        dataConnector.initialise(); 
    3047    } 
  • raptor-client/trunk/test-output/Default suite/Default test.html

    r1201 r1202  
    5858<td>Tests passed/Failed/Skipped:</td><td>2/0/0</td> 
    5959</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> 
    6161</tr> 
    62 <tr><td>Total time:</td><td>0 seconds (222 ms)</td> 
     62<tr><td>Total time:</td><td>0 seconds (227 ms)</td> 
    6363</tr><tr> 
    6464<td>Included groups:</td><td></td> 
  • raptor-client/trunk/test-output/Default suite/Default test.xml

    r1201 r1202  
    11<?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="28 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"> 
    33  <testcase name="cacheTest" time="0.092" classname="uk.ac.cardiff.raptor.event.expansion.RDBMSDataConnectorTest"/> 
    44  <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  
    22<table border="1"> 
    33<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/28 22:44:42</td>   <td>0</td> <td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</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>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td title="uk.ac.cardiff.raptor.event.expansion.RDBMSDataConnectorTest.cacheTest()">cacheTest</td>  
    55  <td>main@1211753909</td>   <td></td> </tr> 
    6 <tr bgcolor="cd6888">  <td>11/11/28 22:44:42</td>   <td>93</td> <td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</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>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td title="uk.ac.cardiff.raptor.event.expansion.RDBMSDataConnectorTest.getAttributesTest()">getAttributesTest</td>  
    77  <td>main@1211753909</td>   <td></td> </tr> 
    8 <tr bgcolor="cd6888">  <td>11/11/28 22:44:42</td>   <td>-115</td> <td>&nbsp;</td><td>&nbsp;</td><td title="&gt;&gt;uk.ac.cardiff.raptor.event.expansion.RDBMSDataConnectorTest.setup()">&gt;&gt;setup</td>  
     8<tr bgcolor="cd6888">  <td>11/11/29 10:53:12</td>   <td>-119</td> <td>&nbsp;</td><td>&nbsp;</td><td title="&gt;&gt;uk.ac.cardiff.raptor.event.expansion.RDBMSDataConnectorTest.setup()">&gt;&gt;setup</td>  
    99<td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td>  <td>main@1211753909</td>   <td></td> </tr> 
    1010</table> 
  • raptor-client/trunk/test-output/Default suite/methods.html

    r1201 r1202  
    22<table border="1"> 
    33<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/28 22:44:42</td>   <td>0</td> <td>&nbsp;</td><td>&nbsp;</td><td title="&gt;&gt;uk.ac.cardiff.raptor.event.expansion.RDBMSDataConnectorTest.setup()">&gt;&gt;setup</td>  
     4<tr bgcolor="cd6888">  <td>11/11/29 10:53:12</td>   <td>0</td> <td>&nbsp;</td><td>&nbsp;</td><td title="&gt;&gt;uk.ac.cardiff.raptor.event.expansion.RDBMSDataConnectorTest.setup()">&gt;&gt;setup</td>  
    55<td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td>  <td>main@1211753909</td>   <td></td> </tr> 
    6 <tr bgcolor="cd6888">  <td>11/11/28 22:44:42</td>   <td>115</td> <td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</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>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td title="uk.ac.cardiff.raptor.event.expansion.RDBMSDataConnectorTest.cacheTest()">cacheTest</td>  
    77  <td>main@1211753909</td>   <td></td> </tr> 
    8 <tr bgcolor="cd6888">  <td>11/11/28 22:44:42</td>   <td>208</td> <td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</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>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td title="uk.ac.cardiff.raptor.event.expansion.RDBMSDataConnectorTest.getAttributesTest()">getAttributesTest</td>  
    99  <td>main@1211753909</td>   <td></td> </tr> 
    1010</table> 
  • raptor-client/trunk/test-output/junitreports/TEST-uk.ac.cardiff.raptor.event.expansion.RDBMSDataConnectorTest.xml

    r1201 r1202  
    11<?xml version="1.0" encoding="UTF-8"?> 
    22<!-- 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"/> 
    45  <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"/> 
    66</testsuite> 
  • raptor-client/trunk/test-output/testng-results.xml

    r1201 r1202  
    33  <reporter-output> 
    44  </reporter-output> 
    5   <suite name="Default suite" duration-ms="222" 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"> 
    66    <groups> 
    77    </groups> 
    8     <test name="Default test" duration-ms="222" 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"> 
    99      <class name="uk.ac.cardiff.raptor.event.expansion.RDBMSDataConnectorTest"> 
    10         <test-method status="PASS" signature="setup()" name="setup" is-config="true" duration-ms="116" 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"> 
    1111        </test-method> 
    12         <test-method status="PASS" signature="cacheTest()" name="cacheTest" duration-ms="92" started-at="2011-11-28T22: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"> 
    1313        </test-method> 
    14         <test-method status="PASS" signature="getAttributesTest()" name="getAttributesTest" duration-ms="5" started-at="2011-11-28T22: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"> 
    1515        </test-method> 
    1616      </class> 
Note: See TracChangeset for help on using the changeset viewer.