PageRenderTime 68ms CodeModel.GetById 9ms app.highlight 7ms RepoModel.GetById 1ms app.codeStats 0ms

/core/src/main/java/org/b3log/solo/repository/impl/ArchiveDateArticleRepositoryImpl.java

http://github.com/b3log/b3log-solo
Java | 86 lines | 41 code | 10 blank | 35 comment | 2 complexity | 354908b74743d4b69985cc36a022f833 MD5 | raw file
Possible License(s): Apache-2.0, LGPL-2.1
 1/*
 2 * Copyright (c) 2009, 2010, 2011, 2012, B3log Team
 3 *
 4 * Licensed under the Apache License, Version 2.0 (the "License");
 5 * you may not use this file except in compliance with the License.
 6 * You may obtain a copy of the License at
 7 *
 8 *     http://www.apache.org/licenses/LICENSE-2.0
 9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package org.b3log.solo.repository.impl;
17
18import org.b3log.latke.Keys;
19import org.b3log.latke.repository.*;
20import org.b3log.solo.model.Article;
21import org.b3log.solo.model.ArchiveDate;
22import org.b3log.solo.repository.ArchiveDateArticleRepository;
23import org.json.JSONArray;
24import org.json.JSONObject;
25
26/**
27 * Archive date-Article relation repository.
28 *
29 * @author <a href="mailto:DL88250@gmail.com">Liang Ding</a>
30 * @version 1.0.0.6, Nov 9, 2011
31 * @since 0.3.1
32 */
33public final class ArchiveDateArticleRepositoryImpl extends AbstractRepository implements ArchiveDateArticleRepository {
34
35    /**
36     * Singleton.
37     */
38    private static final ArchiveDateArticleRepositoryImpl SINGLETON =
39            new ArchiveDateArticleRepositoryImpl(ArchiveDate.ARCHIVE_DATE + "_" + Article.ARTICLE);
40
41    @Override
42    public JSONObject getByArchiveDateId(final String archiveDateId, final int currentPageNum, final int pageSize)
43            throws RepositoryException {
44        final Query query = new Query().setFilter(new PropertyFilter(ArchiveDate.ARCHIVE_DATE + "_" + Keys.OBJECT_ID,
45                                                                     FilterOperator.EQUAL, archiveDateId)).
46                addSort(Article.ARTICLE + "_" + Keys.OBJECT_ID,
47                        SortDirection.DESCENDING).
48                setCurrentPageNum(currentPageNum).
49                setPageSize(pageSize).
50                setPageCount(1);
51
52        return get(query);
53    }
54
55    @Override
56    public JSONObject getByArticleId(final String articleId) throws RepositoryException {
57        final Query query = new Query();
58        query.setFilter(new PropertyFilter(Article.ARTICLE + "_" + Keys.OBJECT_ID, FilterOperator.EQUAL, articleId));
59
60        final JSONObject result = get(query);
61        final JSONArray array = result.optJSONArray(Keys.RESULTS);
62        if (0 == array.length()) {
63            return null;
64        }
65
66        return array.optJSONObject(0);
67    }
68
69    /**
70     * Gets the {@link ArchiveDateArticleRepositoryImpl} singleton.
71     *
72     * @return the singleton
73     */
74    public static ArchiveDateArticleRepositoryImpl getInstance() {
75        return SINGLETON;
76    }
77
78    /**
79     * Private constructor.
80     * 
81     * @param name the specified name
82     */
83    private ArchiveDateArticleRepositoryImpl(final String name) {
84        super(name);
85    }
86}