Query query = pm.newQuery("javax.jdo.query.SQL", queryText); if (max != null) { query.setRange(0, max.shortValue());
query.setResultClass(java.lang.String.class); if (maxTables >= 0) { query.setRange(0, maxTables);
int maxEventResponse = MetastoreConf.getIntVar(conf, ConfVars.METASTORE_MAX_EVENT_RESPONSE); int maxEvents = (rqst.getMaxEvents() < maxEventResponse && rqst.getMaxEvents() > 0) ? rqst.getMaxEvents() : maxEventResponse; query.setRange(0, maxEvents); Collection<MNotificationLog> events = (Collection) query.executeWithArray(parameterVals.toArray(new Object[parameterVals.size()]));
query.setRange(0, maxParts);
private List<String> getPartitionNamesNoTxn(String catName, String dbName, String tableName, short max) { List<String> pns = new ArrayList<>(); if (max == 0) { return pns; } catName = normalizeIdentifier(catName); dbName = normalizeIdentifier(dbName); tableName = normalizeIdentifier(tableName); Query query = pm.newQuery("select partitionName from org.apache.hadoop.hive.metastore.model.MPartition " + "where table.database.name == t1 && table.tableName == t2 && table.database.catalogName == t3 " + "order by partitionName asc"); query.declareParameters("java.lang.String t1, java.lang.String t2, java.lang.String t3"); query.setResult("partitionName"); if (max > 0) { query.setRange(0, max); } Collection<String> names = (Collection<String>) query.execute(dbName, tableName, catName); pns.addAll(names); if (query != null) { query.closeAll(); } return pns; }
private List<MPartition> listMPartitions(String catName, String dbName, String tableName, int max, QueryWrapper queryWrapper) { boolean success = false; List<MPartition> mparts = null; try { openTransaction(); LOG.debug("Executing listMPartitions"); dbName = normalizeIdentifier(dbName); tableName = normalizeIdentifier(tableName); Query query = queryWrapper.query = pm.newQuery(MPartition.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"); query.setOrdering("partitionName ascending"); if (max >= 0) { query.setRange(0, max); } mparts = (List<MPartition>) query.execute(tableName, dbName, catName); LOG.debug("Done executing query for listMPartitions"); pm.retrieveAll(mparts); success = commitTransaction(); LOG.debug("Done retrieving all objects for listMPartitions {}", mparts); } finally { if (!success) { rollbackTransaction(); } } return mparts; }
q.setRange(0, maxParts);
if (maxParts >= 0) { query.setRange(0, maxParts);
if (max >= 0) { query.setRange(0, max);
if (max_parts >= 0) { query.setRange(0, max_parts);
query.setUnique(true); query.setOrdering("version descending"); query.setRange(0, 1); MSchemaVersion mSchemaVersion = (MSchemaVersion)query.execute(name, dbName, catName); pm.retrieve(mSchemaVersion);
Query query = pm.newQuery(University.class,":p.contains(name)"); query.setOrdering("name asc"); query.setRange(0, 5); List univs = q.execute(Arrays.asList(array));
@SuppressWarnings("unchecked") public List<T> getItems() { if (items == null) { Query newQuery = query.getPersistenceManager().newQuery(query); int offset = (page - 1) * pageSize; newQuery.setRange(offset, offset + pageSize); items = (List<T>) newQuery.executeWithMap(map); } return items; }
private List<String> getPartitionNamesNoTxn(String dbName, String tableName, short max) { List<String> pns = new ArrayList<String>(); dbName = HiveStringUtils.normalizeIdentifier(dbName); tableName = HiveStringUtils.normalizeIdentifier(tableName); Query q = pm.newQuery( "select partitionName from org.apache.hadoop.hive.metastore.model.MPartition " + "where table.database.name == t1 && table.tableName == t2 " + "order by partitionName asc"); q.declareParameters("java.lang.String t1, java.lang.String t2"); q.setResult("partitionName"); if(max > 0) { q.setRange(0, max); } Collection names = (Collection) q.execute(dbName, tableName); for (Iterator i = names.iterator(); i.hasNext();) { pns.add((String) i.next()); } return pns; }
/** * Checks if the table associated with class provided is empty * * @param pm PersistenceManager * @param clazz class * @return True is the table is empty * False if it not. */ private boolean isTableEmptyCore(PersistenceManager pm, Class clazz) { Query query = pm.newQuery(clazz); query.addExtension(LOAD_RESULTS_AT_COMMIT, "false"); // setRange is implemented efficiently for MySQL, Postgresql (using the LIMIT SQL keyword) // and Oracle (using the ROWNUM keyword), with the query only finding the objects required // by the user directly in the datastore. For other RDBMS the query will retrieve all // objects up to the "to" record, and will not pass any unnecessary objects that are before // the "from" record. query.setRange(0, 1); return ((List<?>) query.execute()).isEmpty(); }
private List<String> getPartitionNamesNoTxn(String dbName, String tableName, short max) { List<String> pns = new ArrayList<String>(); dbName = HiveStringUtils.normalizeIdentifier(dbName); tableName = HiveStringUtils.normalizeIdentifier(tableName); Query q = pm.newQuery( "select partitionName from org.apache.hadoop.hive.metastore.model.MPartition " + "where table.database.name == t1 && table.tableName == t2 " + "order by partitionName asc"); q.declareParameters("java.lang.String t1, java.lang.String t2"); q.setResult("partitionName"); if(max > 0) { q.setRange(0, max); } Collection names = (Collection) q.execute(dbName, tableName); for (Iterator i = names.iterator(); i.hasNext();) { pns.add((String) i.next()); } return pns; }
private List<String> getPartitionNamesNoTxn(String catName, String dbName, String tableName, short max) { List<String> pns = new ArrayList<>(); if (max == 0) { return pns; } catName = normalizeIdentifier(catName); dbName = normalizeIdentifier(dbName); tableName = normalizeIdentifier(tableName); Query query = pm.newQuery("select partitionName from org.apache.hadoop.hive.metastore.model.MPartition " + "where table.database.name == t1 && table.tableName == t2 && table.database.catalogName == t3 " + "order by partitionName asc"); query.declareParameters("java.lang.String t1, java.lang.String t2, java.lang.String t3"); query.setResult("partitionName"); if (max > 0) { query.setRange(0, max); } Collection<String> names = (Collection<String>) query.execute(dbName, tableName, catName); pns.addAll(names); if (query != null) { query.closeAll(); } return pns; }
@Test public void testRangeIntFunctionFail() { PersistenceManager pm = TestTools.openPM(); pm.currentTransaction().begin(); Query q = null; q = pm.newQuery(TestClass.class); try { q.setRange(-1, 3); fail(); } catch (JDOUserException e) { //good } try { q.setRange(3, 1); fail(); } catch (JDOUserException e) { //good } TestTools.closePM(); }
@SuppressWarnings("unchecked") @Test public void testRangeWithParams() { PersistenceManager pm = TestTools.openPM(); pm.currentTransaction().begin(); Query q = pm.newQuery(TestClass.class); List<TestClass> c0 = (List<TestClass>) q.execute(); List<TestClass> a0 = new ArrayList<>(c0); q.setRange(":min, :max"); List<TestClass> c2 = (List<TestClass>) q.execute(0, 5); List<TestClass> a2 = new ArrayList<>(c2); assertEquals(a0, a2); List<TestClass> c3 = (List<TestClass>) q.execute(1, 4); List<TestClass> a3 = new ArrayList<>(c3); for (int i = 1; i <= 3; i++) { assertEquals(a0.get(i).getString(), a3.get(i-1).getString()); } TestTools.closePM(); }
private void checkSetRangeFails(PersistenceManager pm, String s) { Query q1 = pm.newQuery(TestClass.class); try { q1.setRange(s); q1.compile(); fail(); } catch (JDOUserException e) { //good, we got an JDOUSerException() } try { Query q2 = pm.newQuery(TestClass.class, "RANGE " + s); q2.compile(); fail(); } catch (JDOUserException e) { //good, we got an JDOUSerException() } }