本文整理汇总了Java中org.javalite.activejdbc.Model类的典型用法代码示例。如果您正苦于以下问题:Java Model类的具体用法?Java Model怎么用?Java Model使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Model类属于org.javalite.activejdbc包,在下文中一共展示了Model类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: create
import org.javalite.activejdbc.Model; //导入依赖的package包/类
public static Comment create(Model cv, Integer vote) {
User user = User.create(cv.getLong("user_id"), cv.getString("user_name"));
User modifiedByUser = User.create(cv.getLong("modified_by_user_id"), cv.getString("modified_by_user_name"));
return new Comment(cv.getLong("id"),
user,
modifiedByUser,
cv.getLong("discussion_id"),
cv.getLong("discussion_owner_id"),
cv.getString("text_"),
cv.getLong("path_length"),
cv.getLong("parent_id"),
cv.getLong("parent_user_id"),
cv.getString("breadcrumbs"),
cv.getLong("num_of_parents"),
cv.getLong("num_of_children"),
cv.getInteger("avg_rank"),
vote,
cv.getInteger("number_of_votes"),
cv.getBoolean("deleted"),
cv.getBoolean("read"),
cv.getTimestamp("created"),
cv.getTimestamp("modified"));
}
示例2: convertRankToMap
import org.javalite.activejdbc.Model; //导入依赖的package包/类
public static <T extends Model> Map<Long, Integer> convertRankToMap(List<T> drs, String idColumnName) {
// Convert those votes to a map from id to rank
Map<Long, Integer> rankMap = new HashMap<>();
for (T dr : drs) {
rankMap.put(dr.getLong(idColumnName), dr.getInteger("rank"));
}
try {
log.debug(Tools.JACKSON.writeValueAsString(rankMap));
} catch (JsonProcessingException e) {
e.printStackTrace();
}
return rankMap;
}
示例3: convertRowsToMap
import org.javalite.activejdbc.Model; //导入依赖的package包/类
public static <T extends Model> Map<Long,List<T>> convertRowsToMap(List<T> tags, String idColumnName) {
Map<Long,List<T>> map = new HashMap<>();
for (T dtv : tags) {
Long id = dtv.getLong(idColumnName);
List<T> arr = map.get(id);
if (arr == null) {
arr = new ArrayList<>();
map.put(id, arr);
}
arr.add(dtv);
}
return map;
}
示例4: create
import org.javalite.activejdbc.Model; //导入依赖的package包/类
public static Communities create(List<? extends Model> communities,
List<Tables.CommunityTagView> communityTags,
List<Tables.CommunityUserView> communityUsers,
List<Tables.CommunityRank> communityRanks,
Long count) {
// Build maps keyed by community_id of the votes, tags, and users
Map<Long, Integer> votes = (communityRanks != null) ?
Transformations.convertRankToMap(communityRanks, "community_id") : null;
Map<Long, List<Tables.CommunityTagView>> tagMap = (communityTags != null) ?
Transformations.convertRowsToMap(communityTags, "community_id") : null;
Map<Long, List<Tables.CommunityUserView>> userMap = (communityUsers != null) ?
Transformations.convertRowsToMap(communityUsers, "community_id") : null;
// Convert to a list of community objects
List<Community> cos = new ArrayList<>();
for (Model view : communities) {
Long id = view.getLongId();
Integer vote = (votes != null && votes.get(id) != null) ? votes.get(id) : null;
List<Tables.CommunityTagView> tags = (tagMap != null && tagMap.get(id) != null) ? tagMap.get(id) : null;
List<Tables.CommunityUserView> users = (userMap != null && userMap.get(id) != null) ? userMap.get(id) : null;
Community c = Community.create(view, tags, users, vote);
cos.add(c);
}
return new Communities(cos, count);
}
示例5: create
import org.javalite.activejdbc.Model; //导入依赖的package包/类
public static Comments create(
LazyList<? extends Model> comments,
Map<Long, Integer> votes,
Long topLimit, Long maxDepth) {
List<Comment> commentObjs = Transformations.convertCommentsToEmbeddedObjects(
comments, votes, topLimit, maxDepth);
return new Comments(commentObjs);
}
示例6: replies
import org.javalite.activejdbc.Model; //导入依赖的package包/类
public static Comments replies(LazyList<? extends Model> comments) {
Set<Comment> commentObjs = new LinkedHashSet<>();
for (Model c : comments) {
commentObjs.add(Comment.create(c, null));
}
// Convert to a list
List<Comment> list = new ArrayList<>(commentObjs);
return new Comments(list);
}
示例7: convertCommentsToEmbeddedObjects
import org.javalite.activejdbc.Model; //导入依赖的package包/类
public static List<Comment> convertCommentsToEmbeddedObjects(
List<? extends Model> cvs,
Map<Long, Integer> votes,
Long topLimit, Long maxDepth) {
Map<Long, Comment> commentObjMap = convertCommentThreadedViewToMap(cvs, votes);
List<Comment> cos = convertCommentsMapToEmbeddedObjects(commentObjMap, topLimit, maxDepth);
return cos;
}
示例8: messageNextPage
import org.javalite.activejdbc.Model; //导入依赖的package包/类
public void messageNextPage(Session session, String nextPageDataStr) {
SessionScope ss = SessionScope.findBySession(sessionScopes, session);
// Get the object
NextPageData nextPageData = NextPageData.fromJson(nextPageDataStr);
// Refetch the comments based on the new limit
LazyList<Model> comments = fetchComments(ss);
// send the comments from up to the new limit to them
sendMessage(session, Comments.create(comments,
fetchVotesMap(ss.getUserObj().getId()),
nextPageData.getTopLimit(), nextPageData.getMaxDepth()).json());
}
示例9: fetchComments
import org.javalite.activejdbc.Model; //导入依赖的package包/类
private static LazyList<Model> fetchComments(SessionScope scope) {
if (scope.getTopParentId() != null) {
return CommentBreadcrumbsView.where("discussion_id = ? and parent_id = ?",
scope.getDiscussionId(), scope.getTopParentId());
} else {
return CommentThreadedView.where("discussion_id = ?", scope.getDiscussionId());
}
}
示例10: fetchUserComments
import org.javalite.activejdbc.Model; //导入依赖的package包/类
public static String fetchUserComments(Integer userId, Integer commentUserId, String orderBy,
Integer pageNum, Integer pageSize) {
LazyList<Model> cvs = COMMENT_VIEW.findBySQL(
COMMENT_VIEW_SQL(userId, null, null, null, null, orderBy, commentUserId, null,
pageNum, pageSize, null));
String json = Tools.wrapPaginatorArray(
Tools.replaceNewlines(cvs.toJson(false)),
Long.valueOf(cvs.size()));
return json;
}
示例11: validate
import org.javalite.activejdbc.Model; //导入依赖的package包/类
@Override
public void validate(Model m) {
if(m.get(attribute) == null){
m.addValidator(this, attribute);
return;
}
Object value = m.get(attribute);
if (!(value instanceof String)) {
throw new IllegalArgumentException("attribute " + attribute + " is not String");
}
Matcher matcher = pattern.matcher((String) value);
if(!matcher.matches()){
m.addValidator(this, attribute);
}
}
示例12: convert
import org.javalite.activejdbc.Model; //导入依赖的package包/类
@Override
public void convert(Model m) {
Object val = m.get(attributeName);
if (!(val instanceof java.util.Date) && !blank(val)) {
try {
long time = df.parse(val.toString()).getTime();
java.sql.Date d = new java.sql.Date(time);
m.set(attributeName, d);
} catch (ParseException e) {
m.addValidator(this, attributeName);
}
}
}
示例13: validate
import org.javalite.activejdbc.Model; //导入依赖的package包/类
@Override
public void validate(Model m) {
Object value = m.get(attribute);
if (!(value instanceof String)) {
throw new IllegalArgumentException("Attribute must be a String");
}
if (!lengthOption.validate((String) (m.get(attribute)))) {
m.addValidator(this, attribute);
}
}
示例14: convert
import org.javalite.activejdbc.Model; //导入依赖的package包/类
@Override
public void convert(Model m) {
Object val = m.get(attributeName);
if (!(val instanceof Timestamp) && !blank(val)) {
try {
long time = df.parse(val.toString()).getTime();
Timestamp t = new Timestamp(time);
m.set(attributeName, t);
} catch(ParseException e) {
m.addValidator(this, attributeName);
}
}
}
示例15: validate
import org.javalite.activejdbc.Model; //导入依赖的package包/类
@Override
public void validate(Model m) {
if (blank(m.get(attribute))) {
//TODO: use resource bundles for messages
m.addValidator(this, attribute);
}
}