acquire a write lock on Object obj for Transaction tx.
@param tx the transaction requesting the lock
@param obj the Object to be locked
@return true if successful, else false
336872
public boolean writeLock(TransactionImpl tx, Object obj)
    {
        LockEntry writer = getWriter(obj);
        if (writer == null)
        {
            if (setWriter(tx, obj))
                return true;
            else
                return writeLock(tx, obj);
        }
        if (writer.isOwnedBy(tx))
        {
            return true;    // If I'm the writer, then I can write.
        }
        return false;
    }
953971
public boolean readLock(TransactionImpl tx, Object obj)
    {

        LockEntry writer = getWriter(obj);
        if (writer == null)
        {
            addReader(tx, obj);
            // if there has been a successful write locking, try again
            if (getWriter(obj) == null)
                return true;
            else
            {
                removeReader(tx, obj);
                return readLock(tx, obj);
            }
        }
        if (writer.isOwnedBy(tx))
        {
            return true;    // If I'm the writer, I can read.
        }
        else
        {
            return false;
        }
    }
484248
private void persistTransactions(Transaction tx, String blockNumber)
    {

        LOGGER.debug("Going to save transactions for Block - " + getBlockNumberWithRawData(blockNumber) + "!");
        try
        {
            em.persist(tx);
            LOGGER.debug("Transaction with hash " + tx.getHash() + " is stored!");
        }
        catch (Exception ex)
        {
            LOGGER.error("Transaction with hash " + tx.getHash() + " is not stored. ", ex);
            throw new KunderaException("transaction with hash " + tx.getHash() + " is not stored. ", ex);
        }

    }
717381
function lock(obj, freeze, options) {
    if (options && options.noLocking) {
        return;
    }
    if (freeze) {
        Object.freeze(obj); // freeze the entire object, permanently;
    } else {
        const desc = {
            writable: false,
            configurable: false,
            enumerable: true
        };
        for (const p in obj) {
            Object.defineProperty(obj, p, desc);
        }
    }
}
51519
@Deprecated
    public static boolean writeObjectToFile(Object obj, String file) {
        try {
            writeObjectToFileOrDie(obj, file, LOGGER);
            return true;
        } catch (Exception e) {
            LOGGER.error(e.getClass() + ": writeObjectToFile(" + file + ") encountered exception: " + e.getMessage(), e);
            return false;
        }
    }
78514
public boolean releaseLock(TransactionImpl tx, Object obj)
    {
        LockEntry writer = getWriter(obj);
        if (writer != null && writer.isOwnedBy(tx))
        {
            removeWriter(writer);
            return true;
        }
        if (hasReadLock(tx, obj))
        {
            removeReader(tx, obj);
            return true;
        }
        return false;
    }
888709
def textx_isinstance(obj, obj_cls):
    
    if isinstance(obj, obj_cls):
        return True
    if hasattr(obj_cls, "_tx_fqn") and hasattr(obj, "_tx_fqn"):
        if obj_cls._tx_fqn == obj._tx_fqn:
            return True
    if hasattr(obj_cls, "_tx_inh_by"):
        for cls in obj_cls._tx_inh_by:
            if (textx_isinstance(obj, cls)):
                return True
    return False
