com.eywa.impl.app.mongo.services.ProductTransactionService.java Source code

Java tutorial

Introduction

Here is the source code for com.eywa.impl.app.mongo.services.ProductTransactionService.java

Source

/*
 * 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.ProductTransaction;
import com.mongodb.BasicDBObject;
import com.mongodb.DB;
import com.mongodb.DBObject;
import org.ly.Smartly;
import org.ly.packages.mongo.impl.AbstractMongoService;
import org.ly.packages.mongo.impl.StandardCodedException;
import org.ly.proxies.DBProxy;

import java.util.List;

/**
 * @author angelo.geminiani
 */
public class ProductTransactionService extends AbstractMongoService {

    // --------------------------------------------------------------------
    //               c o n s t r u c t o r
    // --------------------------------------------------------------------

    public ProductTransactionService() throws Exception {
        super((DB) DBProxy.get().getDBMain(), ProductTransaction.COLLECTION, Smartly.getLanguages());
    }

    // --------------------------------------------------------------------
    //               p u b l i c
    // --------------------------------------------------------------------

    @Override
    public int upsert(final DBObject item) throws StandardCodedException {
        return super.upsert(item);
    }

    // --------------------------------------------------------------------
    //               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 ProductTransactionService srvc = new ProductTransactionService();
            return srvc.findById(id);
        } catch (Throwable ignored) {
        }
        return null;
    }

    public static List<DBObject> getBySeller(final String sellerId) {
        try {
            final ProductTransactionService srvc = new ProductTransactionService();
            final DBObject query = new BasicDBObject();
            query.put(ProductTransaction.SELLER_ID, sellerId);
            return srvc.find(query);
        } catch (Throwable ignored) {
        }
        return null;
    }

    public static List<DBObject> getByBuyer(final String buyerId) {
        try {
            final ProductTransactionService srvc = new ProductTransactionService();
            final DBObject query = new BasicDBObject();
            query.put(ProductTransaction.BUYER_ID, buyerId);
            return srvc.find(query);
        } catch (Throwable ignored) {
        }
        return null;
    }

    public static List<DBObject> getByProduct(final String productId) {
        try {
            final ProductTransactionService srvc = new ProductTransactionService();
            final DBObject query = new BasicDBObject();
            query.put(ProductTransaction.PRODUCT_ID, productId);
            return srvc.find(query);
        } catch (Throwable ignored) {
        }
        return null;
    }

}