Commit d93e378b authored by Liang Ding's avatar Liang Ding

🏗 #12515 移除 Repository 层接口

parent 9e9a8ec9
...@@ -35,7 +35,6 @@ import org.b3log.solo.event.*; ...@@ -35,7 +35,6 @@ import org.b3log.solo.event.*;
import org.b3log.solo.model.Option; import org.b3log.solo.model.Option;
import org.b3log.solo.model.Skin; import org.b3log.solo.model.Skin;
import org.b3log.solo.repository.OptionRepository; import org.b3log.solo.repository.OptionRepository;
import org.b3log.solo.repository.impl.OptionRepositoryImpl;
import org.b3log.solo.service.*; import org.b3log.solo.service.*;
import org.b3log.solo.util.Skins; import org.b3log.solo.util.Skins;
import org.b3log.solo.util.Solos; import org.b3log.solo.util.Solos;
...@@ -92,7 +91,7 @@ public final class SoloServletListener extends AbstractServletListener { ...@@ -92,7 +91,7 @@ public final class SoloServletListener extends AbstractServletListener {
JdbcRepository.dispose(); JdbcRepository.dispose();
final OptionRepository optionRepository = beanManager.getReference(OptionRepositoryImpl.class); final OptionRepository optionRepository = beanManager.getReference(OptionRepository.class);
final Transaction transaction = optionRepository.beginTransaction(); final Transaction transaction = optionRepository.beginTransaction();
try { try {
loadPreference(); loadPreference();
......
...@@ -34,7 +34,6 @@ import org.b3log.solo.model.Article; ...@@ -34,7 +34,6 @@ import org.b3log.solo.model.Article;
import org.b3log.solo.model.Comment; import org.b3log.solo.model.Comment;
import org.b3log.solo.model.Option; import org.b3log.solo.model.Option;
import org.b3log.solo.repository.CommentRepository; import org.b3log.solo.repository.CommentRepository;
import org.b3log.solo.repository.impl.CommentRepositoryImpl;
import org.b3log.solo.service.PreferenceQueryService; import org.b3log.solo.service.PreferenceQueryService;
import org.b3log.solo.util.Solos; import org.b3log.solo.util.Solos;
import org.json.JSONObject; import org.json.JSONObject;
...@@ -87,7 +86,7 @@ public class ArticleCommentReplyNotifier extends AbstractEventListener<JSONObjec ...@@ -87,7 +86,7 @@ public class ArticleCommentReplyNotifier extends AbstractEventListener<JSONObjec
final BeanManager beanManager = BeanManager.getInstance(); final BeanManager beanManager = BeanManager.getInstance();
final PreferenceQueryService preferenceQueryService = beanManager.getReference(PreferenceQueryService.class); final PreferenceQueryService preferenceQueryService = beanManager.getReference(PreferenceQueryService.class);
final CommentRepository commentRepository = beanManager.getReference(CommentRepositoryImpl.class); final CommentRepository commentRepository = beanManager.getReference(CommentRepository.class);
try { try {
final String commentEmail = comment.getString(Comment.COMMENT_EMAIL); final String commentEmail = comment.getString(Comment.COMMENT_EMAIL);
......
...@@ -35,7 +35,6 @@ import org.b3log.solo.model.Comment; ...@@ -35,7 +35,6 @@ import org.b3log.solo.model.Comment;
import org.b3log.solo.model.Option; import org.b3log.solo.model.Option;
import org.b3log.solo.model.Page; import org.b3log.solo.model.Page;
import org.b3log.solo.repository.CommentRepository; import org.b3log.solo.repository.CommentRepository;
import org.b3log.solo.repository.impl.CommentRepositoryImpl;
import org.b3log.solo.service.PreferenceQueryService; import org.b3log.solo.service.PreferenceQueryService;
import org.b3log.solo.util.Solos; import org.b3log.solo.util.Solos;
import org.json.JSONObject; import org.json.JSONObject;
...@@ -81,7 +80,7 @@ public class PageCommentReplyNotifier extends AbstractEventListener<JSONObject> ...@@ -81,7 +80,7 @@ public class PageCommentReplyNotifier extends AbstractEventListener<JSONObject>
final BeanManager beanManager = BeanManager.getInstance(); final BeanManager beanManager = BeanManager.getInstance();
final PreferenceQueryService preferenceQueryService = beanManager.getReference(PreferenceQueryService.class); final PreferenceQueryService preferenceQueryService = beanManager.getReference(PreferenceQueryService.class);
final CommentRepository commentRepository = beanManager.getReference(CommentRepositoryImpl.class); final CommentRepository commentRepository = beanManager.getReference(CommentRepository.class);
try { try {
final String commentEmail = comment.getString(Comment.COMMENT_EMAIL); final String commentEmail = comment.getString(Comment.COMMENT_EMAIL);
......
...@@ -27,7 +27,6 @@ import org.b3log.latke.plugin.AbstractPlugin; ...@@ -27,7 +27,6 @@ import org.b3log.latke.plugin.AbstractPlugin;
import org.b3log.latke.plugin.PluginManager; import org.b3log.latke.plugin.PluginManager;
import org.b3log.latke.repository.Transaction; import org.b3log.latke.repository.Transaction;
import org.b3log.solo.repository.PluginRepository; import org.b3log.solo.repository.PluginRepository;
import org.b3log.solo.repository.impl.PluginRepositoryImpl;
import org.b3log.solo.service.PluginMgmtService; import org.b3log.solo.service.PluginMgmtService;
import java.util.List; import java.util.List;
...@@ -55,7 +54,7 @@ public class PluginRefresher extends AbstractEventListener<List<AbstractPlugin>> ...@@ -55,7 +54,7 @@ public class PluginRefresher extends AbstractEventListener<List<AbstractPlugin>>
event.getType(), plugins, PluginRefresher.class.getName()); event.getType(), plugins, PluginRefresher.class.getName());
final BeanManager beanManager = BeanManager.getInstance(); final BeanManager beanManager = BeanManager.getInstance();
final PluginRepository pluginRepository = beanManager.getReference(PluginRepositoryImpl.class); final PluginRepository pluginRepository = beanManager.getReference(PluginRepository.class);
final Transaction transaction = pluginRepository.beginTransaction(); final Transaction transaction = pluginRepository.beginTransaction();
try { try {
......
...@@ -33,8 +33,6 @@ import org.b3log.solo.model.Article; ...@@ -33,8 +33,6 @@ import org.b3log.solo.model.Article;
import org.b3log.solo.model.Page; import org.b3log.solo.model.Page;
import org.b3log.solo.repository.ArticleRepository; import org.b3log.solo.repository.ArticleRepository;
import org.b3log.solo.repository.PageRepository; import org.b3log.solo.repository.PageRepository;
import org.b3log.solo.repository.impl.ArticleRepositoryImpl;
import org.b3log.solo.repository.impl.PageRepositoryImpl;
import org.b3log.solo.service.ArticleQueryService; import org.b3log.solo.service.ArticleQueryService;
import org.b3log.solo.service.PermalinkQueryService; import org.b3log.solo.service.PermalinkQueryService;
import org.json.JSONObject; import org.json.JSONObject;
...@@ -98,10 +96,10 @@ public final class PermalinkFilter implements Filter { ...@@ -98,10 +96,10 @@ public final class PermalinkFilter implements Filter {
final BeanManager beanManager = BeanManager.getInstance(); final BeanManager beanManager = BeanManager.getInstance();
try { try {
final ArticleRepository articleRepository = beanManager.getReference(ArticleRepositoryImpl.class); final ArticleRepository articleRepository = beanManager.getReference(ArticleRepository.class);
article = articleRepository.getByPermalink(permalink); article = articleRepository.getByPermalink(permalink);
if (null == article) { if (null == article) {
final PageRepository pageRepository = beanManager.getReference(PageRepositoryImpl.class); final PageRepository pageRepository = beanManager.getReference(PageRepository.class);
page = pageRepository.getByPermalink(permalink); page = pageRepository.getByPermalink(permalink);
} }
......
...@@ -41,9 +41,9 @@ import org.b3log.solo.model.Tag; ...@@ -41,9 +41,9 @@ import org.b3log.solo.model.Tag;
import org.b3log.solo.model.sitemap.Sitemap; import org.b3log.solo.model.sitemap.Sitemap;
import org.b3log.solo.model.sitemap.URL; import org.b3log.solo.model.sitemap.URL;
import org.b3log.solo.repository.ArchiveDateRepository; import org.b3log.solo.repository.ArchiveDateRepository;
import org.b3log.solo.repository.ArticleRepository;
import org.b3log.solo.repository.PageRepository; import org.b3log.solo.repository.PageRepository;
import org.b3log.solo.repository.TagRepository; import org.b3log.solo.repository.TagRepository;
import org.b3log.solo.repository.impl.ArticleRepositoryImpl;
import org.b3log.solo.service.PreferenceQueryService; import org.b3log.solo.service.PreferenceQueryService;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONObject; import org.json.JSONObject;
...@@ -76,7 +76,7 @@ public class SitemapProcessor { ...@@ -76,7 +76,7 @@ public class SitemapProcessor {
* Article repository. * Article repository.
*/ */
@Inject @Inject
private ArticleRepositoryImpl articleRepository; private ArticleRepository articleRepository;
/** /**
* Page repository. * Page repository.
......
...@@ -19,6 +19,7 @@ package org.b3log.solo.repository; ...@@ -19,6 +19,7 @@ package org.b3log.solo.repository;
import org.b3log.latke.Keys; import org.b3log.latke.Keys;
import org.b3log.latke.repository.*; import org.b3log.latke.repository.*;
import org.b3log.latke.repository.annotation.Repository;
import org.b3log.solo.model.ArchiveDate; import org.b3log.solo.model.ArchiveDate;
import org.b3log.solo.model.Article; import org.b3log.solo.model.Article;
import org.json.JSONArray; import org.json.JSONArray;
...@@ -31,6 +32,7 @@ import org.json.JSONObject; ...@@ -31,6 +32,7 @@ import org.json.JSONObject;
* @version 1.0.0.3, Sep 30, 2018 * @version 1.0.0.3, Sep 30, 2018
* @since 0.3.1 * @since 0.3.1
*/ */
@Repository
public class ArchiveDateArticleRepository extends AbstractRepository { public class ArchiveDateArticleRepository extends AbstractRepository {
/** /**
......
...@@ -22,6 +22,7 @@ import org.b3log.latke.Keys; ...@@ -22,6 +22,7 @@ import org.b3log.latke.Keys;
import org.b3log.latke.logging.Level; import org.b3log.latke.logging.Level;
import org.b3log.latke.logging.Logger; import org.b3log.latke.logging.Logger;
import org.b3log.latke.repository.*; import org.b3log.latke.repository.*;
import org.b3log.latke.repository.annotation.Repository;
import org.b3log.solo.model.ArchiveDate; import org.b3log.solo.model.ArchiveDate;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONObject; import org.json.JSONObject;
...@@ -37,6 +38,7 @@ import java.util.List; ...@@ -37,6 +38,7 @@ import java.util.List;
* @version 1.0.0.3, Sep 30, 2018 * @version 1.0.0.3, Sep 30, 2018
* @since 0.3.1 * @since 0.3.1
*/ */
@Repository
public class ArchiveDateRepository extends AbstractRepository { public class ArchiveDateRepository extends AbstractRepository {
/** /**
......
...@@ -22,6 +22,7 @@ import org.b3log.latke.ioc.Inject; ...@@ -22,6 +22,7 @@ import org.b3log.latke.ioc.Inject;
import org.b3log.latke.logging.Level; import org.b3log.latke.logging.Level;
import org.b3log.latke.logging.Logger; import org.b3log.latke.logging.Logger;
import org.b3log.latke.repository.*; import org.b3log.latke.repository.*;
import org.b3log.latke.repository.annotation.Repository;
import org.b3log.solo.cache.ArticleCache; import org.b3log.solo.cache.ArticleCache;
import org.b3log.solo.model.Article; import org.b3log.solo.model.Article;
import org.json.JSONArray; import org.json.JSONArray;
...@@ -38,6 +39,7 @@ import java.util.List; ...@@ -38,6 +39,7 @@ import java.util.List;
* @version 1.1.1.11, Sep 30, 2018 * @version 1.1.1.11, Sep 30, 2018
* @since 0.3.1 * @since 0.3.1
*/ */
@Repository
public class ArticleRepository extends AbstractRepository { public class ArticleRepository extends AbstractRepository {
/** /**
......
...@@ -17,20 +17,34 @@ ...@@ -17,20 +17,34 @@
*/ */
package org.b3log.solo.repository; package org.b3log.solo.repository;
import org.b3log.latke.repository.Repository; import org.b3log.latke.Keys;
import org.b3log.latke.repository.RepositoryException; import org.b3log.latke.repository.*;
import org.b3log.latke.repository.annotation.Repository;
import org.b3log.solo.model.Category;
import org.b3log.solo.model.Tag;
import org.json.JSONArray;
import org.json.JSONObject; import org.json.JSONObject;
import java.text.Collator;
import java.util.Collections;
import java.util.List; import java.util.List;
/** /**
* Category repository. * Category repository.
* *
* @author <a href="http://88250.b3log.org">Liang Ding</a> * @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.2.0.1, Apr 8, 2017 * @version 1.2.0.2, Sep 30, 2018
* @since 2.0.0 * @since 2.0.0
*/ */
public interface CategoryRepository extends Repository { @Repository
public class CategoryRepository extends AbstractRepository {
/**
* Public constructor.
*/
public CategoryRepository() {
super(Category.CATEGORY);
}
/** /**
* Gets a category by the specified category title. * Gets a category by the specified category title.
...@@ -39,7 +53,16 @@ public interface CategoryRepository extends Repository { ...@@ -39,7 +53,16 @@ public interface CategoryRepository extends Repository {
* @return a category, {@code null} if not found * @return a category, {@code null} if not found
* @throws RepositoryException repository exception * @throws RepositoryException repository exception
*/ */
JSONObject getByTitle(final String categoryTitle) throws RepositoryException; public JSONObject getByTitle(final String categoryTitle) throws RepositoryException {
final Query query = new Query().setFilter(new PropertyFilter(Category.CATEGORY_TITLE, FilterOperator.EQUAL, categoryTitle)).setPageCount(1);
final JSONObject result = get(query);
final JSONArray array = result.optJSONArray(Keys.RESULTS);
if (0 == array.length()) {
return null;
}
return array.optJSONObject(0);
}
/** /**
* Gets a category by the specified category URI. * Gets a category by the specified category URI.
...@@ -48,7 +71,16 @@ public interface CategoryRepository extends Repository { ...@@ -48,7 +71,16 @@ public interface CategoryRepository extends Repository {
* @return a category, {@code null} if not found * @return a category, {@code null} if not found
* @throws RepositoryException repository exception * @throws RepositoryException repository exception
*/ */
JSONObject getByURI(final String categoryURI) throws RepositoryException; public JSONObject getByURI(final String categoryURI) throws RepositoryException {
final Query query = new Query().setFilter(new PropertyFilter(Category.CATEGORY_URI, FilterOperator.EQUAL, categoryURI)).setPageCount(1);
final JSONObject result = get(query);
final JSONArray array = result.optJSONArray(Keys.RESULTS);
if (0 == array.length()) {
return null;
}
return array.optJSONObject(0);
}
/** /**
* Gets the maximum order. * Gets the maximum order.
...@@ -56,7 +88,16 @@ public interface CategoryRepository extends Repository { ...@@ -56,7 +88,16 @@ public interface CategoryRepository extends Repository {
* @return order number, returns {@code -1} if not found * @return order number, returns {@code -1} if not found
* @throws RepositoryException repository exception * @throws RepositoryException repository exception
*/ */
int getMaxOrder() throws RepositoryException; public int getMaxOrder() throws RepositoryException {
final Query query = new Query().addSort(Category.CATEGORY_ORDER, SortDirection.DESCENDING);
final JSONObject result = get(query);
final JSONArray array = result.optJSONArray(Keys.RESULTS);
if (0 == array.length()) {
return -1;
}
return array.optJSONObject(0).optInt(Category.CATEGORY_ORDER);
}
/** /**
* Gets the upper category of the category specified by the given id. * Gets the upper category of the category specified by the given id.
...@@ -65,7 +106,22 @@ public interface CategoryRepository extends Repository { ...@@ -65,7 +106,22 @@ public interface CategoryRepository extends Repository {
* @return upper category, returns {@code null} if not found * @return upper category, returns {@code null} if not found
* @throws RepositoryException repository exception * @throws RepositoryException repository exception
*/ */
JSONObject getUpper(final String id) throws RepositoryException; public JSONObject getUpper(final String id) throws RepositoryException {
final JSONObject category = get(id);
if (null == category) {
return null;
}
final Query query = new Query().setFilter(new PropertyFilter(Category.CATEGORY_ORDER, FilterOperator.LESS_THAN, category.optInt(Category.CATEGORY_ORDER))).
addSort(Category.CATEGORY_ORDER, SortDirection.DESCENDING).setCurrentPageNum(1).setPageSize(1);
final JSONObject result = get(query);
final JSONArray array = result.optJSONArray(Keys.RESULTS);
if (1 != array.length()) {
return null;
}
return array.optJSONObject(0);
}
/** /**
* Gets the under category of the category specified by the given id. * Gets the under category of the category specified by the given id.
...@@ -74,7 +130,22 @@ public interface CategoryRepository extends Repository { ...@@ -74,7 +130,22 @@ public interface CategoryRepository extends Repository {
* @return under category, returns {@code null} if not found * @return under category, returns {@code null} if not found
* @throws RepositoryException repository exception * @throws RepositoryException repository exception
*/ */
JSONObject getUnder(final String id) throws RepositoryException; public JSONObject getUnder(final String id) throws RepositoryException {
final JSONObject category = get(id);
if (null == category) {
return null;
}
final Query query = new Query().setFilter(new PropertyFilter(Category.CATEGORY_ORDER, FilterOperator.GREATER_THAN, category.optInt(Category.CATEGORY_ORDER))).
addSort(Category.CATEGORY_ORDER, SortDirection.ASCENDING).setCurrentPageNum(1).setPageSize(1);
final JSONObject result = get(query);
final JSONArray array = result.optJSONArray(Keys.RESULTS);
if (1 != array.length()) {
return null;
}
return array.optJSONObject(0);
}
/** /**
* Gets a category by the specified order. * Gets a category by the specified order.
...@@ -83,7 +154,16 @@ public interface CategoryRepository extends Repository { ...@@ -83,7 +154,16 @@ public interface CategoryRepository extends Repository {
* @return category, returns {@code null} if not found * @return category, returns {@code null} if not found
* @throws RepositoryException repository exception * @throws RepositoryException repository exception
*/ */
JSONObject getByOrder(final int order) throws RepositoryException; public JSONObject getByOrder(final int order) throws RepositoryException {
final Query query = new Query().setFilter(new PropertyFilter(Category.CATEGORY_ORDER, FilterOperator.EQUAL, order));
final JSONObject result = get(query);
final JSONArray array = result.optJSONArray(Keys.RESULTS);
if (0 == array.length()) {
return null;
}
return array.optJSONObject(0);
}
/** /**
* Gets most used categories (contains the most tags) with the specified number. * Gets most used categories (contains the most tags) with the specified number.
...@@ -92,5 +172,12 @@ public interface CategoryRepository extends Repository { ...@@ -92,5 +172,12 @@ public interface CategoryRepository extends Repository {
* @return a list of most used categories, returns an empty list if not found * @return a list of most used categories, returns an empty list if not found
* @throws RepositoryException repository exception * @throws RepositoryException repository exception
*/ */
List<JSONObject> getMostUsedCategories(final int num) throws RepositoryException; public List<JSONObject> getMostUsedCategories(final int num) throws RepositoryException {
final Query query = new Query().addSort(Category.CATEGORY_ORDER, SortDirection.ASCENDING).
setCurrentPageNum(1).setPageSize(num).setPageCount(1);
final List<JSONObject> ret = getList(query);
Collections.sort(ret, (o1, o2) -> Collator.getInstance(java.util.Locale.CHINA).compare(o1.optString(Tag.TAG_TITLE), o2.optString(Tag.TAG_TITLE)));
return ret;
}
} }
...@@ -17,18 +17,30 @@ ...@@ -17,18 +17,30 @@
*/ */
package org.b3log.solo.repository; package org.b3log.solo.repository;
import org.b3log.latke.repository.Repository; import org.b3log.latke.Keys;
import org.b3log.latke.repository.RepositoryException; import org.b3log.latke.repository.*;
import org.b3log.latke.repository.annotation.Repository;
import org.b3log.solo.model.Category;
import org.b3log.solo.model.Tag;
import org.json.JSONArray;
import org.json.JSONObject; import org.json.JSONObject;
/** /**
* Category-Tag relation repository. * Category-Tag relation repository.
* *
* @author <a href="http://88250.b3log.org">Liang Ding</a> * @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.1.0.1, Mar 31, 2017 * @version 1.1.0.2, Sep 30, 2018
* @since 2.0.0 * @since 2.0.0
*/ */
public interface CategoryTagRepository extends Repository { @Repository
public class CategoryTagRepository extends AbstractRepository {
/**
* Public constructor.
*/
public CategoryTagRepository() {
super(Category.CATEGORY + "_" + Tag.TAG);
}
/** /**
* Gets category-tag relations by the specified category id. * Gets category-tag relations by the specified category id.
...@@ -50,8 +62,12 @@ public interface CategoryTagRepository extends Repository { ...@@ -50,8 +62,12 @@ public interface CategoryTagRepository extends Repository {
* </pre> * </pre>
* @throws RepositoryException repository exception * @throws RepositoryException repository exception
*/ */
JSONObject getByCategoryId(final String categoryId, final int currentPageNum, final int pageSize) public JSONObject getByCategoryId(final String categoryId, final int currentPageNum, final int pageSize) throws RepositoryException {
throws RepositoryException; final Query query = new Query().setFilter(new PropertyFilter(Category.CATEGORY + "_" + Keys.OBJECT_ID, FilterOperator.EQUAL, categoryId)).
setCurrentPageNum(currentPageNum).setPageSize(pageSize).setPageCount(1);
return get(query);
}
/** /**
* Gets category-tag relations by the specified tag id. * Gets category-tag relations by the specified tag id.
...@@ -73,8 +89,12 @@ public interface CategoryTagRepository extends Repository { ...@@ -73,8 +89,12 @@ public interface CategoryTagRepository extends Repository {
* </pre> * </pre>
* @throws RepositoryException repository exception * @throws RepositoryException repository exception
*/ */
JSONObject getByTagId(final String tagId, final int currentPageNum, final int pageSize) public JSONObject getByTagId(final String tagId, final int currentPageNum, final int pageSize) throws RepositoryException {
throws RepositoryException; final Query query = new Query().setFilter(new PropertyFilter(Tag.TAG + "_" + Keys.OBJECT_ID, FilterOperator.EQUAL, tagId)).
setCurrentPageNum(currentPageNum).setPageSize(pageSize).setPageCount(1);
return get(query);
}
/** /**
* Removes category-tag relations by the specified category id. * Removes category-tag relations by the specified category id.
...@@ -82,7 +102,14 @@ public interface CategoryTagRepository extends Repository { ...@@ -82,7 +102,14 @@ public interface CategoryTagRepository extends Repository {
* @param categoryId the specified category id * @param categoryId the specified category id
* @throws RepositoryException repository exception * @throws RepositoryException repository exception
*/ */
void removeByCategoryId(final String categoryId) throws RepositoryException; public void removeByCategoryId(final String categoryId) throws RepositoryException {
final Query query = new Query().setFilter(new PropertyFilter(Category.CATEGORY + "_" + Keys.OBJECT_ID, FilterOperator.EQUAL, categoryId));
final JSONArray relations = get(query).optJSONArray(Keys.RESULTS);
for (int i = 0; i < relations.length(); i++) {
final JSONObject rel = relations.optJSONObject(i);
remove(rel.optString(Keys.OBJECT_ID));
}
}
/** /**
* Removes category-tag relations by the specified tag id. * Removes category-tag relations by the specified tag id.
...@@ -90,5 +117,12 @@ public interface CategoryTagRepository extends Repository { ...@@ -90,5 +117,12 @@ public interface CategoryTagRepository extends Repository {
* @param tagId the specified tag id * @param tagId the specified tag id
* @throws RepositoryException repository exception * @throws RepositoryException repository exception
*/ */
void removeByTagId(final String tagId) throws RepositoryException; public void removeByTagId(final String tagId) throws RepositoryException {
final Query query = new Query().setFilter(new PropertyFilter(Tag.TAG + "_" + Keys.OBJECT_ID, FilterOperator.EQUAL, tagId));
final JSONArray relations = get(query).optJSONArray(Keys.RESULTS);
for (int i = 0; i < relations.length(); i++) {
final JSONObject rel = relations.optJSONObject(i);
remove(rel.optString(Keys.OBJECT_ID));
}
}
} }
...@@ -17,51 +17,165 @@ ...@@ -17,51 +17,165 @@
*/ */
package org.b3log.solo.repository; package org.b3log.solo.repository;
import org.b3log.latke.repository.Repository; import org.b3log.latke.Keys;
import org.b3log.latke.repository.RepositoryException; import org.b3log.latke.ioc.Inject;
import org.b3log.latke.logging.Level;
import org.b3log.latke.logging.Logger;
import org.b3log.latke.repository.*;
import org.b3log.latke.repository.annotation.Repository;
import org.b3log.solo.cache.CommentCache;
import org.b3log.solo.model.Article;
import org.b3log.solo.model.Comment;
import org.json.JSONObject; import org.json.JSONObject;
import java.util.Iterator;
import java.util.List; import java.util.List;
/** /**
* Comment repository. * Comment repository.
* *
* @author <a href="http://88250.b3log.org">Liang Ding</a> * @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.0.0.4, Oct 26, 2011 * @version 1.0.0.5, Sep 30, 2018
* @since 0.3.1 * @since 0.3.1
*/ */
public interface CommentRepository extends Repository { @Repository
public class CommentRepository extends AbstractRepository {
/**
* Logger.
*/
private static final Logger LOGGER = Logger.getLogger(CommentRepository.class);
/**
* Article repository.
*/
@Inject
private ArticleRepository articleRepository;
/**
* Comment cache.
*/
@Inject
private CommentCache commentCache;
/**
* Public constructor.
*/
public CommentRepository() {
super(Comment.COMMENT);
}
@Override
public void remove(final String id) throws RepositoryException {
super.remove(id);
commentCache.removeComment(id);
}
@Override
public JSONObject get(final String id) throws RepositoryException {
JSONObject ret = commentCache.getComment(id);
if (null != ret) {
return ret;
}
ret = super.get(id);
if (null == ret) {
return null;
}
commentCache.putComment(ret);
return ret;
}
@Override
public void update(final String id, final JSONObject comment) throws RepositoryException {
super.update(id, comment);
comment.put(Keys.OBJECT_ID, id);
commentCache.putComment(comment);
}
/** /**
* Gets post comments recently with the specified fetch. * Gets post comments recently with the specified fetch.
* *
* @param fetchSize the specified fetch size * @param fetchSize the specified fetch size
* @return a list of comments recently, returns an empty list if not found * @return a list of comments recently, returns an empty list if not found
* @throws RepositoryException repository exception * @throws RepositoryException repository exception
*/ */
List<JSONObject> getRecentComments(final int fetchSize) public List<JSONObject> getRecentComments(final int fetchSize) throws RepositoryException {
throws RepositoryException; final Query query = new Query().
addSort(Keys.OBJECT_ID, SortDirection.DESCENDING).
setCurrentPageNum(1).setPageSize(fetchSize).setPageCount(1);
final List<JSONObject> ret = getList(query);
// Removes unpublished article related comments
removeForUnpublishedArticles(ret);
return ret;
}
/** /**
* Gets comments with the specified on id, current page number and * Gets comments with the specified on id, current page number and
* page size. * page size.
* *
* @param onId the specified on id * @param onId the specified on id
* @param currentPageNum the specified current page number * @param currentPageNum the specified current page number
* @param pageSize the specified page size * @param pageSize the specified page size
* @return a list of comments, returns an empty list if not found * @return a list of comments, returns an empty list if not found
* @throws RepositoryException repository exception * @throws RepositoryException repository exception
*/ */
List<JSONObject> getComments(final String onId, public List<JSONObject> getComments(final String onId, final int currentPageNum, final int pageSize) throws RepositoryException {
final int currentPageNum, final Query query = new Query().
final int pageSize) throws RepositoryException; addSort(Keys.OBJECT_ID, SortDirection.DESCENDING).
setFilter(new PropertyFilter(Comment.COMMENT_ON_ID, FilterOperator.EQUAL, onId)).
setCurrentPageNum(currentPageNum).setPageSize(pageSize).setPageCount(1);
return getList(query);
}
/** /**
* Removes comments with the specified on id. * Removes comments with the specified on id.
* *
* @param onId the specified on id * @param onId the specified on id
* @return removed count * @return removed count
* @throws RepositoryException repository exception * @throws RepositoryException repository exception
*/ */
int removeComments(final String onId) throws RepositoryException; public int removeComments(final String onId) throws RepositoryException {
final List<JSONObject> comments = getComments(onId, 1, Integer.MAX_VALUE);
for (final JSONObject comment : comments) {
final String commentId = comment.optString(Keys.OBJECT_ID);
remove(commentId);
}
LOGGER.log(Level.DEBUG, "Removed comments[onId={0}, removedCnt={1}]", onId, comments.size());
return comments.size();
}
/**
* Removes comments of unpublished articles for the specified comments.
*
* @param comments the specified comments
* @throws RepositoryException repository exception
*/
private void removeForUnpublishedArticles(final List<JSONObject> comments) throws RepositoryException {
LOGGER.debug("Removing unpublished articles' comments....");
final Iterator<JSONObject> iterator = comments.iterator();
while (iterator.hasNext()) {
final JSONObject comment = iterator.next();
final String commentOnType = comment.optString(Comment.COMMENT_ON_TYPE);
if (Article.ARTICLE.equals(commentOnType)) {
final String articleId = comment.optString(Comment.COMMENT_ON_ID);
if (!articleRepository.isPublished(articleId)) {
iterator.remove();
}
}
}
LOGGER.debug("Removed unpublished articles' comments....");
}
} }
...@@ -17,18 +17,29 @@ ...@@ -17,18 +17,29 @@
*/ */
package org.b3log.solo.repository; package org.b3log.solo.repository;
import org.b3log.latke.repository.Repository; import org.b3log.latke.Keys;
import org.b3log.latke.repository.RepositoryException; import org.b3log.latke.repository.*;
import org.b3log.latke.repository.annotation.Repository;
import org.b3log.solo.model.Link;
import org.json.JSONArray;
import org.json.JSONObject; import org.json.JSONObject;
/** /**
* Link repository. * Link repository.
* *
* @author <a href="http://88250.b3log.org">Liang Ding</a> * @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.0.0.3, Nov 2, 2011 * @version 1.0.0.4, Sep 30, 2018
* @since 0.3.1 * @since 0.3.1
*/ */
public interface LinkRepository extends Repository { @Repository
public class LinkRepository extends AbstractRepository {
/**
* Public constructor.
*/
public LinkRepository() {
super(Link.LINK);
}
/** /**
* Gets a link by the specified address. * Gets a link by the specified address.
...@@ -37,40 +48,97 @@ public interface LinkRepository extends Repository { ...@@ -37,40 +48,97 @@ public interface LinkRepository extends Repository {
* @return link, returns {@code null} if not found * @return link, returns {@code null} if not found
* @throws RepositoryException repository exception * @throws RepositoryException repository exception
*/ */
JSONObject getByAddress(final String address) throws RepositoryException; public JSONObject getByAddress(final String address) throws RepositoryException {
final Query query = new Query().setFilter(new PropertyFilter(Link.LINK_ADDRESS, FilterOperator.EQUAL, address)).setPageCount(1);
final JSONObject result = get(query);
final JSONArray array = result.optJSONArray(Keys.RESULTS);
if (0 == array.length()) {
return null;
}
return array.optJSONObject(0);
}
/** /**
* Gets the maximum order. * Gets the maximum order.
* *
* @return order number, returns {@code -1} if not found * @return order number, returns {@code -1} if not found
* @throws RepositoryException repository exception * @throws RepositoryException repository exception
*/ */
int getMaxOrder() throws RepositoryException; public int getMaxOrder() throws RepositoryException {
final Query query = new Query().addSort(Link.LINK_ORDER, SortDirection.DESCENDING);
final JSONObject result = get(query);
final JSONArray array = result.optJSONArray(Keys.RESULTS);
if (0 == array.length()) {
return -1;
}
return array.optJSONObject(0).optInt(Link.LINK_ORDER);
}
/** /**
* Gets the upper link of the link specified by the given id. * Gets the upper link of the link specified by the given id.
* *
* @param id the given id * @param id the given id
* @return upper link, returns {@code null} if not found * @return upper link, returns {@code null} if not found
* @throws RepositoryException repository exception * @throws RepositoryException repository exception
*/ */
JSONObject getUpper(final String id) throws RepositoryException; public JSONObject getUpper(final String id) throws RepositoryException {
final JSONObject link = get(id);
if (null == link) {
return null;
}
final Query query = new Query().setFilter(new PropertyFilter(Link.LINK_ORDER, FilterOperator.LESS_THAN, link.optInt(Link.LINK_ORDER))).
addSort(Link.LINK_ORDER, SortDirection.DESCENDING).setCurrentPageNum(1).setPageSize(1);
final JSONObject result = get(query);
final JSONArray array = result.optJSONArray(Keys.RESULTS);
if (1 != array.length()) {
return null;
}
return array.optJSONObject(0);
}
/** /**
* Gets the under link of the link specified by the given id. * Gets the under link of the link specified by the given id.
* *
* @param id the given id * @param id the given id
* @return under link, returns {@code null} if not found * @return under link, returns {@code null} if not found
* @throws RepositoryException repository exception * @throws RepositoryException repository exception
*/ */
JSONObject getUnder(final String id) throws RepositoryException; public JSONObject getUnder(final String id) throws RepositoryException {
final JSONObject link = get(id);
if (null == link) {
return null;
}
final Query query = new Query().setFilter(new PropertyFilter(Link.LINK_ORDER, FilterOperator.GREATER_THAN, link.optInt(Link.LINK_ORDER))).
addSort(Link.LINK_ORDER, SortDirection.ASCENDING).setCurrentPageNum(1).setPageSize(1);
final JSONObject result = get(query);
final JSONArray array = result.optJSONArray(Keys.RESULTS);
if (1 != array.length()) {
return null;
}
return array.optJSONObject(0);
}
/** /**
* Gets a link by the specified order. * Gets a link by the specified order.
* *
* @param order the specified order * @param order the specified order
* @return link, returns {@code null} if not found * @return link, returns {@code null} if not found
* @throws RepositoryException repository exception * @throws RepositoryException repository exception
*/ */
JSONObject getByOrder(final int order) throws RepositoryException; public JSONObject getByOrder(final int order) throws RepositoryException {
final Query query = new Query().setFilter(new PropertyFilter(Link.LINK_ORDER, FilterOperator.EQUAL, order));
final JSONObject result = get(query);
final JSONArray array = result.optJSONArray(Keys.RESULTS);
if (0 == array.length()) {
return null;
}
return array.optJSONObject(0);
}
} }
...@@ -17,18 +17,77 @@ ...@@ -17,18 +17,77 @@
*/ */
package org.b3log.solo.repository; package org.b3log.solo.repository;
import org.b3log.latke.repository.Repository; import org.b3log.latke.Keys;
import org.b3log.latke.repository.RepositoryException; import org.b3log.latke.ioc.Inject;
import org.b3log.latke.repository.*;
import org.b3log.latke.repository.annotation.Repository;
import org.b3log.solo.cache.OptionCache;
import org.b3log.solo.model.Option;
import org.json.JSONObject; import org.json.JSONObject;
import java.util.List;
/** /**
* Option repository. * Option repository.
* *
* @author <a href="http://88250.b3log.org">Liang Ding</a> * @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.1.0.0, Sep 19, 2018 * @version 1.1.0.1, Sep 30, 2018
* @since 0.6.0 * @since 0.6.0
*/ */
public interface OptionRepository extends Repository { @Repository
public class OptionRepository extends AbstractRepository {
/**
* Option cache.
*/
@Inject
private OptionCache optionCache;
/**
* Public constructor.
*/
public OptionRepository() {
super(Option.OPTION);
}
@Override
public void remove(final String id) throws RepositoryException {
final JSONObject option = get(id);
if (null == option) {
return;
}
super.remove(id);
optionCache.removeOption(id);
final String category = option.optString(Option.OPTION_CATEGORY);
optionCache.removeCategory(category);
}
@Override
public JSONObject get(final String id) throws RepositoryException {
JSONObject ret = optionCache.getOption(id);
if (null != ret) {
return ret;
}
ret = super.get(id);
if (null == ret) {
return null;
}
optionCache.putOption(ret);
return ret;
}
@Override
public void update(final String id, final JSONObject option) throws RepositoryException {
super.update(id, option);
option.put(Keys.OBJECT_ID, id);
optionCache.putOption(option);
}
/** /**
* Gets options with the specified category. * Gets options with the specified category.
...@@ -46,5 +105,25 @@ public interface OptionRepository extends Repository { ...@@ -46,5 +105,25 @@ public interface OptionRepository extends Repository {
* </pre>, returns {@code null} if not found * </pre>, returns {@code null} if not found
* @throws RepositoryException repository exception * @throws RepositoryException repository exception
*/ */
JSONObject getOptions(final String category) throws RepositoryException; public JSONObject getOptions(final String category) throws RepositoryException {
final JSONObject cached = optionCache.getCategory(category);
if (null != cached) {
return cached;
}
final JSONObject ret = new JSONObject();
try {
final List<JSONObject> options = getList(new Query().setFilter(new PropertyFilter(Option.OPTION_CATEGORY, FilterOperator.EQUAL, category)));
if (0 == options.size()) {
return null;
}
options.stream().forEach(option -> ret.put(option.optString(Keys.OBJECT_ID), option.opt(Option.OPTION_VALUE)));
optionCache.putCategory(category, ret);
return ret;
} catch (final Exception e) {
throw new RepositoryException(e);
}
}
} }
...@@ -17,8 +17,13 @@ ...@@ -17,8 +17,13 @@
*/ */
package org.b3log.solo.repository; package org.b3log.solo.repository;
import org.b3log.latke.repository.Repository; import org.b3log.latke.Keys;
import org.b3log.latke.repository.RepositoryException; import org.b3log.latke.ioc.Inject;
import org.b3log.latke.repository.*;
import org.b3log.latke.repository.annotation.Repository;
import org.b3log.solo.cache.PageCache;
import org.b3log.solo.model.Page;
import org.json.JSONArray;
import org.json.JSONObject; import org.json.JSONObject;
import java.util.List; import java.util.List;
...@@ -27,19 +32,74 @@ import java.util.List; ...@@ -27,19 +32,74 @@ import java.util.List;
* Page repository. * Page repository.
* *
* @author <a href="http://88250.b3log.org">Liang Ding</a> * @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.0.0.6, Dec 31, 2011 * @version 1.0.0.7, Sep 30, 2018
* @since 0.3.1 * @since 0.3.1
*/ */
public interface PageRepository extends Repository { @Repository
public class PageRepository extends AbstractRepository {
/**
* Page cache.
*/
@Inject
private PageCache pageCache;
/**
* Public constructor.
*/
public PageRepository() {
super(Page.PAGE);
}
@Override
public void remove(final String id) throws RepositoryException {
super.remove(id);
pageCache.removePage(id);
}
@Override
public JSONObject get(final String id) throws RepositoryException {
JSONObject ret = pageCache.getPage(id);
if (null != ret) {
return ret;
}
ret = super.get(id);
if (null == ret) {
return null;
}
pageCache.putPage(ret);
return ret;
}
@Override
public void update(final String id, final JSONObject page) throws RepositoryException {
super.update(id, page);
page.put(Keys.OBJECT_ID, id);
pageCache.putPage(page);
}
/** /**
* Gets a page by the specified permalink. * Gets a page by the specified permalink.
* *
* @param permalink the specified permalink * @param permalink the specified permalink
* @return page, returns {@code null} if not found * @return page, returns {@code null} if not found
* @throws RepositoryException repository exception * @throws RepositoryException repository exception
*/ */
JSONObject getByPermalink(final String permalink) throws RepositoryException; public JSONObject getByPermalink(final String permalink) throws RepositoryException {
final Query query = new Query().setFilter(new PropertyFilter(Page.PAGE_PERMALINK, FilterOperator.EQUAL, permalink)).setPageCount(1);
final JSONObject result = get(query);
final JSONArray array = result.optJSONArray(Keys.RESULTS);
if (0 == array.length()) {
return null;
}
return array.optJSONObject(0);
}
/** /**
* Gets the maximum order. * Gets the maximum order.
...@@ -47,34 +107,82 @@ public interface PageRepository extends Repository { ...@@ -47,34 +107,82 @@ public interface PageRepository extends Repository {
* @return order number, returns {@code -1} if not found * @return order number, returns {@code -1} if not found
* @throws RepositoryException repository exception * @throws RepositoryException repository exception
*/ */
int getMaxOrder() throws RepositoryException; public int getMaxOrder() throws RepositoryException {
final Query query = new Query().addSort(Page.PAGE_ORDER, SortDirection.DESCENDING).setPageCount(1);
final JSONObject result = get(query);
final JSONArray array = result.optJSONArray(Keys.RESULTS);
if (0 == array.length()) {
return -1;
}
return array.optJSONObject(0).optInt(Page.PAGE_ORDER);
}
/** /**
* Gets the upper page of the page specified by the given id. * Gets the upper page of the page specified by the given id.
* *
* @param id the given id * @param id the given id
* @return upper page, returns {@code null} if not found * @return upper page, returns {@code null} if not found
* @throws RepositoryException repository exception * @throws RepositoryException repository exception
*/ */
JSONObject getUpper(final String id) throws RepositoryException; public JSONObject getUpper(final String id) throws RepositoryException {
final JSONObject page = get(id);
if (null == page) {
return null;
}
final Query query = new Query().setFilter(new PropertyFilter(Page.PAGE_ORDER, FilterOperator.LESS_THAN, page.optInt(Page.PAGE_ORDER))).
addSort(Page.PAGE_ORDER, SortDirection.DESCENDING).setCurrentPageNum(1).setPageSize(1).setPageCount(1);
final JSONObject result = get(query);
final JSONArray array = result.optJSONArray(Keys.RESULTS);
if (1 != array.length()) {
return null;
}
return array.optJSONObject(0);
}
/** /**
* Gets the under page of the page specified by the given id. * Gets the under page of the page specified by the given id.
* *
* @param id the given id * @param id the given id
* @return under page, returns {@code null} if not found * @return under page, returns {@code null} if not found
* @throws RepositoryException repository exception * @throws RepositoryException repository exception
*/ */
JSONObject getUnder(final String id) throws RepositoryException; public JSONObject getUnder(final String id) throws RepositoryException {
final JSONObject page = get(id);
if (null == page) {
return null;
}
final Query query = new Query().setFilter(new PropertyFilter(Page.PAGE_ORDER, FilterOperator.GREATER_THAN, page.optInt(Page.PAGE_ORDER))).
addSort(Page.PAGE_ORDER, SortDirection.ASCENDING).setCurrentPageNum(1).setPageSize(1).setPageCount(1);
final JSONObject result = get(query);
final JSONArray array = result.optJSONArray(Keys.RESULTS);
if (1 != array.length()) {
return null;
}
return array.optJSONObject(0);
}
/** /**
* Gets a page by the specified order. * Gets a page by the specified order.
* *
* @param order the specified order * @param order the specified order
* @return page, returns {@code null} if not found * @return page, returns {@code null} if not found
* @throws RepositoryException repository exception * @throws RepositoryException repository exception
*/ */
JSONObject getByOrder(final int order) throws RepositoryException; public JSONObject getByOrder(final int order) throws RepositoryException {
final Query query = new Query().setFilter(new PropertyFilter(Page.PAGE_ORDER, FilterOperator.EQUAL, order)).setPageCount(1);
final JSONObject result = get(query);
final JSONArray array = result.optJSONArray(Keys.RESULTS);
if (0 == array.length()) {
return null;
}
return array.optJSONObject(0);
}
/** /**
* Gets pages. * Gets pages.
...@@ -82,5 +190,9 @@ public interface PageRepository extends Repository { ...@@ -82,5 +190,9 @@ public interface PageRepository extends Repository {
* @return a list of pages, returns an empty list if not found * @return a list of pages, returns an empty list if not found
* @throws RepositoryException repository exception * @throws RepositoryException repository exception
*/ */
List<JSONObject> getPages() throws RepositoryException; public List<JSONObject> getPages() throws RepositoryException {
final Query query = new Query().addSort(Page.PAGE_ORDER, SortDirection.ASCENDING).setPageCount(1);
return getList(query);
}
} }
...@@ -17,13 +17,24 @@ ...@@ -17,13 +17,24 @@
*/ */
package org.b3log.solo.repository; package org.b3log.solo.repository;
import org.b3log.latke.repository.Repository; import org.b3log.latke.model.Plugin;
import org.b3log.latke.repository.AbstractRepository;
import org.b3log.latke.repository.annotation.Repository;
/** /**
* Plugin repository. * Plugin repository.
* *
* @author <a href="http://88250.b3log.org">Liang Ding</a> * @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.0.0.0, Jan 24, 2013 * @version 1.0.0.1, Sep 30, 2018
* @since 0.3.1 * @since 0.3.1
*/ */
public interface PluginRepository extends Repository {} @Repository
public class PluginRepository extends AbstractRepository {
/**
* Public constructor.
*/
public PluginRepository() {
super(Plugin.PLUGIN);
}
}
...@@ -17,8 +17,11 @@ ...@@ -17,8 +17,11 @@
*/ */
package org.b3log.solo.repository; package org.b3log.solo.repository;
import org.b3log.latke.repository.Repository; import org.b3log.latke.Keys;
import org.b3log.latke.repository.RepositoryException; import org.b3log.latke.repository.*;
import org.b3log.latke.repository.annotation.Repository;
import org.b3log.solo.model.Article;
import org.b3log.solo.model.Tag;
import org.json.JSONObject; import org.json.JSONObject;
import java.util.List; import java.util.List;
...@@ -27,10 +30,18 @@ import java.util.List; ...@@ -27,10 +30,18 @@ import java.util.List;
* Tag-Article repository. * Tag-Article repository.
* *
* @author <a href="http://88250.b3log.org">Liang Ding</a> * @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.0.0.3, Nov 8, 2011 * @version 1.0.0.4, Sep 30, 2018
* @since 0.3.1 * @since 0.3.1
*/ */
public interface TagArticleRepository extends Repository { @Repository
public class TagArticleRepository extends AbstractRepository {
/**
* Public constructor.
*/
public TagArticleRepository() {
super(Tag.TAG + "_" + Article.ARTICLE);
}
/** /**
* Gets tag-article relations by the specified article id. * Gets tag-article relations by the specified article id.
...@@ -46,17 +57,21 @@ public interface TagArticleRepository extends Repository { ...@@ -46,17 +57,21 @@ public interface TagArticleRepository extends Repository {
* </pre> * </pre>
* @throws RepositoryException repository exception * @throws RepositoryException repository exception
*/ */
List<JSONObject> getByArticleId(final String articleId) public List<JSONObject> getByArticleId(final String articleId) throws RepositoryException {
throws RepositoryException; final Query query = new Query().setFilter(new PropertyFilter(Article.ARTICLE + "_" + Keys.OBJECT_ID, FilterOperator.EQUAL, articleId)).
setPageCount(1);
return getList(query);
}
/** /**
* Gets tag-article relations by the specified tag id. * Gets tag-article relations by the specified tag id.
* *
* @param tagId the specified tag id * @param tagId the specified tag id
* @param currentPageNum the specified current page number, MUST greater * @param currentPageNum the specified current page number, MUST greater
* then {@code 0} * then {@code 0}
* @param pageSize the specified page size(count of a page contains objects), * @param pageSize the specified page size(count of a page contains objects),
* MUST greater then {@code 0} * MUST greater then {@code 0}
* @return for example * @return for example
* <pre> * <pre>
* { * {
...@@ -72,7 +87,11 @@ public interface TagArticleRepository extends Repository { ...@@ -72,7 +87,11 @@ public interface TagArticleRepository extends Repository {
* </pre> * </pre>
* @throws RepositoryException repository exception * @throws RepositoryException repository exception
*/ */
JSONObject getByTagId(final String tagId, public JSONObject getByTagId(final String tagId, final int currentPageNum, final int pageSize) throws RepositoryException {
final int currentPageNum, final Query query = new Query().setFilter(new PropertyFilter(Tag.TAG + "_" + Keys.OBJECT_ID, FilterOperator.EQUAL, tagId)).
final int pageSize) throws RepositoryException; addSort(Article.ARTICLE + "_" + Keys.OBJECT_ID, SortDirection.DESCENDING).
setCurrentPageNum(currentPageNum).setPageSize(pageSize).setPageCount(1);
return get(query);
}
} }
...@@ -17,31 +17,63 @@ ...@@ -17,31 +17,63 @@
*/ */
package org.b3log.solo.repository; package org.b3log.solo.repository;
import org.b3log.latke.repository.Repository; import org.b3log.latke.Keys;
import org.b3log.latke.repository.RepositoryException; import org.b3log.latke.ioc.Inject;
import org.b3log.latke.repository.*;
import org.b3log.latke.repository.annotation.Repository;
import org.b3log.solo.model.Tag;
import org.json.JSONArray;
import org.json.JSONObject; import org.json.JSONObject;
import java.text.Collator;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List; import java.util.List;
/** /**
* Tag repository. * Tag repository.
* *
* @author <a href="http://88250.b3log.org">Liang Ding</a> * @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.0.0.1, Aug 12, 2010 * @version 1.0.0.2, Sep 30, 2018
* @since 0.3.1 * @since 0.3.1
*/ */
public interface TagRepository extends Repository { @Repository
public class TagRepository extends AbstractRepository {
/**
* Public constructor.
*/
public TagRepository() {
super(Tag.TAG);
}
/**
* Tag-Article relation repository.
*/
@Inject
private TagArticleRepository tagArticleRepository;
/** /**
* Gets tags of an article specified by the article id. * Gets tags of an article specified by the article id.
* *
* @param articleId the specified article id * @param articleId the specified article id
* @return a list of tags of the specified article, returns an empty list * @return a list of tags of the specified article, returns an empty list
* if not found * if not found
* @throws RepositoryException repository exception * @throws RepositoryException repository exception
*/ */
List<JSONObject> getByArticleId(final String articleId) public List<JSONObject> getByArticleId(final String articleId) throws RepositoryException {
throws RepositoryException; final List<JSONObject> ret = new ArrayList<>();
final List<JSONObject> tagArticleRelations = tagArticleRepository.getByArticleId(articleId);
for (final JSONObject tagArticleRelation : tagArticleRelations) {
final String tagId = tagArticleRelation.optString(Tag.TAG + "_" + Keys.OBJECT_ID);
final JSONObject tag = get(tagId);
ret.add(tag);
}
return ret;
}
/** /**
* Gets a tag by the specified tag title. * Gets a tag by the specified tag title.
...@@ -50,7 +82,17 @@ public interface TagRepository extends Repository { ...@@ -50,7 +82,17 @@ public interface TagRepository extends Repository {
* @return a tag, {@code null} if not found * @return a tag, {@code null} if not found
* @throws RepositoryException repository exception * @throws RepositoryException repository exception
*/ */
JSONObject getByTitle(final String tagTitle) throws RepositoryException; public JSONObject getByTitle(final String tagTitle) throws RepositoryException {
final Query query = new Query().setFilter(new PropertyFilter(Tag.TAG_TITLE, FilterOperator.EQUAL, tagTitle)).setPageCount(1);
final JSONObject result = get(query);
final JSONArray array = result.optJSONArray(Keys.RESULTS);
if (0 == array.length()) {
return null;
}
return array.optJSONObject(0);
}
/** /**
* Gets most used tags with the specified number. * Gets most used tags with the specified number.
...@@ -59,5 +101,12 @@ public interface TagRepository extends Repository { ...@@ -59,5 +101,12 @@ public interface TagRepository extends Repository {
* @return a list of most used tags, returns an empty list if not found * @return a list of most used tags, returns an empty list if not found
* @throws RepositoryException repository exception * @throws RepositoryException repository exception
*/ */
List<JSONObject> getMostUsedTags(final int num) throws RepositoryException; public List<JSONObject> getMostUsedTags(final int num) throws RepositoryException {
final Query query = new Query().addSort(Tag.TAG_PUBLISHED_REFERENCE_COUNT, SortDirection.DESCENDING).
setCurrentPageNum(1).setPageSize(num).setPageCount(1);
final List<JSONObject> tagJoList = getList(query);
Collections.sort(tagJoList, (o1, o2) -> Collator.getInstance(java.util.Locale.CHINA).compare(o1.optString(Tag.TAG_TITLE), o2.optString(Tag.TAG_TITLE)));
return tagJoList;
}
} }
...@@ -17,18 +17,76 @@ ...@@ -17,18 +17,76 @@
*/ */
package org.b3log.solo.repository; package org.b3log.solo.repository;
import org.b3log.latke.repository.Repository; import org.b3log.latke.Keys;
import org.b3log.latke.repository.RepositoryException; import org.b3log.latke.ioc.Inject;
import org.b3log.latke.model.Role;
import org.b3log.latke.model.User;
import org.b3log.latke.repository.*;
import org.b3log.latke.repository.annotation.Repository;
import org.b3log.solo.cache.UserCache;
import org.json.JSONArray;
import org.json.JSONObject; import org.json.JSONObject;
import java.util.List;
/** /**
* User repository. * User repository.
* *
* @author <a href="http://88250.b3log.org">Liang Ding</a> * @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.1.0.0, Sep 21, 2018 * @version 1.1.0.1, Sep 30, 2018
* @since 0.3.1 * @since 0.3.1
*/ */
public interface UserRepository extends Repository { @Repository
public class UserRepository extends AbstractRepository {
/**
* User cache.
*/
@Inject
private UserCache userCache;
/**
* Public constructor.
*/
public UserRepository() {
super(User.USER);
}
@Override
public void remove(final String id) throws RepositoryException {
super.remove(id);
userCache.removeUser(id);
}
@Override
public JSONObject get(final String id) throws RepositoryException {
JSONObject ret = userCache.getUser(id);
if (null != ret) {
return ret;
}
ret = super.get(id);
if (null == ret) {
return null;
}
userCache.putUser(ret);
return ret;
}
@Override
public void update(final String id, final JSONObject user) throws RepositoryException {
super.update(id, user);
user.put(Keys.OBJECT_ID, id);
userCache.putUser(user);
if (Role.ADMIN_ROLE.equals(user.optString(User.USER_ROLE))) {
userCache.putAdmin(user);
}
}
/** /**
* Gets a user by the specified username. * Gets a user by the specified username.
...@@ -37,7 +95,16 @@ public interface UserRepository extends Repository { ...@@ -37,7 +95,16 @@ public interface UserRepository extends Repository {
* @return user, returns {@code null} if not found * @return user, returns {@code null} if not found
* @throws RepositoryException repository exception * @throws RepositoryException repository exception
*/ */
JSONObject getByUserName(final String userName) throws RepositoryException; public JSONObject getByUserName(final String userName) throws RepositoryException {
final Query query = new Query().setPageCount(1).
setFilter(new PropertyFilter(User.USER_NAME, FilterOperator.EQUAL, userName));
final List<JSONObject> users = getList(query);
if (users.isEmpty()) {
return null;
}
return users.get(0);
}
/** /**
* Gets a user by the specified email. * Gets a user by the specified email.
...@@ -46,7 +113,25 @@ public interface UserRepository extends Repository { ...@@ -46,7 +113,25 @@ public interface UserRepository extends Repository {
* @return user, returns {@code null} if not found * @return user, returns {@code null} if not found
* @throws RepositoryException repository exception * @throws RepositoryException repository exception
*/ */
JSONObject getByEmail(final String email) throws RepositoryException; public JSONObject getByEmail(final String email) throws RepositoryException {
JSONObject ret = userCache.getUserByEmail(email);
if (null != ret) {
return ret;
}
final Query query = new Query().setPageCount(1).
setFilter(new PropertyFilter(User.USER_EMAIL, FilterOperator.EQUAL, email.toLowerCase().trim()));
final JSONObject result = get(query);
final JSONArray array = result.optJSONArray(Keys.RESULTS);
if (0 == array.length()) {
return null;
}
ret = array.optJSONObject(0);
userCache.putUser(ret);
return ret;
}
/** /**
* Gets the administrator user. * Gets the administrator user.
...@@ -54,5 +139,22 @@ public interface UserRepository extends Repository { ...@@ -54,5 +139,22 @@ public interface UserRepository extends Repository {
* @return administrator user, returns {@code null} if not found or error * @return administrator user, returns {@code null} if not found or error
* @throws RepositoryException repository exception * @throws RepositoryException repository exception
*/ */
JSONObject getAdmin() throws RepositoryException; public JSONObject getAdmin() throws RepositoryException {
JSONObject ret = userCache.getAdmin();
if (null != ret) {
return ret;
}
final Query query = new Query().setFilter(new PropertyFilter(User.USER_ROLE, FilterOperator.EQUAL, Role.ADMIN_ROLE)).setPageCount(1);
final JSONObject result = get(query);
final JSONArray array = result.optJSONArray(Keys.RESULTS);
if (0 == array.length()) {
return null;
}
ret = array.optJSONObject(0);
userCache.putAdmin(ret);
return ret;
}
} }
/*
* Solo - A small and beautiful blogging system written in Java.
* Copyright (c) 2010-2018, b3log.org & hacpai.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package org.b3log.solo.repository.impl;
import org.b3log.latke.Keys;
import org.b3log.latke.repository.*;
import org.b3log.latke.repository.annotation.Repository;
import org.b3log.solo.model.Category;
import org.b3log.solo.model.Tag;
import org.b3log.solo.repository.CategoryRepository;
import org.json.JSONArray;
import org.json.JSONObject;
import java.text.Collator;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
/**
* Category repository.
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.1.0.2, Apr 19, 2017
* @since 2.0.0
*/
@Repository
public class CategoryRepositoryImpl extends AbstractRepository implements CategoryRepository {
/**
* Public constructor.
*/
public CategoryRepositoryImpl() {
super(Category.CATEGORY);
}
@Override
public JSONObject getByTitle(final String categoryTitle) throws RepositoryException {
final Query query = new Query().
setFilter(new PropertyFilter(Category.CATEGORY_TITLE, FilterOperator.EQUAL, categoryTitle)).
setPageCount(1);
final JSONObject result = get(query);
final JSONArray array = result.optJSONArray(Keys.RESULTS);
if (0 == array.length()) {
return null;
}
return array.optJSONObject(0);
}
@Override
public JSONObject getByURI(final String categoryURI) throws RepositoryException {
final Query query = new Query().
setFilter(new PropertyFilter(Category.CATEGORY_URI, FilterOperator.EQUAL, categoryURI)).
setPageCount(1);
final JSONObject result = get(query);
final JSONArray array = result.optJSONArray(Keys.RESULTS);
if (0 == array.length()) {
return null;
}
return array.optJSONObject(0);
}
@Override
public int getMaxOrder() throws RepositoryException {
final Query query = new Query();
query.addSort(Category.CATEGORY_ORDER, SortDirection.DESCENDING);
final JSONObject result = get(query);
final JSONArray array = result.optJSONArray(Keys.RESULTS);
if (0 == array.length()) {
return -1;
}
return array.optJSONObject(0).optInt(Category.CATEGORY_ORDER);
}
@Override
public JSONObject getByOrder(final int order) throws RepositoryException {
final Query query = new Query();
query.setFilter(new PropertyFilter(Category.CATEGORY_ORDER, FilterOperator.EQUAL, order));
final JSONObject result = get(query);
final JSONArray array = result.optJSONArray(Keys.RESULTS);
if (0 == array.length()) {
return null;
}
return array.optJSONObject(0);
}
@Override
public List<JSONObject> getMostUsedCategories(final int num) throws RepositoryException {
final Query query = new Query().addSort(Category.CATEGORY_ORDER, SortDirection.ASCENDING).
setCurrentPageNum(1).setPageSize(num).setPageCount(1);
final List<JSONObject> ret = getList(query);
sortJSONCategoryList(ret);
return ret;
}
@Override
public JSONObject getUpper(final String id) throws RepositoryException {
final JSONObject category = get(id);
if (null == category) {
return null;
}
final Query query = new Query();
query.setFilter(new PropertyFilter(Category.CATEGORY_ORDER, FilterOperator.LESS_THAN, category.optInt(Category.CATEGORY_ORDER))).
addSort(Category.CATEGORY_ORDER, SortDirection.DESCENDING);
query.setCurrentPageNum(1);
query.setPageSize(1);
final JSONObject result = get(query);
final JSONArray array = result.optJSONArray(Keys.RESULTS);
if (1 != array.length()) {
return null;
}
return array.optJSONObject(0);
}
@Override
public JSONObject getUnder(final String id) throws RepositoryException {
final JSONObject category = get(id);
if (null == category) {
return null;
}
final Query query = new Query();
query.setFilter(new PropertyFilter(Category.CATEGORY_ORDER, FilterOperator.GREATER_THAN, category.optInt(Category.CATEGORY_ORDER))).
addSort(Category.CATEGORY_ORDER, SortDirection.ASCENDING);
query.setCurrentPageNum(1);
query.setPageSize(1);
final JSONObject result = get(query);
final JSONArray array = result.optJSONArray(Keys.RESULTS);
if (1 != array.length()) {
return null;
}
return array.optJSONObject(0);
}
private void sortJSONCategoryList(final List<JSONObject> tagJoList) {
Collections.sort(tagJoList, new Comparator<JSONObject>() {
@Override
public int compare(final JSONObject o1, final JSONObject o2) {
return Collator.getInstance(java.util.Locale.CHINA).
compare(o1.optString(Tag.TAG_TITLE), o2.optString(Tag.TAG_TITLE));
}
});
}
}
/*
* Solo - A small and beautiful blogging system written in Java.
* Copyright (c) 2010-2018, b3log.org & hacpai.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package org.b3log.solo.repository.impl;
import org.b3log.latke.Keys;
import org.b3log.latke.repository.*;
import org.b3log.latke.repository.annotation.Repository;
import org.b3log.solo.model.Category;
import org.b3log.solo.model.Tag;
import org.b3log.solo.repository.CategoryTagRepository;
import org.json.JSONArray;
import org.json.JSONObject;
/**
* Category-Tag relation repository.
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.1.0.0, Mar 31, 2017
* @since 2.0.0
*/
@Repository
public class CategoryTagRepositoryImpl extends AbstractRepository implements CategoryTagRepository {
/**
* Public constructor.
*/
public CategoryTagRepositoryImpl() {
super(Category.CATEGORY + "_" + Tag.TAG);
}
@Override
public JSONObject getByCategoryId(final String categoryId, final int currentPageNum, final int pageSize)
throws RepositoryException {
final Query query = new Query().
setFilter(new PropertyFilter(Category.CATEGORY + "_" + Keys.OBJECT_ID, FilterOperator.EQUAL, categoryId)).
setCurrentPageNum(currentPageNum).setPageSize(pageSize).setPageCount(1);
return get(query);
}
@Override
public JSONObject getByTagId(final String tagId, final int currentPageNum, final int pageSize)
throws RepositoryException {
final Query query = new Query().
setFilter(new PropertyFilter(Tag.TAG + "_" + Keys.OBJECT_ID, FilterOperator.EQUAL, tagId)).
setCurrentPageNum(currentPageNum).setPageSize(pageSize).setPageCount(1);
return get(query);
}
@Override
public void removeByCategoryId(final String categoryId) throws RepositoryException {
final Query query = new Query().
setFilter(new PropertyFilter(Category.CATEGORY + "_" + Keys.OBJECT_ID, FilterOperator.EQUAL, categoryId));
final JSONArray relations = get(query).optJSONArray(Keys.RESULTS);
for (int i = 0; i < relations.length(); i++) {
final JSONObject rel = relations.optJSONObject(i);
remove(rel.optString(Keys.OBJECT_ID));
}
}
@Override
public void removeByTagId(final String tagId) throws RepositoryException {
final Query query = new Query().
setFilter(new PropertyFilter(Tag.TAG + "_" + Keys.OBJECT_ID, FilterOperator.EQUAL, tagId));
final JSONArray relations = get(query).optJSONArray(Keys.RESULTS);
for (int i = 0; i < relations.length(); i++) {
final JSONObject rel = relations.optJSONObject(i);
remove(rel.optString(Keys.OBJECT_ID));
}
}
}
/*
* Solo - A small and beautiful blogging system written in Java.
* Copyright (c) 2010-2018, b3log.org & hacpai.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package org.b3log.solo.repository.impl;
import org.b3log.latke.Keys;
import org.b3log.latke.ioc.Inject;
import org.b3log.latke.logging.Level;
import org.b3log.latke.logging.Logger;
import org.b3log.latke.repository.*;
import org.b3log.latke.repository.annotation.Repository;
import org.b3log.solo.cache.CommentCache;
import org.b3log.solo.model.Article;
import org.b3log.solo.model.Comment;
import org.b3log.solo.repository.ArticleRepository;
import org.b3log.solo.repository.CommentRepository;
import org.json.JSONObject;
import java.util.Iterator;
import java.util.List;
/**
* Comment repository.
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.0.0.10, Aug 27, 2018
* @since 0.3.1
*/
@Repository
public class CommentRepositoryImpl extends AbstractRepository implements CommentRepository {
/**
* Logger.
*/
private static final Logger LOGGER = Logger.getLogger(CommentRepositoryImpl.class);
/**
* Article repository.
*/
@Inject
private ArticleRepository articleRepository;
/**
* Comment cache.
*/
@Inject
private CommentCache commentCache;
/**
* Public constructor.
*/
public CommentRepositoryImpl() {
super(Comment.COMMENT);
}
@Override
public void remove(final String id) throws RepositoryException {
super.remove(id);
commentCache.removeComment(id);
}
@Override
public JSONObject get(final String id) throws RepositoryException {
JSONObject ret = commentCache.getComment(id);
if (null != ret) {
return ret;
}
ret = super.get(id);
if (null == ret) {
return null;
}
commentCache.putComment(ret);
return ret;
}
@Override
public void update(final String id, final JSONObject comment) throws RepositoryException {
super.update(id, comment);
comment.put(Keys.OBJECT_ID, id);
commentCache.putComment(comment);
}
@Override
public int removeComments(final String onId) throws RepositoryException {
final List<JSONObject> comments = getComments(onId, 1, Integer.MAX_VALUE);
for (final JSONObject comment : comments) {
final String commentId = comment.optString(Keys.OBJECT_ID);
remove(commentId);
}
LOGGER.log(Level.DEBUG, "Removed comments[onId={0}, removedCnt={1}]", onId, comments.size());
return comments.size();
}
@Override
public List<JSONObject> getComments(final String onId, final int currentPageNum, final int pageSize)
throws RepositoryException {
final Query query = new Query().
addSort(Keys.OBJECT_ID, SortDirection.DESCENDING).
setFilter(new PropertyFilter(Comment.COMMENT_ON_ID, FilterOperator.EQUAL, onId)).
setCurrentPageNum(currentPageNum).setPageSize(pageSize).setPageCount(1);
return getList(query);
}
@Override
public List<JSONObject> getRecentComments(final int num) throws RepositoryException {
final Query query = new Query().
addSort(Keys.OBJECT_ID, SortDirection.DESCENDING).
setCurrentPageNum(1).setPageSize(num).setPageCount(1);
final List<JSONObject> ret = getList(query);
// Removes unpublished article related comments
removeForUnpublishedArticles(ret);
return ret;
}
/**
* Removes comments of unpublished articles for the specified comments.
*
* @param comments the specified comments
* @throws RepositoryException repository exception
*/
private void removeForUnpublishedArticles(final List<JSONObject> comments) throws RepositoryException {
LOGGER.debug("Removing unpublished articles' comments....");
final Iterator<JSONObject> iterator = comments.iterator();
while (iterator.hasNext()) {
final JSONObject comment = iterator.next();
final String commentOnType = comment.optString(Comment.COMMENT_ON_TYPE);
if (Article.ARTICLE.equals(commentOnType)) {
final String articleId = comment.optString(Comment.COMMENT_ON_ID);
if (!articleRepository.isPublished(articleId)) {
iterator.remove();
}
}
}
LOGGER.debug("Removed unpublished articles' comments....");
}
/**
* Sets the article repository with the specified article repository.
*
* @param articleRepository the specified article repository
*/
public void setArticleRepository(final ArticleRepository articleRepository) {
this.articleRepository = articleRepository;
}
}
/*
* Solo - A small and beautiful blogging system written in Java.
* Copyright (c) 2010-2018, b3log.org & hacpai.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package org.b3log.solo.repository.impl;
import org.b3log.latke.Keys;
import org.b3log.latke.repository.*;
import org.b3log.latke.repository.annotation.Repository;
import org.b3log.solo.model.Link;
import org.b3log.solo.repository.LinkRepository;
import org.json.JSONArray;
import org.json.JSONObject;
/**
* Link repository.
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.0.0.5, Nov 10, 2011
* @since 0.3.1
*/
@Repository
public class LinkRepositoryImpl extends AbstractRepository implements LinkRepository {
/**
* Public constructor.
*/
public LinkRepositoryImpl() {
super(Link.LINK);
}
@Override
public JSONObject getByAddress(final String address) throws RepositoryException {
final Query query = new Query().setFilter(new PropertyFilter(Link.LINK_ADDRESS, FilterOperator.EQUAL, address)).setPageCount(1);
final JSONObject result = get(query);
final JSONArray array = result.optJSONArray(Keys.RESULTS);
if (0 == array.length()) {
return null;
}
return array.optJSONObject(0);
}
@Override
public int getMaxOrder() throws RepositoryException {
final Query query = new Query();
query.addSort(Link.LINK_ORDER, SortDirection.DESCENDING);
final JSONObject result = get(query);
final JSONArray array = result.optJSONArray(Keys.RESULTS);
if (0 == array.length()) {
return -1;
}
return array.optJSONObject(0).optInt(Link.LINK_ORDER);
}
@Override
public JSONObject getByOrder(final int order) throws RepositoryException {
final Query query = new Query();
query.setFilter(new PropertyFilter(Link.LINK_ORDER, FilterOperator.EQUAL, order));
final JSONObject result = get(query);
final JSONArray array = result.optJSONArray(Keys.RESULTS);
if (0 == array.length()) {
return null;
}
return array.optJSONObject(0);
}
@Override
public JSONObject getUpper(final String id) throws RepositoryException {
final JSONObject link = get(id);
if (null == link) {
return null;
}
final Query query = new Query();
query.setFilter(new PropertyFilter(Link.LINK_ORDER, FilterOperator.LESS_THAN, link.optInt(Link.LINK_ORDER))).addSort(Link.LINK_ORDER,
SortDirection.DESCENDING);
query.setCurrentPageNum(1);
query.setPageSize(1);
final JSONObject result = get(query);
final JSONArray array = result.optJSONArray(Keys.RESULTS);
if (1 != array.length()) {
return null;
}
return array.optJSONObject(0);
}
@Override
public JSONObject getUnder(final String id) throws RepositoryException {
final JSONObject link = get(id);
if (null == link) {
return null;
}
final Query query = new Query();
query.setFilter(new PropertyFilter(Link.LINK_ORDER, FilterOperator.GREATER_THAN, link.optInt(Link.LINK_ORDER))).addSort(
Link.LINK_ORDER, SortDirection.ASCENDING);
query.setCurrentPageNum(1);
query.setPageSize(1);
final JSONObject result = get(query);
final JSONArray array = result.optJSONArray(Keys.RESULTS);
if (1 != array.length()) {
return null;
}
return array.optJSONObject(0);
}
}
/*
* Solo - A small and beautiful blogging system written in Java.
* Copyright (c) 2010-2018, b3log.org & hacpai.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package org.b3log.solo.repository.impl;
import org.b3log.latke.Keys;
import org.b3log.latke.ioc.Inject;
import org.b3log.latke.repository.*;
import org.b3log.latke.repository.annotation.Repository;
import org.b3log.solo.cache.OptionCache;
import org.b3log.solo.model.Option;
import org.b3log.solo.repository.OptionRepository;
import org.json.JSONObject;
import java.util.List;
/**
* Option repository.
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.0.0.2, Sep 19, 2018
* @since 0.6.0
*/
@Repository
public class OptionRepositoryImpl extends AbstractRepository implements OptionRepository {
/**
* Option cache.
*/
@Inject
private OptionCache optionCache;
/**
* Public constructor.
*/
public OptionRepositoryImpl() {
super(Option.OPTION);
}
@Override
public void remove(final String id) throws RepositoryException {
final JSONObject option = get(id);
if (null == option) {
return;
}
super.remove(id);
optionCache.removeOption(id);
final String category = option.optString(Option.OPTION_CATEGORY);
optionCache.removeCategory(category);
}
@Override
public JSONObject get(final String id) throws RepositoryException {
JSONObject ret = optionCache.getOption(id);
if (null != ret) {
return ret;
}
ret = super.get(id);
if (null == ret) {
return null;
}
optionCache.putOption(ret);
return ret;
}
@Override
public void update(final String id, final JSONObject option) throws RepositoryException {
super.update(id, option);
option.put(Keys.OBJECT_ID, id);
optionCache.putOption(option);
}
@Override
public JSONObject getOptions(final String category) throws RepositoryException {
final JSONObject cached = optionCache.getCategory(category);
if (null != cached) {
return cached;
}
final JSONObject ret = new JSONObject();
try {
final List<JSONObject> options = getList(new Query().setFilter(new PropertyFilter(Option.OPTION_CATEGORY, FilterOperator.EQUAL, category)));
if (0 == options.size()) {
return null;
}
options.stream().forEach(option -> ret.put(option.optString(Keys.OBJECT_ID), option.opt(Option.OPTION_VALUE)));
optionCache.putCategory(category, ret);
return ret;
} catch (final Exception e) {
throw new RepositoryException(e);
}
}
}
/*
* Solo - A small and beautiful blogging system written in Java.
* Copyright (c) 2010-2018, b3log.org & hacpai.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package org.b3log.solo.repository.impl;
import org.b3log.latke.Keys;
import org.b3log.latke.ioc.Inject;
import org.b3log.latke.repository.*;
import org.b3log.latke.repository.annotation.Repository;
import org.b3log.solo.cache.PageCache;
import org.b3log.solo.model.Page;
import org.b3log.solo.repository.PageRepository;
import org.json.JSONArray;
import org.json.JSONObject;
import java.util.List;
/**
* Page repository.
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.1.0.10, Aug 27, 2018
* @since 0.3.1
*/
@Repository
public class PageRepositoryImpl extends AbstractRepository implements PageRepository {
/**
* Page cache.
*/
@Inject
private PageCache pageCache;
/**
* Public constructor.
*/
public PageRepositoryImpl() {
super(Page.PAGE);
}
@Override
public void remove(final String id) throws RepositoryException {
super.remove(id);
pageCache.removePage(id);
}
@Override
public JSONObject get(final String id) throws RepositoryException {
JSONObject ret = pageCache.getPage(id);
if (null != ret) {
return ret;
}
ret = super.get(id);
if (null == ret) {
return null;
}
pageCache.putPage(ret);
return ret;
}
@Override
public void update(final String id, final JSONObject page) throws RepositoryException {
super.update(id, page);
page.put(Keys.OBJECT_ID, id);
pageCache.putPage(page);
}
@Override
public JSONObject getByPermalink(final String permalink) throws RepositoryException {
final Query query = new Query().setFilter(new PropertyFilter(Page.PAGE_PERMALINK, FilterOperator.EQUAL, permalink)).setPageCount(1);
final JSONObject result = get(query);
final JSONArray array = result.optJSONArray(Keys.RESULTS);
if (0 == array.length()) {
return null;
}
return array.optJSONObject(0);
}
@Override
public int getMaxOrder() throws RepositoryException {
final Query query = new Query().addSort(Page.PAGE_ORDER, SortDirection.DESCENDING).setPageCount(1);
final JSONObject result = get(query);
final JSONArray array = result.optJSONArray(Keys.RESULTS);
if (0 == array.length()) {
return -1;
}
return array.optJSONObject(0).optInt(Page.PAGE_ORDER);
}
@Override
public JSONObject getUpper(final String id) throws RepositoryException {
final JSONObject page = get(id);
if (null == page) {
return null;
}
final Query query = new Query().setFilter(new PropertyFilter(Page.PAGE_ORDER, FilterOperator.LESS_THAN, page.optInt(Page.PAGE_ORDER))).
addSort(Page.PAGE_ORDER, SortDirection.DESCENDING).setCurrentPageNum(1).setPageSize(1).setPageCount(1);
final JSONObject result = get(query);
final JSONArray array = result.optJSONArray(Keys.RESULTS);
if (1 != array.length()) {
return null;
}
return array.optJSONObject(0);
}
@Override
public JSONObject getUnder(final String id) throws RepositoryException {
final JSONObject page = get(id);
if (null == page) {
return null;
}
final Query query = new Query().setFilter(new PropertyFilter(Page.PAGE_ORDER, FilterOperator.GREATER_THAN, page.optInt(Page.PAGE_ORDER))).
addSort(Page.PAGE_ORDER, SortDirection.ASCENDING).setCurrentPageNum(1).setPageSize(1).setPageCount(1);
final JSONObject result = get(query);
final JSONArray array = result.optJSONArray(Keys.RESULTS);
if (1 != array.length()) {
return null;
}
return array.optJSONObject(0);
}
@Override
public JSONObject getByOrder(final int order) throws RepositoryException {
final Query query = new Query().setFilter(new PropertyFilter(Page.PAGE_ORDER, FilterOperator.EQUAL, order)).setPageCount(1);
final JSONObject result = get(query);
final JSONArray array = result.optJSONArray(Keys.RESULTS);
if (0 == array.length()) {
return null;
}
return array.optJSONObject(0);
}
@Override
public List<JSONObject> getPages() throws RepositoryException {
final Query query = new Query().addSort(Page.PAGE_ORDER, SortDirection.ASCENDING).setPageCount(1);
return getList(query);
}
}
/*
* Solo - A small and beautiful blogging system written in Java.
* Copyright (c) 2010-2018, b3log.org & hacpai.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package org.b3log.solo.repository.impl;
import org.b3log.latke.model.Plugin;
import org.b3log.latke.repository.AbstractRepository;
import org.b3log.latke.repository.annotation.Repository;
import org.b3log.solo.repository.PluginRepository;
/**
* Plugin repository.
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.0.0.0, Jul 21, 2011
* @since 0.3.1
*/
@Repository
public class PluginRepositoryImpl extends AbstractRepository implements PluginRepository {
/**
* Public constructor.
*/
public PluginRepositoryImpl() {
super(Plugin.PLUGIN);
}
}
/*
* Solo - A small and beautiful blogging system written in Java.
* Copyright (c) 2010-2018, b3log.org & hacpai.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package org.b3log.solo.repository.impl;
import org.b3log.latke.Keys;
import org.b3log.latke.repository.*;
import org.b3log.latke.repository.annotation.Repository;
import org.b3log.solo.model.Article;
import org.b3log.solo.model.Tag;
import org.b3log.solo.repository.TagArticleRepository;
import org.json.JSONObject;
import java.util.List;
/**
* Tag-Article relation repository.
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.0.0.10, Aug 27, 2018
* @since 0.3.1
*/
@Repository
public class TagArticleRepositoryImpl extends AbstractRepository implements TagArticleRepository {
/**
* Public constructor.
*/
public TagArticleRepositoryImpl() {
super(Tag.TAG + "_" + Article.ARTICLE);
}
@Override
public List<JSONObject> getByArticleId(final String articleId) throws RepositoryException {
final Query query = new Query().setFilter(new PropertyFilter(Article.ARTICLE + "_" + Keys.OBJECT_ID, FilterOperator.EQUAL, articleId)).
setPageCount(1);
return getList(query);
}
@Override
public JSONObject getByTagId(final String tagId, final int currentPageNum, final int pageSize) throws RepositoryException {
final Query query = new Query().setFilter(new PropertyFilter(Tag.TAG + "_" + Keys.OBJECT_ID, FilterOperator.EQUAL, tagId)).
addSort(Article.ARTICLE + "_" + Keys.OBJECT_ID, SortDirection.DESCENDING).
setCurrentPageNum(currentPageNum).setPageSize(pageSize).setPageCount(1);
return get(query);
}
}
/*
* Solo - A small and beautiful blogging system written in Java.
* Copyright (c) 2010-2018, b3log.org & hacpai.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package org.b3log.solo.repository.impl;
import org.b3log.latke.Keys;
import org.b3log.latke.ioc.Inject;
import org.b3log.latke.repository.*;
import org.b3log.latke.repository.annotation.Repository;
import org.b3log.solo.model.Tag;
import org.b3log.solo.repository.TagArticleRepository;
import org.b3log.solo.repository.TagRepository;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.text.Collator;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
/**
* Tag repository.
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.1.1.2, Aug 27, 2018
* @since 0.3.1
*/
@Repository
public class TagRepositoryImpl extends AbstractRepository implements TagRepository {
/**
* Tag-Article relation repository.
*/
@Inject
private TagArticleRepository tagArticleRepository;
/**
* Public constructor.
*/
public TagRepositoryImpl() {
super(Tag.TAG);
}
@Override
public JSONObject getByTitle(final String tagTitle) throws RepositoryException {
final Query query = new Query().setFilter(new PropertyFilter(Tag.TAG_TITLE, FilterOperator.EQUAL, tagTitle)).setPageCount(1);
final JSONObject result = get(query);
final JSONArray array = result.optJSONArray(Keys.RESULTS);
if (0 == array.length()) {
return null;
}
return array.optJSONObject(0);
}
@Override
public List<JSONObject> getMostUsedTags(final int num) throws RepositoryException {
final Query query = new Query().addSort(Tag.TAG_PUBLISHED_REFERENCE_COUNT, SortDirection.DESCENDING).
setCurrentPageNum(1).setPageSize(num).setPageCount(1);
final List<JSONObject> tagJoList = getList(query);
sortJSONTagList(tagJoList);
return tagJoList;
}
@Override
public List<JSONObject> getByArticleId(final String articleId) throws RepositoryException {
final List<JSONObject> ret = new ArrayList<>();
final List<JSONObject> tagArticleRelations = tagArticleRepository.getByArticleId(articleId);
for (final JSONObject tagArticleRelation : tagArticleRelations) {
final String tagId = tagArticleRelation.optString(Tag.TAG + "_" + Keys.OBJECT_ID);
final JSONObject tag = get(tagId);
ret.add(tag);
}
return ret;
}
/**
* Sets tag article repository with the specified tag article repository.
*
* @param tagArticleRepository the specified tag article repository
*/
public void setTagArticleRepository(final TagArticleRepository tagArticleRepository) {
this.tagArticleRepository = tagArticleRepository;
}
private void sortJSONTagList(final List<JSONObject> tagJoList) {
Collections.sort(tagJoList, (o1, o2) -> {
try {
return Collator.getInstance(java.util.Locale.CHINA)
.compare(o1.getString(Tag.TAG_TITLE), o2.getString(Tag.TAG_TITLE));
} catch (final JSONException e) {
throw new RuntimeException(e);
}
});
}
}
/*
* Solo - A small and beautiful blogging system written in Java.
* Copyright (c) 2010-2018, b3log.org & hacpai.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package org.b3log.solo.repository.impl;
import org.b3log.latke.Keys;
import org.b3log.latke.ioc.Inject;
import org.b3log.latke.model.Role;
import org.b3log.latke.model.User;
import org.b3log.latke.repository.*;
import org.b3log.latke.repository.annotation.Repository;
import org.b3log.solo.cache.UserCache;
import org.b3log.solo.repository.UserRepository;
import org.json.JSONArray;
import org.json.JSONObject;
import java.util.List;
/**
* User repository.
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.1.0.10, Sep 21, 2018
* @since 0.3.1
*/
@Repository
public class UserRepositoryImpl extends AbstractRepository implements UserRepository {
/**
* User cache.
*/
@Inject
private UserCache userCache;
/**
* Public constructor.
*/
public UserRepositoryImpl() {
super(User.USER);
}
@Override
public void remove(final String id) throws RepositoryException {
super.remove(id);
userCache.removeUser(id);
}
@Override
public JSONObject get(final String id) throws RepositoryException {
JSONObject ret = userCache.getUser(id);
if (null != ret) {
return ret;
}
ret = super.get(id);
if (null == ret) {
return null;
}
userCache.putUser(ret);
return ret;
}
@Override
public void update(final String id, final JSONObject user) throws RepositoryException {
super.update(id, user);
user.put(Keys.OBJECT_ID, id);
userCache.putUser(user);
if (Role.ADMIN_ROLE.equals(user.optString(User.USER_ROLE))) {
userCache.putAdmin(user);
}
}
@Override
public JSONObject getByUserName(final String userName) throws RepositoryException {
final Query query = new Query().setPageCount(1).
setFilter(new PropertyFilter(User.USER_NAME, FilterOperator.EQUAL, userName));
final List<JSONObject> users = getList(query);
if (users.isEmpty()) {
return null;
}
return users.get(0);
}
@Override
public JSONObject getByEmail(final String email) throws RepositoryException {
JSONObject ret = userCache.getUserByEmail(email);
if (null != ret) {
return ret;
}
final Query query = new Query().setPageCount(1).
setFilter(new PropertyFilter(User.USER_EMAIL, FilterOperator.EQUAL, email.toLowerCase().trim()));
final JSONObject result = get(query);
final JSONArray array = result.optJSONArray(Keys.RESULTS);
if (0 == array.length()) {
return null;
}
ret = array.optJSONObject(0);
userCache.putUser(ret);
return ret;
}
@Override
public JSONObject getAdmin() throws RepositoryException {
JSONObject ret = userCache.getAdmin();
if (null != ret) {
return ret;
}
final Query query = new Query().setFilter(new PropertyFilter(User.USER_ROLE, FilterOperator.EQUAL, Role.ADMIN_ROLE)).setPageCount(1);
final JSONObject result = get(query);
final JSONArray array = result.optJSONArray(Keys.RESULTS);
if (0 == array.length()) {
return null;
}
ret = array.optJSONObject(0);
userCache.putAdmin(ret);
return ret;
}
}
Subproject commit b1349979a6e5b1e12fe6b27d0324017506f44dad Subproject commit 4bd78b7cfa6e23403ee7383677f323fa137b230d
...@@ -25,7 +25,6 @@ import org.b3log.latke.repository.jdbc.util.JdbcRepositories; ...@@ -25,7 +25,6 @@ import org.b3log.latke.repository.jdbc.util.JdbcRepositories;
import org.b3log.solo.api.MetaWeblogAPI; import org.b3log.solo.api.MetaWeblogAPI;
import org.b3log.solo.cache.*; import org.b3log.solo.cache.*;
import org.b3log.solo.repository.*; import org.b3log.solo.repository.*;
import org.b3log.solo.repository.impl.*;
import org.b3log.solo.service.*; import org.b3log.solo.service.*;
import org.testng.annotations.AfterClass; import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeClass;
...@@ -100,7 +99,7 @@ public abstract class AbstractTestCase { ...@@ -100,7 +99,7 @@ public abstract class AbstractTestCase {
* @return category-tag repository * @return category-tag repository
*/ */
public CategoryTagRepository getCategoryTagRepository() { public CategoryTagRepository getCategoryTagRepository() {
return beanManager.getReference(CategoryTagRepositoryImpl.class); return beanManager.getReference(CategoryTagRepository.class);
} }
/** /**
...@@ -109,7 +108,7 @@ public abstract class AbstractTestCase { ...@@ -109,7 +108,7 @@ public abstract class AbstractTestCase {
* @return category repository * @return category repository
*/ */
public CategoryRepository getCategoryRepository() { public CategoryRepository getCategoryRepository() {
return beanManager.getReference(CategoryRepositoryImpl.class); return beanManager.getReference(CategoryRepository.class);
} }
/** /**
...@@ -118,7 +117,7 @@ public abstract class AbstractTestCase { ...@@ -118,7 +117,7 @@ public abstract class AbstractTestCase {
* @return user repository * @return user repository
*/ */
public UserRepository getUserRepository() { public UserRepository getUserRepository() {
return beanManager.getReference(UserRepositoryImpl.class); return beanManager.getReference(UserRepository.class);
} }
/** /**
...@@ -127,7 +126,7 @@ public abstract class AbstractTestCase { ...@@ -127,7 +126,7 @@ public abstract class AbstractTestCase {
* @return link repository * @return link repository
*/ */
public LinkRepository getLinkRepository() { public LinkRepository getLinkRepository() {
return beanManager.getReference(LinkRepositoryImpl.class); return beanManager.getReference(LinkRepository.class);
} }
/** /**
...@@ -145,7 +144,7 @@ public abstract class AbstractTestCase { ...@@ -145,7 +144,7 @@ public abstract class AbstractTestCase {
* @return tag repository * @return tag repository
*/ */
public TagRepository getTagRepository() { public TagRepository getTagRepository() {
return beanManager.getReference(TagRepositoryImpl.class); return beanManager.getReference(TagRepository.class);
} }
/** /**
...@@ -154,7 +153,7 @@ public abstract class AbstractTestCase { ...@@ -154,7 +153,7 @@ public abstract class AbstractTestCase {
* @return tag-article repository * @return tag-article repository
*/ */
public TagArticleRepository getTagArticleRepository() { public TagArticleRepository getTagArticleRepository() {
return beanManager.getReference(TagArticleRepositoryImpl.class); return beanManager.getReference(TagArticleRepository.class);
} }
/** /**
...@@ -163,7 +162,7 @@ public abstract class AbstractTestCase { ...@@ -163,7 +162,7 @@ public abstract class AbstractTestCase {
* @return page repository * @return page repository
*/ */
public PageRepository getPageRepository() { public PageRepository getPageRepository() {
return beanManager.getReference(PageRepositoryImpl.class); return beanManager.getReference(PageRepository.class);
} }
/** /**
...@@ -172,7 +171,7 @@ public abstract class AbstractTestCase { ...@@ -172,7 +171,7 @@ public abstract class AbstractTestCase {
* @return comment repository * @return comment repository
*/ */
public CommentRepository getCommentRepository() { public CommentRepository getCommentRepository() {
return beanManager.getReference(CommentRepositoryImpl.class); return beanManager.getReference(CommentRepository.class);
} }
/** /**
...@@ -199,7 +198,7 @@ public abstract class AbstractTestCase { ...@@ -199,7 +198,7 @@ public abstract class AbstractTestCase {
* @return plugin repository * @return plugin repository
*/ */
public PluginRepository getPluginRepository() { public PluginRepository getPluginRepository() {
return beanManager.getReference(PluginRepositoryImpl.class); return beanManager.getReference(PluginRepository.class);
} }
/** /**
...@@ -208,7 +207,7 @@ public abstract class AbstractTestCase { ...@@ -208,7 +207,7 @@ public abstract class AbstractTestCase {
* @return option repository * @return option repository
*/ */
public OptionRepository getOptionRepository() { public OptionRepository getOptionRepository() {
return beanManager.getReference(OptionRepositoryImpl.class); return beanManager.getReference(OptionRepository.class);
} }
/** /**
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
* You should have received a copy of the GNU Affero General Public License * You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package org.b3log.solo.repository.impl; package org.b3log.solo.repository;
import org.b3log.latke.Keys; import org.b3log.latke.Keys;
import org.b3log.latke.repository.Transaction; import org.b3log.latke.repository.Transaction;
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
* You should have received a copy of the GNU Affero General Public License * You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package org.b3log.solo.repository.impl; package org.b3log.solo.repository;
import junit.framework.Assert; import junit.framework.Assert;
import org.apache.commons.lang.time.DateUtils; import org.apache.commons.lang.time.DateUtils;
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
* You should have received a copy of the GNU Affero General Public License * You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package org.b3log.solo.repository.impl; package org.b3log.solo.repository;
import org.b3log.latke.Keys; import org.b3log.latke.Keys;
import org.b3log.latke.repository.Query; import org.b3log.latke.repository.Query;
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
* You should have received a copy of the GNU Affero General Public License * You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package org.b3log.solo.repository.impl; package org.b3log.solo.repository;
import org.b3log.latke.repository.Transaction; import org.b3log.latke.repository.Transaction;
import org.b3log.solo.AbstractTestCase; import org.b3log.solo.AbstractTestCase;
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
* You should have received a copy of the GNU Affero General Public License * You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package org.b3log.solo.repository.impl; package org.b3log.solo.repository;
import org.b3log.latke.repository.Transaction; import org.b3log.latke.repository.Transaction;
import org.b3log.solo.AbstractTestCase; import org.b3log.solo.AbstractTestCase;
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
* You should have received a copy of the GNU Affero General Public License * You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package org.b3log.solo.repository.impl; package org.b3log.solo.repository;
import org.b3log.latke.repository.Transaction; import org.b3log.latke.repository.Transaction;
import org.b3log.solo.AbstractTestCase; import org.b3log.solo.AbstractTestCase;
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
* You should have received a copy of the GNU Affero General Public License * You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package org.b3log.solo.repository.impl; package org.b3log.solo.repository;
import org.b3log.latke.Keys; import org.b3log.latke.Keys;
import org.b3log.latke.repository.Transaction; import org.b3log.latke.repository.Transaction;
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
* You should have received a copy of the GNU Affero General Public License * You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package org.b3log.solo.repository.impl; package org.b3log.solo.repository;
import org.b3log.latke.Keys; import org.b3log.latke.Keys;
import org.b3log.latke.repository.Transaction; import org.b3log.latke.repository.Transaction;
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
* You should have received a copy of the GNU Affero General Public License * You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package org.b3log.solo.repository.impl; package org.b3log.solo.repository;
import org.b3log.solo.AbstractTestCase; import org.b3log.solo.AbstractTestCase;
import org.b3log.solo.repository.PluginRepository; import org.b3log.solo.repository.PluginRepository;
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
* You should have received a copy of the GNU Affero General Public License * You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package org.b3log.solo.repository.impl; package org.b3log.solo.repository;
import java.util.List; import java.util.List;
import junit.framework.Assert; import junit.framework.Assert;
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
* You should have received a copy of the GNU Affero General Public License * You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package org.b3log.solo.repository.impl; package org.b3log.solo.repository;
import java.util.List; import java.util.List;
import junit.framework.Assert; import junit.framework.Assert;
......
...@@ -15,7 +15,7 @@ ...@@ -15,7 +15,7 @@
* You should have received a copy of the GNU Affero General Public License * You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>. * along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
package org.b3log.solo.repository.impl; package org.b3log.solo.repository;
import org.b3log.latke.Keys; import org.b3log.latke.Keys;
import org.b3log.latke.model.Role; import org.b3log.latke.model.Role;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment