当前位置: 首页>>代码示例>>Java>>正文


Java JPQLStatement类代码示例

本文整理汇总了Java中org.apache.olingo.odata2.jpa.processor.api.jpql.JPQLStatement的典型用法代码示例。如果您正苦于以下问题:Java JPQLStatement类的具体用法?Java JPQLStatement怎么用?Java JPQLStatement使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


JPQLStatement类属于org.apache.olingo.odata2.jpa.processor.api.jpql包,在下文中一共展示了JPQLStatement类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: parseToJPASelectExpression

import org.apache.olingo.odata2.jpa.processor.api.jpql.JPQLStatement; //导入依赖的package包/类
/**
 * This method parses the select clause
 *
 * @param tableAlias
 * @param selectedFields
 * @return a select expression
 */
public static String parseToJPASelectExpression(final String tableAlias, final ArrayList<String> selectedFields) {

  if ((selectedFields == null) || (selectedFields.isEmpty())) {
    return tableAlias;
  }

  String selectClause = EMPTY;
  Iterator<String> itr = selectedFields.iterator();
  int count = 0;

  while (itr.hasNext()) {
    selectClause = selectClause + tableAlias + JPQLStatement.DELIMITER.PERIOD + itr.next();
    count++;

    if (count < selectedFields.size()) {
      selectClause = selectClause + JPQLStatement.DELIMITER.COMMA + JPQLStatement.DELIMITER.SPACE;
    }
  }
  return selectClause;
}
 
开发者ID:apache,项目名称:olingo-odata2,代码行数:28,代码来源:ODataExpressionParser.java

示例2: parseKeyPropertiesToJPAOrderByExpression

import org.apache.olingo.odata2.jpa.processor.api.jpql.JPQLStatement; //导入依赖的package包/类
public static String parseKeyPropertiesToJPAOrderByExpression(
    final List<EdmProperty> edmPropertylist, final String tableAlias) throws ODataJPARuntimeException {
  String propertyName = null;
  String orderExpression = "";
  if (edmPropertylist == null) {
    return orderExpression;
  }
  for (EdmProperty edmProperty : edmPropertylist) {
    try {
      EdmMapping mapping = edmProperty.getMapping();
      if (mapping != null && mapping.getInternalName() != null) {
        propertyName = mapping.getInternalName();// For embedded/complex keys
      } else {
        propertyName = edmProperty.getName();
      }
    } catch (EdmException e) {
      throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.GENERAL.addContent(e.getMessage()), e);
    }
    orderExpression += tableAlias + JPQLStatement.DELIMITER.PERIOD + propertyName + " , ";
  }
  return normalizeOrderByExpression(orderExpression);
}
 
开发者ID:apache,项目名称:olingo-odata2,代码行数:23,代码来源:ODataExpressionParser.java

示例3: createJPQLQuery

import org.apache.olingo.odata2.jpa.processor.api.jpql.JPQLStatement; //导入依赖的package包/类
private String createJPQLQuery() throws ODataJPARuntimeException {

    StringBuilder jpqlQuery = new StringBuilder();
    String tableAlias = context.getJPAEntityAlias();
    String fromClause = context.getJPAEntityName() + JPQLStatement.DELIMITER.SPACE + tableAlias;

    jpqlQuery.append(JPQLStatement.KEYWORD.SELECT).append(JPQLStatement.DELIMITER.SPACE);
    jpqlQuery.append(context.getSelectExpression()).append(JPQLStatement.DELIMITER.SPACE);
    jpqlQuery.append(JPQLStatement.KEYWORD.FROM).append(JPQLStatement.DELIMITER.SPACE);
    jpqlQuery.append(fromClause);

    if (context.getKeyPredicates() != null && !context.getKeyPredicates().isEmpty()) {
      jpqlQuery.append(JPQLStatement.DELIMITER.SPACE);
      jpqlQuery.append(JPQLStatement.KEYWORD.WHERE).append(JPQLStatement.DELIMITER.SPACE);
      jpqlQuery.append(ODataExpressionParser
          .parseKeyPredicates(context.getKeyPredicates(), context.getJPAEntityAlias()));
    }

    return jpqlQuery.toString();

  }
 
开发者ID:apache,项目名称:olingo-odata2,代码行数:22,代码来源:JPQLSelectSingleStatementBuilder.java

示例4: testBuild

