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

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

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

Query.setUnique介绍

[英]Specify that only the first result of the query should be returned, rather than a collection. The execute method will return null if the query result size is 0.
[中]指定只返回查询的第一个结果,而不是集合。如果查询结果大小为0,execute方法将返回null。

代码示例

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

private Query createActivePlanQuery() {
 openTransaction();
 Query query = pm.newQuery(MWMResourcePlan.class, "status == activeStatus && ns == nsname");
 query.declareParameters("java.lang.String activeStatus, java.lang.String nsname");
 query.setUnique(true);
 return query;
}

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

private Query createGetResourcePlanQuery() {
 openTransaction();
 Query query = pm.newQuery(MWMResourcePlan.class, "name == rpname && ns == nsname");
 query.declareParameters("java.lang.String rpname, java.lang.String nsname");
 query.setUnique(true);
 return query;
}

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

private boolean isViewTable(String catName, String dbName, String tblName) throws MetaException {
 Query query = null;
 try {
  String queryText = "select \"TBL_TYPE\" from " + TBLS + "" +
    " inner join " + DBS + " on " + TBLS + ".\"DB_ID\" = " + DBS + ".\"DB_ID\" " +
    " where " + TBLS + ".\"TBL_NAME\" = ? and " + DBS + ".\"NAME\" = ? and " + DBS + ".\"CTLG_NAME\" = ?";
  Object[] params = new Object[] { tblName, dbName, catName };
  query = pm.newQuery("javax.jdo.query.SQL", queryText);
  query.setUnique(true);
  Object result = executeWithArray(query, params, queryText);
  return (result != null) && result.toString().equals(TableType.VIRTUAL_VIEW.toString());
 } finally {
  if (query != null) {
   query.closeAll();
  }
 }
}

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

private MDelegationToken getTokenFrom(String tokenId) {
 Query query = pm.newQuery(MDelegationToken.class, "tokenIdentifier == tokenId");
 query.declareParameters("java.lang.String tokenId");
 query.setUnique(true);
 MDelegationToken delegationToken = (MDelegationToken) query.execute(tokenId);
 if (query != null) {
  query.closeAll();
 }
 return delegationToken;
}

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

@SuppressWarnings("unchecked")
public List<MRoleMap> listMRoleMembers(String roleName) {
 boolean success = false;
 Query query = null;
 List<MRoleMap> mRoleMemeberList = new ArrayList<>();
 try {
  LOG.debug("Executing listRoleMembers");
  openTransaction();
  query = pm.newQuery(MRoleMap.class, "role.roleName == t1");
  query.declareParameters("java.lang.String t1");
  query.setUnique(false);
  List<MRoleMap> mRoles = (List<MRoleMap>) query.execute(roleName);
  pm.retrieveAll(mRoles);
  success = commitTransaction();
  mRoleMemeberList.addAll(mRoles);
  LOG.debug("Done retrieving all objects for listRoleMembers");
 } finally {
  rollbackAndCleanup(success, query);
 }
 return mRoleMemeberList;
}

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

@Override
public boolean removeMasterKey(Integer id) {
 LOG.debug("Begin executing removeMasterKey");
 boolean success = false;
 Query query = null;
 MMasterKey masterKey;
 try {
  openTransaction();
  query = pm.newQuery(MMasterKey.class, "keyId == id");
  query.declareParameters("java.lang.Integer id");
  query.setUnique(true);
  masterKey = (MMasterKey) query.execute(id);
  if (null != masterKey) {
   pm.deletePersistent(masterKey);
  }
  success = commitTransaction();
 } finally {
  rollbackAndCleanup(success, query);
 }
 LOG.debug("Done executing removeMasterKey with status : {}", success);
 return (null != masterKey) && success;
}

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

private MSerDeInfo getMSerDeInfo(String serDeName) throws MetaException {
 Query query = null;
 try {
  query = pm.newQuery(MSerDeInfo.class, "name == serDeName");
  query.declareParameters("java.lang.String serDeName");
  query.setUnique(true);
  MSerDeInfo mSerDeInfo = (MSerDeInfo)query.execute(serDeName);
  pm.retrieve(mSerDeInfo);
  return mSerDeInfo;
 } finally {
  if (query != null) {
   query.closeAll();
  }
 }
}

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

