当前位置: 首页>>代码示例>>Java>>正文


Java ParaObject类代码示例

本文整理汇总了Java中com.erudika.para.core.ParaObject的典型用法代码示例。如果您正苦于以下问题:Java ParaObject类的具体用法?Java ParaObject怎么用?Java ParaObject使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ParaObject类属于com.erudika.para.core包,在下文中一共展示了ParaObject类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: indexAll

import com.erudika.para.core.ParaObject; //导入依赖的package包/类
@Override
public <P extends ParaObject> void indexAll(String appid, List<P> objects) {
	if (StringUtils.isBlank(appid) || objects == null || objects.isEmpty()) {
		return;
	}
	BulkRequestBuilder brb = client().prepareBulk();
	for (ParaObject po : objects) {
		brb.add(client().prepareIndex(getIndexName(appid), getType(), po.getId()).
				setSource(ElasticSearchUtils.getSourceFromParaObject(po)));
	}
	if (brb.numberOfActions() > 0) {
		ActionListener<BulkResponse> responseHandler = ElasticSearchUtils.getBulkIndexResponseHandler();
		if (isAsyncEnabled()) {
			brb.execute(responseHandler);
		} else {
			responseHandler.onResponse(brb.execute().actionGet());
		}
	}
	logger.debug("Search.indexAll() {}", objects.size());
}
 
开发者ID:Erudika,项目名称:para-search-elasticsearch,代码行数:21,代码来源:ElasticSearch.java

示例2: unindexAll

import com.erudika.para.core.ParaObject; //导入依赖的package包/类
@Override
public <P extends ParaObject> void unindexAll(String appid, List<P> objects) {
	if (StringUtils.isBlank(appid) || objects == null || objects.isEmpty()) {
		return;
	}
	BulkRequestBuilder brb = client().prepareBulk();
	for (ParaObject po : objects) {
		brb.add(client().prepareDelete(getIndexName(appid), getType(), po.getId()));
	}
	if (brb.numberOfActions() > 0) {
		ActionListener<BulkResponse> responseHandler = ElasticSearchUtils.getBulkIndexResponseHandler();
		if (isAsyncEnabled()) {
			brb.execute(responseHandler);
		} else {
			responseHandler.onResponse(brb.execute().actionGet());
		}
	}
	logger.debug("Search.unindexAll() {}", objects.size());
}
 
开发者ID:Erudika,项目名称:para-search-elasticsearch,代码行数:20,代码来源:ElasticSearch.java

示例3: create

import com.erudika.para.core.ParaObject; //导入依赖的package包/类
@Override
public <P extends ParaObject> String create(String appid, P so) {
	if (so == null) {
		return null;
	}
	if (StringUtils.isBlank(so.getId())) {
		so.setId(Utils.getNewId());
	}
	if (so.getTimestamp() == null) {
		so.setTimestamp(Utils.timestamp());
	}
	so.setAppid(appid);
	so.setIndexed(false); // skip indexing - already indexed here
	search.index(appid, ParaObjectUtils.setAnnotatedFields(ParaObjectUtils.toObject(so.getType()),
			ParaObjectUtils.getAnnotatedFields(so), null));
	logger.debug("DAO.create() {}", so.getId());
	return so.getId();
}
 
开发者ID:Erudika,项目名称:para-search-elasticsearch,代码行数:19,代码来源:IndexBasedDAO.java

示例4: createAll

import com.erudika.para.core.ParaObject; //导入依赖的package包/类
@Override
public <P extends ParaObject> void createAll(String appid, List<P> objects) {
	if (StringUtils.isBlank(appid) || objects == null) {
		return;
	}
	Iterator<P> iter = objects.iterator();
	while (iter.hasNext()) {
		P p = iter.next();
		if (p == null) {
			iter.remove();
			continue;
		}
		p.setAppid(appid);
		p.setIndexed(false);
		if (StringUtils.isBlank(p.getId())) {
			p.setId(Utils.getNewId());
		}
		if (p.getTimestamp() == null) {
			p.setTimestamp(Utils.timestamp());
		}
	}
	search.indexAll(appid, objects);
	logger.debug("DAO.createAll() {}", objects.size());
}
 
开发者ID:Erudika,项目名称:para-search-elasticsearch,代码行数:25,代码来源:IndexBasedDAO.java

示例5: readAll

import com.erudika.para.core.ParaObject; //导入依赖的package包/类
@Override
public <P extends ParaObject> Map<String, P> readAll(String appid, List<String> keys, boolean getAllColumns) {
	if (keys == null || StringUtils.isBlank(appid)) {
		return Collections.emptyMap();
	}
	Map<String, P> results = new LinkedHashMap<String, P>(keys.size());
	List<P> list = search.findByIds(getAppidWithRouting(appid), keys);

	for (P p : list) {
		if (p != null) {
			results.put(p.getId(), p);
		}
	}

	logger.debug("DAO.readAll() {}", results.size());
	return results;
}
 
