javax.jdo.Query.executeWithArray()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(18.8k)|赞(0)|评价(0)|浏览(138)

本文整理了Java中javax.jdo.Query.executeWithArray方法的一些代码示例,展示了Query.executeWithArray的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Query.executeWithArray方法的具体详情如下:
包路径:javax.jdo.Query
类名称:Query
方法名:executeWithArray

Query.executeWithArray介绍

[英]Execute the query and return the filtered Collection.

The execution of the query obtains the values of the parameters and matches them against the declared parameters in order. The names of the declared parameters are ignored. The type of the declared parameters must match the type of the passed parameters, except that the passed parameters might need to be unwrapped to get their primitive values.

The filter, import, declared parameters, declared variables, and ordering statements are verified for consistency.

Each element in the candidate Collection is examined to see that it is assignment compatible to the Class of the query. It is then evaluated by the Boolean expression of the filter. The element passes the filter if there exist unique values for all variables for which the filter expression evaluates to true.

Cancellation of the query using cancel() will result in JDOQueryInterruptedException being thrown here.
[中]执行查询并返回经过筛选的Collection
查询的执行将获得参数的值,并按顺序将其与声明的参数进行匹配。已声明参数的名称将被忽略。声明的参数的类型必须与传递的参数的类型匹配,但传递的参数可能需要展开才能获得其基本值。
验证筛选器、导入、声明的参数、声明的变量和排序语句的一致性。
检查候选项Collection中的每个元素,以确定它是否与查询的Class兼容。然后由过滤器的布尔表达式计算。如果筛选表达式的计算结果为true的所有变量都存在唯一值,则元素将通过筛选。
使用cancel()取消查询将导致在此处抛出JDOQueryInterruptedException。

代码示例

代码示例来源:origin: apache/hive

@SuppressWarnings("unchecked")
static <T> T executeWithArray(Query query, Object[] params, String sql) throws MetaException {
 try {
  return (T)((params == null) ? query.execute() : query.executeWithArray(params));
 } catch (Exception ex) {
  StringBuilder errorBuilder = new StringBuilder("Failed to execute [" + sql + "] with parameters [");
  if (params != null) {
   boolean isFirst = true;
   for (Object param : params) {
    errorBuilder.append((isFirst ? "" : ", ") + param);
    isFirst = false;
   }
  }
  LOG.warn(errorBuilder.toString() + "]", ex);
  // We just logged an exception with (in case of JDO) a humongous callstack. Make a new one.
  throw new MetaException("See previous errors; " + ex.getMessage());
 }
}

代码示例来源:origin: apache/hive

@SuppressWarnings("unchecked")
private <T> List<T> queryByPartitionNames(String catName, String dbName, String tableName,
  List<String> partNames, Class<T> clazz, String tbCol, String dbCol, String partCol,
  String catCol) {
 ObjectPair<Query, Object[]> queryAndParams = makeQueryByPartitionNames(catName,
   dbName, tableName, partNames, clazz, tbCol, dbCol, partCol, catCol);
 return (List<T>)queryAndParams.getFirst().executeWithArray(queryAndParams.getSecond());
}

代码示例来源:origin: apache/hive

public int getNumPartitionsViaSqlFilter(SqlFilterForPushdown filter) throws MetaException {
 boolean doTrace = LOG.isDebugEnabled();
 String catName = filter.table.getCatName().toLowerCase();
 String dbName = filter.table.getDbName().toLowerCase();
 String tblName = filter.table.getTableName().toLowerCase();
 // Get number of partitions by doing count on PART_ID.
 String queryText = "select count(" + PARTITIONS + ".\"PART_ID\") from " + PARTITIONS + ""
  + "  inner join " + TBLS + " on " + PARTITIONS + ".\"TBL_ID\" = " + TBLS + ".\"TBL_ID\" "
  + "    and " + TBLS + ".\"TBL_NAME\" = ? "
  + "  inner join " + DBS + " on " + TBLS + ".\"DB_ID\" = " + DBS + ".\"DB_ID\" "
  + "     and " + DBS + ".\"NAME\" = ? "
  + join(filter.joins, ' ')
  + " where " + DBS + ".\"CTLG_NAME\" = ? "
  + (filter.filter == null || filter.filter.trim().isEmpty() ? "" : (" and " + filter.filter));
 Object[] params = new Object[filter.params.size() + 3];
 params[0] = tblName;
 params[1] = dbName;
 params[2] = catName;
 for (int i = 0; i < filter.params.size(); ++i) {
  params[i + 3] = filter.params.get(i);
 }
 long start = doTrace ? System.nanoTime() : 0;
 Query query = pm.newQuery("javax.jdo.query.SQL", queryText);
 query.setUnique(true);
 int sqlResult = MetastoreDirectSqlUtils.extractSqlInt(query.executeWithArray(params));
 long queryTime = doTrace ? System.nanoTime() : 0;
 MetastoreDirectSqlUtils.timingTrace(doTrace, queryText, start, queryTime);
 return sqlResult;
}

