Get client customer ID from the adwords session, and convert it to Long type.

@param session the AdWords session
@return the client customer ID in the AdWords session, or VIRTUAL_CID if absent
172450
public static long getClientCustomerId(AdWordsSession session) {
    String accountIdStr = session.getClientCustomerId();

    // clientCustomerId might be absent from AdWordsSession, e.g., for
    // ReportDefinitionService.getReportFields() and CustomerService.getCustomers().
    // In this case, use ONE virtual account to handle rate limit of ALL unknown accounts combined.
    if (accountIdStr == null) {
      return VIRTUAL_CID;
    }

    try {
      return Long.parseLong(accountIdStr.replace("-", ""));
    } catch (NumberFormatException e) {
      throw new RateLimiterException("Encountered invalid CID: " + accountIdStr, e);
    }
  }
778968
private static long getMaxBidId(Client client) {
        long currentMaxBidId = 0;
        try {
            VoltTable vt = client.callProcedure("@AdHoc", "select max(id) from bids").getResults()[0];
            vt.advanceRow();
            currentMaxBidId = vt.getLong(0);
            if (vt.wasNull()) {
                currentMaxBidId = 0;
            }
        } catch (IOException | ProcCallException e) {
            e.printStackTrace();
        }

        return currentMaxBidId;
    }
1178008
protected final Object getIdentifier(Object value, SessionFactoryImplementor sessionFactory) throws HibernateException {
		if ( value == null ) {
			return null;
		}

		final EntityPersister persister = sessionFactory.getMetamodel().entityPersister( delegate.getAssociatedEntityName() );
		final String uniqueKeyPropertyName = delegate.getRHSUniqueKeyPropertyName();

		if ( StringHelper.isEmpty( uniqueKeyPropertyName ) ) {
			return persister.getIdentifier( value, null );
		}
		else {
			Object propertyValue = persister.getPropertyValue( value, uniqueKeyPropertyName );
			// We now have the value of the property-ref we reference.  However,
			// we need to dig a little deeper, as that property might also be
			// an entity type, in which case we need to resolve its identifier
			Type type = persister.getPropertyType( uniqueKeyPropertyName );
			GridType gridType = typeTranslator.getType( type );
			if ( gridType.isEntityType() ) {
				propertyValue = getIdentifier( propertyValue, sessionFactory );
			}

			return propertyValue;
		}
	}
576639
private static BiddingStrategyConfiguration getAdGroupBiddingStrategyConfiguration(
      AdWordsServicesInterface services, AdWordsSession session, Long adGroupId)
      throws ApiException, RemoteException {
    AdGroupServiceInterface adGroupService = services.get(session, AdGroupServiceInterface.class);

    Selector selector = new SelectorBuilder()
        .fields(
            AdGroupField.Id,
            AdGroupField.BiddingStrategyType,
            AdGroupField.BiddingStrategyId,
            AdGroupField.BiddingStrategyName)
        .equalsId(adGroupId).build();

    AdGroupPage adGroupPage = adGroupService.get(selector);

    if (adGroupPage.getEntries() == null || adGroupPage.getEntries().length == 0) {
      throw new IllegalArgumentException("No ad group found with ID " + adGroupId);
    }

    AdGroup adGroup = adGroupPage.getEntries(0);

    Preconditions.checkState(adGroup.getBiddingStrategyConfiguration() != null,
        "Unexpected state - ad group ID %s has a null BiddingStrategyConfiguration", adGroupId);
    return adGroup.getBiddingStrategyConfiguration();
  }
