Changeset 3747


Ignore:
Timestamp:
Sep 18, 2007, 8:59:23 AM (16 years ago)
Author:
Nicklas Nordborg
Message:

Fixes #766: Batchers may be registered with a DbControl? even if constructor throw an exception

Location:
branches/2.4-stable
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • branches/2.4-stable/src/core/net/sf/basedb/core/AbstractBatcher.java

    r3679 r3747  
    7575 
    7676  /**
    77     Constructor that initiate everything.
    78 
    79     @param dc The <code>DbControl</code> to get database access
     77    Constructor for a batcher.
    8078    @throws BaseException If there is an error
    8179  */
    82   AbstractBatcher(DbControl dc)
    83   {
    84     assert dc != null : "dc == null";
    85     this.dc = new WeakReference<DbControl>(dc);
    86     this.sc = dc.getSessionControl();
     80  AbstractBatcher()
     81  {
    8782    this.batchSize = Config.getInt("db.batch-size", 50);
    88     dc.addBatcher(this);
    8983  }
    9084
     
    133127  {
    134128    sc.updateLastAccess();
     129  }
     130 
     131  /**
     132    Set the DbControl that is controlling this batcher. This
     133    method MUST be called by all subclasses after successful construction
     134    of a batcher. This method also registers the batcher with the DbControl
     135    using {@link DbControl#addBatcher(Batcher)}
     136    @since 2.4.2
     137  */
     138  protected final void setDbControl(DbControl dc)
     139  {
     140    assert dc != null : "dc == null";
     141    this.dc = new WeakReference<DbControl>(dc);
     142    this.sc = dc.getSessionControl();
     143    dc.addBatcher(this);
    135144  }
    136145 
  • branches/2.4-stable/src/core/net/sf/basedb/core/BasicBatcher.java

    r3679 r3747  
    131131    Constructor that initiate everything.
    132132
    133     @param dc DbControl to get database access
    134133    @param dataClass The class of the data objects that are accepted by this batcher
    135134    @param entityName The entity name of the data as known by Hibernate, use null
     
    137136    @throws BaseException If there is an error
    138137  */
    139   BasicBatcher(DbControl dc, Class<D> dataClass, String entityName)
    140     throws BaseException
    141   {
    142     super(dc);
     138  BasicBatcher(org.hibernate.Session session, Class<D> dataClass, String entityName)
     139    throws BaseException
     140  {
     141    super();
    143142    assert dataClass != null : "dataClass == null";
    144143   
     
    159158    try
    160159    {
    161       java.sql.Connection c = HibernateUtil.getConnection(dc.getHibernateSession());
     160      java.sql.Connection c = HibernateUtil.getConnection(session);
    162161      insertStatement = c.prepareStatement(insertSql);
    163162      updateStatement = c.prepareStatement(updateSql);
  • branches/2.4-stable/src/core/net/sf/basedb/core/DbControl.java

    r3679 r3747  
    269269          batcher.close();
    270270        }
    271         catch (BaseException ex)
     271        catch (Throwable ex)
    272272        {
    273273          log.warn("Exception during rollback in batcher.close()", ex);
     
    281281      if (hStatelessSession != null) HibernateUtil.close(hStatelessSession);
    282282    }
    283     catch (BaseException ex)
     283    catch (Throwable ex)
    284284    {
    285285      log.warn("Exception during rollback in Hibernate", ex);
  • branches/2.4-stable/src/core/net/sf/basedb/core/FeatureBatcher.java

    r3679 r3747  
    9191    throws BaseException
    9292  {
    93     super(dc, FeatureData.class, null);
     93    super(dc.getHibernateSession(), FeatureData.class, null);
    9494    this.arrayDesign = arrayDesign;
    9595    this.arrayDesignData = arrayDesign.getData();
    9696    this.isAffy = arrayDesign.isAffyChip();
     97    setDbControl(dc);
    9798  }
    9899
  • branches/2.4-stable/src/core/net/sf/basedb/core/FilterBatcher.java

    r3679 r3747  
    142142  FilterBatcher(DbControl dc, BioAssaySet bioAssaySet)
    143143  {
    144     super(dc);
     144    super();
    145145    this.bioAssaySet = bioAssaySet;
    146146    this.bytesPerRow = VirtualTable.FILTER.getBytesPerRow(bioAssaySet.getRawDataType());
     147    setDbControl(dc);
    147148  }
    148149
  • branches/2.4-stable/src/core/net/sf/basedb/core/MappingBatcher.java

    r3679 r3747  
    106106  MappingBatcher(DbControl dc, DataCube dataCube)
    107107  {
    108     super(dc);
     108    super();
    109109    this.dataCube = dataCube;
    110110    this.noRawMapping = dataCube.isInDatabase();
    111111    this.bytesPerRow = VirtualTable.RAWPARENTS.getBytesPerRow(dataCube.getRawDataType());
     112    setDbControl(dc);
    112113  }
    113114
  • branches/2.4-stable/src/core/net/sf/basedb/core/PositionBatcher.java

    r3679 r3747  
    106106  PositionBatcher(DbControl dc, DataCube dataCube)
    107107  {
    108     super(dc);
     108    super();
    109109    this.dataCube = dataCube;
    110110    this.bytesPerRow = VirtualTable.POSITION.getBytesPerRow(dataCube.getRawDataType());
     111    setDbControl(dc);
    111112  }
    112113
  • branches/2.4-stable/src/core/net/sf/basedb/core/PositionExtraValueBatcher.java

    r3679 r3747  
    154154  PositionExtraValueBatcher(DbControl dc, ExtraValue extraValue)
    155155  {
    156     super(dc);
     156    super();
    157157    this.extraValue = extraValue;
    158158    this.bytesPerRow = extraValue.getVirtualTable().getBytesPerRow(extraValue.getRawDataType());
    159159    this.valueType = extraValue.getExtraValueType().getValueType();
    160160    this.sqlType = valueType.getSQLType();
     161    setDbControl(dc);
    161162  }
    162163
  • branches/2.4-stable/src/core/net/sf/basedb/core/RawDataBatcher.java

    r3679 r3747  
    161161    throws BaseException
    162162  {
    163     super(dc, RawData.class, rawBioAssay.getRawDataType().getEntityName());
     163    super(dc.getHibernateSession(), RawData.class, rawBioAssay.getRawDataType().getEntityName());
    164164    this.rawBioAssay = rawBioAssay;
    165165    this.rawBioAssayData = rawBioAssay.getData();
     
    205205      this.preloaded = null;
    206206    }
     207    setDbControl(dc);
    207208  }
    208209
  • branches/2.4-stable/src/core/net/sf/basedb/core/ReporterBatcher.java

    r3679 r3747  
    7777    throws BaseException
    7878  {
    79     super(dc, ReporterData.class, null);
     79    super(dc.getHibernateSession(), ReporterData.class, null);
    8080    extendedProperties = ExtendedProperties.getProperties("ReporterData");
    8181    batchedExternalIds = HibernateUtil.getDbEngine().caseInsensitiveComparison() ?
    8282      new TreeSet<String>(String.CASE_INSENSITIVE_ORDER) : new HashSet<String>();
     83    setDbControl(dc);
    8384  }
    8485
  • branches/2.4-stable/src/core/net/sf/basedb/core/SpotBatcher.java

    r3679 r3747  
    141141  SpotBatcher(DbControl dc, BioAssaySet bioAssaySet)
    142142  {
    143     super(dc);
     143    super();
    144144    this.bioAssaySet = bioAssaySet;
    145145    this.numChannels = bioAssaySet.getRawDataType().getChannels();
    146146    this.bytesPerRow = VirtualTable.SPOT.getBytesPerRow(bioAssaySet.getRawDataType());
     147    setDbControl(dc);
    147148  }
    148149
  • branches/2.4-stable/src/core/net/sf/basedb/core/SpotExtraValueBatcher.java

    r3679 r3747  
    144144  SpotExtraValueBatcher(DbControl dc, ExtraValue extraValue)
    145145  {
    146     super(dc);
     146    super();
    147147    this.extraValue = extraValue;
    148148    this.bytesPerRow = extraValue.getVirtualTable().getBytesPerRow(extraValue.getRawDataType());
    149149    this.valueType = extraValue.getExtraValueType().getValueType();
    150150    this.sqlType = valueType.getSQLType();
     151    setDbControl(dc);
    151152  }
    152153
  • branches/2.4-stable/www/exception/exception.jsp

    r3711 r3747  
    204204    StackTraceElement[] st = ex.getStackTrace();
    205205    out.println("<pre>");
     206    out.println(exceptionClassName);
    206207    int i = 0;
    207208    for (i=0; i < st.length && i < 8; i++)
    208209    {
    209210      out.print("...at ");
    210       out.println(st[i].toString().replaceAll("net.sf.basedb.core.", ""));
     211      out.println(HTML.encodeTags(st[i].toString().replaceAll("net.sf.basedb.core.", "")));
    211212    }
    212213    out.println("</pre>");
     
    219220        {
    220221          out.print("...at ");
    221           out.println(st[j].toString().replaceAll("net.sf.basedb.core.", ""));
     222          out.println(HTML.encodeTags(st[j].toString().replaceAll("net.sf.basedb.core.", "")));
    222223        }
    223224        ex = ex.getCause();
Note: See TracChangeset for help on using the changeset viewer.