代码示例来源:origin: apache/hive

query.setResult("functionName");
query.setOrdering("functionName ascending");
Collection names = (Collection) query.executeWithArray(parameterVals.toArray(new String[parameterVals.size()]));
funcs = new ArrayList<>();
for (Iterator i = names.iterator(); i.hasNext();) {

代码示例来源:origin: apache/hive

@Override
public List<String> getDatabases(String catName, String pattern) throws MetaException {
 if (pattern == null || pattern.equals("*")) {
  return getAllDatabases(catName);
 }
 boolean commited = false;
 List<String> databases = null;
 Query query = null;
 try {
  openTransaction();
  // Take the pattern and split it on the | to get all the composing
  // patterns
  String[] subpatterns = pattern.trim().split("\\|");
  StringBuilder filterBuilder = new StringBuilder();
  List<String> parameterVals = new ArrayList<>(subpatterns.length);
  appendSimpleCondition(filterBuilder, "catalogName", new String[] {catName}, parameterVals);
  appendPatternCondition(filterBuilder, "name", subpatterns, parameterVals);
  query = pm.newQuery(MDatabase.class, filterBuilder.toString());
  query.setResult("name");
  query.setOrdering("name ascending");
  Collection<String> names = (Collection<String>) query.executeWithArray(parameterVals.toArray(new String[0]));
  databases = new ArrayList<>(names);
  commited = commitTransaction();
 } finally {
  rollbackAndCleanup(commited, query);
 }
 return databases;
}

代码示例来源:origin: apache/hive

@Override
 public List<MTableColumnStatistics> run(List<String> input)
   throws MetaException {
  String filter = "tableName == t1 && dbName == t2 && catName == t3 && (";
  String paramStr = "java.lang.String t1, java.lang.String t2, java.lang.String t3";
  Object[] params = new Object[input.size() + 3];
  params[0] = table.getTableName();
  params[1] = table.getDbName();
  params[2] = table.getCatName();
  for (int i = 0; i < input.size(); ++i) {
   filter += ((i == 0) ? "" : " || ") + "colName == c" + i;
   paramStr += ", java.lang.String c" + i;
   params[i + 3] = input.get(i);
  }
  filter += ")";
  query.setFilter(filter);
  query.declareParameters(paramStr);
  List<MTableColumnStatistics> paritial = (List<MTableColumnStatistics>) query.executeWithArray(params);
  pm.retrieveAll(paritial);
  return paritial;
 }
});

代码示例来源:origin: apache/hive

@Override
public List<HiveObjectPrivilege> listPartitionGrantsAll(String catName, String dbName, String tableName,
  String partitionName) {
 boolean success = false;
 Query query = null;
 try {
  openTransaction();
  LOG.debug("Executing listPrincipalPartitionGrantsAll");
  query =
    pm.newQuery(MPartitionPrivilege.class,
      "partition.table.tableName == t3 && partition.table.database.name == t4 && "
        + "partition.table.database.catalogName == t5 && partition.partitionName == t6");
  query.declareParameters("java.lang.String t3, java.lang.String t4, java.lang.String t5, " +
    "java.lang.String t6");
  List<MPartitionPrivilege> mSecurityTabPartList =
    (List<MPartitionPrivilege>) query.executeWithArray(tableName, dbName, catName, partitionName);
  LOG.debug("Done executing query for listPrincipalPartitionGrantsAll");
  pm.retrieveAll(mSecurityTabPartList);
  List<HiveObjectPrivilege> result = convertPartition(mSecurityTabPartList);
  success = commitTransaction();
  LOG.debug("Done retrieving all objects for listPrincipalPartitionGrantsAll");
  return result;
 } finally {
  rollbackAndCleanup(success, query);
 }
}

