Package sc.db

Class DBObject

  • All Implemented Interfaces:
    IDBObject, IObjectId

    public class DBObject
    extends java.lang.Object
    implements IDBObject
    Database object class, usually stored as a code-generated field _dbObject in a given instance. Manages the persistent state for the wrapping instance, using layered "DBTypeDescriptors" - used to map properties from a primary table/database (to get the id properties), then merge in auxiliary tables/databases. This is "mostly thread-safe" class. Instances can be cached and shared in scopes under the "highlander" principle - one entity instance with a given id visible in a given process. Individual fields and the default getX/setX methods operate on cached values, lazily populated by executing queries, that each populate one or more properties at a time. If two threads try to query the same group, one performs the query, the other waits. Updates are stored in a transaction-specific way so that pending changes are only visible to the current thread. Each object stores a set of pendingOps - TxUpdate, Insert, or Delete for this instance in different transactions. The getX method looks in the list of pendingOps and returns a pending update before the cached value. During the 'commit', the object instance itself is locked and all values from the committed transaction are applied to the cached value. It's possible to use getX methods without synchronizing on the instance, but to ensure a transactionally consistent view of an instance, sync on the instance while calling getX/setX or store make sure it's stored a synchronized scope.
    • Field Detail

      • fstate

        protected long fstate
      • wrapper

        public IDBObject wrapper
        The object used for storing properties for this DBObject. When null, this instance is used for properties. When not null, this instance is stored as the _dbObject field in a "wrapper" instance where this is our pointer back.
      • pendingOps

        public final java.util.List<TxOperation> pendingOps
      • replacedBy

        public IDBObject replacedBy
        This will be set when this DBObject has been replaced for some reason by another one. Each operation will be redirected to the replaced version... maybe due to a race condition during the creation, because an instance was deserialized using the existing version.
    • Constructor Detail

      • DBObject

        public DBObject()
      • DBObject

        public DBObject​(IDBObject wrapper)
    • Method Detail

      • init

        public void init()
      • getInst

        public IDBObject getInst()
        Returns the persistent instance with the getX/setX methods
      • dbFetch

        public PropUpdate dbFetch​(java.lang.String property)
      • dbFetchWithRefId

        public PropUpdate dbFetchWithRefId​(java.lang.String property)
      • dbFetchDefault

        public boolean dbFetchDefault()
      • dbSetIdProp

        public PropUpdate dbSetIdProp​(java.lang.String propertyName,
                                      java.lang.Object propertyValue,
                                      java.lang.Object oldVal)
      • dbSetProp

        public PropUpdate dbSetProp​(java.lang.String propertyName,
                                    java.lang.Object propertyValue,
                                    java.lang.Object oldValue)
        Called to update the saved representation of the instance. Returns null to allow the assignment in the field. If it returns non-null, the setX method will just return. Note: In the current implementation if there's a change to the property made that's local to the thread, the Bind.sendEvent call should be made by the framework since the setX method won't do anything else... for example, in a reverse relationship change.
      • dbInsert

        public void dbInsert​(boolean queue)
        Specified by:
        dbInsert in interface IDBObject
      • dbDelete

        public void dbDelete​(boolean queue)
        Specified by:
        dbDelete in interface IDBObject
      • dbValidate

        public java.util.Map<java.lang.String,​java.lang.String> dbValidate()
        Description copied from interface: IDBObject
        Returns Map of propertyName to error message by calling validateX methods for any changed properties.
        Specified by:
        dbValidate in interface IDBObject
      • dbRefresh

        public boolean dbRefresh()
        Description copied from interface: IDBObject
        Used to either select a 'protototype instance' or refresh all previously selected groups on a persistent instance. Returns false if the prototype instance does not exist, or the persistent instance does not exist
        Specified by:
        dbRefresh in interface IDBObject
      • isTransient

        public boolean isTransient()
      • setTransient

        public void setTransient​(boolean val)
      • isPrototype

        public boolean isPrototype()
      • clearPrototype

        public void clearPrototype()
      • setPrototype

        public void setPrototype​(boolean val)
      • initProtoProperties

        public void initProtoProperties​(java.lang.String... protoProps)
      • setPropertyInPath

        public void setPropertyInPath​(java.lang.String propPath,
                                      java.lang.Object value)
      • getPropertyInPath

        public java.lang.Object getPropertyInPath​(java.lang.String propPath)
      • getProperty

        public java.lang.Object getProperty​(java.lang.String propName)
      • isPendingInsert

        public boolean isPendingInsert()
      • registerNew

        public void registerNew()
      • markStopped

        public void markStopped()
      • markRemoved

        public void markRemoved()
      • setObjectId

        public void setObjectId​(java.lang.String str)
      • getObjectId

        public java.lang.String getObjectId()
        Specified by:
        getObjectId in interface IObjectId
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • getFetchedStateString

        public static java.lang.String getFetchedStateString​(DBTypeDescriptor dbTypeDesc,
                                                             long fstate)
      • getDBId

        public java.lang.Object getDBId()
        Specified by:
        getDBId in interface IDBObject
      • setDBId

        public void setDBId​(java.lang.Object dbId)
      • stop

        public void stop()
      • isActive

        public boolean isActive()
      • getStateString

        public java.lang.String getStateString()
      • dbGetPropertyWithRefId

        public static PropUpdate dbGetPropertyWithRefId​(IDBObject wrapper,
                                                        DBObject obj,
                                                        java.lang.String prop)
      • dbSetProperty

        public static PropUpdate dbSetProperty​(DBObject obj,
                                               java.lang.String propName,
                                               java.lang.Object propVal,
                                               java.lang.Object oldValue)
      • dbSetIdProperty

        public static PropUpdate dbSetIdProperty​(DBObject obj,
                                                 java.lang.String propName,
                                                 java.lang.Object propVal,
                                                 java.lang.Object oldVal)
      • equalProps

        public boolean equalProps​(DBObject other)