import org.apache.olingo.odata2.jpa.processor.api.jpql.JPQLStatement; //导入依赖的package包/类
@Test
public void testBuild() throws Exception {
  setUp(getJoinClauseList());
  JPQLJoinStatementBuilder jpqlJoinStatementBuilder = new JPQLJoinStatementBuilder(context);
  try {
    JPQLStatement jpqlStatement = jpqlJoinStatementBuilder.build();
    assertEquals(
        "SELECT mat FROM SOHeader soh JOIN soh.soItem soi JOIN soi.material mat WHERE soh.buyerId = 2 AND "
            +
            "soh.createdBy = 'Peter' AND soi.shId = soh.soId AND mat.id = 'abc' "
            +
            "ORDER BY mat.buyerId asc , mat.city desc",
            jpqlStatement.toString());
  } catch (ODataJPARuntimeException e) {
    fail("Should not have come here");
  }

}
 
开发者ID:apache,项目名称:olingo-odata2,代码行数:19,代码来源:JPQLJoinStatementBuilderTest.java

示例5: testBuild

import org.apache.olingo.odata2.jpa.processor.api.jpql.JPQLStatement; //导入依赖的package包/类
@Test
public void testBuild() throws Exception {
  setUp(getJoinClauseList());
  JPQLJoinSelectSingleStatementBuilder jpqlJoinSelectsingleStatementBuilder =
      new JPQLJoinSelectSingleStatementBuilder(context);
  try {
    JPQLStatement jpqlStatement = jpqlJoinSelectsingleStatementBuilder.build();
    assertEquals(
        "SELECT gt1 FROM SOHeader soh JOIN soh.soItem soi JOIN soi.material mat WHERE soh.soId = 1 AND " +
            "soi.shId = soh.soId AND mat.id = 'abc'",
            jpqlStatement.toString());
  } catch (ODataJPARuntimeException e) {
    fail("Should not have come here");
  }

}
 
开发者ID:apache,项目名称:olingo-odata2,代码行数:17,代码来源:JPQLJoinSelectSingleStatementBuilderTest.java

示例6: build

import org.apache.olingo.odata2.jpa.processor.api.jpql.JPQLStatement; //导入依赖的package包/类
@Override
public JPQLStatement build() throws ODataJPARuntimeException {
  jpqlStatement = createStatement(createJPQLQuery());
  ODataParameterizedWhereExpressionUtil.setJPQLStatement(jpqlStatement.toString());
  ODataExpressionParser.reInitializePositionalParameters();
  return jpqlStatement;

}
 
开发者ID:apache,项目名称:olingo-odata2,代码行数:9,代码来源:JPQLJoinSelectSingleStatementBuilder.java

示例7: createJPQLQuery

import org.apache.olingo.odata2.jpa.processor.api.jpql.JPQLStatement; //导入依赖的package包/类
private String createJPQLQuery() throws ODataJPARuntimeException {

    StringBuilder jpqlQuery = new StringBuilder();
    String tableAlias = context.getJPAEntityAlias();
    String fromClause = context.getJPAEntityName() + JPQLStatement.DELIMITER.SPACE + tableAlias;

    jpqlQuery.append(JPQLStatement.KEYWORD.SELECT).append(JPQLStatement.DELIMITER.SPACE);
    if (context.getType().equals(JPQLContextType.SELECT_COUNT)) { // $COUNT
      jpqlQuery.append(JPQLStatement.KEYWORD.COUNT).append(JPQLStatement.DELIMITER.SPACE);
      jpqlQuery.append(JPQLStatement.DELIMITER.PARENTHESIS_LEFT).append(JPQLStatement.DELIMITER.SPACE);
      jpqlQuery.append(context.getSelectExpression()).append(JPQLStatement.DELIMITER.SPACE);
      jpqlQuery.append(JPQLStatement.DELIMITER.PARENTHESIS_RIGHT).append(JPQLStatement.DELIMITER.SPACE);
    } else {// Normal
      jpqlQuery.append(context.getSelectExpression()).append(JPQLStatement.DELIMITER.SPACE);
    }

    jpqlQuery.append(JPQLStatement.KEYWORD.FROM).append(JPQLStatement.DELIMITER.SPACE);
    jpqlQuery.append(fromClause);

    if (context.getWhereExpression() != null) {
      jpqlQuery.append(JPQLStatement.DELIMITER.SPACE);
      jpqlQuery.append(JPQLStatement.KEYWORD.WHERE).append(JPQLStatement.DELIMITER.SPACE);
      jpqlQuery.append(context.getWhereExpression());
    }

    if (context.getOrderByCollection() != null && context.getOrderByCollection().length() > 0) {

      StringBuilder orderByBuilder = new StringBuilder();
      orderByBuilder.append(context.getOrderByCollection());
      jpqlQuery.append(JPQLStatement.DELIMITER.SPACE);
      jpqlQuery.append(JPQLStatement.KEYWORD.ORDERBY).append(JPQLStatement.DELIMITER.SPACE);
      jpqlQuery.append(orderByBuilder);
    }

    return jpqlQuery.toString();

  }
 
