Checks whether given class descriptor has a primary key.

@param classDef   The class descriptor
@param checkLevel The current check level (this constraint is only checked in strict)
@exception ConstraintException If the constraint has been violated
496313
private void checkPrimaryKey(ClassDescriptorDef classDef, String checkLevel) throws ConstraintException
    {
        if (CHECKLEVEL_NONE.equals(checkLevel))
        {
            return;
        }

        if (classDef.getBooleanProperty(PropertyHelper.OJB_PROPERTY_GENERATE_TABLE_INFO, true) &&
            classDef.getPrimaryKeys().isEmpty())
        {
            LogHelper.warn(true,
                           getClass(),
                           "checkPrimaryKey",
                           "The class "+classDef.getName()+" has no primary key");
        }
    }
1368415
private function validateFieldCriteria(ClassMetadata $class, $fieldName): void
    {
        if (!$class->hasField($fieldName) && !$class->hasAssociation($fieldName)) {
            throw new ConstraintDefinitionException(sprintf("The field '%s' is not mapped by Doctrine, so it cannot be validated for uniqueness.", $fieldName));
        }
    }
153118
protected void checkEntity(InputProblemReporter rep, String id, EntityDecl ent)
        throws XMLStreamException
    {
        if (ent == null) {
            rep.reportValidationProblem("Referenced entity '"+id+"' not defined");
        } else if (ent.isParsed()) {
            rep.reportValidationProblem("Referenced entity '"+id+"' is not an unparsed entity");
        }
    }
1223329
public static Index getPrimaryKeyIndex(Table catalogTable) throws Exception {

        // We first need to find the pkey constraint
        Constraint catalog_constraint = null;
        for (Constraint c : catalogTable.getConstraints()) {
            if (c.getType() == ConstraintType.PRIMARY_KEY.getValue()) {
                catalog_constraint = c;
                break;
            }
        }
        if (catalog_constraint == null) {
            throw new Exception("ERROR: Table '" + catalogTable.getTypeName() + "' does not have a PRIMARY KEY constraint");
        }

        // And then grab the index that it is using
        return (catalog_constraint.getIndex());
    }
919461
private static boolean mightInheritFromException(ClassDescriptor d) {
        while (d != null) {
            try {
                if ("java.lang.Exception".equals(d.getDottedClassName())) {
                    return true;
                }
                XClass classNameAndInfo = Global.getAnalysisCache().getClassAnalysis(XClass.class, d);
                d = classNameAndInfo.getSuperclassDescriptor();
            } catch (CheckedAnalysisException e) {
                return true; // don't know
            }
        }
        return false;
    }
1090679
public boolean hasSubtypes(ClassDescriptor classDescriptor) throws ClassNotFoundException {
        Set<ClassDescriptor> subtypes = getDirectSubtypes(classDescriptor);
        if (DEBUG) {
            System.out.println("Direct subtypes of " + classDescriptor + " are " + subtypes);
        }
        return !subtypes.isEmpty();
    }
832461
private void checkId(FieldDescriptorDef fieldDef, String checkLevel) throws ConstraintException
    {
        if (CHECKLEVEL_NONE.equals(checkLevel))
        {
            return;
        }

        String id = fieldDef.getProperty(PropertyHelper.OJB_PROPERTY_ID);

        if ((id != null) && (id.length() > 0))
        {
            try
            {
                Integer.parseInt(id);
            }
            catch (NumberFormatException ex)
            {
                throw new ConstraintException("The id attribute of field "+fieldDef.getName()+" in class "+fieldDef.getOwner().getName()+" is not a valid number");
            }
        }
    }
1325269
public <E> E findById(final Class<E> entityClass, final Object primaryKey)
    {
        E e = find(entityClass, primaryKey);
        if (e == null)
        {
            return null;
        }

        // Return a copy of this entity
        return (E) (e);
    }
753994
private static boolean classIsJPAEntity(JavaClass cls) {
		AnnotationEntry[] annotations = cls.getAnnotationEntries();
		if (annotations != null) {
			for (AnnotationEntry annotation : annotations) {
				if ("Ljavax/persistence/Entity;".equals(annotation.getAnnotationType())) {
					return true;
				}
			}
		}

		return false;
	}
1096435
Constraint getFKConstraintForColumns(Table tableMain, int[] mainCols,
                                         int[] refCols) {

        for (int i = 0, size = constraintList.length; i < size; i++) {
            Constraint c = constraintList[i];

            if (c.isEquivalent(tableMain, mainCols, this, refCols)) {
                return c;
            }
        }

        return null;
    }
942859
private boolean checkValidClass(Class<?> clazz) {
        return clazz.isAnnotationPresent(Entity.class) || clazz.isAnnotationPresent(MappedSuperclass.class)
            || clazz.isAnnotationPresent(Embeddable.class);

    }
1307269
public void check(ReferenceDescriptorDef refDef, String checkLevel) throws ConstraintException
    {
        ensureClassRef(refDef, checkLevel);
        checkProxyPrefetchingLimit(refDef, checkLevel);
    }
