Package com.im.commons.progress
Interface DFLockable
-
- All Known Implementing Classes:
SimpleLockable
public interface DFLockableMost of DIF write methods (methods which modifies data or model somehow) use locking. Before such a method is called you must obtain a lock, put it toDFEnvironmentRWand then pass this environment to the data modification method. Each lockable provides only a singleDFLockinstance at the same time. Lock should be held by calling thread to prevent other threads to doing modifications concurrently. It is forbidden to obtain a lock and use it from two different threads. Results of such actions are unpredictable and can corrupt the DIF internal status.DFLockableis a lock provider. There are moreDFLockableinstances in the system. You always need to choose the appropriate way how to obtain theDFLockableinstance for your specific DIF operation.In many cases
DIFUtilities.getLockable(yourObject)methods can help you with this, but these methods are just utilities which delegates to the real source of appropriateDFLockable.Once you lock the object using the appropriate
DFLockableprovider, perform the operation, never forget to release the lock (seeDFLockfor more details).Currently there are at least six types of known lockable types in DIF APIs. You can obtain them directly or for some of them also use
DIFUtilitiesmethods mentioned above.Types Description How many instances exists Where to find it Details Global DDL for shared items ( com.im.df.api.ddlpackage)One instance per DFSchemaDFSchema.getLockable()For manipulation with shared global DDL objects ( DFSchema,DFEntity,DFField,DFDataTree,DFRelationship). This object is usually "locked forever" if you are not admin and aren't in single user modeGlobal DDL for user specific items One instance per DFSchemaDFSchema.getUserLockable()For manipulation with user specific (user owned) objects ( DFView,DFQuery,DFList). Typically even users with no access rights for data or schema modifications can obtain this lock.DML for data modifications in one DFEntityOne instance per com.im.df.api.dml.DFEntityDataProviderwhich means one for each entity defined in the schemacom.im.df.api.dml.DFEntityDataProvider.getLockable()For manipulation with data of one DFEntitywhich typically means one DB tableDFResultSetoperations (com.im.df.api.dmlpackage)One instance per DFResultSetcom.im.df.api.dml.DFResultSet.getLockable()For changing any property of DFResultSetand all itsDFResultSet.VertexState(s). For example if you want to change sorting, apply a new query, etc.DFSchemaProvideroperations (com.im.df.apipackage)One instance per DFSchemaProviderwhich means one perDFSchemaDFSchemaProvider.getLockable()For changing the state of DFSchemaProvider- which means for opening/closing connection.Other service specific lockables (e.g. com.im.df.api.capabilities.IJCUserDetailsService)One instance per such a service For example IJCUserDetailsService.getLockable()For performing write operations on such a service object - in this case for example for adding or removeing users. - Author:
- Petr Hamernik
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringPROP_LOCKEDFired when lock managed by this lockable is acquired or released.
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description voidaddPropertyChangeListener(java.beans.PropertyChangeListener pcl)Register to listen toPROP_LOCKEDproperty change.voidcheckLock(DFLock testedLock)Checks whether the lock belongs to this lockable.booleanisLocked()Is a valid lock held by someone already?booleanisLockedForever()Is this lockable constantly locked? This can be used for lockables which are in readonly mode (e.g.DFLockobtainLock(java.lang.String reason)Obtains the lock; fails withAlreadyLockedExceptionif the object is already locked.voidremovePropertyChangeListener(java.beans.PropertyChangeListener pcl)Unregister to listen toPROP_LOCKEDproperty change.
-
-
-
Field Detail
-
PROP_LOCKED
static final java.lang.String PROP_LOCKED
Fired when lock managed by this lockable is acquired or released.- See Also:
- Constant Field Values
-
-
Method Detail
-
obtainLock
DFLock obtainLock(java.lang.String reason) throws AlreadyLockedException
Obtains the lock; fails withAlreadyLockedExceptionif the object is already locked.- Parameters:
reason- The localized string explaining the operation or reason for locking. May benull.- Returns:
- The lock, if one can be obtained. Never returns
null, throws exception instead. - Throws:
AlreadyLockedException- if lockable provided another instance ofDFLockbefore and this lock is still active
-
isLocked
boolean isLocked()
Is a valid lock held by someone already?- Returns:
trueif locked
-
isLockedForever
boolean isLockedForever()
Is this lockable constantly locked? This can be used for lockables which are in readonly mode (e.g. when you log in as a user without appropriate access rights). If this method returnstrue, it means thatisLocked()returnstrueduring whole life time of this object and will never change. Lockable which is "forever locked" will never change this status to unlocked during one session. It also means that you don't need to listen toPROP_LOCKEDproperty on thisDFLockable, because it will be never fired.- Returns:
trueif "forever locked"
-
addPropertyChangeListener
void addPropertyChangeListener(java.beans.PropertyChangeListener pcl)
Register to listen toPROP_LOCKEDproperty change.- Parameters:
pcl- The PropertyChangeListener to register
-
removePropertyChangeListener
void removePropertyChangeListener(java.beans.PropertyChangeListener pcl)
Unregister to listen toPROP_LOCKEDproperty change.- Parameters:
pcl- Th PropertyChangeListener to unregister
-
checkLock
void checkLock(DFLock testedLock)
Checks whether the lock belongs to this lockable.- Parameters:
testedLock- The lock to check- Throws:
java.lang.IllegalStateException- thrown when the lock does not belongs to this lockable.
-
-