开发者ID:apache,项目名称:olingo-odata2,代码行数:38,代码来源:JPQLSelectStatementBuilder.java

示例8: buildQuery

import org.apache.olingo.odata2.jpa.processor.api.jpql.JPQLStatement; //导入依赖的package包/类
private Query buildQuery(UriInfo uriParserResultView, UriInfoType type)
    throws EdmException,
    ODataJPAModelException, ODataJPARuntimeException {

  JPQLContextType contextType = determineJPQLContextType(uriParserResultView, type);
  JPQLContext jpqlContext = buildJPQLContext(contextType, uriParserResultView);
  JPQLStatement jpqlStatement = JPQLStatement.createBuilder(jpqlContext).build();

  Query query = em.createQuery(normalizeMembers(em, jpqlStatement.toString()));
  Map<String, Map<Integer, Object>> parameterizedMap = ODataParameterizedWhereExpressionUtil.
      getParameterizedQueryMap();
  if (parameterizedMap != null && parameterizedMap.size() > 0) {
    for (Entry<String, Map<Integer, Object>> parameterEntry : parameterizedMap.entrySet()) {
      if (jpqlStatement.toString().contains(parameterEntry.getKey())) {
        Map<Integer, Object> positionalParameters = parameterEntry.getValue();
        for (Entry<Integer, Object> param : positionalParameters.entrySet()) {
          if (param.getValue() instanceof Calendar || param.getValue() instanceof Timestamp) {
            query.setParameter(param.getKey(), (Calendar) param.getValue(), TemporalType.TIMESTAMP);
          } else if (param.getValue() instanceof Time) {
            query.setParameter(param.getKey(), (Time) param.getValue(), TemporalType.TIME);
          } else {
            query.setParameter(param.getKey(), param.getValue());
          }
        }
        parameterizedMap.remove(parameterEntry.getKey());
        ODataParameterizedWhereExpressionUtil.setJPQLStatement(null);
        break;
      }
    }
  }
  return query;
}
 
开发者ID:apache,项目名称:olingo-odata2,代码行数:33,代码来源:JPAQueryBuilder.java

示例9: removeExtraClause

import org.apache.olingo.odata2.jpa.processor.api.jpql.JPQLStatement; //导入依赖的package包/类
/**
 * Check if the statement contains ORDERBY having x.y.z kind of format
 * It will remove those values before checking for normalization 
 * and later added back
 * */
private static String removeExtraClause(String jpqlQuery) {
  String query = jpqlQuery;
  if(query.contains(JPQLStatement.KEYWORD.ORDERBY )){
    int index = query.indexOf(JPQLStatement.KEYWORD.ORDERBY);
    query = query.substring(0, index);  
  }
  return query;
}
 
开发者ID:apache,项目名称:olingo-odata2,代码行数:14,代码来源:JPAQueryBuilder.java

示例10: replacePositionalParameters