414271
@Override
    public void visitClassContext(ClassContext classContext) {
        JavaClass jclass = classContext.getJavaClass();

        // We can ignore classes that were compiled for anything
        // less than JDK 1.5. This should avoid lots of unnecessary work
        // when analyzing code for older VM targets.
        if (BCELUtil.preTiger(jclass)) {
            return;
        }

        boolean sawUtilConcurrentLocks = false;
        for (Constant c : jclass.getConstantPool().getConstantPool()) {
            if (c instanceof ConstantMethodref) {
                ConstantMethodref m = (ConstantMethodref) c;
                ConstantClass cl = (ConstantClass) jclass.getConstantPool().getConstant(m.getClassIndex());
                ConstantUtf8 name = (ConstantUtf8) jclass.getConstantPool().getConstant(cl.getNameIndex());
                String nameAsString = name.getBytes();
                if (nameAsString.startsWith("java/util/concurrent/locks")) {
                    sawUtilConcurrentLocks = true;
                }

            }
        }
        if (sawUtilConcurrentLocks) {
            super.visitClassContext(classContext);
        }
    }
613973
private void ensureLength(FieldDescriptorDef fieldDef, String checkLevel)
    {
        if (!fieldDef.hasProperty(PropertyHelper.OJB_PROPERTY_LENGTH))
        {
            String defaultLength = JdbcTypeHelper.getDefaultLengthFor(fieldDef.getProperty(PropertyHelper.OJB_PROPERTY_JDBC_TYPE));

            if (defaultLength != null)
            {
                LogHelper.warn(true,
                               FieldDescriptorConstraints.class,
                               "ensureLength",
                               "The field "+fieldDef.getName()+" in class "+fieldDef.getOwner().getName()+" has no length setting though its jdbc type requires it (in most databases); using default length of "+defaultLength);
                fieldDef.setProperty(PropertyHelper.OJB_PROPERTY_LENGTH, defaultLength);
            }
        }
    }
973325
public static Predicate<Class<?>> classIs(final Class<?> reference) {
        return candidate -> candidate != null && candidate.equals(reference);
    }
936044
@Override
	public void typeCheck()
	{
		boolean nothing = true;
		boolean hasSystem = false;

		for (SClassDefinition c1 : classes)
		{
			c1.setType(assistantFactory.createSClassDefinitionAssistant().getType(c1));
			for (SClassDefinition c2 : classes)
			{
				if (c1 != c2 && c1.getName().equals(c2.getName()))
				{
					TypeChecker.report(3426, "Class " + c1.getName()
							+ " duplicates " + c2.getName(), c1.getName().getLocation());
				}
			}

			if (!c1.getTypeChecked())
			{
				nothing = false;
			}

			if (c1 instanceof ASystemClassDefinition)
			{
				if (hasSystem)
				{
					TypeChecker.report(3294, "Only one system class permitted", c1.getLocation());
				} else
				{
					hasSystem = true;
				}
			}
		}

		if (nothing)
		{
			return;
		}

		Environment allClasses = getAllClassesEnvronment();

		for (SClassDefinition c : classes)
		{
			if (!c.getTypeChecked())
			{
				assistantFactory.createSClassDefinitionAssistant().implicitDefinitions(c, allClasses);
			}
		}

		for (SClassDefinition c : classes)
		{
			if (!c.getTypeChecked())
			{
				try
				{
					Environment self = new PrivateClassEnvironment(assistantFactory, c, allClasses);
					assistantFactory.createSClassDefinitionAssistant().typeResolve(c, null, new TypeCheckInfo(assistantFactory, self));
				} catch (TypeCheckException te)
				{
					report(3427, te.getMessage(), te.location);
					
    				if (te.extras != null)
    				{
    					for (TypeCheckException e: te.extras)
    					{
    						report(3427, e.getMessage(), e.location);
    					}
    				}
				} catch (AnalysisException te)
				{
					report(3431, te.getMessage(), null);// FIXME: internal error
				}
			}
		}

		for (SClassDefinition c : classes)
		{
			if (!c.getTypeChecked())
			{
				assistantFactory.createSClassDefinitionAssistant().checkOver(c);
			}
		}

		QuestionAnswerAdaptor<TypeCheckInfo, PType> tc = getTypeCheckVisitor();
		for (Pass pass : Pass.values())
		{
			for (SClassDefinition c : classes)
			{
				if (!c.getTypeChecked())
				{
					try
					{
						Environment self = new PrivateClassEnvironment(assistantFactory, c, allClasses);
						assistantFactory.createSClassDefinitionAssistant().typeCheckPass(c, pass, self, tc);
					} catch (TypeCheckException te)
					{
						report(3428, te.getMessage(), te.location);
						
	    				if (te.extras != null)
	    				{
	    					for (TypeCheckException e: te.extras)
	    					{
	    						report(3428, e.getMessage(), e.location);
	    					}
	    				}
					} catch (AnalysisException te)
					{
						report(3431, te.getMessage(), null);// FIXME: internal error
					}
				}
			}
		}

		List<PDefinition> allDefs = new Vector<PDefinition>();

		for (SClassDefinition c : classes)
		{
			if (!c.getTypeChecked())
			{
				assistantFactory.createSClassDefinitionAssistant().initializedCheck(c);
				assistantFactory.createPDefinitionAssistant().unusedCheck(c);
				allDefs.addAll(c.getDefinitions());
			}
		}
    	
    	cyclicDependencyCheck(allDefs);
	}
130884
public void addClass(ClassDescriptorDef classDef)
    {
        classDef.setOwner(this);
        // Regardless of the format of the class name, we're using the fully qualified format
        // This is safe because of the package & class naming constraints of the Java language
        _classDefs.put(classDef.getQualifiedName(), classDef);
    }