org.apache.openjpa.jdbc.meta.strats
Class StateComparisonVersionStrategy

java.lang.Object
  extended by org.apache.openjpa.jdbc.meta.strats.AbstractStrategy
      extended by org.apache.openjpa.jdbc.meta.strats.AbstractVersionStrategy
          extended by org.apache.openjpa.jdbc.meta.strats.StateComparisonVersionStrategy
All Implemented Interfaces:
Serializable, Strategy, VersionStrategy

public class StateComparisonVersionStrategy
extends AbstractVersionStrategy

Uses a state image to determine whether concurrency violations take place.

Author:
Abe White
See Also:
Serialized Form

Nested Class Summary
static class StateComparisonVersionStrategy.CustomUpdate
          Row implementation we use to pass to versionable mappings so they can set up the where conditions we need to add to update statements.
 
Field Summary
static String ALIAS
           
 
Fields inherited from class org.apache.openjpa.jdbc.meta.strats.AbstractVersionStrategy
vers
 
Constructor Summary
StateComparisonVersionStrategy()
           
 
Method Summary
 void afterLoad(OpenJPAStateManager sm, JDBCStore store)
          This method is called after data is loaded into the instance, in case the version indicator works off of a state image.
 boolean checkVersion(OpenJPAStateManager sm, JDBCStore store, boolean updateVersion)
          Checks the version of the given state manager with the version stored in memory.
 int compareVersion(Object v1, Object v2)
           
 void customInsert(OpenJPAStateManager sm, JDBCStore store)
          This method is for class mappings that take over the insert process, but still want to use this indicator for optimistic locking.
 StateComparisonVersionStrategy.CustomUpdate customUpdate(OpenJPAStateManager sm, JDBCStore store, Table table, boolean record)
          This method is for class mappings that take over the update process, but still want to use this indicator for optimistic locking.
 String getAlias()
          Return the alias of this strategy.
 void insert(OpenJPAStateManager sm, JDBCStore store, RowManager rm)
          Set values for the mapping into the proper rows.
 void map(boolean adapt)
          Map the owning mapping using this strategy.
 void update(OpenJPAStateManager sm, JDBCStore store, RowManager rm)
          Set values for the mapping into the proper rows.
 
Methods inherited from class org.apache.openjpa.jdbc.meta.strats.AbstractVersionStrategy
getBulkUpdateValues, load, select, setVersion
 
Methods inherited from class org.apache.openjpa.jdbc.meta.strats.AbstractStrategy
customDelete, customUpdate, delete, initialize, isCustomDelete, isCustomInsert, isCustomUpdate
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.apache.openjpa.jdbc.meta.Strategy
customDelete, customUpdate, delete, initialize, isCustomDelete, isCustomInsert, isCustomUpdate
 

Field Detail

ALIAS

public static final String ALIAS
See Also:
Constant Field Values
Constructor Detail

StateComparisonVersionStrategy

public StateComparisonVersionStrategy()
Method Detail

getAlias

public String getAlias()
Description copied from interface: Strategy
Return the alias of this strategy. For custom strategies, return the full class name.

Specified by:
getAlias in interface Strategy
Overrides:
getAlias in class AbstractStrategy

map

public void map(boolean adapt)
Description copied from interface: Strategy
Map the owning mapping using this strategy.

Specified by:
map in interface Strategy
Overrides:
map in class AbstractStrategy
Parameters:
adapt - if true, use the owning mapping's raw mapping info to set its ORM data; if false, ORM data will already be set

insert

public void insert(OpenJPAStateManager sm,
                   JDBCStore store,
                   RowManager rm)
            throws SQLException
Description copied from interface: Strategy
Set values for the mapping into the proper rows. For class mappings, this method will be called only after the corresponding method has been called for all fields of this mapping.

Specified by:
insert in interface Strategy
Overrides:
insert in class AbstractStrategy
Throws:
SQLException

customInsert

public void customInsert(OpenJPAStateManager sm,
                         JDBCStore store)
                  throws SQLException
This method is for class mappings that take over the insert process, but still want to use this indicator for optimistic locking.

Specified by:
customInsert in interface Strategy
Overrides:
customInsert in class AbstractStrategy
Throws:
SQLException

update

public void update(OpenJPAStateManager sm,
                   JDBCStore store,
                   RowManager rm)
            throws SQLException
Description copied from interface: Strategy
Set values for the mapping into the proper rows.

Specified by:
update in interface Strategy
Overrides:
update in class AbstractStrategy
Throws:
SQLException
See Also:
Strategy.insert(org.apache.openjpa.kernel.OpenJPAStateManager, org.apache.openjpa.jdbc.kernel.JDBCStore, org.apache.openjpa.jdbc.sql.RowManager)

customUpdate

public StateComparisonVersionStrategy.CustomUpdate customUpdate(OpenJPAStateManager sm,
                                                                JDBCStore store,
                                                                Table table,
                                                                boolean record)
                                                         throws SQLException
This method is for class mappings that take over the update process, but still want to use this indicator for optimistic locking.

Parameters:
sm - the instance to test
store - store manager context
table - only state image values in this table will be tested; if the custom mapping uses different updates for different tables, this method can be called multiple times for the multiple tables
record - set this parameter to true the last time you call this method, so the indicator can setup the next version of the given state manager
Returns:
a StateComparisonVersionStrategy.CustomUpdate whose getSQL method yields a boolean SQL expression that tests whether the current record is equal to our recorded state image, and whose setParameters method parameterizes the given prepared statement with the values used in the above boolean expression
Throws:
SQLException

afterLoad

public void afterLoad(OpenJPAStateManager sm,
                      JDBCStore store)
Description copied from interface: VersionStrategy
This method is called after data is loaded into the instance, in case the version indicator works off of a state image.

Specified by:
afterLoad in interface VersionStrategy
Overrides:
afterLoad in class AbstractVersionStrategy

checkVersion

public boolean checkVersion(OpenJPAStateManager sm,
                            JDBCStore store,
                            boolean updateVersion)
                     throws SQLException
Description copied from interface: VersionStrategy
Checks the version of the given state manager with the version stored in memory.

Specified by:
checkVersion in interface VersionStrategy
Overrides:
checkVersion in class AbstractVersionStrategy
Returns:
true if the in-memory version was up-to-date, false otherwise
Throws:
SQLException

compareVersion

public int compareVersion(Object v1,
                          Object v2)
Specified by:
compareVersion in interface VersionStrategy
Overrides:
compareVersion in class AbstractVersionStrategy
See Also:
StoreManager.compareVersion(org.apache.openjpa.kernel.OpenJPAStateManager, java.lang.Object, java.lang.Object)


Copyright © 2006-2011 Apache Software Foundation. All Rights Reserved.