import org.apache.olingo.odata2.jpa.processor.api.jpql.JPQLStatement; //导入依赖的package包/类
private String replacePositionalParameters(String whereExpression) {
  Map<Integer, Object> positionalParameters = ODataExpressionParser.getPositionalParameters();
  for (Entry<Integer, Object> param : positionalParameters.entrySet()) {
    Integer key = param.getKey();
    if (param.getValue() instanceof String) {
      whereExpression = whereExpression.replaceAll("\\?" + String.valueOf(key), "\'" + param.getValue() + "\'");
    } else if (param.getValue() instanceof Timestamp || param.getValue() instanceof Calendar){
      Calendar datetime = (Calendar) param.getValue();
      String year = String.format("%04d", datetime.get(Calendar.YEAR));
      String month = String.format("%02d", datetime.get(Calendar.MONTH) + 1);
      String day = String.format("%02d", datetime.get(Calendar.DAY_OF_MONTH));
      String hour = String.format("%02d", datetime.get(Calendar.HOUR_OF_DAY));
      String min = String.format("%02d", datetime.get(Calendar.MINUTE));
      String sec = String.format("%02d", datetime.get(Calendar.SECOND));
      String value =
          year + JPQLStatement.DELIMITER.HYPHEN + month + JPQLStatement.DELIMITER.HYPHEN + day
              + JPQLStatement.DELIMITER.SPACE + hour + JPQLStatement.DELIMITER.COLON + min
              + JPQLStatement.DELIMITER.COLON + sec + JPQLStatement.KEYWORD.OFFSET;
      whereExpression = whereExpression.replaceAll("\\?" + String.valueOf(key), value);
    } else if(param.getValue() instanceof Byte[]){
      byte[] byteValue = convertToByte((Byte[])param.getValue());
      whereExpression = whereExpression.replaceAll("\\?" + String.valueOf(key), new String(byteValue));
    }else {
      whereExpression = whereExpression.replaceAll("\\?" + String.valueOf(key), param.getValue().toString());
    }
  }
  ODataExpressionParser.reInitializePositionalParameters();
  return whereExpression;
}
 
开发者ID:apache,项目名称:olingo-odata2,代码行数:30,代码来源:ODataFilterExpressionParserTest.java

示例11: createJPQLQuery

import org.apache.olingo.odata2.jpa.processor.api.jpql.JPQLStatement; //导入依赖的package包/类
private String createJPQLQuery() throws ODataJPARuntimeException {

    StringBuilder jpqlQuery = new StringBuilder();
    StringBuilder joinWhereCondition = null;

    jpqlQuery.append(JPQLStatement.KEYWORD.SELECT).append(JPQLStatement.DELIMITER.SPACE);
    jpqlQuery.append(context.getSelectExpression()).append(JPQLStatement.DELIMITER.SPACE);
    jpqlQuery.append(JPQLStatement.KEYWORD.FROM).append(JPQLStatement.DELIMITER.SPACE);

    if (context.getJPAJoinClauses() != null && !context.getJPAJoinClauses().isEmpty()) {
      List<JPAJoinClause> joinClauseList = context.getJPAJoinClauses();
      JPAJoinClause joinClause = joinClauseList.get(0);
      String joinCondition = joinClause.getJoinCondition();
      joinWhereCondition = new StringBuilder();
      if (joinCondition != null) {
        joinWhereCondition.append(joinCondition);
      }
      String relationShipAlias = null;
      joinClause = joinClauseList.get(1);
      jpqlQuery.append(joinClause.getEntityName()).append(JPQLStatement.DELIMITER.SPACE);
      jpqlQuery.append(joinClause.getEntityAlias());

      int i = 1;
      int limit = joinClauseList.size();
      relationShipAlias = joinClause.getEntityAlias();
      while (i < limit) {
        jpqlQuery.append(JPQLStatement.DELIMITER.SPACE);
        jpqlQuery.append(JPQLStatement.KEYWORD.JOIN).append(JPQLStatement.DELIMITER.SPACE);

        joinClause = joinClauseList.get(i);
        jpqlQuery.append(relationShipAlias).append(JPQLStatement.DELIMITER.PERIOD);
        jpqlQuery.append(joinClause.getEntityRelationShip()).append(JPQLStatement.DELIMITER.SPACE);
        jpqlQuery.append(joinClause.getEntityRelationShipAlias());

        relationShipAlias = joinClause.getEntityRelationShipAlias();
        i++;

        joinCondition = joinClause.getJoinCondition();
        if (joinCondition != null) {
          joinWhereCondition.append(JPQLStatement.DELIMITER.SPACE + JPQLStatement.Operator.AND
              + JPQLStatement.DELIMITER.SPACE);

          joinWhereCondition.append(joinCondition);
        }

      }
    } else {
      throw ODataJPARuntimeException.throwException(ODataJPARuntimeException.JOIN_CLAUSE_EXPECTED, null);
    }

    if (joinWhereCondition.length() > 0) {
      jpqlQuery.append(JPQLStatement.DELIMITER.SPACE);
      jpqlQuery.append(JPQLStatement.KEYWORD.WHERE).append(JPQLStatement.DELIMITER.SPACE);
      jpqlQuery.append(joinWhereCondition.toString());
    }

    return jpqlQuery.toString();

  }
 
