View Javadoc

    1   /***
    2    *
    3    * Copyright 2004 Hiram Chirino
    4    *
    5    * Licensed under the Apache License, Version 2.0 (the "License");
    6    * you may not use this file except in compliance with the License.
    7    * You may obtain a copy of the License at
    8    *
    9    * http://www.apache.org/licenses/LICENSE-2.0
    10   *
    11   * Unless required by applicable law or agreed to in writing, software
    12   * distributed under the License is distributed on an "AS IS" BASIS,
    13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    14   * See the License for the specific language governing permissions and
    15   * limitations under the License.
    16   *
    17   **/
    18  package org.codehaus.activemq.store.jdbc.adapter;
    19
    20  import org.codehaus.activemq.store.jdbc.StatementProvider;
    21
    22  /***
    23   * A StatementProvider filter that caches the responses
    24   * of the filtered StatementProvider.
    25   *
    26   * @version $Revision: 1.3 $
    27   */
    28  public class CachingStatementProvider implements StatementProvider {
    29
    30      final private StatementProvider statementProvider;
    31
    32      private String addMessageStatment;
    33      private String addXidStatment;
    34      private String[] createSchemaStatments;
    35      private String[] dropSchemaStatments;
    36      private String findAllMessagesStatment;
    37      private String findAllTxStatment;
    38      private String findAllXidStatment;
    39      private String findLastSequenceId;
    40      private String findMessageStatment;
    41      private String findXidStatment;
    42      private String removeMessageStatment;
    43      private String removeXidStatment;
    44      private String updateMessageStatment;
    45      private String updateXidStatment;
    46
    47  	private String createDurableSubStatment;
    48
    49  	private String updateDurableSubStatment;
    50
    51  	private String findDurableSubStatment;
    52
    53  	private String findAllDurableSubMessagesStatment;
    54
    55  	private String updateLastAckOfDurableSub;
    56
    57  	private String findMessageSequenceIdStatment;
    58
    59      /***
    60       * @param statementProvider
    61       */
    62      public CachingStatementProvider(StatementProvider statementProvider) {
    63          this.statementProvider = statementProvider;
    64      }
    65
    66      public StatementProvider getNext() {
    67          return statementProvider;
    68      }
    69
    70      /***
    71       * @return
    72       */
    73      public String getAddMessageStatment() {
    74          if (addMessageStatment == null) {
    75              addMessageStatment = statementProvider.getAddMessageStatment();
    76          }
    77          return addMessageStatment;
    78      }
    79
    80      /***
    81       * @return
    82       */
    83      public String getAddXidStatment() {
    84          if (addXidStatment == null) {
    85              addXidStatment = statementProvider.getAddXidStatment();
    86          }
    87          return addXidStatment;
    88      }
    89
    90      /***
    91       * @return
    92       */
    93      public String[] getCreateSchemaStatments() {
    94          if( createSchemaStatments==null ) {
    95              createSchemaStatments = statementProvider.getCreateSchemaStatments();
    96          }
    97          return createSchemaStatments;
    98      }
    99
    100     /***
    101      * @return
    102      */
    103     public String[] getDropSchemaStatments() {
    104         if( dropSchemaStatments==null ) {
    105             dropSchemaStatments = statementProvider.getDropSchemaStatments();
    106         }
    107         return dropSchemaStatments;
    108     }
    109
    110     /***
    111      * @return
    112      */
    113     public String getFindAllMessagesStatment() {
    114         if( findAllMessagesStatment==null ) {
    115             findAllMessagesStatment = statementProvider.getFindAllMessagesStatment();
    116         }
    117         return findAllMessagesStatment;
    118     }
    119
    120     /***
    121      * @return
    122      */
    123     public String getFindAllTxStatment() {
    124         if( findAllTxStatment == null ) {
    125             findAllTxStatment = statementProvider.getFindAllTxStatment();
    126         }
    127         return findAllTxStatment;
    128     }
    129
    130     /***
    131      * @return
    132      */
    133     public String getFindAllXidStatment() {
    134         if( findAllXidStatment==null ) {
    135             findAllXidStatment = statementProvider.getFindAllXidStatment();
    136         }
    137         return findAllXidStatment;
    138     }
    139
    140     /***
    141      * @return
    142      */
    143     public String getFindLastSequenceId() {
    144         if( findLastSequenceId==null ) {
    145             findLastSequenceId = statementProvider.getFindLastSequenceId();
    146         }
    147         return findLastSequenceId;
    148     }
    149
    150     /***
    151      * @return
    152      */
    153     public String getFindMessageStatment() {
    154         if( findMessageStatment==null ) {
    155             findMessageStatment = statementProvider.getFindMessageStatment();
    156         }
    157         return findMessageStatment;
    158     }
    159
    160     /***
    161      * @return
    162      */
    163     public String getFindXidStatment() {
    164         if( findXidStatment==null ) {
    165             findXidStatment = statementProvider.getFindXidStatment();
    166         }
    167         return findXidStatment;
    168     }
    169
    170     /***
    171      * @return
    172      */
    173     public String getRemoveMessageStatment() {
    174         if( removeMessageStatment==null ) {
    175             removeMessageStatment = statementProvider.getRemoveMessageStatment();
    176         }
    177         return removeMessageStatment;
    178     }
    179
    180     /***
    181      * @return
    182      */
    183     public String getRemoveXidStatment() {
    184         if( removeXidStatment==null ) {
    185             removeXidStatment = statementProvider.getRemoveXidStatment();
    186         }
    187         return removeXidStatment;
    188     }
    189
    190     /***
    191      * @return
    192      */
    193     public String getUpdateMessageStatment() {
    194         if( updateMessageStatment==null ) {
    195             updateMessageStatment = statementProvider.getUpdateMessageStatment();
    196         }
    197         return updateMessageStatment;
    198     }
    199
    200     /***
    201      * @return
    202      */
    203     public String getUpdateXidStatment() {
    204         if( updateXidStatment==null ) {
    205             updateXidStatment = statementProvider.getUpdateXidStatment();
    206         }
    207         return updateXidStatment;
    208     }
    209
    210 	/***
    211 	 * @see org.codehaus.activemq.store.jdbc.StatementProvider#getCreateDurableSubStatment()
    212 	 */
    213 	public String getCreateDurableSubStatment() {
    214 		if(createDurableSubStatment==null) {
    215 			createDurableSubStatment = statementProvider.getCreateDurableSubStatment();
    216 		}
    217 		return createDurableSubStatment;
    218 	}
    219
    220 	/***
    221 	 * @see org.codehaus.activemq.store.jdbc.StatementProvider#getUpdateDurableSubStatment()
    222 	 */
    223 	public String getUpdateDurableSubStatment() {
    224 		if( updateDurableSubStatment == null ) {
    225 			updateDurableSubStatment = statementProvider.getUpdateDurableSubStatment();
    226 		}
    227 		return updateDurableSubStatment;
    228 	}
    229
    230 	/***
    231 	 * @see org.codehaus.activemq.store.jdbc.StatementProvider#getFindDurableSubStatment()
    232 	 */
    233 	public String getFindDurableSubStatment() {
    234 		if(findDurableSubStatment==null) {
    235 			findDurableSubStatment = statementProvider.getFindDurableSubStatment();
    236 		}
    237 		return findDurableSubStatment;
    238 	}
    239 	/***
    240 	 * @return
    241 	 */
    242 	public String getFindAllDurableSubMessagesStatment() {
    243 		if(findAllDurableSubMessagesStatment==null) {
    244 			findAllDurableSubMessagesStatment = statementProvider.getFindAllDurableSubMessagesStatment();
    245 		}
    246 		return findAllDurableSubMessagesStatment;
    247 	}
    248 	/***
    249 	 * @return
    250 	 */
    251 	public String getUpdateLastAckOfDurableSub() {
    252 		if(updateLastAckOfDurableSub==null) {
    253 			updateLastAckOfDurableSub = statementProvider.getUpdateLastAckOfDurableSub();
    254 		}
    255 		return updateLastAckOfDurableSub;
    256 	}
    257
    258 	public String getFindMessageSequenceIdStatment() {
    259 		if ( findMessageSequenceIdStatment==null ) {
    260 			findMessageSequenceIdStatment = statementProvider.getFindMessageSequenceIdStatment();
    261 		}
    262 		return findMessageSequenceIdStatment;
    263 	}
    264 }