private void lockForUpdate() throws MetaException {
 String selectQuery = "select \"NEXT_EVENT_ID\" from \"NOTIFICATION_SEQUENCE\"";
 String selectForUpdateQuery = sqlGenerator.addForUpdateClause(selectQuery);
 new RetryingExecutor(conf, () -> {
  prepareQuotes();
  Query query = pm.newQuery("javax.jdo.query.SQL", selectForUpdateQuery);
  query.setUnique(true);
  // only need to execute it to get db Lock
  query.execute();
  query.closeAll();
 }).run();
}

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

private  boolean constraintNameAlreadyExists(String name) {
 boolean commited = false;
 Query constraintExistsQuery = null;
 String constraintNameIfExists = null;
 try {
  openTransaction();
  name = normalizeIdentifier(name);
  constraintExistsQuery = pm.newQuery(MConstraint.class, "constraintName == name");
  constraintExistsQuery.declareParameters("java.lang.String name");
  constraintExistsQuery.setUnique(true);
  constraintExistsQuery.setResult("name");
  constraintNameIfExists = (String) constraintExistsQuery.execute(name);
  commited = commitTransaction();
 } finally {
  rollbackAndCleanup(commited, constraintExistsQuery);
 }
 return constraintNameIfExists != null && !constraintNameIfExists.isEmpty();
}

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

@Override
public Type getType(String typeName) {
 Type type = null;
 boolean commited = false;
 Query query = null;
 try {
  openTransaction();
  query = pm.newQuery(MType.class, "name == typeName");
  query.declareParameters("java.lang.String typeName");
  query.setUnique(true);
  MType mtype = (MType) query.execute(typeName.trim());
  pm.retrieve(type);
  if (mtype != null) {
   type = getType(mtype);
  }
  commited = commitTransaction();
 } finally {
  rollbackAndCleanup(commited, query);
 }
 return type;
}

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

private MRole getMRole(String roleName) {
 MRole mrole = null;
 boolean commited = false;
 Query query = null;
 try {
  openTransaction();
  query = pm.newQuery(MRole.class, "roleName == t1");
  query.declareParameters("java.lang.String t1");
  query.setUnique(true);
  mrole = (MRole) query.execute(roleName);
  pm.retrieve(mrole);
  commited = commitTransaction();
 } finally {
  rollbackAndCleanup(commited, query);
 }
 return mrole;
}

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

private boolean poolHasChildren(MWMResourcePlan resourcePlan, String poolPath) {
 boolean commited = false;
 Query query = null;
 try {
  openTransaction();
  query = pm.newQuery(MWMPool.class, "resourcePlan == rp && path.startsWith(poolPath)");
  query.declareParameters("MWMResourcePlan rp, java.lang.String poolPath");
  query.setResult("count(this)");
  query.setUnique(true);
  Long count = (Long) query.execute(resourcePlan, poolPath + ".");
  commited = commitTransaction();
  return count != null && count > 0;
 } finally {
  rollbackAndCleanup(commited, query);
 }
}

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

private MCatalog getMCatalog(String catalogName) throws MetaException {
 boolean committed = false;
 Query query = null;
 try {
  openTransaction();
  catalogName = normalizeIdentifier(catalogName);
  query = pm.newQuery(MCatalog.class, "name == catname");
  query.declareParameters("java.lang.String catname");
  query.setUnique(true);
  MCatalog mCat = (MCatalog)query.execute(catalogName);
  pm.retrieve(mCat);
  committed = commitTransaction();
  return mCat;
 } finally {
  rollbackAndCleanup(committed, query);
 }
}

代码示例来源: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 MISchema getMISchema(String catName, String dbName, String name) {
 Query query = null;
 try {
  name = normalizeIdentifier(name);
  dbName = normalizeIdentifier(dbName);
  catName = normalizeIdentifier(catName);
  query = pm.newQuery(MISchema.class,
    "name == schemaName && db.name == dbname && db.catalogName == cat");
  query.declareParameters(
    "java.lang.String schemaName, java.lang.String dbname, java.lang.String cat");
  query.setUnique(true);
  MISchema mSchema = (MISchema)query.execute(name, dbName, catName);
  pm.retrieve(mSchema);
  return mSchema;
 } finally {
  if (query != null) {
   query.closeAll();
  }
 }
}

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

