Commit 4af1a1bb authored by Liang Ding's avatar Liang Ding

c

parent 2afd5b47
/* /*
* Copyright (c) 2009, 2010, 2011, 2012, B3log Team * Copyright (c) 2009, 2010, 2011, 2012, B3log Team
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.b3log.solo.repository.impl; package org.b3log.solo.repository.impl;
import org.b3log.latke.Keys; import org.b3log.latke.Keys;
import org.b3log.latke.repository.AbstractRepository; import org.b3log.latke.repository.*;
import org.b3log.latke.repository.FilterOperator; import org.b3log.solo.model.Article;
import org.b3log.latke.repository.Query; import org.b3log.solo.model.ArchiveDate;
import org.b3log.solo.model.Article; import org.b3log.solo.repository.ArchiveDateArticleRepository;
import org.b3log.latke.repository.RepositoryException; import org.json.JSONArray;
import org.b3log.latke.repository.SortDirection; import org.json.JSONObject;
import org.b3log.solo.model.ArchiveDate;
import org.b3log.solo.repository.ArchiveDateArticleRepository; /**
import org.json.JSONArray; * Archive date-Article relation repository.
import org.json.JSONObject; *
* @author <a href="mailto:DL88250@gmail.com">Liang Ding</a>
/** * @version 1.0.0.6, Nov 9, 2011
* Archive date-Article relation repository. * @since 0.3.1
* */
* @author <a href="mailto:DL88250@gmail.com">Liang Ding</a> public final class ArchiveDateArticleRepositoryImpl extends AbstractRepository implements ArchiveDateArticleRepository {
* @version 1.0.0.6, Nov 9, 2011
* @since 0.3.1 /**
*/ * Singleton.
public final class ArchiveDateArticleRepositoryImpl extends AbstractRepository implements ArchiveDateArticleRepository { */
private static final ArchiveDateArticleRepositoryImpl SINGLETON =
/** new ArchiveDateArticleRepositoryImpl(ArchiveDate.ARCHIVE_DATE + "_" + Article.ARTICLE);
* Singleton.
*/ @Override
private static final ArchiveDateArticleRepositoryImpl SINGLETON = public JSONObject getByArchiveDateId(final String archiveDateId, final int currentPageNum, final int pageSize)
new ArchiveDateArticleRepositoryImpl(ArchiveDate.ARCHIVE_DATE + "_" + Article.ARTICLE); throws RepositoryException {
final Query query = new Query().setFilter(new PropertyFilter(ArchiveDate.ARCHIVE_DATE + "_" + Keys.OBJECT_ID,
@Override FilterOperator.EQUAL, archiveDateId)).
public JSONObject getByArchiveDateId(final String archiveDateId, final int currentPageNum, final int pageSize) addSort(Article.ARTICLE + "_" + Keys.OBJECT_ID,
throws RepositoryException { SortDirection.DESCENDING).
final Query query = new Query().addFilter(ArchiveDate.ARCHIVE_DATE + "_" + Keys.OBJECT_ID, setCurrentPageNum(currentPageNum).
FilterOperator.EQUAL, archiveDateId). setPageSize(pageSize).
addSort(Article.ARTICLE + "_" + Keys.OBJECT_ID, setPageCount(1);
SortDirection.DESCENDING).
setCurrentPageNum(currentPageNum). return get(query);
setPageSize(pageSize). }
setPageCount(1);
@Override
return get(query); public JSONObject getByArticleId(final String articleId) throws RepositoryException {
} final Query query = new Query();
query.setFilter(new PropertyFilter(Article.ARTICLE + "_" + Keys.OBJECT_ID, FilterOperator.EQUAL, articleId));
@Override
public JSONObject getByArticleId(final String articleId) throws RepositoryException { final JSONObject result = get(query);
final Query query = new Query(); final JSONArray array = result.optJSONArray(Keys.RESULTS);
query.addFilter(Article.ARTICLE + "_" + Keys.OBJECT_ID, FilterOperator.EQUAL, articleId); if (0 == array.length()) {
return null;
final JSONObject result = get(query); }
final JSONArray array = result.optJSONArray(Keys.RESULTS);
if (0 == array.length()) { return array.optJSONObject(0);
return null; }
}
/**
return array.optJSONObject(0); * Gets the {@link ArchiveDateArticleRepositoryImpl} singleton.
} *
* @return the singleton
/** */
* Gets the {@link ArchiveDateArticleRepositoryImpl} singleton. public static ArchiveDateArticleRepositoryImpl getInstance() {
* return SINGLETON;
* @return the singleton }
*/
public static ArchiveDateArticleRepositoryImpl getInstance() { /**
return SINGLETON; * Private constructor.
} *
* @param name the specified name
/** */
* Private constructor. private ArchiveDateArticleRepositoryImpl(final String name) {
* super(name);
* @param name the specified name }
*/ }
private ArchiveDateArticleRepositoryImpl(final String name) {
super(name);
}
}
/* /*
* Copyright (c) 2009, 2010, 2011, 2012, B3log Team * Copyright (c) 2009, 2010, 2011, 2012, B3log Team
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.b3log.solo.repository.impl; package org.b3log.solo.repository.impl;
import java.text.ParseException; import java.text.ParseException;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import org.b3log.latke.Keys; import org.b3log.latke.Keys;
import org.b3log.latke.repository.AbstractRepository; import org.b3log.latke.repository.*;
import org.b3log.latke.repository.FilterOperator; import org.b3log.latke.util.CollectionUtils;
import org.b3log.latke.repository.Query; import org.b3log.solo.model.ArchiveDate;
import org.b3log.latke.repository.RepositoryException; import org.b3log.solo.repository.ArchiveDateRepository;
import org.b3log.latke.repository.SortDirection; import org.json.JSONArray;
import org.b3log.latke.util.CollectionUtils; import org.json.JSONObject;
import org.b3log.solo.model.ArchiveDate;
import org.b3log.solo.repository.ArchiveDateRepository; /**
import org.json.JSONArray; * Archive date repository.
import org.json.JSONObject; *
* @author <a href="mailto:DL88250@gmail.com">Liang Ding</a>
/** * @version 1.0.0.6, Dec 31, 2011
* Archive date repository. * @since 0.3.1
* */
* @author <a href="mailto:DL88250@gmail.com">Liang Ding</a> public final class ArchiveDateRepositoryImpl extends AbstractRepository implements ArchiveDateRepository {
* @version 1.0.0.6, Dec 31, 2011
* @since 0.3.1 /**
*/ * Logger.
public final class ArchiveDateRepositoryImpl extends AbstractRepository implements ArchiveDateRepository { */
private static final Logger LOGGER = Logger.getLogger(ArchiveDateRepositoryImpl.class.getName());
/** /**
* Logger. * Singleton.
*/ */
private static final Logger LOGGER = Logger.getLogger(ArchiveDateRepositoryImpl.class.getName()); private static final ArchiveDateRepositoryImpl SINGLETON = new ArchiveDateRepositoryImpl(ArchiveDate.ARCHIVE_DATE);
/**
* Singleton. @Override
*/ public JSONObject getByArchiveDate(final String archiveDate) throws RepositoryException {
private static final ArchiveDateRepositoryImpl SINGLETON = new ArchiveDateRepositoryImpl(ArchiveDate.ARCHIVE_DATE); long time = 0L;
try {
@Override time = ArchiveDate.DATE_FORMAT.parse(archiveDate).getTime();
public JSONObject getByArchiveDate(final String archiveDate) throws RepositoryException { } catch (final ParseException e) {
long time = 0L; LOGGER.log(Level.SEVERE, "Can not parse archive date [" + archiveDate + "]", e);
try { throw new RepositoryException("Can not parse archive date [" + archiveDate + "]");
time = ArchiveDate.DATE_FORMAT.parse(archiveDate).getTime(); }
} catch (final ParseException e) {
LOGGER.log(Level.SEVERE, "Can not parse archive date [" + archiveDate + "]", e); final Query query = new Query();
throw new RepositoryException("Can not parse archive date [" + archiveDate + "]"); query.setFilter(new PropertyFilter(ArchiveDate.ARCHIVE_TIME, FilterOperator.EQUAL, time)).setPageCount(1);
}
final JSONObject result = get(query);
final Query query = new Query(); final JSONArray array = result.optJSONArray(Keys.RESULTS);
query.addFilter(ArchiveDate.ARCHIVE_TIME, FilterOperator.EQUAL, time).setPageCount(1);
if (0 == array.length()) {
final JSONObject result = get(query); return null;
final JSONArray array = result.optJSONArray(Keys.RESULTS); }
if (0 == array.length()) { return array.optJSONObject(0);
return null; }
}
@Override
return array.optJSONObject(0); public List<JSONObject> getArchiveDates() throws RepositoryException {
} final org.b3log.latke.repository.Query query =
new Query().addSort(ArchiveDate.ARCHIVE_TIME, SortDirection.DESCENDING).setPageCount(1);
@Override final JSONObject result = get(query);
public List<JSONObject> getArchiveDates() throws RepositoryException {
final org.b3log.latke.repository.Query query = final JSONArray archiveDates = result.optJSONArray(Keys.RESULTS);
new Query().addSort(ArchiveDate.ARCHIVE_TIME, SortDirection.DESCENDING).setPageCount(1); final List<JSONObject> ret = CollectionUtils.jsonArrayToList(archiveDates);
final JSONObject result = get(query);
removeForUnpublishedArticles(ret);
final JSONArray archiveDates = result.optJSONArray(Keys.RESULTS);
final List<JSONObject> ret = CollectionUtils.jsonArrayToList(archiveDates); return ret;
}
removeForUnpublishedArticles(ret);
/**
return ret; * Removes archive dates of unpublished articles from the specified archive
} * dates.
*
/** * @param archiveDates the specified archive dates
* Removes archive dates of unpublished articles from the specified archive * @throws RepositoryException repository exception
* dates. */
* private void removeForUnpublishedArticles(final List<JSONObject> archiveDates) throws RepositoryException {
* @param archiveDates the specified archive dates final Iterator<JSONObject> iterator = archiveDates.iterator();
* @throws RepositoryException repository exception while (iterator.hasNext()) {
*/ final JSONObject archiveDate = iterator.next();
private void removeForUnpublishedArticles(final List<JSONObject> archiveDates) throws RepositoryException { if (0 == archiveDate.optInt(ArchiveDate.ARCHIVE_DATE_PUBLISHED_ARTICLE_COUNT)) {
final Iterator<JSONObject> iterator = archiveDates.iterator(); iterator.remove();
while (iterator.hasNext()) { }
final JSONObject archiveDate = iterator.next(); }
if (0 == archiveDate.optInt(ArchiveDate.ARCHIVE_DATE_PUBLISHED_ARTICLE_COUNT)) { }
iterator.remove();
} /**
} * Gets the {@link ArchiveDateRepositoryImpl} singleton.
} *
* @return the singleton
/** */
* Gets the {@link ArchiveDateRepositoryImpl} singleton. public static ArchiveDateRepositoryImpl getInstance() {
* return SINGLETON;
* @return the singleton }
*/
public static ArchiveDateRepositoryImpl getInstance() { /**
return SINGLETON; * Private constructor.
} *
* @param name the specified name
/** */
* Private constructor. private ArchiveDateRepositoryImpl(final String name) {
* super(name);
* @param name the specified name }
*/ }
private ArchiveDateRepositoryImpl(final String name) {
super(name);
}
}
/* /*
* Copyright (c) 2009, 2010, 2011, 2012, B3log Team * Copyright (c) 2009, 2010, 2011, 2012, B3log Team
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
package org.b3log.solo.repository.impl; package org.b3log.solo.repository.impl;
import java.util.logging.Logger; import java.util.logging.Logger;
import org.b3log.latke.Keys; import org.b3log.latke.Keys;
import org.b3log.latke.repository.AbstractRepository; import org.b3log.latke.repository.*;
import org.b3log.latke.repository.FilterOperator; import org.b3log.solo.model.Link;
import org.b3log.latke.repository.Query; import org.b3log.solo.repository.LinkRepository;
import org.b3log.latke.repository.RepositoryException; import org.json.JSONArray;
import org.b3log.latke.repository.SortDirection; import org.json.JSONObject;
import org.b3log.solo.model.Link;
import org.b3log.solo.repository.LinkRepository; /**
import org.json.JSONArray; * Link repository.
import org.json.JSONObject; *
* @author <a href="mailto:DL88250@gmail.com">Liang Ding</a>
/** * @version 1.0.0.5, Nov 10, 2011
* Link repository. * @since 0.3.1
* */
* @author <a href="mailto:DL88250@gmail.com">Liang Ding</a> public final class LinkRepositoryImpl extends AbstractRepository implements LinkRepository {
* @version 1.0.0.5, Nov 10, 2011
* @since 0.3.1 /**
*/ * Logger.
public final class LinkRepositoryImpl extends AbstractRepository implements LinkRepository { */
private static final Logger LOGGER = Logger.getLogger(LinkRepositoryImpl.class.getName());
/** /**
* Logger. * Singleton.
*/ */
private static final Logger LOGGER = Logger.getLogger(LinkRepositoryImpl.class.getName()); private static final LinkRepositoryImpl SINGLETON = new LinkRepositoryImpl(Link.LINK);
/**
* Singleton. @Override
*/ public JSONObject getByAddress(final String address) throws RepositoryException {
private static final LinkRepositoryImpl SINGLETON = new LinkRepositoryImpl(Link.LINK); final Query query = new Query().setFilter(
new PropertyFilter(Link.LINK_ADDRESS, FilterOperator.EQUAL, address)).
@Override setPageCount(1);
public JSONObject getByAddress(final String address) throws RepositoryException {
final Query query = new Query().addFilter(Link.LINK_ADDRESS, FilterOperator.EQUAL, address). final JSONObject result = get(query);
setPageCount(1); final JSONArray array = result.optJSONArray(Keys.RESULTS);
final JSONObject result = get(query); if (0 == array.length()) {
final JSONArray array = result.optJSONArray(Keys.RESULTS); return null;
}
if (0 == array.length()) {
return null; return array.optJSONObject(0);
} }
return array.optJSONObject(0); @Override
} public int getMaxOrder() throws RepositoryException {
final Query query = new Query();
@Override query.addSort(Link.LINK_ORDER, SortDirection.DESCENDING);
public int getMaxOrder() throws RepositoryException {
final Query query = new Query(); final JSONObject result = get(query);
query.addSort(Link.LINK_ORDER, SortDirection.DESCENDING); final JSONArray array = result.optJSONArray(Keys.RESULTS);
final JSONObject result = get(query); if (0 == array.length()) {
final JSONArray array = result.optJSONArray(Keys.RESULTS); return -1;
}
if (0 == array.length()) {
return -1; return array.optJSONObject(0).optInt(Link.LINK_ORDER);
} }
return array.optJSONObject(0).optInt(Link.LINK_ORDER); @Override
} public JSONObject getByOrder(final int order) throws RepositoryException {
final Query query = new Query();
@Override query.setFilter(new PropertyFilter(Link.LINK_ORDER, FilterOperator.EQUAL, order));
public JSONObject getByOrder(final int order) throws RepositoryException {
final Query query = new Query(); final JSONObject result = get(query);
query.addFilter(Link.LINK_ORDER, FilterOperator.EQUAL, order); final JSONArray array = result.optJSONArray(Keys.RESULTS);
final JSONObject result = get(query); if (0 == array.length()) {
final JSONArray array = result.optJSONArray(Keys.RESULTS); return null;
}
if (0 == array.length()) {
return null; return array.optJSONObject(0);
} }
return array.optJSONObject(0); @Override
} public JSONObject getUpper(final String id) throws RepositoryException {
final JSONObject link = get(id);
@Override if (null == link) {
public JSONObject getUpper(final String id) throws RepositoryException { return null;
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))).
final Query query = new Query(); addSort(Link.LINK_ORDER, SortDirection.DESCENDING);
query.addFilter(Link.LINK_ORDER, FilterOperator.LESS_THAN, link.optInt(Link.LINK_ORDER)). query.setCurrentPageNum(1);
addSort(Link.LINK_ORDER, SortDirection.DESCENDING); query.setPageSize(1);
query.setCurrentPageNum(1);
query.setPageSize(1); final JSONObject result = get(query);
final JSONArray array = result.optJSONArray(Keys.RESULTS);
final JSONObject result = get(query);
final JSONArray array = result.optJSONArray(Keys.RESULTS); if (1 != array.length()) {
return null;
if (1 != array.length()) { }
return null;
} return array.optJSONObject(0);
}
return array.optJSONObject(0);
} @Override
public JSONObject getUnder(final String id) throws RepositoryException {
@Override final JSONObject link = get(id);
public JSONObject getUnder(final String id) throws RepositoryException { if (null == link) {
final JSONObject link = get(id); return null;
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))).
final Query query = new Query(); addSort(Link.LINK_ORDER, SortDirection.ASCENDING);
query.addFilter(Link.LINK_ORDER, FilterOperator.GREATER_THAN, link.optInt(Link.LINK_ORDER)). query.setCurrentPageNum(1);
addSort(Link.LINK_ORDER, SortDirection.ASCENDING); query.setPageSize(1);
query.setCurrentPageNum(1);
query.setPageSize(1); final JSONObject result = get(query);
final JSONArray array = result.optJSONArray(Keys.RESULTS);
final JSONObject result = get(query);
final JSONArray array = result.optJSONArray(Keys.RESULTS); if (1 != array.length()) {
return null;
if (1 != array.length()) { }
return null;
} return array.optJSONObject(0);
}
return array.optJSONObject(0);
} /**
* Gets the {@link LinkRepositoryImpl} singleton.
/** *
* Gets the {@link LinkRepositoryImpl} singleton. * @return the singleton
* */
* @return the singleton public static LinkRepositoryImpl getInstance() {
*/ return SINGLETON;
public static LinkRepositoryImpl getInstance() { }
return SINGLETON;
} /**
* Private constructor.
/** *
* Private constructor. * @param name the specified name
* */
* @param name the specified name private LinkRepositoryImpl(final String name) {
*/ super(name);
private LinkRepositoryImpl(final String name) { }
super(name); }
}
}
#
# Copyright (C) 2009, 2010, 2011, B3log Team
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
#
# Description: ease skin (mock for test).
# Version: 1.0.0.0, Jun 27, 2012
# Author: Liang Ding
#
name=ease
version=1.0.1
forSolo=0.4.6
memo=\u56de\u5f52\u606c\u9759
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!-- <!--
Description: B3log Solo parent POM. Description: B3log Solo parent POM.
Version: 2.0.2.0, Jun 19, 2012 Version: 2.0.2.1, Jun 27, 2012
Author: Liang Ding Author: Liang Ding
--> -->
<project xmlns="http://maven.apache.org/POM/4.0.0" <project xmlns="http://maven.apache.org/POM/4.0.0"
...@@ -32,7 +32,7 @@ ...@@ -32,7 +32,7 @@
<org.b3log.latke.version>0.5.0-SNAPSHOT</org.b3log.latke.version> <org.b3log.latke.version>0.5.0-SNAPSHOT</org.b3log.latke.version>
<org.b3log.latke-gae.version>0.5.0-SNAPSHOT</org.b3log.latke-gae.version> <org.b3log.latke-gae.version>0.5.0-SNAPSHOT</org.b3log.latke-gae.version>
<org.b3log.latke-repository-mysql.version>0.5.0-SNAPSHOT</org.b3log.latke-repository-mysql.version> <org.b3log.latke-repository-mysql.version>0.5.0-SNAPSHOT</org.b3log.latke-repository-mysql.version>
<gae.version>1.6.5</gae.version> <gae.version>1.7.0</gae.version>
<freemarker-gae.version>2.3.19</freemarker-gae.version> <freemarker-gae.version>2.3.19</freemarker-gae.version>
<jsoup.version>1.5.2</jsoup.version> <jsoup.version>1.5.2</jsoup.version>
......
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