Clover coverage report - Ledge Components - SNAPSHOT
Coverage timestamp: Fri Nov 17 2006 05:13:20 CET
file stats: LOC: 754   Methods: 61
NCLOC: 447   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
DBParameters.java 95.5% 89.1% 91.8% 90.2%
coverage coverage
 1    //
 2    //Copyright (c) 2003, Caltha - Gajda, Krzewski, Mach, Potempski Sp.J.
 3    //All rights reserved.
 4    //
 5    //Redistribution and use in source and binary forms, with or without modification,
 6    //are permitted provided that the following conditions are met:
 7    //
 8    //* Redistributions of source code must retain the above copyright notice,
 9    //this list of conditions and the following disclaimer.
 10    //* Redistributions in binary form must reproduce the above copyright notice,
 11    //this list of conditions and the following disclaimer in the documentation
 12    //and/or other materials provided with the distribution.
 13    //* Neither the name of the Caltha - Gajda, Krzewski, Mach, Potempski Sp.J.
 14    //nor the names of its contributors may be used to endorse or promote products
 15    //derived from this software without specific prior written permission.
 16    //
 17    //THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 18    //AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 19    //WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 20    //IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
 21    //INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
 22    //BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
 23    //OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 24    //WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 25    //ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 26    //POSSIBILITY OF SUCH DAMAGE.
 27    //
 28   
 29    package org.objectledge.parameters.db;
 30   
 31    import java.sql.Connection;
 32    import java.sql.PreparedStatement;
 33    import java.sql.SQLException;
 34    import java.util.ArrayList;
 35    import java.util.Arrays;
 36    import java.util.Collections;
 37    import java.util.Date;
 38    import java.util.HashSet;
 39    import java.util.Iterator;
 40    import java.util.List;
 41    import java.util.Set;
 42   
 43    import org.jcontainer.dna.Logger;
 44    import org.objectledge.database.Database;
 45    import org.objectledge.database.DatabaseUtils;
 46    import org.objectledge.parameters.DefaultParameters;
 47    import org.objectledge.parameters.Parameters;
 48    import org.objectledge.parameters.ScopedParameters;
 49   
 50    /**
 51    * A persistent implementation of parameters container.
 52    *
 53    * @author <a href="mailto:pablo@caltha.com">Pawel Potempski</a>
 54    * @version $Id: DBParameters.java,v 1.10 2005/12/20 09:09:32 pablo Exp $
 55    */
 56    public class DBParameters implements Parameters
 57    {
 58    /** the logger */
 59    private Logger logger;
 60   
 61    /** db access component */
 62    private Database database;
 63   
 64    /** container id */
 65    private long id;
 66   
 67    /** internal container */
 68    private DefaultParameters container;
 69   
 70    /** internal container */
 71    private DefaultParameters shadow;
 72   
 73    /** modified */
 74    private HashSet<String> modified;
 75   
 76    /**
 77    * Create the container.
 78    *
 79    * @param parameters the initial parameters.
 80    * @param id the database identifier.
 81    * @param database the db access component
 82    * @param logger the logger.
 83    */
 84  2346 public DBParameters(Parameters parameters, long id, Database database, Logger logger)
 85    {
 86  2346 modified = new HashSet<String>();
 87  2346 this.logger = logger;
 88  2346 this.database = database;
 89  2346 if(parameters != null)
 90    {
 91  46 container = new DefaultParameters(parameters);
 92  46 shadow = new DefaultParameters(parameters);
 93    }
 94    else
 95    {
 96  2300 container = new DefaultParameters();
 97  2300 shadow = new DefaultParameters();
 98    }
 99  2346 this.id = id;
 100    }
 101   
 102    /**
 103    * {@inheritDoc}
 104    */
 105  276 public String get(String name)
 106    {
 107  276 return container.get(name);
 108    }
 109   
 110    /**
 111    * {@inheritDoc}
 112    */
 113  230 public String get(String name, String defaultValue)
 114    {
 115  230 return container.get(name, defaultValue);
 116    }
 117   
 118    /**
 119    * {@inheritDoc}
 120    */
 121  322 public String[] getStrings(String name)
 122    {
 123  322 return container.getStrings(name); }
 124   
 125    /**
 126    * {@inheritDoc}
 127    */
 128  184 public boolean getBoolean(String name)
 129    {
 130  184 return container.getBoolean(name);
 131    }
 132   
 133    /**
 134    * {@inheritDoc}
 135    */
 136  276 public boolean getBoolean(String name, boolean defaultValue)
 137    {
 138  276 return container.getBoolean(name, defaultValue);
 139    }
 140   
 141    /**
 142    * {@inheritDoc}
 143    */
 144  322 public boolean[] getBooleans(String name)
 145    {
 146  322 return container.getBooleans(name);
 147    }
 148   
 149   
 150    /**
 151    * {@inheritDoc}
 152    */
 153  184 public Date getDate(String name)
 154    {
 155  184 return container.getDate(name);
 156    }
 157   
 158    /**
 159    * {@inheritDoc}
 160    */
 161  92 public Date getDate(String name, Date defaultValue)
 162    {
 163  92 return container.getDate(name, defaultValue);
 164    }
 165   
 166    /**
 167    * {@inheritDoc}
 168    */
 169  184 public Date[] getDates(String name)
 170    {
 171  184 return container.getDates(name);
 172    }
 173   
 174    /**
 175    * {@inheritDoc}
 176    */
 177  184 public float getFloat(String name) throws NumberFormatException
 178    {
 179  184 return container.getFloat(name);
 180    }
 181   
 182    /**
 183    * {@inheritDoc}
 184    */
 185  322 public float getFloat(String name, float defaultValue)
 186    {
 187  322 return container.getFloat(name, defaultValue);
 188    }
 189   
 190    /**
 191    * {@inheritDoc}
 192    */
 193  230 public float[] getFloats(String name) throws NumberFormatException
 194    {
 195  230 return container.getFloats(name);
 196    }
 197   
 198    /**
 199    * {@inheritDoc}
 200    */
 201  184 public int getInt(String name) throws NumberFormatException
 202    {
 203  184 return container.getInt(name);
 204   
 205    }
 206   
 207    /**
 208    * {@inheritDoc}
 209    */
 210  184 public int getInt(String name, int defaultValue)
 211    {
 212  184 return container.getInt(name, defaultValue);
 213    }
 214   
 215    /**
 216    * {@inheritDoc}
 217    */
 218  368 public int[] getInts(String name)
 219    {
 220  368 return container.getInts(name);
 221    }
 222   
 223    /**
 224    * {@inheritDoc}
 225    */
 226  184 public long getLong(String name) throws NumberFormatException
 227    {
 228  184 return container.getLong(name);
 229    }
 230   
 231    /**
 232    * {@inheritDoc}
 233    */
 234  184 public long getLong(String name, long defaultValue)
 235    {
 236  184 return container.getLong(name,defaultValue);
 237    }
 238   
 239    /**
 240    * {@inheritDoc}
 241    */
 242  184 public long[] getLongs(String name) throws NumberFormatException
 243    {
 244  184 return container.getLongs(name);
 245    }
 246   
 247    /**
 248    * {@inheritDoc}
 249    */
 250  552 public String[] getParameterNames()
 251    {
 252  552 return container.getParameterNames();
 253    }
 254   
 255    /**
 256    * {@inheritDoc}
 257    */
 258  598 public boolean isDefined(String name)
 259    {
 260  598 return container.isDefined(name);
 261    }
 262   
 263    /**
 264    * {@inheritDoc}
 265    */
 266  46 public void remove()
 267    {
 268  46 container.remove();
 269  46 List<String> all = Arrays.asList(container.getParameterNames());
 270  46 modified.addAll(all);
 271  46 update();
 272    }
 273   
 274    /**
 275    * {@inheritDoc}
 276    */
 277  46 public void remove(String name)
 278    {
 279  46 container.remove(name);
 280  46 modified.add(name);
 281  46 update();
 282    }
 283   
 284    /**
 285    * {@inheritDoc}
 286    */
 287  92 public void remove(String name, String value)
 288    {
 289  92 container.remove(name,value);
 290  92 modified.add(name);
 291  92 update();
 292    }
 293   
 294    /**
 295    * {@inheritDoc}
 296    */
 297  0 public void remove(String name, Date value)
 298    {
 299  0 container.remove(name,value);
 300  0 modified.add(name);
 301  0 update();
 302    }
 303   
 304    /**
 305    * {@inheritDoc}
 306    */
 307  46 public void remove(String name, float value)
 308    {
 309  46 container.remove(name,value);
 310  46 modified.add(name);
 311  46 update();
 312    }
 313   
 314    /**
 315    * {@inheritDoc}
 316    */
 317  46 public void remove(String name, int value)
 318    {
 319  46 container.remove(name,value);
 320  46 modified.add(name);
 321  46 update();
 322    }
 323   
 324    /**
 325    * {@inheritDoc}
 326    */
 327  46 public void remove(String name, long value)
 328    {
 329  46 container.remove(name,value);
 330  46 modified.add(name);
 331  46 update();
 332    }
 333   
 334    /**
 335    * Remove all parameters with a name contained in given set.
 336    *
 337    * @param keys the set of keys.
 338    */
 339  46 public void remove(Set<String> keys)
 340    {
 341  46 container.remove(keys);
 342  46 modified.addAll(keys);
 343  46 update();
 344    }
 345   
 346    /**
 347    * Remove all except those with a keys specified in the set.
 348    *
 349    * @param keys the set of names.
 350    */
 351  46 public void removeExcept(Set<String> keys)
 352    {
 353  46 container.removeExcept(keys);
 354  46 List<String> all = new ArrayList<String>(Arrays.asList(container.getParameterNames()));
 355  46 all.removeAll(keys);
 356  46 modified.addAll(all);
 357  46 update();
 358    }
 359   
 360    /**
 361    * {@inheritDoc}
 362    */
 363  1012 public void set(String name, String value)
 364    {
 365  1012 container.set(name, value);
 366  1012 modified.add(name);
 367  1012 update();
 368    }
 369   
 370    /**
 371    * {@inheritDoc}
 372    */
 373  46 public void set(String name, String[] values)
 374    {
 375  46 container.set(name, values);
 376  46 modified.add(name);
 377  46 update();
 378    }
 379   
 380    /**
 381    * {@inheritDoc}
 382    */
 383  0 public void set(String name, Date value)
 384    {
 385  0 container.set(name, value);
 386  0 modified.add(name);
 387  0 update();
 388    }
 389   
 390    /**
 391    * {@inheritDoc}
 392    */
 393  0 public void set(String name, Date[] values)
 394    {
 395  0 container.set(name, values);
 396  0 modified.add(name);
 397  0 update();
 398    }
 399   
 400    /**
 401    * {@inheritDoc}
 402    */
 403  138 public void set(String name, boolean value)
 404    {
 405  138 container.set(name, value);
 406  138 modified.add(name);
 407  138 update();
 408    }
 409   
 410    /**
 411    * {@inheritDoc}
 412    */
 413  46 public void set(String name, boolean[] values)
 414    {
 415  46 container.set(name, values);
 416  46 modified.add(name);
 417  46 update();
 418    }
 419   
 420    /**
 421    * {@inheritDoc}
 422    */
 423  138 public void set(String name, float value)
 424    {
 425  138 container.set(name, value);
 426  138 modified.add(name);
 427  138 update();
 428    }
 429   
 430    /**
 431    * {@inheritDoc}
 432    */
 433  46 public void set(String name, float[] values)
 434    {
 435  46 container.set(name, values);
 436  46 modified.add(name);
 437  46 update();
 438    }
 439   
 440    /**
 441    * {@inheritDoc}
 442    */
 443  138 public void set(String name, int value)
 444    {
 445  138 container.set(name, value);
 446  138 modified.add(name);
 447  138 update();
 448    }
 449   
 450    /**
 451    * {@inheritDoc}
 452    */
 453  46 public void set(String name, int[] values)
 454    {
 455  46 container.set(name, values);
 456  46 modified.add(name);
 457  46 update();
 458    }
 459   
 460    /**
 461    * {@inheritDoc}
 462    */
 463  138 public void set(String name, long value)
 464    {
 465  138 container.set(name, value);
 466  138 modified.add(name);
 467  138 update();
 468    }
 469   
 470    /**
 471    * {@inheritDoc}
 472    */
 473  46 public void set(String name, long[] values)
 474    {
 475  46 container.set(name, values);
 476  46 modified.add(name);
 477  46 update();
 478    }
 479   
 480    /**
 481    * {@inheritDoc}
 482    */
 483  0 public void set(Parameters parameters)
 484    {
 485  0 String[] names = container.getParameterNames();
 486  0 for(String name:names)
 487    {
 488  0 modified.add(name);
 489    }
 490  0 container.set(parameters);
 491  0 names = parameters.getParameterNames();
 492  0 for(String name:names)
 493    {
 494  0 modified.add(name);
 495    }
 496  0 update();
 497    }
 498   
 499