MetaDataQuery.java 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /**
  2. * Copyright (c) 2015-2016, Michael Yang 杨福海 (fuhai999@gmail.com).
  3. *
  4. * Licensed under the GNU Lesser General Public License (LGPL) ,Version 3.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.gnu.org/licenses/lgpl-3.0.txt
  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. */
  16. package io.jpress.model.query;
  17. import java.math.BigInteger;
  18. import java.util.List;
  19. import io.jpress.model.Metadata;
  20. public class MetaDataQuery extends JBaseQuery {
  21. protected static final Metadata DAO = new Metadata();
  22. private static final MetaDataQuery QUERY = new MetaDataQuery();
  23. public static MetaDataQuery me() {
  24. return QUERY;
  25. }
  26. public List<Metadata> findListByTypeAndId(String type, BigInteger id) {
  27. return DAO.doFind("object_type = ? and object_id = ?", type, id);
  28. }
  29. public Metadata findFirstByTypeAndValue(String type, String key, Object value) {
  30. return DAO.doFindFirst("object_type = ? and meta_key = ? and meta_value = ?", type, key, value);
  31. }
  32. public List<Metadata> findListByTypeAndValue(String type, String key, Object value) {
  33. return DAO.doFind("object_type = ? and meta_key = ? and meta_value = ?", type, key, value);
  34. }
  35. public Metadata findByTypeAndIdAndKey(String type, BigInteger id, String key) {
  36. String cachekey = type + id + key;
  37. return DAO.doFindFirstByCache(Metadata.CACHE_NAME, cachekey,
  38. "object_type = ? and object_id = ? and meta_key = ? ", type, id, key);
  39. }
  40. }