Checks jcr locks for consistency. Defines if there is a node with lockIsDeep or lockOwner property
(basically means that the node is to be locked)
and has no corresponding record in LockManager persistent layer (db table);
or the opposite.
439442
public void checkLocksInDataBase(boolean autoRepair)
   {
      SecurityHelper.validateSecurityPermission(JCRRuntimePermissions.MANAGE_REPOSITORY_PERMISSION);

      ResultSet resultSet = null;
      PreparedStatement preparedStatement = null;
      Connection jdbcConnection = null;
      try
      {
         jdbcConnection = jdbcDataContainer.getConnectionFactory().getJdbcConnection();
         preparedStatement = jdbcConnection.prepareStatement(lockInspectionQuery.getStatement());
         resultSet = preparedStatement.executeQuery();

         Set<String> lockedInJCRITEM = new HashSet<String>();
         while (resultSet.next())
         {
            lockedInJCRITEM.add(removeWorkspacePrefix(resultSet.getString(DBConstants.COLUMN_PARENTID)));
         }

         Set<String> lockedInJCRLOCK = lockHandler.getLockedNodesIds();

         checkConsistencyInJCRITEM(lockedInJCRITEM, lockedInJCRLOCK, autoRepair);
         checkConsistencyInJCRLOCK(lockedInJCRITEM, lockedInJCRLOCK, autoRepair);
      }
      catch (SQLException e)
      {
         logExceptionAndSetInconsistency("Unexpected exception during LOCK DB checking.", e);
      }
      catch (NamingException e)
      {
         logExceptionAndSetInconsistency("Unexpected exception during LOCK DB checking.", e);
      }
      catch (RepositoryConfigurationException e)
      {
         logExceptionAndSetInconsistency("Unexpected exception during LOCK DB checking.", e);
      }
      catch (RepositoryException e)
      {
         logExceptionAndSetInconsistency("Unexpected exception during LOCK DB checking.", e);
      }
      finally
      {
         JDBCUtils.freeResources(resultSet, preparedStatement, jdbcConnection);
      }
   }
266061
private void checkCollectionForeignkeys(ModelDef modelDef, String checkLevel) throws ConstraintException
    {
        if (CHECKLEVEL_NONE.equals(checkLevel))
        {
            return;
        }

        ClassDescriptorDef      classDef;
        CollectionDescriptorDef collDef;

        for (Iterator it = modelDef.getClasses(); it.hasNext();)
        {
            classDef = (ClassDescriptorDef)it.next();
            for (Iterator collIt = classDef.getCollections(); collIt.hasNext();)
            {
                collDef = (CollectionDescriptorDef)collIt.next();
                if (!collDef.getBooleanProperty(PropertyHelper.OJB_PROPERTY_IGNORE, false))
                {
                    if (collDef.hasProperty(PropertyHelper.OJB_PROPERTY_INDIRECTION_TABLE))
                    {
                        checkIndirectionTable(modelDef, collDef);
                    }
                    else
                    {    
                        checkCollectionForeignkeys(modelDef, collDef);
                    }
                }
            }
        }
    }
739491
public boolean hasReadLock(TransactionImpl tx, Object obj)
	{
		try
		{
			LockEntry lock = new LockEntry(new Identity(obj,getBroker()).toString(), tx.getGUID());
			boolean result = hasReadLockRemote(lock);			
			return result;
		}
		catch (Throwable t)
		{
			log.error("Cannot check read lock for object " + obj + " in transaction " + tx, t);
			return false;
		}
	}
