Java Code Examples for javax.jdo.Query#setResultClass()

The following examples show how to use javax.jdo.Query#setResultClass() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PaperclipsForInvoiceForLeaseRepository.java    From estatio with Apache License 2.0 7 votes vote down vote up
/**
 * It's necessary to use the low-level API because the candidate class ({@link PaperclipForInvoice}) and the
 * result class ({@link InvoiceForLease}) are different.
 */
@Programmatic
public List<InvoiceForLease> findInvoicesByYearWithSupportingDocuments(final int year) {

    final PersistenceManager jdoPersistenceManager = isisJdoSupport.getJdoPersistenceManager();
    final Query query = jdoPersistenceManager.newNamedQuery(
            PaperclipForInvoice.class,
            "findInvoicesByInvoiceDateBetweenWithSupportingDocuments");
    query.setResultClass(InvoiceForLease.class);

    try {
        final LocalDate invoiceDateFrom = new LocalDate(year,1,1);
        final LocalDate invoiceDateTo = invoiceDateFrom.plusYears(1);

        final List results = (List) query.executeWithMap(ImmutableMap.of(
                "invoiceDateFrom", invoiceDateFrom,
                "invoiceDateTo", invoiceDateTo
        ));
        return Lists.newArrayList(results);
    } finally {
        query.closeAll();
    }
}
 
Example 2
Source File: JdoUserClusterStore.java    From seldon-server with Apache License 2.0 6 votes vote down vote up
public TransientUserClusters getTransientClusters(long checkpoint) {
	final PersistenceManager pm = getPM();
	Query query = pm.newQuery( "javax.jdo.query.SQL","select max(t_id) from user_clusters_transient");
	query.setResultClass(Long.class);
	query.setUnique(true);
	Long lastId =  (Long) query.execute();
	if (lastId != null && lastId > checkpoint)
	{
		if (logger.isDebugEnabled())
			logger.debug("Loading new transient clusters as checkpoint is "+checkpoint+" and found checkpoint is " + lastId);
		query = pm.newQuery( "javax.jdo.query.SQL","select user_id,t.cluster_id,weight,lastupdate,group_id from user_clusters_transient t, cluster_update, cluster_group where t.cluster_id=cluster_group.cluster_id and t.t_id>? order by user_id asc");
		query.setResultClass(UserCluster.class);
		List<UserCluster> clusters =  (List<UserCluster>) query.execute(checkpoint);
		return new TransientUserClusters(lastId,new ArrayList<>(clusters));
	}
	else
		return new TransientUserClusters(lastId,new ArrayList<UserCluster>());
}
 
Example 3
Source File: IncomingInvoiceRepository.java    From estatio with Apache License 2.0 6 votes vote down vote up
@Programmatic
public boolean findCreditNotesInStateOf(
        final BankAccount creditorBankAccount,
        final List<IncomingInvoiceApprovalState> upstreamStates) {
    final PersistenceManager jdoPersistenceManager = isisJdoSupport.getJdoPersistenceManager();
    final String sql = constructSqlForCreditNotesInStateOf(upstreamStates);
    final Query query = jdoPersistenceManager.newQuery("javax.jdo.query.SQL", sql);
    try {
        query.setResultClass(Integer.class);
        final DatastoreIdImpl datastoreId = (DatastoreIdImpl) JDOHelper.getObjectId(creditorBankAccount);
        final long idKeyAsObject = (long) datastoreId.getKeyAsObject();
        final ForwardQueryResult result = (ForwardQueryResult) query.executeWithMap(ImmutableMap.of("bankAccountId", idKeyAsObject));
        return !result.isEmpty();
    } finally {
        if (query!=null) query.closeAll();
    }
}
 
Example 4
Source File: SqlItemPeer.java    From seldon-server with Apache License 2.0 5 votes vote down vote up
public Integer getItemCluster(long itemId) {
	Collection<Integer> res = new ArrayList<>();
	Query query = pm.newQuery( "javax.jdo.query.SQL", "select cluster_id from item_clusters where item_id="+itemId);
	query.setResultClass(Integer.class);
	query.setUnique(true);
	return (Integer) query.execute();
}
 
