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.2 $
    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      /***
    58       * @param statementProvider
    59       */
    60      public CachingStatementProvider(StatementProvider statementProvider) {
    61          this.statementProvider = statementProvider;
    62      }
    63
    64      public StatementProvider getNext() {
    65          return statementProvider;
    66      }
    67
    68      /***
    69       * @return
    70       */
    71      public String getAddMessageStatment() {
    72          if (addMessageStatment == null) {
    73              addMessageStatment = statementProvider.getAddMessageStatment();
    74          }
    75          return addMessageStatment;
    76      }
    77
    78      /***
    79       * @return
    80       */
    81      public String getAddXidStatment() {
    82          if (addXidStatment == null) {
    83              addXidStatment = statementProvider.getAddXidStatment();
    84          }
    85          return addXidStatment;
    86      }
    87
    88      /***
    89       * @return
    90       */
    91      public String[] getCreateSchemaStatments() {
    92          if( createSchemaStatments==null ) {
    93              createSchemaStatments = statementProvider.getCreateSchemaStatments();
    94          }
    95          return createSchemaStatments;
    96      }
    97
    98      /***
    99       * @return
    100      */
    101     public String[] getDropSchemaStatments() {
    102         if( dropSchemaStatments==null ) {
    103             dropSchemaStatments = statementProvider.getDropSchemaStatments();
    104         }
    105         return dropSchemaStatments;
    106     }
    107
    108     /***
    109      * @return
    110      */
    111     public String getFindAllMessagesStatment() {
    112         if( findAllMessagesStatment==null ) {
    113             findAllMessagesStatment = statementProvider.getFindAllMessagesStatment();
    114         }
    115         return findAllMessagesStatment;
    116     }
    117
    118     /***
    119      * @return
    120      */
    121     public String getFindAllTxStatment() {
    122         if( findAllTxStatment == null ) {
    123             findAllTxStatment = statementProvider.getFindAllTxStatment();
    124         }
    125         return findAllTxStatment;
    126     }
    127
    128     /***
    129      * @return
    130      */
    131     public String getFindAllXidStatment() {
    132         if( findAllXidStatment==null ) {
    133             findAllXidStatment = statementProvider.getFindAllXidStatment();
    134         }
    135         return findAllXidStatment;
    136     }
    137
    138     /***
    139      * @return
    140      */
    141     public String getFindLastSequenceId() {
    142         if( findLastSequenceId==null ) {
    143             findLastSequenceId = statementProvider.getFindLastSequenceId();
    144         }
    145         return findLastSequenceId;
    146     }
    147
    148     /***
    149      * @return
    150      */
    151     public String getFindMessageStatment() {
    152         if( findMessageStatment==null ) {
    153             findMessageStatment = statementProvider.getFindMessageStatment();
    154         }
    155         return findMessageStatment;
    156     }
    157
    158     /***
    159      * @return
    160      */
    161     public String getFindXidStatment() {
    162         if( findXidStatment==null ) {
    163             findXidStatment = statementProvider.getFindXidStatment();
    164         }
    165         return findXidStatment;
    166     }
    167
    168     /***
    169      * @return
    170      */
    171     public String getRemoveMessageStatment() {
    172         if( removeMessageStatment==null ) {
    173             removeMessageStatment = statementProvider.getRemoveMessageStatment();
    174         }
    175         return removeMessageStatment;
    176     }
    177
    178     /***
    179      * @return
    180      */
    181     public String getRemoveXidStatment() {
    182         if( removeXidStatment==null ) {
    183             removeXidStatment = statementProvider.getRemoveXidStatment();
    184         }
    185         return removeXidStatment;
    186     }
    187
    188     /***
    189      * @return
    190      */
    191     public String getUpdateMessageStatment() {
    192         if( updateMessageStatment==null ) {
    193             updateMessageStatment = statementProvider.getUpdateMessageStatment();
    194         }
    195         return updateMessageStatment;
    196     }
    197
    198     /***
    199      * @return
    200      */
    201     public String getUpdateXidStatment() {
    202         if( updateXidStatment==null ) {
    203             updateXidStatment = statementProvider.getUpdateXidStatment();
    204         }
    205         return updateXidStatment;
    206     }
    207
    208 	/***
    209 	 * @see org.codehaus.activemq.store.jdbc.StatementProvider#getCreateDurableSubStatment()
    210 	 */
    211 	public String getCreateDurableSubStatment() {
    212 		if(createDurableSubStatment==null) {
    213 			createDurableSubStatment = statementProvider.getCreateDurableSubStatment();
    214 		}
    215 		return createDurableSubStatment;
    216 	}
    217
    218 	/***
    219 	 * @see org.codehaus.activemq.store.jdbc.StatementProvider#getUpdateDurableSubStatment()
    220 	 */
    221 	public String getUpdateDurableSubStatment() {
    222 		if( updateDurableSubStatment == null ) {
    223 			updateDurableSubStatment = statementProvider.getUpdateDurableSubStatment();
    224 		}
    225 		return updateDurableSubStatment;
    226 	}
    227
    228 	/***
    229 	 * @see org.codehaus.activemq.store.jdbc.StatementProvider#getFindDurableSubStatment()
    230 	 */
    231 	public String getFindDurableSubStatment() {
    232 		if(findDurableSubStatment==null) {
    233 			findDurableSubStatment = statementProvider.getFindDurableSubStatment();
    234 		}
    235 		return findDurableSubStatment;
    236 	}
    237 	/***
    238 	 * @return
    239 	 */
    240 	public String getFindAllDurableSubMessagesStatment() {
    241 		if(findAllDurableSubMessagesStatment==null) {
    242 			findAllDurableSubMessagesStatment = statementProvider.getFindAllDurableSubMessagesStatment();
    243 		}
    244 		return findAllDurableSubMessagesStatment;
    245 	}
    246 	/***
    247 	 * @return
    248 	 */
    249 	public String getUpdateLastAckOfDurableSub() {
    250 		if(updateLastAckOfDurableSub==null) {
    251 			updateLastAckOfDurableSub = statementProvider.getUpdateLastAckOfDurableSub();
    252 		}
    253 		return updateLastAckOfDurableSub;
    254 	}
    255 }