开发者ID:apache,项目名称:olingo-odata2,代码行数:60,代码来源:JPQLJoinSelectSingleStatementBuilder.java

示例12: normalizeMembers

import org.apache.olingo.odata2.jpa.processor.api.jpql.JPQLStatement; //导入依赖的package包/类
private static String normalizeMembers(EntityManager em, String jpqlQuery) {  
  
  //check if clause values are string with x.y.z format
  //starting with quotes;
  String query = checkConditionValues(jpqlQuery);
  //remove any orderby clause parameters  with x.y.z format
  //no normalization for such clause
  query = removeExtraClause(jpqlQuery);
  // check if normalization is needed (if query contains "x.y.z" elements
  // starting with space or parenthesis)
  Matcher normalizationNeededMatcher = NORMALIZATION_NEEDED_PATTERN.matcher(query);
  if (!normalizationNeededMatcher.find()) {
    return jpqlQuery;
  }

  if (containsEmbeddedAttributes(em, jpqlQuery)) {
    return jpqlQuery;
  }
  
  String normalizedJpqlQuery = jpqlQuery;
  Map<String, String> joinAliases = new HashMap<String, String>();

  // collect information about existing joins/aliases
  Matcher joinAliasMatcher = JOIN_ALIAS_PATTERN.matcher(normalizedJpqlQuery);
  if (joinAliasMatcher.find()) {
    for (int i = 1; i <= joinAliasMatcher.groupCount(); i++) {
      String[] joinAlias = joinAliasMatcher.group(i).split(String.valueOf(JPQLStatement.DELIMITER.SPACE));
      joinAliases.put(joinAlias[0], joinAlias[1]);
    }
  }
  // normalize query
  boolean normalizationNeeded = true;
  while (normalizationNeeded) {
    String membershipToNormalize = normalizationNeededMatcher.group(1);

    // get member info
    String memberInfo = membershipToNormalize.substring(0,
        ordinalIndexOf(membershipToNormalize, JPQLStatement.DELIMITER.PERIOD, 1));

    String alias;
    if (joinAliases.containsKey(memberInfo)) {
      // use existing alias
      alias = joinAliases.get(memberInfo);
    } else {
      // create new join/alias
      alias = "R" + (joinAliases.size() + 1);

      int joinInsertPosition = normalizedJpqlQuery.indexOf(JPQLStatement.KEYWORD.WHERE);
      if (joinInsertPosition == -1) {
        joinInsertPosition = normalizedJpqlQuery.indexOf(JPQLStatement.KEYWORD.ORDERBY);
      }
      normalizedJpqlQuery = normalizedJpqlQuery.substring(0, joinInsertPosition) + JPQLStatement.KEYWORD.JOIN
          + JPQLStatement.DELIMITER.SPACE + memberInfo + JPQLStatement.DELIMITER.SPACE + alias
          + JPQLStatement.DELIMITER.SPACE + normalizedJpqlQuery.substring(joinInsertPosition);

      joinAliases.put(memberInfo, alias);
    }

    // use alias
    normalizedJpqlQuery = normalizedJpqlQuery.replaceAll(memberInfo + "\\" + JPQLStatement.DELIMITER.PERIOD,
        alias + JPQLStatement.DELIMITER.PERIOD);
    //check for values like "x.y.z"
    query = checkConditionValues(normalizedJpqlQuery);
    query = removeExtraClause(normalizedJpqlQuery);
    // check if further normalization is needed
    normalizationNeededMatcher = NORMALIZATION_NEEDED_PATTERN.matcher(query);
    normalizationNeeded = normalizationNeededMatcher.find();
  }
  
  // add distinct to avoid duplicates in result set
  return normalizedJpqlQuery.replaceFirst(
      JPQLStatement.KEYWORD.SELECT + JPQLStatement.DELIMITER.SPACE,
      JPQLStatement.KEYWORD.SELECT_DISTINCT + JPQLStatement.DELIMITER.SPACE);
}
 
开发者ID:apache,项目名称:olingo-odata2,代码行数:75,代码来源:JPAQueryBuilder.java


注:本文中的org.apache.olingo.odata2.jpa.processor.api.jpql.JPQLStatement类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。