private MWMPool getPool(MWMResourcePlan resourcePlan, String poolPath)
  throws NoSuchObjectException {
 poolPath = normalizeIdentifier(poolPath);
 boolean commited = false;
 Query query = null;
 try {
  openTransaction();
  query = pm.newQuery(MWMPool.class, "resourcePlan == rp && path == poolPath");
  query.declareParameters("MWMResourcePlan rp, java.lang.String poolPath");
  query.setUnique(true);
  MWMPool mPool = (MWMPool) query.execute(resourcePlan, poolPath);
  commited = commitTransaction();
  if (mPool == null) {
   throw new NoSuchObjectException("Cannot find pool: " + poolPath);
  }
  pm.retrieve(mPool);
  return mPool;
 } finally {
  rollbackAndCleanup(commited, query);
 }
}

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

private MWMTrigger getTrigger(MWMResourcePlan resourcePlan, String triggerName)
  throws NoSuchObjectException {
 triggerName = normalizeIdentifier(triggerName);
 boolean commited = false;
 Query query = null;
 try {
  openTransaction();
  // Get the MWMTrigger object from DN
  query = pm.newQuery(MWMTrigger.class, "resourcePlan == rp && name == triggerName");
  query.declareParameters("MWMResourcePlan rp, java.lang.String triggerName");
  query.setUnique(true);
  MWMTrigger mTrigger = (MWMTrigger) query.execute(resourcePlan, triggerName);
  if (mTrigger == null) {
   throw new NoSuchObjectException("Cannot find trigger with name: " + triggerName);
  }
  pm.retrieve(mTrigger);
  commited = commitTransaction();
  return mTrigger;
 } finally {
  rollbackAndCleanup(commited, query);
 }
}

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

private MFunction getMFunction(String catName, String db, String function) {
 MFunction mfunc = null;
 boolean commited = false;
 Query query = null;
 try {
  openTransaction();
  catName = normalizeIdentifier(catName);
  db = normalizeIdentifier(db);
  function = normalizeIdentifier(function);
  query = pm.newQuery(MFunction.class,
    "functionName == function && database.name == db && database.catalogName == catName");
  query.declareParameters("java.lang.String function, java.lang.String db, java.lang.String catName");
  query.setUnique(true);
  mfunc = (MFunction) query.execute(function, db, catName);
  pm.retrieve(mfunc);
  commited = commitTransaction();
 } finally {
  rollbackAndCleanup(commited, query);
 }
 return mfunc;
}

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

private MCreationMetadata getCreationMetadata(String catName, String dbName, String tblName) {
 boolean commited = false;
 MCreationMetadata mcm = null;
 Query query = null;
 catName = normalizeIdentifier(catName);
 dbName = normalizeIdentifier(dbName);
 tblName = normalizeIdentifier(tblName);
 try {
  openTransaction();
  query = pm.newQuery(
    MCreationMetadata.class, "tblName == table && dbName == db && catalogName == cat");
  query.declareParameters("java.lang.String table, java.lang.String db, java.lang.String cat");
  query.setUnique(true);
  mcm = (MCreationMetadata) query.execute(tblName, dbName, catName);
  pm.retrieve(mcm);
  commited = commitTransaction();
 } finally {
  rollbackAndCleanup(commited, query);
 }
 return mcm;
}

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

@SuppressWarnings("nls")
private MDatabase getMDatabase(String catName, String name) throws NoSuchObjectException {
 MDatabase mdb = null;
 boolean commited = false;
 Query query = null;
 try {
  openTransaction();
  name = normalizeIdentifier(name);
  catName = normalizeIdentifier(catName);
  query = pm.newQuery(MDatabase.class, "name == dbname && catalogName == catname");
  query.declareParameters("java.lang.String dbname, java.lang.String catname");
  query.setUnique(true);
  mdb = (MDatabase) query.execute(name, catName);
  pm.retrieve(mdb);
  commited = commitTransaction();
 } finally {
  rollbackAndCleanup(commited, query);
 }
 if (mdb == null) {
  throw new NoSuchObjectException("There is no database " + catName + "." + name);
 }
 return mdb;
}

相关文章