566783
protected void removeLock(String nodeIdentifier)
   {
      try
      {
         NodeData nData = (NodeData)dataManager.getItemData(nodeIdentifier);

         //Skip removing, because that node was removed in other node of cluster.  
         if (nData == null)
         {
            return;
         }

         PlainChangesLog changesLog =
            new PlainChangesLogImpl(new ArrayList<ItemState>(), IdentityConstants.SYSTEM, ExtendedEvent.UNLOCK);

         ItemData lockOwner =
            copyItemData((PropertyData)dataManager.getItemData(nData, new QPathEntry(Constants.JCR_LOCKOWNER, 1),
               ItemType.PROPERTY));

         //Skip removing, because that lock was removed in other node of cluster.  
         if (lockOwner == null)
         {
            return;
         }

         changesLog.add(ItemState.createDeletedState(lockOwner));

         ItemData lockIsDeep =
            copyItemData((PropertyData)dataManager.getItemData(nData, new QPathEntry(Constants.JCR_LOCKISDEEP, 1),
               ItemType.PROPERTY));

         //Skip removing, because that lock was removed in other node of cluster.  
         if (lockIsDeep == null)
         {
            return;
         }

         changesLog.add(ItemState.createDeletedState(lockIsDeep));

         // lock probably removed by other thread
         if (lockOwner == null && lockIsDeep == null)
         {
            return;
         }

         dataManager.save(new TransactionChangesLog(changesLog));
      }
      catch (JCRInvalidItemStateException e)
      {
         //Skip property not found in DB, because that lock property was removed in other node of cluster.
         if (LOG.isDebugEnabled())
         {
            LOG.debug("The propperty was removed in other node of cluster.", e);
         }

      }
      catch (RepositoryException e)
      {
         LOG.error("Error occur during removing lock" + e.getLocalizedMessage(), e);
      }
   }
478827
@Override
    protected void onPersist(EntityMetadata entityMetadata, Object entity, Object id, List<RelationHolder> rlHolders)
    {
        if (log.isDebugEnabled())
            log.debug("Persisting " + entity);

        // All Modifying Neo4J operations must be executed within a transaction
        checkActiveTransaction();

        GraphDatabaseService graphDb = getConnection();

        try
        {

            // Top level node
            Node node = mapper.getNodeFromEntity(entity, id, graphDb, entityMetadata, isUpdate);

            if (node != null)
            {
                MetamodelImpl metamodel = (MetamodelImpl) kunderaMetadata.getApplicationMetadata().getMetamodel(
                        getPersistenceUnit());

                ((Neo4JTransaction) resource).addProcessedNode(id, node);

                if (!rlHolders.isEmpty())
                {
                    for (RelationHolder rh : rlHolders)
                    {
                        // Search Node (to be connected to ) in Neo4J graph
                        EntityMetadata targetNodeMetadata = KunderaMetadataManager.getEntityMetadata(kunderaMetadata,
                                rh.getRelationValue().getClass());
                        Object targetNodeKey = PropertyAccessorHelper.getId(rh.getRelationValue(), targetNodeMetadata);
                        // Node targetNode = mapper.searchNode(targetNodeKey,
                        // targetNodeMetadata, graphDb);

                        Node targetNode = null; // Target node connected through
                                                // relationship

                        /**
                         * If Relationship is with an entity in Neo4J, Target
                         * node must already have been created Get a handle of
                         * it from processed nodes and add edges to it. Else, if
                         * relationship is with an entity in a database other
                         * than Neo4J, create a "Proxy Node" that points to a
                         * row in other database. This proxy node contains key
                         * equal to primary key of row in other database.
                         * */

                        if (isEntityForNeo4J(targetNodeMetadata))
                        {
                            targetNode = ((Neo4JTransaction) resource).getProcessedNode(targetNodeKey);
                        }
                        else
                        {
                            // Create Proxy nodes for insert requests
                            if (!isUpdate)
                            {
                                targetNode = mapper.createProxyNode(id, targetNodeKey, graphDb, entityMetadata,
                                        targetNodeMetadata);
                            }
                        }

                        if (targetNode != null)
                        {
                            // Join this node (source node) to target node via
                            // relationship
                            DynamicRelationshipType relType = DynamicRelationshipType.withName(rh.getRelationName());
                            Relationship relationship = node.createRelationshipTo(targetNode, relType);

                            // Populate relationship's own properties into it
                            Object relationshipObj = rh.getRelationVia();
                            if (relationshipObj != null)
                            {
                                mapper.populateRelationshipProperties(entityMetadata, targetNodeMetadata, relationship,
                                        relationshipObj);

                                // After relationship creation, manually index
                                // it if desired
                                EntityMetadata relationMetadata = KunderaMetadataManager.getEntityMetadata(
                                        kunderaMetadata, relationshipObj.getClass());
                                if (!isUpdate)
                                {
                                    indexer.indexRelationship(relationMetadata, graphDb, relationship, metamodel);
                                }
                                else
                                {
                                    indexer.updateRelationshipIndex(relationMetadata, graphDb, relationship, metamodel);
                                }

                            }
                        }

                    }
                }

                // After node creation, manually index this node, if desired
                if (!isUpdate)
                {
                    indexer.indexNode(entityMetadata, graphDb, node, metamodel);
                }
                else
                {
                    indexer.updateNodeIndex(entityMetadata, graphDb, node, metamodel);
                }
            }

        }
        catch (Exception e)
        {
            log.error("Error while persisting entity " + entity + ", Caused by: ", e);
            throw new PersistenceException(e);
        }
    }