48051
public static void runExample(
      AdWordsServicesInterface adWordsServices, AdWordsSession session) throws RemoteException {
    // Get the CampaignService.
    ManagedCustomerServiceInterface managedCustomerService =
        adWordsServices.get(session, ManagedCustomerServiceInterface.class);

    // Create account.
    ManagedCustomer customer = new ManagedCustomer();
    customer.setName("Customer created with ManagedCustomerService on " + new DateTime());
    customer.setCurrencyCode("EUR");
    customer.setDateTimeZone("Europe/London");

    // Create operations.
    ManagedCustomerOperation operation = new ManagedCustomerOperation();
    operation.setOperand(customer);
    operation.setOperator(Operator.ADD);

    ManagedCustomerOperation[] operations = new ManagedCustomerOperation[] {operation};

    // Add account.
    ManagedCustomerReturnValue result = managedCustomerService.mutate(operations);

    // Display accounts.
    for (ManagedCustomer customerResult : result.getValue()) {
      System.out.printf("Account with customer ID %d was created.%n",
          customerResult.getCustomerId());
    }
  }
666733
protected String getTableName(PersistentEntity domainClass, String sessionFactoryBeanName) {
        Mapping m = getMapping(domainClass);
        String tableName = null;
        if (m != null && m.getTableName() != null) {
            tableName = m.getTableName();
        }
        if (tableName == null) {
            String shortName = domainClass.getJavaClass().getSimpleName();
            PersistentEntityNamingStrategy namingStrategy = this.namingStrategy;

            if(namingStrategy != null) {
                tableName = namingStrategy.resolveTableName(domainClass);
            }
            if(tableName == null) {
                tableName = getNamingStrategy(sessionFactoryBeanName).classToTableName(shortName);
            }
        }
        return tableName;
    }
27676
private static function getPredefinedCustomTargetingKeyIds(
        ServiceFactory $serviceFactory,
        AdManagerSession $session
    ) {
        $customTargetingKeyIds = [];

        $customTargetingService = $serviceFactory->createCustomTargetingService(
            $session
        );

        // Create a statement to get all custom targeting keys.
        $pageSize = StatementBuilder::SUGGESTED_PAGE_LIMIT;
        $statementBuilder = (new StatementBuilder())->where('type = :type')
            ->orderBy('id ASC')
            ->limit($pageSize)
            ->withBindVariableValue('type', CustomTargetingKeyType::PREDEFINED);

        // Retrieve a small amount of custom targeting keys at a time, paging
        // through until all custom targeting keys have been retrieved.
        $totalResultSetSize = 0;
        do {
            $page = $customTargetingService->getCustomTargetingKeysByStatement(
                $statementBuilder->toStatement()
            );

            if ($page->getResults() !== null) {
                $totalResultSetSize = $page->getTotalResultSetSize();
                $i = $page->getStartIndex();
                foreach ($page->getResults() as $customTargetingKey) {
                    printf(
                        "%d) Custom targeting key with ID %d, name '%s', and"
                        . " display name '%s' was found.%s",
                        $i++,
                        $customTargetingKey->getId(),
                        $customTargetingKey->getName(),
                        $customTargetingKey->getDisplayName(),
                        PHP_EOL
                    );
                    $customTargetingKeyIds[] = $customTargetingKey->getId();
                }
            }

            $statementBuilder->increaseOffsetBy($pageSize);
        } while ($statementBuilder->getOffset() < $totalResultSetSize);

        printf(
            "Number of keys found: %d%s%s",
            $totalResultSetSize,
            PHP_EOL,
            PHP_EOL
        );

        return $customTargetingKeyIds;
    }
371725
protected function loadClientSessionId(): string
    {
        $sessionId = '';
        if (isset($_COOKIE[$this->cookieName])) {
            $sessionId = $_COOKIE[$this->cookieName];
        }
        if ($sessionId == '') {
            return $sessionId;
        }
        if ($this->isValidSessionId($sessionId)) {
            return $sessionId;
        } else {
            return '';
        }
    }
1247054
public String getID() {
        byte[] genBytes = new byte[_byteArraySize];
        synchronized (_random) {
            _random.nextBytes(genBytes);
        }
        String id = convertSessionIdBytesToSessionId(genBytes, _sessionIDLength);
        if (tc.isDebugEnabled()) {
            Tr.debug(tc, "sessionID=" + id);
        }
        return id;
    }