1096372
protected void saveClonedState(Transaction transaction)
                    throws ObjectManagerException {
        final String methodName = "saveClonedState";
        if (Tracing.isAnyTracingEnabled() && trace.isEntryEnabled())
            trace.entry(this, cclass, methodName, transaction);

        // Loop over all of the ObjecStores.
        java.util.Iterator objectStoreIterator = objectStores.values()
                        .iterator();
        while (objectStoreIterator.hasNext()) {
            ObjectStore objectStore = (ObjectStore) objectStoreIterator.next();

            // Don't bother with ObjectStores that can't be used for recovery.
            if (objectStore.getContainsRestartData()) {

                // Locate any existing copy.
                Token objectManagerStateCloneToken = new Token(objectStore,
                                                               ObjectStore.objectManagerStateIdentifier.longValue());
                // Swap for the definitive Token, if there is one.
                objectManagerStateCloneToken = objectStore.like(objectManagerStateCloneToken);

                ObjectManagerState objectManagerStateClone = (ObjectManagerState) objectManagerStateCloneToken.getManagedObject();

                // Does the cloned state already exist?
                if (objectManagerStateClone == null) {
                    objectManagerStateClone = new ObjectManagerState();
                    objectManagerStateClone.objectStores = objectStores;
                    objectManagerStateClone.becomeCloneOf(this);
                    objectManagerStateCloneToken.setManagedObject(objectManagerStateClone);
                    transaction.add(objectManagerStateClone);

                } else {
                    transaction.lock(objectManagerStateClone);
                    objectManagerStateClone.objectStores = objectStores;
                    objectManagerStateClone.becomeCloneOf(this);
                    transaction.replace(objectManagerStateClone);
                } //  if (objectManagerStateClone == null).
            } // if (objectStore.getContainsRestartData()).
        } // While objectStoreIterator.hasNext().

        if (Tracing.isAnyTracingEnabled() && trace.isEntryEnabled())
            trace.exit(this, cclass, methodName);
    }
907385
public boolean upgradeLock(TransactionImpl tx, Object obj)
    {
        LockEntry writer = getWriter(obj);
        if (writer == null)
        {
            Collection readers = this.getReaders(obj);
            if (readers.size() == 1)
            {
                LockEntry reader = (LockEntry) readers.iterator().next();
                if (reader.isOwnedBy(tx))
                {
                    if (upgradeLock(reader))
                        return true;
                    else
                        return upgradeLock(tx, obj);
                }
            }
            else if (readers.size() == 0)
            {
                if (setWriter(tx, obj))
                    return true;
                else
                    return upgradeLock(tx, obj);
            }


        }
        else if (writer.isOwnedBy(tx))
        {
            return true;    // If I already have Write, then I've upgraded.
        }

        return false;
    }
180632
private boolean writeLockAvailable(int type) {
        if (mReadLocks == 0 && mWriteLockHeld == null) {
            return (type == UPGRADABLE) ? true : mUpgradableLockHeld == null;
        }
        return false;
    }
978174
@Override
	public void writeObject(Object o)
	{
		synchronized (this)
		{
			ArrayList<Object> prePending = objPrePendingCache.get(o);
			if (prePending == null)
			{
				boolean oldWritingObject = writingObject;
				writingObject = true;
				try
				{
					super.writeObject(o);
				}
				finally
				{
					writingObject = oldWritingObject;
				}
			}
			else
			{
				flushPrePending.clear();
				flushPrePending.addAll(prePending);
			}

			// root object
			if (!writingObject)
			{
				boolean isNotCached = prePending == null;
				// is not cached, add to cache
				if (isNotCached && o != null)
				{
					prePending = new ArrayList<Object>();
					prePending.addAll(flushPrePending);
					objPrePendingCache.put(o, prePending);
				}

				// add to pending
				flushPending.addAll(flushPrePending);
				flushPendingStat.addAll(flushPrePending);
				flushPrePending.clear();

				if (isNotCached && flushPending.contains(o))
				{
					flushPendingStat.remove(o);
				}
				else
				{
					flushPending.add(o);
				}
				if (needOwner)
				{
					this.flushPending.remove(owner);
					this.flushPending.add(0, owner);
				}
			}
		}
	}
1332163
public boolean setWriter(TransactionImpl tx, Object obj)
    {
        checkTimedOutLocks();

        Identity oid = new Identity(obj, tx.getBroker());
        LockEntry writer = new LockEntry(oid.toString(),
                tx.getGUID(),
                System.currentTimeMillis(),
                LockStrategyFactory.getIsolationLevel(obj),
                LockEntry.LOCK_WRITE);
        String oidString = oid.toString();
        setWriterInternal(writer, oidString);
        return true;
    }