Example 5
Source File: SqlItemPeer.java    From seldon-server with Apache License 2.0 5 votes vote down vote up
@Override
public List<Long> getRecentItemIds(Set<Integer> dimensions, int limit, ConsumerBean c) {
	Query query;
	if (dimensions.isEmpty() || (dimensions.size() == 1 && dimensions.iterator().next() == Constants.DEFAULT_DIMENSION))
		query = pm.newQuery("javax.jdo.query.SQL","select i.item_id from items i order by i.item_id desc limit "+limit);			
	else
		query = pm.newQuery("javax.jdo.query.SQL","select i.item_id from items i natural join item_map_enum e join dimension d on (d.dim_id in ("+StringUtils.join(dimensions, ",")+") and e.attr_id=d.attr_id and e.value_id=d.value_id and i.type=d.item_type) order by i.item_id desc limit "+limit);

	query.setResultClass(Long.class);
	Collection<Long> res = (Collection<Long>) query.execute();
	List<Long> resf = new ArrayList<>(res);
	query.closeAll();
	return resf;
}
 
Example 6
Source File: SqlItemPeer.java    From seldon-server with Apache License 2.0 5 votes vote down vote up
@Override
public List<Long> getRecentItemIdsTwoDimensions(Set<Integer> dimensions, int dimension2,int limit, ConsumerBean c) {
	Query query;
	if (dimensions.isEmpty() || (dimensions.size() == 1 && dimensions.iterator().next() == Constants.DEFAULT_DIMENSION))
		query = pm.newQuery("javax.jdo.query.SQL","select i.item_id from items i natural join item_map_enum e join dimension d on (d.dim_id = ? and e.attr_id=d.attr_id and e.value_id=d.value_id and i.type=d.item_type) order by i.item_id desc limit "+limit);
	else
		query = pm.newQuery("javax.jdo.query.SQL","select i.item_id from items i natural join item_map_enum e join dimension d on (d.dim_id in ("+StringUtils.join(dimensions, ",")+") and e.attr_id=d.attr_id and e.value_id=d.value_id and i.type=d.item_type) join item_map_enum e2 on (i.item_id=e2.item_id) join dimension d2 on (d2.dim_id = ? and e2.attr_id=d2.attr_id and e2.value_id=d2.value_id and i.type=d2.item_type) order by i.item_id desc limit "+limit);
		
	query.setResultClass(Long.class);
	Collection<Long> res = (Collection<Long>) query.execute(dimension2);
	List<Long> resf = new ArrayList<>(res);
	query.closeAll();
	return resf;
}
 
Example 7
Source File: SqlItemPeer.java    From seldon-server with Apache License 2.0 5 votes vote down vote up
@Override
public Integer getDimensionForAttrName(long itemId, String name) {
	Query query = pm.newQuery( "javax.jdo.query.SQL", "select dim_id from dimension natural join item_map_enum join item_attr on (item_attr.attr_id=item_map_enum.attr_id) where item_attr.name=? and item_map_enum.item_id=?");
	query.setResultClass(Integer.class);
	query.setUnique(true);
	return (Integer) query.execute(name,itemId);
}
 
Example 8
Source File: JdoClusterCountStore.java    From seldon-server with Apache License 2.0 5 votes vote down vote up
/**
 * timestamp and time is ignore for db counts - the db value for these is used. They are assumed to be up-todate with clusters.
 */
@Override
public double getCount(int clusterId, long itemId,long timestamp) {
	final PersistenceManager pm = getPM();
	Query query = pm.newQuery( "javax.jdo.query.SQL", "select count from cluster_counts where id=? and item_id=?" );
	query.setResultClass(Double.class);
	query.setUnique(true);
	Double count = (Double) query.execute(clusterId, itemId);
	if (count != null)
		return count;
	else
		return 0D;
}
 
Example 9
Source File: JdoUserClusterStore.java    From seldon-server with Apache License 2.0 5 votes vote down vote up
@Override
public List<UserCluster> getClusters(long userId) {
	final PersistenceManager pm = getPM();
	Query query = pm.newQuery( "javax.jdo.query.SQL","select user_id,user_clusters.cluster_id,weight,lastupdate,group_id from user_clusters, cluster_update, cluster_group where user_id=? and user_clusters.cluster_id=cluster_group.cluster_id");
	query.setResultClass(UserCluster.class);
	return (List<UserCluster>) query.execute(userId);
}
 