14873
private void addClientId(String clientId) {
        //Sometimes the client Id will be null. For instance in the case QueueConnectionFactory, there is no default client Id specified in metatype.xml.
        if (clientId == null)
            return; //do nothing

        ConcurrentHashMap<String, Integer> clientIdTable = JmsFactoryFactoryImpl.getClientIdTable();

        if (clientIdTable.containsKey(clientId)) {
            clientIdTable.put(clientId, clientIdTable.get(clientId).intValue() + 1);
        } else {
            clientIdTable.put(clientId, 1);
        }

    }
911753
public static String getSessionId(final HttpServletRequest pRequest) {
        HttpSession session = pRequest.getSession();

        return (session != null) ? session.getId() : null;
    }
879241
public Client getClient(int clientId) throws Exception {
        Client client = null;

        PreparedStatement statement = null;
        ResultSet results = null;
        try (Connection sqlConnection = sqlService.getConnection()) {
            String queryString = "SELECT * FROM " + Constants.DB_TABLE_CLIENT +
                " WHERE " + Constants.GENERIC_ID + " = ?";

            statement = sqlConnection.prepareStatement(queryString);
            statement.setInt(1, clientId);

            results = statement.executeQuery();
            if (results.next()) {
                client = this.getClientFromResultSet(results);
            }
        } catch (Exception e) {
            throw e;
        } finally {
            try {
                if (results != null) {
                    results.close();
                }
            } catch (Exception e) {
            }
            try {
                if (statement != null) {
                    statement.close();
                }
            } catch (Exception e) {
            }
        }

        return client;
    }
1304187
public String getSessionId(HttpServletRequest request) {
		String sessionId = request.getParameter(ACCESSTOKEN);
		if(isBlank(sessionId)){
			sessionId = request.getHeader(ACCESSTOKEN);
		}
		if(isBlank(sessionId)){
			Cookie[] cookies = request.getCookies();
			if(cookies == null)return null;
			for (Cookie cookie : cookies) {
				if(sessionIdName.equals(cookie.getName())){
					sessionId = cookie.getValue();
					break;
				}
			}
		}
		return sessionId;
	}