代码示例来源:origin: apache/hive

@SuppressWarnings("unchecked")
private List<MTablePrivilege> listAllTableGrants(String catName, String dbName, String tableName) {
 boolean success = false;
 Query query = null;
 List<MTablePrivilege> mSecurityTabList = new ArrayList<>();
 tableName = normalizeIdentifier(tableName);
 dbName = normalizeIdentifier(dbName);
 catName = normalizeIdentifier(catName);
 try {
  LOG.debug("Executing listAllTableGrants");
  openTransaction();
  String queryStr = "table.tableName == t1 && table.database.name == t2" +
    "&& table.database.catalogName == t3";
  query = pm.newQuery(MTablePrivilege.class, queryStr);
  query.declareParameters("java.lang.String t1, java.lang.String t2, java.lang.String t3");
  List<MTablePrivilege> mPrivs  =
    (List<MTablePrivilege>) query.executeWithArray(tableName, dbName, catName);
  LOG.debug("Done executing query for listAllTableGrants");
  pm.retrieveAll(mPrivs);
  success = commitTransaction();
  mSecurityTabList.addAll(mPrivs);
  LOG.debug("Done retrieving all objects for listAllTableGrants");
 } finally {
  rollbackAndCleanup(success, query);
 }
 return mSecurityTabList;
}

代码示例来源:origin: apache/hive

@Override
public List<HiveObjectPrivilege> listPartitionColumnGrantsAll(
  String catName, String dbName, String tableName, String partitionName, String columnName) {
 boolean success = false;
 Query query = null;
 try {
  openTransaction();
  LOG.debug("Executing listPartitionColumnGrantsAll");
  query =
    pm.newQuery(MPartitionColumnPrivilege.class,
      "partition.table.tableName == t3 && partition.table.database.name == t4 && "
        + "partition.table.database.name == t5 && "
        + "partition.partitionName == t6 && columnName == t7");
  query.declareParameters("java.lang.String t3, java.lang.String t4, java.lang.String t5," +
    "java.lang.String t6, java.lang.String t7");
  List<MPartitionColumnPrivilege> mSecurityTabPartList =
    (List<MPartitionColumnPrivilege>) query.executeWithArray(tableName, dbName, catName,
      partitionName, columnName);
  LOG.debug("Done executing query for listPartitionColumnGrantsAll");
  pm.retrieveAll(mSecurityTabPartList);
  List<HiveObjectPrivilege> result = convertPartCols(mSecurityTabPartList);
  success = commitTransaction();
  LOG.debug("Done retrieving all objects for listPartitionColumnGrantsAll");
  return result;
 } finally {
  rollbackAndCleanup(success, query);
 }
}

代码示例来源:origin: apache/hive

@SuppressWarnings("unchecked")
private List<MPartitionPrivilege> listTableAllPartitionGrants(String catName, String dbName, String tableName) {
 tableName = normalizeIdentifier(tableName);
 dbName = normalizeIdentifier(dbName);
 catName = normalizeIdentifier(catName);
 boolean success = false;
 Query query = null;
 List<MPartitionPrivilege> mSecurityTabPartList = new ArrayList<>();
 try {
  LOG.debug("Executing listTableAllPartitionGrants");
  openTransaction();
  String queryStr = "partition.table.tableName == t1 && partition.table.database.name == t2 " +
    "&& partition.table.database.catalogName == t3";
  query = pm.newQuery(MPartitionPrivilege.class, queryStr);
  query.declareParameters("java.lang.String t1, java.lang.String t2, java.lang.String t3");
  List<MPartitionPrivilege> mPrivs =
    (List<MPartitionPrivilege>) query.executeWithArray(tableName, dbName, catName);
  pm.retrieveAll(mPrivs);
  success = commitTransaction();
  mSecurityTabPartList.addAll(mPrivs);
  LOG.debug("Done retrieving all objects for listTableAllPartitionGrants");
 } finally {
  rollbackAndCleanup(success, query);
 }
 return mSecurityTabPartList;
}

代码示例来源:origin: apache/hive