开发者ID:Erudika,项目名称:para-search-elasticsearch,代码行数:18,代码来源:IndexBasedDAO.java

示例6: index

import com.erudika.para.core.ParaObject; //导入依赖的package包/类
@Override
public void index(String appid, ParaObject po) {
	if (po == null || StringUtils.isBlank(appid)) {
		return;
	}
	try {
		IndexRequestBuilder irb = client().prepareIndex(getIndexName(appid), getType(), po.getId()).
				setSource(ElasticSearchUtils.getSourceFromParaObject(po));
		ActionListener<IndexResponse> responseHandler = ElasticSearchUtils.getIndexResponseHandler();
		if (isAsyncEnabled()) {
			irb.execute(responseHandler);
		} else {
			responseHandler.onResponse(irb.execute().actionGet());
		}
		logger.debug("Search.index() {}", po.getId());
	} catch (Exception e) {
		logger.warn(null, e);
	}
}
 
开发者ID:Erudika,项目名称:para-search-elasticsearch,代码行数:20,代码来源:ElasticSearch.java

示例7: unindex

import com.erudika.para.core.ParaObject; //导入依赖的package包/类
@Override
public void unindex(String appid, ParaObject po) {
	if (po == null || StringUtils.isBlank(po.getId()) || StringUtils.isBlank(appid)) {
		return;
	}
	try {
		DeleteRequestBuilder drb = client().prepareDelete(getIndexName(appid), getType(), po.getId());
		ActionListener<DeleteResponse> responseHandler = ElasticSearchUtils.getIndexResponseHandler();
		if (isAsyncEnabled()) {
			drb.execute(responseHandler);
		} else {
			responseHandler.onResponse(drb.execute().actionGet());
		}
		logger.debug("Search.unindex() {}", po.getId());
	} catch (Exception e) {
		logger.warn(null, e);
	}
}
 
开发者ID:Erudika,项目名称:para-search-elasticsearch,代码行数:19,代码来源:ElasticSearch.java

示例8: findTermInList

import com.erudika.para.core.ParaObject; //导入依赖的package包/类
@Override
public <P extends ParaObject> List<P> findTermInList(String appid, String type,
		String field, List<?> terms, Pager... pager) {
	if (StringUtils.isBlank(field) || terms == null) {
		return Collections.emptyList();
	}
	QueryBuilder qb;
	if (nestedMode() && field.startsWith(PROPS_PREFIX)) {
		QueryBuilder bfb = null;
		BoolQueryBuilder fb = boolQuery();
		for (Object term : terms) {
			bfb = keyValueBoolQuery(field, String.valueOf(term));
			fb.should(bfb);
		}
		qb = nestedPropsQuery(terms.size() > 1 ? fb : bfb);
	} else {
		qb = termsQuery(field, terms);
	}
	return searchQuery(appid, type, qb, pager);
}
 
开发者ID:Erudika,项目名称:para-search-elasticsearch,代码行数:21,代码来源:ElasticSearch.java

示例9: findQuery

import com.erudika.para.core.ParaObject; //导入依赖的package包/类
@Override
public <P extends ParaObject> List<P> findQuery(String appid, String type,
		String query, Pager... pager) {
	if (StringUtils.isBlank(query)) {
		return Collections.emptyList();
	}
	// a basic implementation of support for nested queries in query string
	// https://github.com/elastic/elasticsearch/issues/11322
	QueryBuilder qb;
	if (nestedMode() && query.matches(PROPS_REGEX)) {
		qb = convertQueryStringToNestedQuery(query);
		if (qb == null) {
			return Collections.emptyList();
		}
	} else {
		qb = queryStringQuery(qs(query)).allowLeadingWildcard(false);
	}
	return searchQuery(appid, type, qb, pager);
}
 
开发者ID:Erudika,项目名称:para-search-elasticsearch,代码行数:20,代码来源:ElasticSearch.java

示例10: findTerms

import com.erudika.para.core.ParaObject; //导入依赖的package包/类
@Override
@SuppressWarnings("unchecked")
public <P extends ParaObject> List<P> findTerms(String appid, String type,
		Map<String, ?> terms, boolean mustMatchAll, Pager... pager) {
	if (terms == null || terms.isEmpty()) {
		return Collections.emptyList();
	}

	QueryBuilder fb = getTermsQuery(terms, mustMatchAll);

	if (fb == null) {
		return Collections.emptyList();
	} else {
		return searchQuery(appid, type, fb, pager);
	}
}
 
开发者ID:Erudika,项目名称:para-search-elasticsearch,代码行数:17,代码来源:ElasticSearch.java

示例11: getParaObjectFromSource

import com.erudika.para.core.ParaObject; //导入依赖的package包/类
/**
 * Converts the source of an ES document to {@link ParaObject}.
 * @param <P> object type
 * @param source a map of keys and values coming from ES
 * @return a new ParaObject
 */