83518
private void checkReferenceForeignkeys(ModelDef modelDef, ReferenceDescriptorDef refDef) throws ConstraintException
    {
        String foreignkey = refDef.getProperty(PropertyHelper.OJB_PROPERTY_FOREIGNKEY);

        if ((foreignkey == null) || (foreignkey.length() == 0))
        {
            throw new ConstraintException("The reference "+refDef.getName()+" in class "+refDef.getOwner().getName()+" has no foreignkeys");
        }

        // we know that the class is present because the reference constraints have been checked already
        ClassDescriptorDef ownerClass = (ClassDescriptorDef)refDef.getOwner();
        ArrayList          keyFields;
        FieldDescriptorDef keyField;
        
        try
        {
            keyFields = ownerClass.getFields(foreignkey);
        }
        catch (NoSuchFieldException ex)
        {
            throw new ConstraintException("The reference "+refDef.getName()+" in class "+refDef.getOwner().getName()+" specifies a foreignkey "+ex.getMessage()+" that is not a persistent field in its owner class "+ownerClass.getName());
        }
        for (int idx = 0; idx < keyFields.size(); idx++)
        {
            keyField = (FieldDescriptorDef)keyFields.get(idx);
            if (keyField.getBooleanProperty(PropertyHelper.OJB_PROPERTY_IGNORE, false))
            {
                throw new ConstraintException("The reference "+refDef.getName()+" in class "+ownerClass.getName()+" uses the field "+keyField.getName()+" as foreignkey although this field is ignored in this class");
            }
        }
            
        // for the referenced class and any subtype that is instantiable (i.e. not an interface or abstract class)
        // there must be the same number of primary keys and the jdbc types of the primary keys must
        // match the jdbc types of the foreignkeys (in the correct order)
        String             targetClassName = refDef.getProperty(PropertyHelper.OJB_PROPERTY_CLASS_REF);
        ArrayList          queue           = new ArrayList();
        ClassDescriptorDef referencedClass;
        ArrayList          primFields;
        FieldDescriptorDef primField;
        String             primType;
        String             keyType;
        
        queue.add(modelDef.getClass(targetClassName));

        while (!queue.isEmpty())
        {
            referencedClass = (ClassDescriptorDef)queue.get(0);
            queue.remove(0);

            for (Iterator it = referencedClass.getExtentClasses(); it.hasNext();)
            {
                queue.add(it.next());
            }
            if (!referencedClass.getBooleanProperty(PropertyHelper.OJB_PROPERTY_GENERATE_REPOSITORY_INFO, true))
            {
                continue;
            }
            primFields = referencedClass.getPrimaryKeys();
            if (primFields.size() != keyFields.size())
            {
                throw new ConstraintException("The number of foreignkeys ("+keyFields.size()+") of the reference "+refDef.getName()+" in class "+refDef.getOwner().getName()+" doesn't match the number of primarykeys ("+primFields.size()+") of the referenced class (or its subclass) "+referencedClass.getName());
            }
            for (int idx = 0; idx < primFields.size(); idx++)
            {
                keyField  = (FieldDescriptorDef)keyFields.get(idx);
                primField = (FieldDescriptorDef)primFields.get(idx);
                primType  = primField.getProperty(PropertyHelper.OJB_PROPERTY_JDBC_TYPE);
                keyType   = keyField.getProperty(PropertyHelper.OJB_PROPERTY_JDBC_TYPE);
                if (!primType.equals(keyType))
                {
                    throw new ConstraintException("The jdbc-type of foreignkey "+keyField.getName()+" of the reference "+refDef.getName()+" in class "+refDef.getOwner().getName()+" doesn't match the jdbc-type of the corresponding primarykey "+primField.getName()+" of the referenced class (or its subclass) "+referencedClass.getName());
                }
            }
        }
    }