@SuppressWarnings("unchecked")
private List<MPartitionColumnPrivilege> listTableAllPartitionColumnGrants(
  String catName, String dbName, String tableName) {
 boolean success = false;
 Query query = null;
 tableName = normalizeIdentifier(tableName);
 dbName = normalizeIdentifier(dbName);
 catName = normalizeIdentifier(catName);
 List<MPartitionColumnPrivilege> mSecurityColList = new ArrayList<>();
 try {
  LOG.debug("Executing listTableAllPartitionColumnGrants");
  openTransaction();
  String queryStr = "partition.table.tableName == t1 && partition.table.database.name == t2 " +
    "&& partition.table.database.catalogName == t3";
  query = pm.newQuery(MPartitionColumnPrivilege.class, queryStr);
  query.declareParameters("java.lang.String t1, java.lang.String t2, java.lang.String t3");
  List<MPartitionColumnPrivilege> mPrivs =
    (List<MPartitionColumnPrivilege>) query.executeWithArray(tableName, dbName, catName);
  pm.retrieveAll(mPrivs);
  success = commitTransaction();
  mSecurityColList.addAll(mPrivs);
  LOG.debug("Done retrieving all objects for listTableAllPartitionColumnGrants");
 } finally {
  rollbackAndCleanup(success, query);
 }
 return mSecurityColList;
}

代码示例来源:origin: apache/hive