166586
@Override
  public void update(Object obj) {
    lock.writeLock().lock();
    try {
      populated = true;
      this.queueActionLocked(DeltaType.Updated, obj);
    } finally {
      lock.writeLock().unlock();
    }
  }
563580
private void lock(Object obtainer) throws PSQLException {
    if (lockedFor == obtainer) {
      throw new PSQLException(GT.tr("Tried to obtain lock while already holding it"),
          PSQLState.OBJECT_NOT_IN_STATE);

    }
    waitOnLock();
    lockedFor = obtainer;
  }
654230
public static TransactionException transactionReadOnly(TransactionOLTP tx) {
        return create(ErrorMessage.TRANSACTION_READ_ONLY.getMessage(tx.keyspace()));
    }
557326
private boolean cleanLockedObjects(ITransaction transaction,
            LockedObject lo, boolean temporary) {

        if (lo._children == null) {
            if (lo._owner == null) {
                if (temporary) {
                    lo.removeTempLockedObject();
                } else {
                    lo.removeLockedObject();
                }

                return true;
            } else {
                return false;
            }
        } else {
            boolean canDelete = true;
            int limit = lo._children.length;
            for (int i = 0; i < limit; i++) {
                if (!cleanLockedObjects(transaction, lo._children[i], temporary)) {
                    canDelete = false;
                } else {

                    // because the deleting shifts the array
                    i--;
                    limit--;
                }
            }
            if (canDelete) {
                if (lo._owner == null) {
                    if (temporary) {
                        lo.removeTempLockedObject();
                    } else {
                        lo.removeLockedObject();
                    }
                    return true;
                } else {
                    return false;
                }
            } else {
                return false;
            }
        }
    }
70088
def writeObject(self, obj, is_proxy=False):
        
        if self.use_proxies and not is_proxy:
            self.writeProxy(obj)

            return

        self.stream.write(TYPE_OBJECT)

        ref = self.context.getObjectReference(obj)

        if ref != -1:
            self._writeInteger(ref << 1)

            return

        self.context.addObject(obj)

        # object is not referenced, serialise it
        kls = obj.__class__
        definition = self.context.getClass(kls)
        alias = None
        class_ref = False # if the class definition is a reference

        if definition:
            class_ref = True
            alias = definition.alias
        else:
            alias = self.context.getClassAlias(kls)
            definition = ClassDefinition(alias)

            self.context.addClass(definition, alias.klass)

        if class_ref:
            self.stream.write(definition.reference)
        else:
            ref = 0

            if definition.encoding != ObjectEncoding.EXTERNAL:
                ref += definition.attr_len << 4

            final_reference = encode_int(ref | definition.encoding << 2 |
                REFERENCE_BIT << 1 | REFERENCE_BIT)

            self.stream.write(final_reference)

            definition.reference = encode_int(
                definition.reference << 2 | REFERENCE_BIT)

            if alias.anonymous:
                self.stream.write('\x01')
            else:
                self.serialiseString(alias.alias)

            # work out what the final reference for the class will be.
            # this is okay because the next time an object of the same
            # class is encoded, class_ref will be True and never get here
            # again.

        if alias.external:
            obj.__writeamf__(DataOutput(self))

            return

        attrs = alias.getEncodableAttributes(obj, codec=self)

        if alias.static_attrs:
            if not class_ref:
                [self.serialiseString(attr) for attr in alias.static_attrs]

            for attr in alias.static_attrs:
                value = attrs.pop(attr)

                self.writeElement(value)

            if definition.encoding == ObjectEncoding.STATIC:
                return

        if definition.encoding == ObjectEncoding.DYNAMIC:
            if attrs:
                for attr, value in attrs.iteritems():
                    if type(attr) in python.int_types:
                        attr = str(attr)

                    self.serialiseString(attr)
                    self.writeElement(value)

            self.stream.write('\x01')