422583
@Override
    public boolean isLocked()
    {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.entry(tc, "isLocked");

        final boolean isLocked = (state == SIMPState.LOCKED);

        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.exit(tc, "isLocked", Boolean.valueOf(isLocked));

        return isLocked;
    }
154624
private boolean is_locked(Key<Job> job_key) { 
    if( _lockers==null ) return false;
    for( int i=(_lockers.length==1?0:1); i<_lockers.length; i++ ) {
      Key k = _lockers[i];
      if( job_key==k || (job_key != null && k != null && job_key.equals(k)) ) return true;
    }
    return false;
  }
817632
@Override
	public final boolean isLocked(int handle) throws DataStoreException 
    {
        if (SAFE_MODE) checkHandle(handle);
		return locks.get(handle);
	}
245010
public synchronized boolean lock() throws KeeperException, InterruptedException {
        if (isClosed()) {
            return false;
        }
        ensurePathExists(dir);

        return (Boolean) retryOperation(zop);
    }
208892
protected void peerAddedLock (String nodeName, NodeObject.Lock lock)
    {
        // check for hijacking
        if (_nodeobj.locks.contains(lock)) {
            log.warning("Client hijacked lock owned by this node", "lock", lock, "node", nodeName);
            droppedLock(lock);
        }

        // notify the handler, if any
        LockHandler handler = _locks.get(lock);
        if (handler != null) {
            handler.peerAddedLock(nodeName);
        }
    }
52174
protected boolean isLockedException ( SQLiteException maybeLocked ) {
    try {
      if (Class.forName("android.database.sqlite.SQLiteDatabaseLockedException", false, getClass().getClassLoader()).isAssignableFrom(maybeLocked.getClass()) ) {
        return true;
      }
    } catch (ClassNotFoundException e) {
      // no android.database.sqlite.SQLiteDatabaseLockedException
    }
    return false;
  }
74751
public boolean isLockLive(String nodeId) throws LockException
   {
      try
      {
         return isLockLive.run(nodeId);
      }
      catch (LockException e)
      {
         if (LOG.isTraceEnabled())
         {
            LOG.trace("An exception occurred: " + e.getMessage());
         }
      }
      return false;
   }
857855
public void lockNode(final NodeId node) {
		Lockable<SharedBufferNode> sharedBufferNode = sharedBuffer.getEntry(node);
		if (sharedBufferNode != null) {
			sharedBufferNode.lock();
			sharedBuffer.upsertEntry(node, sharedBufferNode);
		}
	}
863177
public void deadlockCheck(DeadlockChecker deadlockChecker) {
      if (deadlockChecker == null) {
         return; //no-op
      }
      LockPlaceHolder holder = current;
      if (holder != null) {
         for (LockPlaceHolder pending : pendingRequest) {
            pending.checkDeadlock(deadlockChecker, holder.owner);
         }
      }
   }
379202
public static boolean isStatement(JCTree tree) {
        return (tree instanceof JCStatement) &&
                !tree.hasTag(CLASSDEF) &&
                !tree.hasTag(Tag.BLOCK) &&
                !tree.hasTag(METHODDEF);
    }
164091
protected boolean isLocked( EditableDocument doc ) {
        return hasProperty(doc, JcrLexicon.LOCK_OWNER) || hasProperty(doc, JcrLexicon.LOCK_IS_DEEP);
    }