本文整理了Java中javax.jdo.Query.setResultClass
方法的一些代码示例,展示了Query.setResultClass
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Query.setResultClass
方法的具体详情如下:
包路径:javax.jdo.Query
类名称:Query
方法名:setResultClass
[英]Specify the type of object in which to return each element of the result of invoking #execute or one of its siblings. If the result is not set or set to null, the result class defaults to the candidate class of the query. If the result consists of one expression, the result class defaults to the type of that expression. If the result consists of more than one expression, the result class defaults to Object[]. The result class may be specified to be one of the java.lang classes Character, Boolean, Byte, Short, Integer, Long, Float, Double, String, or Object[]; or one of the java.math classes BigInteger or BigDecimal; or the java.util class Date; or one of the java.sql classes Date, Time, or Timestamp; or a user-defined class.
If there are multiple result expressions, the result class must be able to hold all elements of the result specification or a JDOUserException is thrown.
If there is only one result expression, the result class must be assignable from the type of the result expression or must be able to hold all elements of the result specification. A single value must be able to be coerced into the specified result class (treating wrapper classes as equivalent to their unwrapped primitive types) or by matching. If the result class does not satisfy these conditions, a JDOUserException is thrown.
A constructor of a result class specified in the setResult method will be used if the results specification matches the parameters of the constructor by position and type. If more than one constructor satisfies the requirements, the JDO implementation chooses one of them. If no constructor satisfies the results requirements, or if the result class is specified via the setResultClass method, the following requirements apply:
A user-defined result class must have a no-args constructor and one or more public set
or put
methods or fields.
Each result expression must match one of:
a public field that matches the name of the result expression and is of the type (treating wrapper types equivalent to primitive types) of the result expression;
set
method that returns void and matches the name of the result expression and takes a single parameter which is the exact type of the result expression;void put(Object, Object)
. During processing of the results, the first argument is the name of the result expression and the second argument is the value from the query result.set
methods.set
或put
方法或字段。set
方法,该方法返回void并与结果表达式的名称匹配,并使用一个与结果表达式的类型完全相同的参数;set
方法期间不会调用任何持久性行为。代码示例来源:origin: apache/hive
query.declareImports("import java.lang.String");
query.setResult("tableName");
query.setResultClass(java.lang.String.class);
if (maxTables >= 0) {
query.setRange(0, maxTables);
代码示例来源:origin: apache/hive
/**
* Gets partition names from the table via ORM (JDOQL) name filter.
* @param dbName Database name.
* @param tblName Table name.
* @param partNames Partition names to get the objects for.
* @return Resulting partitions.
*/
private List<Partition> getPartitionsViaOrmFilter(String catName,
String dbName, String tblName, List<String> partNames) throws MetaException {
if (partNames.isEmpty()) {
return new ArrayList<>();
}
ObjectPair<Query, Map<String, String>> queryWithParams =
getPartQueryWithParams(catName, dbName, tblName, partNames);
Query query = queryWithParams.getFirst();
query.setResultClass(MPartition.class);
query.setClass(MPartition.class);
query.setOrdering("partitionName ascending");
@SuppressWarnings("unchecked")
List<MPartition> mparts = (List<MPartition>)query.executeWithMap(queryWithParams.getSecond());
List<Partition> partitions = convertToParts(catName, dbName, tblName, mparts);
if (query != null) {
query.closeAll();
}
return partitions;
}
代码示例来源:origin: apache/sentry
@VisibleForTesting
List<MPath> getMPaths() throws Exception {
return tm.executeTransaction(pm -> {
long currentSnapshotID = getCurrentAuthzPathsSnapshotID(pm);
Query query = pm.newQuery("SQL",
"SELECT p.PATH_NAME FROM AUTHZ_PATH p " +
"JOIN AUTHZ_PATHS_MAPPING a ON a.AUTHZ_OBJ_ID = p.AUTHZ_OBJ_ID " +
"WHERE a.AUTHZ_SNAPSHOT_ID = ?"
);
query.setResultClass(MPath.class);
return (List<MPath>) query.execute(currentSnapshotID);
});
}
代码示例来源:origin: edu.berkeley.cs.shark/hive-metastore
query.declareImports("import java.lang.String");
query.setResult("tableName");
query.setResultClass(java.lang.String.class);
if (maxTables >= 0) {
query.setRange(0, maxTables);
代码示例来源:origin: org.spark-project.hive/hive-metastore
query.declareImports("import java.lang.String");
query.setResult("tableName");
query.setResultClass(java.lang.String.class);
if (maxTables >= 0) {
query.setRange(0, maxTables);
代码示例来源:origin: org.apache.hive/hive-standalone-metastore
query.declareImports("import java.lang.String");
query.setResult("tableName");
query.setResultClass(java.lang.String.class);
if (maxTables >= 0) {
query.setRange(0, maxTables);
代码示例来源:origin: com.mysema.querydsl/querydsl-jdo
private Query createQuery(boolean forCount) {
SQLSerializer serializer = new SQLSerializer(configuration);
if (union != null) {
serializer.serializeUnion(union, queryMixin.getMetadata(), unionAll);
} else {
serializer.serialize(queryMixin.getMetadata(), forCount);
}
// create Query
if (logger.isDebugEnabled()) {
logger.debug(serializer.toString());
}
Query query = persistenceManager.newQuery("javax.jdo.query.SQL",serializer.toString());
orderedConstants = serializer.getConstants();
queries.add(query);
if (!forCount) {
List<? extends Expression<?>> projection = queryMixin.getMetadata().getProjection();
if (projection.get(0) instanceof FactoryExpression) {
this.projection = (FactoryExpression<?>)projection.get(0);
}
} else {
query.setResultClass(Long.class);
}
return query;
}
代码示例来源:origin: com.facebook.presto.hive/hive-apache
query.declareImports("import java.lang.String");
query.setResult("tableName");
query.setResultClass(java.lang.String.class);
if (maxTables >= 0) {
query.setRange(0, maxTables);
代码示例来源:origin: com.facebook.presto.hive/hive-apache
private List<MPartition> getMPartitionsViaOrmFilter(String dbName,
String tblName, List<String> partNames, Out<Query> out) {
ObjectPair<Query, Map<String, String>> queryWithParams =
getPartQueryWithParams(dbName, tblName, partNames);
Query query = out.val = queryWithParams.getFirst();
query.setResultClass(MPartition.class);
query.setClass(MPartition.class);
query.setOrdering("partitionName ascending");
@SuppressWarnings("unchecked")
List<MPartition> result = (List<MPartition>)query.executeWithMap(queryWithParams.getSecond());
return result;
}
代码示例来源:origin: org.spark-project.hive/hive-metastore
private List<MPartition> getMPartitionsViaOrmFilter(String dbName,
String tblName, List<String> partNames, Out<Query> out) {
ObjectPair<Query, Map<String, String>> queryWithParams =
getPartQueryWithParams(dbName, tblName, partNames);
Query query = out.val = queryWithParams.getFirst();
query.setResultClass(MPartition.class);
query.setClass(MPartition.class);
query.setOrdering("partitionName ascending");
@SuppressWarnings("unchecked")
List<MPartition> result = (List<MPartition>)query.executeWithMap(queryWithParams.getSecond());
return result;
}
代码示例来源:origin: org.apache.hive/hive-standalone-metastore
/**
* Gets partition names from the table via ORM (JDOQL) name filter.
* @param dbName Database name.
* @param tblName Table name.
* @param partNames Partition names to get the objects for.
* @return Resulting partitions.
*/
private List<Partition> getPartitionsViaOrmFilter(String catName,
String dbName, String tblName, List<String> partNames) throws MetaException {
if (partNames.isEmpty()) {
return new ArrayList<>();
}
ObjectPair<Query, Map<String, String>> queryWithParams =
getPartQueryWithParams(catName, dbName, tblName, partNames);
Query query = queryWithParams.getFirst();
query.setResultClass(MPartition.class);
query.setClass(MPartition.class);
query.setOrdering("partitionName ascending");
@SuppressWarnings("unchecked")
List<MPartition> mparts = (List<MPartition>)query.executeWithMap(queryWithParams.getSecond());
List<Partition> partitions = convertToParts(catName, dbName, tblName, mparts);
if (query != null) {
query.closeAll();
}
return partitions;
}
代码示例来源:origin: org.apache.continuum/continuum-store
public Map<Integer, ProjectGroupSummary> getProjectsSummary()
{
PersistenceManager pm = getPersistenceManager();
Transaction tx = pm.currentTransaction();
try
{
tx.begin();
Extent extent = pm.getExtent( Project.class );
Query query = pm.newQuery( extent );
query.setResult( "projectGroup.id as projectGroupId, state as projectState, count(state) as size" );
query.setResultClass( ProjectSummaryResult.class );
query.setGrouping( "projectGroup.id, state" );
List<ProjectSummaryResult> results = (List<ProjectSummaryResult>) query.execute();
Map<Integer, ProjectGroupSummary> summaries = processProjectGroupSummary( results );
tx.commit();
return summaries;
}
finally
{
rollback( tx );
}
}
代码示例来源:origin: tzaeschke/zoodb
q.setResultClass(EmpWrapper.class);
Collection<EmpWrapper> infos = (Collection<EmpWrapper>) q.execute (new Float (30000.));
Iterator<EmpWrapper> it = infos.iterator();
代码示例来源:origin: tzaeschke/zoodb
q.setResultClass(EmpInfo.class);
Collection<EmpInfo> infos = (Collection<EmpInfo>) q.execute (new Float (30000.));
Iterator<EmpInfo> it = infos.iterator();
代码示例来源:origin: org.datanucleus/datanucleus-api-jdo
query.setResultClass(resultCls);
代码示例来源:origin: tzaeschke/zoodb
q.declareParameters ("String deptName");
q.setResult("name, salary, boss as reportsTo");
q.setResultClass(Info.class);
Collection<Info> names = (Collection<Info>) q.execute("R&D");
Iterator<Info> it = names.iterator();
代码示例来源:origin: tzaeschke/zoodb
q.declareParameters ("String deptName");
q.setResult("new Info(name, salary, boss)");
q.setResultClass(Info.class);
Collection<Info> names = (Collection<Info>) q.execute("R&D");
Iterator<Info> it = names.iterator();
代码示例来源:origin: tzaeschke/zoodb
/**
* 14.10.14 Selection of a Single Field
* This query returns a single field of a single Employee.
*/
@Test
public void testQuery_14_10_14() {
PersistenceManager pm = TestTools.openPM();
pm.currentTransaction().begin();
Query q = pm.newQuery (Employee.class, "name == empName");
q.declareParameters ("String empName");
q.setResult("salary");
q.setResultClass(Float.class);
q.setUnique(true);
Float salary = (Float) q.execute ("Michael");
// <query name="single">
// [!CDATA[
// select unique new Float(salary)
// where dept.name == :deptName
// ]]
// </query>
assertNotNull(salary);
//assertEquals(40001., salary);
assertTrue(Math.abs(40001. - salary) < 0.00001);
TestTools.closePM(pm);
}
代码示例来源:origin: jpox/jpox
query.setResultClass(resultCls);
内容来源于网络,如有侵权,请联系作者删除!