123813
public static void runExample(
      AdWordsServicesInterface adWordsServices, AdWordsSession session) throws RemoteException {
    // Get the UserListService.
    AdwordsUserListServiceInterface userListService =
        adWordsServices.get(session, AdwordsUserListServiceInterface.class);

    // Get the ConversionTrackerService.
    ConversionTrackerServiceInterface conversionTrackerService =
        adWordsServices.get(session, ConversionTrackerServiceInterface.class);

    // Create conversion type (tag).
    UserListConversionType conversionType = new UserListConversionType();
    conversionType.setName("Mars cruise customers #" + System.currentTimeMillis());

    // Create remarketing user list.
    BasicUserList userList = new BasicUserList();
    userList.setName("Mars cruise customers #" + System.currentTimeMillis());
    userList.setDescription("A list of mars cruise customers in the last year");
    userList.setMembershipLifeSpan(365L);
    userList.setConversionTypes(new UserListConversionType[] {conversionType});

    // You can optionally provide these field(s).
    userList.setStatus(UserListMembershipStatus.OPEN);

    // Create operations.
    UserListOperation operation = new UserListOperation();
    operation.setOperand(userList);
    operation.setOperator(Operator.ADD);

    UserListOperation[] operations = new UserListOperation[] {operation};

    // Add user list.
    UserListReturnValue result = userListService.mutate(operations);

    // Display results.
    // Capture the ID(s) of the conversion.
    List<String> conversionIds = new ArrayList<>();
    for (UserList userListResult : result.getValue()) {
      if (userListResult instanceof BasicUserList) {
        BasicUserList remarketingUserList = (BasicUserList) userListResult;
        for (UserListConversionType userListConversionType :
            remarketingUserList.getConversionTypes()) {
          conversionIds.add(userListConversionType.getId().toString());
        }
      }
    }

    // Create predicate and selector.
    Selector selector = new SelectorBuilder()
        .fields("Id", "GoogleGlobalSiteTag", "GoogleEventSnippet")
        .in(AdwordsUserListField.Id, conversionIds.toArray(new String[0]))
        .build();

    // Get all conversion trackers.
    Map<Long, AdWordsConversionTracker> conversionTrackers =
        new HashMap<Long, AdWordsConversionTracker>();
    ConversionTrackerPage page = conversionTrackerService.get(selector);
    if (page != null && page.getEntries() != null) {
      conversionTrackers =
          Arrays.stream(page.getEntries())
              .collect(
                  Collectors.toMap(
                      conversionTracker -> conversionTracker.getId(),
                      conversionTracker -> (AdWordsConversionTracker) conversionTracker));
    }

    // Display user lists.
    for (UserList userListResult : result.getValue()) {
      System.out.printf("User list with name '%s' and ID %d was added.%n",
          userListResult.getName(), userListResult.getId());

      // Display user list associated conversion code snippets.
      if (userListResult instanceof BasicUserList) {
        BasicUserList remarketingUserList = (BasicUserList) userListResult;
        for (UserListConversionType userListConversionType : remarketingUserList
            .getConversionTypes()) {
          ConversionTracker conversionTracker =
              conversionTrackers.get(userListConversionType.getId());
          System.out.printf(
              "Google global site tag:%n%s%n%n", conversionTracker.getGoogleGlobalSiteTag());
          System.out.printf(
              "Google event snippet:%n%s%n%n", conversionTracker.getGoogleEventSnippet());
        }
      }
    }
  }
211702
public static void runExample(AdManagerServices adManagerServices, AdManagerSession session)
      throws RemoteException {
    CompanyServiceInterface companyService =
        adManagerServices.get(session, CompanyServiceInterface.class);

    // Create a statement to select companies.
    StatementBuilder statementBuilder =
        new StatementBuilder()
            .where("type = :type")
            .orderBy("id ASC")
            .limit(StatementBuilder.SUGGESTED_PAGE_LIMIT)
            .withBindVariableValue("type", CompanyType.ADVERTISER.toString());

    // Retrieve a small amount of companies at a time, paging through
    // until all companies have been retrieved.
    int totalResultSetSize = 0;
    do {
      CompanyPage page = companyService.getCompaniesByStatement(statementBuilder.toStatement());

      if (page.getResults() != null) {
        // Print out some information for each company.
        totalResultSetSize = page.getTotalResultSetSize();
        int i = page.getStartIndex();
        for (Company company : page.getResults()) {
          System.out.printf(
              "%d) Company with ID %d, name '%s', and type '%s' was found.%n",
              i++, company.getId(), company.getName(), company.getType());
        }
      }

      statementBuilder.increaseOffsetBy(StatementBuilder.SUGGESTED_PAGE_LIMIT);
    } while (statementBuilder.getOffset() < totalResultSetSize);

    System.out.printf("Number of results found: %d%n", totalResultSetSize);
  }
866468
public Long getLoggedUserId() {
    HttpSession session = getRequest().getSession(false);
    return session == null ? null : (Long) session.getAttribute("loggedUserId");
  }
360097
public static void runExample(AdWordsServicesInterface adWordsServices, AdWordsSession session)
      throws RemoteException {
    Budget budget = createBudget(adWordsServices, session);

    Campaign campaign = createCampaign(adWordsServices, session, budget);
    AdGroup adGroup = createAdGroup(adWordsServices, session, campaign);
    createExpandedDSA(adWordsServices, session, adGroup);
    addWebPageCriteria(adWordsServices, session, adGroup);
  }