@RequiresSession
  public PrincipalTypeEntity ensurePrincipalTypeCreated(int principalType) {
    PrincipalTypeEntity principalTypeEntity = findById(principalType);
    if (principalTypeEntity == null) {
      principalTypeEntity = new PrincipalTypeEntity();
      principalTypeEntity.setId(principalType);
      switch (principalType) {
        case PrincipalTypeEntity.USER_PRINCIPAL_TYPE:
          principalTypeEntity.setName(PrincipalTypeEntity.USER_PRINCIPAL_TYPE_NAME);
          break;
        case PrincipalTypeEntity.GROUP_PRINCIPAL_TYPE:
          principalTypeEntity.setName(PrincipalTypeEntity.GROUP_PRINCIPAL_TYPE_NAME);
          break;
        case PrincipalTypeEntity.ROLE_PRINCIPAL_TYPE:
          principalTypeEntity.setName(PrincipalTypeEntity.ROLE_PRINCIPAL_TYPE_NAME);
          break;
        default:
          throw new IllegalArgumentException("Unknown principal type ID=" + principalType);
      }
      create(principalTypeEntity);
    }
    return principalTypeEntity;
  }
Creates and returns principal type if it wasn't persisted yet.

@param principalType id of principal type
@return principal type
ambari-server/src/main/java/org/apache/ambari/server/orm/dao/PrincipalTypeDAO.java