Java tutorial
/* * EYWA.COM (Eywa Commerce) * This program is an integrated platform with E-Commerce and Configurator system. * Support: Please, contact the Author on http://www.smartfeeling.org. * Copyright (C) 2014 Gian Angelo Geminiani * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ /* * */ package com.eywa.impl.app.mongo.services; import com.eywa.impl.app.mongo.entities.Image; import com.mongodb.BasicDBObject; import com.mongodb.DB; import com.mongodb.DBObject; import org.ly.Smartly; import org.ly.commons.util.StringUtils; import org.ly.packages.mongo.impl.AbstractMongoService; import org.ly.proxies.DBProxy; import java.util.List; /** * @author angelo.geminiani */ public class ImageService extends AbstractMongoService { // -------------------------------------------------------------------- // c o n s t r u c t o r // -------------------------------------------------------------------- public ImageService() throws Exception { super((DB) DBProxy.get().getDBMain(), Image.COLLECTION, Smartly.getLanguages()); } // -------------------------------------------------------------------- // p u b l i c // -------------------------------------------------------------------- // -------------------------------------------------------------------- // p r i v a t e // -------------------------------------------------------------------- // -------------------------------------------------------------------- // S T A T I C p r i v a t e // -------------------------------------------------------------------- // -------------------------------------------------------------------- // S T A T I C // -------------------------------------------------------------------- public static DBObject get(final String id) { try { final ImageService srvc = new ImageService(); return srvc.findById(id); } catch (Throwable ignored) { } return null; } public static List<DBObject> getByEntityId(final String entityId, final String uid) { try { final ImageService srvc = new ImageService(); final DBObject query = new BasicDBObject(); query.put(Image.ENTITY_ID, entityId); if (StringUtils.hasText(uid)) { query.put(Image.UID, uid); } return srvc.find(query, null, new String[] { Image.CREATIONDATE }, null); } catch (Throwable ignored) { } return null; } public static DBObject remove(final String id) { try { final ImageService srvc = new ImageService(); final DBObject item = srvc.findById(id); if (null != item) { srvc.removeById(id); } return item; } catch (Throwable ignored) { } return null; } public static DBObject create(final String entityId, final String uid) { try { final ImageService srvc = new ImageService(); final DBObject item = new Image(entityId); Image.setUid(item, uid); srvc.upsert(item); return item; } catch (Throwable ignored) { } return null; } }