Example 10
Source File: JdoUserClusterStore.java    From seldon-server with Apache License 2.0 5 votes vote down vote up
@Override
public List<UserCluster> getClusters() {
	final PersistenceManager pm = getPM();
	Query query = pm.newQuery( "javax.jdo.query.SQL","select user_id,user_clusters.cluster_id,weight,lastupdate,group_id from user_clusters, cluster_update, cluster_group where user_clusters.cluster_id=cluster_group.cluster_id order by user_id asc");
	query.setResultClass(UserCluster.class);
	return (List<UserCluster>) query.execute();
}
 
Example 11
Source File: JdoUserClusterStore.java    From seldon-server with Apache License 2.0 5 votes vote down vote up
@Override
public int getNumUsersWithClusters() {
	final PersistenceManager pm = getPM();
	Query query = pm.newQuery( "javax.jdo.query.SQL","select count(distinct user_id) from user_clusters");
	query.setResultClass(Integer.class);
	query.setUnique(true);
	return (Integer) query.execute();
}
 
Example 12
Source File: JdoUserClusterStore.java    From seldon-server with Apache License 2.0 5 votes vote down vote up
@Override
public long getCurrentTimestamp() {
	final PersistenceManager pm = getPM();
	Query query = pm.newQuery( "javax.jdo.query.SQL","select lastupdate from cluster_update");
	query.setResultClass(Long.class);
	query.setUnique(true);
	return (Long) query.execute();
}
 
Example 13
Source File: JdoClusterFromReferrer.java    From seldon-server with Apache License 2.0 5 votes vote down vote up
private void updateClusterMap()
{
	PersistenceManager pm = JDOFactory.get().getPersistenceManager(client);
	if (pm != null)
	{
		Query query = pm.newQuery( "javax.jdo.query.SQL","select referrer,cluster from cluster_referrer");
		query.setResultClass(ClusterReferrer.class);
		List<ClusterReferrer> res = (List<ClusterReferrer>) query.execute();
		logger.info("Getting READ lock");
		lock.writeLock().lock();
		try
		{
			ConcurrentHashMap<String,Integer> clusterMapNew = new ConcurrentHashMap<>();
			for(ClusterReferrer r : res)
			{
				logger.info("Updating cluster map for "+client+" with referrer:"+r.getReferrer()+" cluster:"+r.getCluster());
				clusterMapNew.put(r.getReferrer(), r.getCluster());
			}

			clusterMap = clusterMapNew;
		}
		finally
		{
			lock.writeLock().unlock();
			logger.info("Released WRITE lock");
		}
		
	}
	else
		logger.error("Failed to get persistence manager for client "+client);
}
 
Example 14
Source File: IncomingInvoiceItemRepository.java    From estatio with Apache License 2.0 5 votes vote down vote up
@Programmatic
public List<LocalDate> findDistinctReportDates() {
    final PersistenceManager pm = isisJdoSupport.getJdoPersistenceManager();
    final Query query = pm.newQuery(IncomingInvoiceItem.class);
    query.setResultClass(LocalDate.class);
    query.setResult("distinct reportedDate");
    query.setOrdering("reportedDate descending");
    query.setFilter("reportedDate != null"); // EST-1838: Null value was set to LocalDate#now by DN
    return executeListAndClose(query);
}
 
Example 15
Source File: StatusMessageSummaryCache.java    From estatio with Apache License 2.0 5 votes vote down vote up
private List<InvoiceIdAndStatusMessageSummary> find(final Long invoiceId) {
    final PersistenceManager jdoPersistenceManager = isisJdoSupport.getJdoPersistenceManager();

    final String sql = readSql();
    final Query query = jdoPersistenceManager.newQuery("javax.jdo.query.SQL", sql);
    query.setResultClass(InvoiceIdAndStatusMessageSummary.class);

    return (List<InvoiceIdAndStatusMessageSummary>) query.executeWithMap(ImmutableMap.of("invoiceId", invoiceId));
}
 
Example 16
Source File: SqlActionPeer.java    From seldon-server with Apache License 2.0 4 votes vote down vote up
@Override
public List<Long> getRecentUserActions(long userId) {
	Query query = pm.newQuery( "javax.jdo.query.SQL", "select item_id from actions where user_id=? order by action_id desc limit 20");
	query.setResultClass(Long.class);
	return (List<Long>) query.execute(userId);
}