Home » apache-openjpa-1.1.0-source » org.apache.openjpa » kernel » [javadoc | source]
    1   /*
    2    * Licensed to the Apache Software Foundation (ASF) under one
    3    * or more contributor license agreements.  See the NOTICE file
    4    * distributed with this work for additional information
    5    * regarding copyright ownership.  The ASF licenses this file
    6    * to you under the Apache License, Version 2.0 (the
    7    * "License"); you may not use this file except in compliance
    8    * with the License.  You may obtain a copy of the License at
    9    *
   10    * http://www.apache.org/licenses/LICENSE-2.0
   11    *
   12    * Unless required by applicable law or agreed to in writing,
   13    * software distributed under the License is distributed on an
   14    * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
   15    * KIND, either express or implied.  See the License for the
   16    * specific language governing permissions and limitations
   17    * under the License.    
   18    */
   19   package org.apache.openjpa.kernel;
   20   
   21   import java.util.BitSet;
   22   
   23   import org.apache.openjpa.util.OpenJPAException;
   24   import org.apache.openjpa.util.StoreException;
   25   
   26   /**
   27    * Wraps the native store manager to handle calls using custom
   28    * {@link PCResultObjectProvider}s.
   29    *
   30    * @author Abe White
   31    */
   32   class ROPStoreManager
   33       extends DelegatingStoreManager {
   34   
   35       public ROPStoreManager(StoreManager delegate) {
   36           super(delegate);
   37       }
   38   
   39       public boolean exists(OpenJPAStateManager sm, Object context) {
   40           if (context instanceof PCResultObjectProvider)
   41               context = null;
   42           return super.exists(sm, context);
   43       }
   44   
   45       public boolean initialize(OpenJPAStateManager sm, PCState state,
   46           FetchConfiguration fetch, Object context) {
   47           if (context instanceof PCResultObjectProvider) {
   48               try {
   49                   ((PCResultObjectProvider) context).initialize(sm, state, fetch);
   50               } catch (OpenJPAException ke) {
   51                   throw ke;
   52               } catch (Exception e) {
   53                   throw new StoreException(e);
   54               }
   55               return true;
   56           }
   57           return super.initialize(sm, state, fetch, context);
   58       }
   59   
   60       public boolean syncVersion(OpenJPAStateManager sm, Object context) {
   61           // the only way this gets called with a rop context is if the
   62           // rop didn't load any version info on initialize, so just null
   63           // it out so we don't get unexpected results when our delegate
   64           // expectes a different context type
   65           if (context instanceof PCResultObjectProvider)
   66               context = null;
   67           return super.syncVersion(sm, context);
   68       }
   69   
   70       public boolean load(OpenJPAStateManager sm, BitSet fields,
   71           FetchConfiguration fetch, int lockLevel, Object context) {
   72           // the only way this gets called with a rop context is if the
   73           // rop didn't load the field on initialize, so just null
   74           // it out so we don't get unexpected results when our delegate
   75           // expectes a different context type
   76           if (context instanceof PCResultObjectProvider)
   77               context = null;
   78           return super.load(sm, fields, fetch, lockLevel, context);
   79       }
   80   }

Save This Page
Home » apache-openjpa-1.1.0-source » org.apache.openjpa » kernel » [javadoc | source]