query.declareParameters("java.lang.String t1, java.lang.String t2, java.lang.String t3, " +
     "java.lang.String t4");
 mSecurityTabPartList = (List<MTablePrivilege>) query.executeWithArray(tableName, dbName, catName, authorizer);
} else {
 query = pm.newQuery(MTablePrivilege.class,
     "table.tableName == t1 && table.database.name == t2 && table.database.catalogName == t3");
 query.declareParameters("java.lang.String t1, java.lang.String t2, java.lang.String t3");
 mSecurityTabPartList = (List<MTablePrivilege>) query.executeWithArray(tableName, dbName, catName);

代码示例来源:origin: apache/hive

"database.name == t1 && database.catalogName == t2 && authorizer == t3");
 query.declareParameters("java.lang.String t1, java.lang.String t2, java.lang.String t3");
 mSecurityDBList = (List<MDBPrivilege>) query.executeWithArray(dbName, catName, authorizer);
} else {
 Query query = queryWrapper.query = pm.newQuery(MDBPrivilege.class,
   "database.name == t1 && database.catalogName == t2");
 query.declareParameters("java.lang.String t1, java.lang.String t2");
 mSecurityDBList = (List<MDBPrivilege>) query.executeWithArray(dbName, catName);

代码示例来源:origin: apache/hive

@Override
public List<HiveObjectPrivilege> listTableColumnGrantsAll(String catName, String dbName, String tableName,
  String columnName) {
 boolean success = false;
 Query query = null;
 dbName = normalizeIdentifier(dbName);
 tableName = normalizeIdentifier(tableName);
 try {
  openTransaction();
  LOG.debug("Executing listPrincipalTableColumnGrantsAll");
  query =
    pm.newQuery(MTableColumnPrivilege.class,
      "table.tableName == t3 && table.database.name == t4 && " +
        "table.database.catalogName == t5 && columnName == t6");
  query.declareParameters("java.lang.String t3, java.lang.String t4, java.lang.String t5, " +
    "java.lang.String t6");
  List<MTableColumnPrivilege> mSecurityTabPartList =
    (List<MTableColumnPrivilege>) query.executeWithArray(tableName, dbName,
      catName, columnName);
  LOG.debug("Done executing query for listPrincipalTableColumnGrantsAll");
  pm.retrieveAll(mSecurityTabPartList);
  List<HiveObjectPrivilege> result = convertTableCols(mSecurityTabPartList);
  success = commitTransaction();
  LOG.debug("Done retrieving all objects for listPrincipalTableColumnGrantsAll");
  return result;
 } finally {
  rollbackAndCleanup(success, query);
 }
}

代码示例来源:origin: apache/hive

query.setResult("tableName");
query.setOrdering("tableName ascending");
Collection<String> names = (Collection<String>) query.executeWithArray(parameterVals.toArray(new String[0]));
tbls = new ArrayList<>(names);
commited = commitTransaction();

代码示例来源:origin: apache/hive

@Override
public boolean isPartitionMarkedForEvent(String catName, String dbName, String tblName,
  Map<String, String> partName, PartitionEventType evtType) throws UnknownTableException,
  MetaException, InvalidPartitionException, UnknownPartitionException {
 boolean success = false;
 Query query = null;
 try {
  LOG.debug("Begin Executing isPartitionMarkedForEvent");
  openTransaction();
  query = pm.newQuery(MPartitionEvent.class,
      "dbName == t1 && tblName == t2 && partName == t3 && eventType == t4 && catalogName == t5");
  query
    .declareParameters("java.lang.String t1, java.lang.String t2, java.lang.String t3, int t4," +
      "java.lang.String t5");
  Table tbl = getTable(catName, dbName, tblName, null); // Make sure dbName and tblName are valid.
  if (null == tbl) {
   throw new UnknownTableException("Table: " + tblName + " is not found.");
  }
  Collection<MPartitionEvent> partEvents =
    (Collection<MPartitionEvent>) query.executeWithArray(dbName, tblName,
      getPartitionStr(tbl, partName), evtType.getValue(), catName);
  pm.retrieveAll(partEvents);
  success = commitTransaction();
  LOG.debug("Done executing isPartitionMarkedForEvent");
  return (partEvents != null && !partEvents.isEmpty()) ? true : false;
 } finally {
  rollbackAndCleanup(success, query);
 }
}

代码示例来源:origin: apache/hive

query.declareParameters("java.lang.String t1, java.lang.String t2");
 mSecurityTabPartList =
   (List<MPartitionColumnPrivilege>) query.executeWithArray(principalName,
     principalType.toString());
} else {

代码示例来源:origin: apache/hive

@Override
public List<String> getMaterializedViewsForRewriting(String catName, String dbName)
  throws MetaException, NoSuchObjectException {
 final String db_name = normalizeIdentifier(dbName);
 catName = normalizeIdentifier(catName);
 boolean commited = false;
 Query<?> query = null;
 List<String> tbls = null;
 try {
  openTransaction();
  dbName = normalizeIdentifier(dbName);
  query = pm.newQuery(MTable.class,
    "database.name == db && database.catalogName == cat && tableType == tt && rewriteEnabled == re");
  query.declareParameters(
    "java.lang.String db, java.lang.String cat, java.lang.String tt, boolean re");
  query.setResult("tableName");
  Collection<String> names = (Collection<String>) query.executeWithArray(
    db_name, catName, TableType.MATERIALIZED_VIEW.toString(), true);
  tbls = new ArrayList<>(names);
  commited = commitTransaction();
 } finally {
  rollbackAndCleanup(commited, query);
 }
 return tbls;
}

代码示例来源:origin: apache/hive

private MRoleMap getMSecurityUserRoleMap(String userName, PrincipalType principalType,
  String roleName) {
 MRoleMap mRoleMember = null;
 boolean commited = false;
 Query query = null;
 try {
  openTransaction();
  query =
    pm.newQuery(MRoleMap.class,
      "principalName == t1 && principalType == t2 && role.roleName == t3");
  query.declareParameters("java.lang.String t1, java.lang.String t2, java.lang.String t3");
  query.setUnique(true);
  mRoleMember = (MRoleMap) query.executeWithArray(userName, principalType.toString(), roleName);
  pm.retrieve(mRoleMember);
  commited = commitTransaction();
 } finally {
  rollbackAndCleanup(commited, query);
 }
 return mRoleMember;
}

代码示例来源:origin: apache/hive

private MSchemaVersion getMSchemaVersion(String catName, String dbName, String schemaName, int version) {
 Query query = null;
 try {
  dbName = normalizeIdentifier(dbName);
  schemaName = normalizeIdentifier(schemaName);
  query = pm.newQuery(MSchemaVersion.class,
    "iSchema.name == schemaName && iSchema.db.name == dbName &&" +
      "iSchema.db.catalogName == cat && version == schemaVersion");
  query.declareParameters( "java.lang.String schemaName, java.lang.String dbName," +
    "java.lang.String cat, java.lang.Integer schemaVersion");
  query.setUnique(true);
  MSchemaVersion mSchemaVersion =
    (MSchemaVersion)query.executeWithArray(schemaName, dbName, catName, version);
  pm.retrieve(mSchemaVersion);
  if (mSchemaVersion != null) {
   pm.retrieveAll(mSchemaVersion.getCols());
   if (mSchemaVersion.getSerDe() != null) {
    pm.retrieve(mSchemaVersion.getSerDe());
   }
  }
  return mSchemaVersion;
 } finally {
  if (query != null) {
   query.closeAll();
  }
 }
}

相关文章