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.entities; import com.eywa.impl.app.IAppConstants; import com.eywa.impl.app.mongo.ICollectionNames; import com.mongodb.DBObject; import org.ly.commons.util.DateUtils; import org.ly.commons.util.FormatUtils; import org.ly.commons.util.StringUtils; import org.ly.packages.mongo.impl.MongoObject; import org.ly.packages.mongo.impl.util.MongoUtils; /** * BUY/SELL TRANSACTIONS */ public class ProductTransaction extends MongoObject { // ------------------------------------------------------------------------ // Constants // ------------------------------------------------------------------------ public static final String COLLECTION = ICollectionNames.PRODUCT_TRANSACTIONS; // ------------------------------------------------------------------------ // fields // ------------------------------------------------------------------------ public static final String ID = IAppConstants.ID; public static final String CREATIONDATE = IAppConstants.CREATIONDATE; // string public static final String CREATION_DATE = IAppConstants.CREATION_DATE; // milliseconds public static final String PRODUCT_ID = IAppConstants.PRODUCT_ID; public static final String SELLER_ID = IAppConstants.SELLER_ID; public static final String BUYER_ID = IAppConstants.BUYER_ID; public static final String PRICE = IAppConstants.PRICE; public static final String CURRENCY_CODE = IAppConstants.CURRENCY_CODE; public ProductTransaction() { init(this); } // ------------------------------------------------------------------------ // S T A T I C // ------------------------------------------------------------------------ public static String createUUID() { return COLLECTION.concat("_").concat(MongoUtils.createUUID()); } public static void init(final DBObject item) { if (!StringUtils.hasText(getId(item))) { item.put(ID, createUUID()); item.put(CREATIONDATE, FormatUtils.getNow()); item.put(CREATION_DATE, DateUtils.now().getTime()); } } public static String getId(final DBObject item) { return MongoUtils.getString(item, ID); } public static void setId(final DBObject item, final String value) { MongoUtils.put(item, ID, value); } public static String getCreationDate(final DBObject item) { return MongoUtils.getString(item, CREATIONDATE); } public static String getProductId(final DBObject item) { return MongoUtils.getString(item, PRODUCT_ID); } public static void setProductId(final DBObject item, final String value) { MongoUtils.put(item, PRODUCT_ID, value); } public static String getSellerId(final DBObject item) { return MongoUtils.getString(item, SELLER_ID); } public static void setSellerId(final DBObject item, final String value) { MongoUtils.put(item, SELLER_ID, value); } public static String getBuyerId(final DBObject item) { return MongoUtils.getString(item, BUYER_ID); } public static void setBuyerId(final DBObject item, final String value) { MongoUtils.put(item, BUYER_ID, value); } public static double getPrice(final DBObject item) { return MongoUtils.getDouble(item, PRICE); } public static void setPrice(final DBObject item, final double value) { MongoUtils.put(item, PRICE, value); } public static String getCurrencyCode(final DBObject item) { return MongoUtils.getString(item, CURRENCY_CODE); } public static void setCurrencyCode(final DBObject item, final String value) { MongoUtils.put(item, CURRENCY_CODE, value); } // ------------------------------------------------------------------------ // P R I V A T E // ------------------------------------------------------------------------ }