static <P extends ParaObject> P getParaObjectFromSource(Map<String, Object> source) {
	if (source == null) {
		return null;
	}
	Map<String, Object> data = new HashMap<>(source.size());
	data.putAll(source);
	// retrieve the JSON for the original properties field and deserialize it
	if (nestedMode() && data.containsKey(PROPS_JSON)) {
		try {
			Map<String, Object> props = ParaObjectUtils.getJsonReader(Map.class).
					readValue((String) data.get(PROPS_JSON));
			data.put(PROPS_FIELD, props);
		} catch (Exception e) {
			logger.error(null, e);
		}
		data.remove(PROPS_JSON);
	}
	data.remove("_docid");
	return ParaObjectUtils.setAnnotatedFields(data);
}
 
开发者ID:Erudika,项目名称:para-search-elasticsearch,代码行数:27,代码来源:ElasticSearchUtils.java

示例12: testRangeQuery

import com.erudika.para.core.ParaObject; //导入依赖的package包/类
@Test
public void testRangeQuery() {
	// many terms
	Map<String, Object> terms1 = new HashMap<String, Object>();
	terms1.put(Config._TIMESTAMP + " <", 1111111111L);

	Map<String, Object> terms2 = new HashMap<String, Object>();
	terms2.put(Config._TIMESTAMP + "<=", u.getTimestamp());

	List<ParaObject> res1 = s.findTerms(u.getType(), terms1, true);
	List<ParaObject> res2 = s.findTerms(u.getType(), terms2, true);

	assertEquals(1, res1.size());
	assertEquals(1, res2.size());

	assertEquals(u.getId(), res1.get(0).getId());
	assertEquals(u.getId(), res2.get(0).getId());
}
 
开发者ID:Erudika,项目名称:para-search-elasticsearch,代码行数:19,代码来源:ElasticSearchIT.java

示例13: delete

import com.erudika.para.core.ParaObject; //导入依赖的package包/类
public void delete() {
	// delete post
	ArrayList<ParaObject> children = new ArrayList<ParaObject>();
	ArrayList<String> ids = new ArrayList<String>();
	// delete Comments
	children.addAll(client().getChildren(this, Utils.type(Comment.class)));
	// delete Revisions
	children.addAll(client().getChildren(this, Utils.type(Revision.class)));

	if (canHaveChildren()) {
		for (ParaObject reply : client().getChildren(this, Utils.type(Reply.class))) {
			// delete Comments
			children.addAll(client().getChildren(reply, Utils.type(Comment.class)));
			// delete Revisions
			children.addAll(client().getChildren(reply, Utils.type(Revision.class)));
		}
	}
	for (ParaObject child : children) {
		ids.add(child.getId());
	}
	client().deleteAll(ids);
	client().delete(this);
}
 
开发者ID:Erudika,项目名称:scoold,代码行数:24,代码来源:Post.java

示例14: updateRow

import com.erudika.para.core.ParaObject; //导入依赖的package包/类
private <P extends ParaObject> void updateRow(P so, String appid) {
	if (so == null || so.getId() == null || StringUtils.isBlank(appid)) {
		return;
	}
	try {
		String oldRow = readRow(so.getId(), appid);
		if (oldRow != null) {
			Map<String, Object> oldData = ParaObjectUtils.getJsonReader(Map.class).readValue(oldRow);
			Map<String, Object> newData = ParaObjectUtils.getAnnotatedFields(so, Locked.class);
			oldData.putAll(newData);
			PreparedStatement ps = getPreparedStatement("UPDATE " +
					CassandraUtils.getTableNameForAppid(appid) + " SET json = ? WHERE id = ?;");
			getClient().execute(ps.bind(ParaObjectUtils.getJsonWriterNoIdent().
					writeValueAsString(oldData), so.getId()));
			logger.debug("Updated id: " + so.getId());
		}
	} catch (Exception e) {
		logger.error(null, e);
	}
}
 
开发者ID:Erudika,项目名称:para-dao-cassandra,代码行数:21,代码来源:CassandraDAO.java

示例15: createAll

import com.erudika.para.core.ParaObject; //导入依赖的package包/类
@Override
public <P extends ParaObject> void createAll(String appid, List<P> objects) {
	if (objects == null || objects.isEmpty() || StringUtils.isBlank(appid)) {
		return;
	}
	List<Document> documents = new ArrayList<Document>();
	for (ParaObject so : objects) {
		if (so != null) {
			if (StringUtils.isBlank(so.getId())) {
				so.setId(MongoDBUtils.generateNewId());
				logger.debug("Generated id: " + so.getId());
			}
			if (so.getTimestamp() == null) {
				so.setTimestamp(Utils.timestamp());
			}
			so.setAppid(appid);
			documents.add(toRow(so, null, false, true));
		}
	}
	if (!documents.isEmpty()) {
		getTable(appid).insertMany(documents);
	}
	logger.debug("DAO.createAll() {}", objects.size());
}
 
开发者ID:Erudika,项目名称:para-dao-mongodb,代码行数:25,代码来源:MongoDBDAO.java


注:本文中的com.erudika.para.core.ParaObject类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。