Example usage for com.mongodb DBCursor next

List of usage examples for com.mongodb DBCursor next

Introduction

In this page you can find the example usage for com.mongodb DBCursor next.

Prototype

@Override
public DBObject next() 

Source Link

Document

Returns the object the cursor is at and moves the cursor ahead by one.

Usage

From source file:com.bigdid.model.Feedback_Order_Months.java

public LinkedHashMap<String, int[]> getFeedback() {
    DBCursor obj = coll.find();
    String current_date = "0";
    String prev_date = "0";
    int counter = 0;
    int[] count = new int[4];
    ;/*  w  ww  .j  a va2s  .c om*/
    while (obj.hasNext()) {

        DBObject dbObj = obj.next();
        //            prev_date = current_date;
        //            Date d = (Date) dbObj.get("Order_Date");

        current_date = (String) dbObj.get("month");
        //
        //            int prev_excellent = 0;
        //            int prev_good = 0;
        //            int prev_average = 0;
        //            int prev_bad=0;

        if (dbObj.get("Feedback").equals("Excellent")) {
            count[0] = (Integer) dbObj.get("f_count");

            data.put(current_date, count);
            counter++;
        }
        if (dbObj.get("Feedback").equals("Good")) {
            count[1] = (Integer) dbObj.get("f_count");

            data.put(current_date, count);
            counter++;
        }
        if (dbObj.get("Feedback").equals("Average")) {
            count[2] = (Integer) dbObj.get("f_count");

            data.put(current_date, count);
            counter++;
        }
        if (dbObj.get("Feedback").equals("Bad")) {
            count[3] = (Integer) dbObj.get("f_count");

            data.put(current_date, count);
            counter++;
        }

        if (counter % 4 == 0) {
            //    System.out.println(current_date);
            //    System.out.println(count[0]);
            //    System.out.println(count[1]);
            //    System.out.println(count[2]);
            //    System.out.println(count[3]);
            data.put(current_date, count);

            count = new int[4];
        }

    }

    return data;
}

From source file:com.bigdid.model.Feedback_Order_Weeks.java

public LinkedHashMap<String, int[]> getFeedback() {
    DBCursor obj = coll.find();
    String current_date = "0";
    String prev_date = "0";
    int counter = 0;
    int[] count = new int[4];
    ;//from   w  ww . j av a2s.c o  m
    while (obj.hasNext()) {

        DBObject dbObj = obj.next();
        //            prev_date = current_date;
        //            Date d = (Date) dbObj.get("Order_Date");

        current_date = (String) dbObj.get("week");
        //
        //            int prev_excellent = 0;
        //            int prev_good = 0;
        //            int prev_average = 0;
        //            int prev_bad=0;

        if (dbObj.get("Feedback").equals("Excellent")) {
            count[0] = (Integer) dbObj.get("f_count");

            data.put(current_date, count);
            counter++;
        }
        if (dbObj.get("Feedback").equals("Good")) {
            count[1] = (Integer) dbObj.get("f_count");

            data.put(current_date, count);
            counter++;
        }
        if (dbObj.get("Feedback").equals("Average")) {
            count[2] = (Integer) dbObj.get("f_count");

            data.put(current_date, count);
            counter++;
        }
        if (dbObj.get("Feedback").equals("Bad")) {
            count[3] = (Integer) dbObj.get("f_count");

            data.put(current_date, count);
            counter++;
        }

        if (counter % 4 == 0) {
            //    System.out.println(current_date);
            //    System.out.println(count[0]);
            //    System.out.println(count[1]);
            //    System.out.println(count[2]);
            //    System.out.println(count[3]);
            data.put(current_date, count);
            count = new int[4];
        }

    }

    return data;
}

From source file:com.bigdid.model.Revenue_Item.java

public ArrayList<String> getItem() throws UnknownHostException {
    ArrayList<String> item = new ArrayList<String>();

    int i = 0;//from w  w w  .  j a va 2  s.co m
    DBCursor obj = coll.find();
    while (obj.hasNext()) {

        item.add((String) obj.next().get("Item"));
        i++;

    }

    return item;
}

From source file:com.bigdid.model.Revenue_Item.java

public ArrayList<Integer> getRevenue() throws UnknownHostException {

    ArrayList<Integer> revenue = new ArrayList<Integer>();
    int i = 0;/*from w ww  . j  ava2  s. c  o  m*/
    DBCursor obj = coll.find();

    int size = obj.size();

    for (i = 0; i < size; i++) {
        revenue.add((Integer) obj.next().get("Order_Value"));
    }

    return revenue;
}

From source file:com.bigdid.model.Revenue_Location.java

public Map<String, Integer> getLocationRevenue() throws UnknownHostException {
    HashMap<String, Integer> locationRevenue = new HashMap<String, Integer>();

    int i = 0;//w  w  w . j a v a 2 s .  c  o m
    BasicDBObject whereQuery = new BasicDBObject("Order_Value", -1);

    DBCursor obj = coll.find().sort(whereQuery).limit(10);

    while (obj.hasNext()) {
        DBObject dbObj = obj.next();

        locationRevenue.put((String) dbObj.get("Location"), (Integer) dbObj.get("Order_Value"));

    }
    Map<String, Integer> map = sortByValues(locationRevenue);

    return map;
}

From source file:com.bigdid.model.Sentiment_Date_Revised_one.java

public LinkedHashMap<String, int[]> getSentiment() {
    DBCursor obj = coll.find();
    String current_date = "0";
    String prev_date = "0";
    int prev_positive = 0;

    while (obj.hasNext()) {
        DBObject dbObj = obj.next();
        prev_date = current_date;/*from   ww  w  .jav  a  2s  .c om*/

        current_date = (String) dbObj.get("date").toString().substring(4, 10) + " "
                + (String) dbObj.get("date").toString().substring(24);

        int[] count = new int[3];

        if (prev_date.equals(current_date)) { //current day is previous day so negative sentiment for sure
            count[0] = (Integer) dbObj.get("order_count");
            count[1] = prev_positive;
            count[2] = (Integer) dbObj.get("count");

            data.put(current_date, count);

        } else { //new day---- 2 cases positive or negative
            if (dbObj.get("sentiment").equals("positive")) {
                count[0] = (Integer) dbObj.get("order_count");
                count[1] = (Integer) dbObj.get("count");
                count[2] = 0;

                data.put(current_date, count);
                prev_positive = count[1];

            }

            if (dbObj.get("sentiment").equals("negative")) { //first date is negative
                count[0] = (Integer) dbObj.get("order_count");
                count[1] = 0;
                count[2] = (Integer) dbObj.get("count");

                data.put(current_date, count);

            }
        }
    }

    return data;

}

From source file:com.bigdid.model.Sentiment_Month_Revised_one.java

public LinkedHashMap<String, int[]> getSentiment() {
    DBCursor obj = coll.find();
    String current_date = "0";
    String prev_date = "0";
    int prev_positive = 0;
    while (obj.hasNext()) {
        DBObject dbObj = obj.next();
        prev_date = current_date;//from ww  w .  jav  a2 s .  c om
        current_date = (String) dbObj.get("month");
        int[] count = new int[3];

        if (prev_date.equals(current_date)) { //current day is previous day so negative sentiment for sure
            count[0] = (Integer) dbObj.get("o_count");
            count[1] = prev_positive;
            count[2] = (Integer) dbObj.get("s_count");

            data.put(current_date, count);

        } else { //new day---- 2 cases positive or negative
            if (dbObj.get("sentiment").equals("positive")) {
                count[0] = (Integer) dbObj.get("o_count");
                count[1] = (Integer) dbObj.get("s_count");
                ;
                count[2] = 0;

                data.put(current_date, count);
                prev_positive = count[1];

            }

            if (dbObj.get("sentiment").equals("negative")) { //first date is negative
                count[0] = (Integer) dbObj.get("o_count");
                count[1] = 0;
                count[2] = (Integer) dbObj.get("s_count");

                data.put(current_date, count);

            }
        }
    }

    return data;

}

From source file:com.bigdid.model.Sentiment_Week_Revised_one.java

public LinkedHashMap<String, int[]> getSentiment() {
    DBCursor obj = coll.find();
    String current_date = "0";
    String prev_date = "0";
    int prev_positive = 0;
    while (obj.hasNext()) {
        DBObject dbObj = obj.next();
        prev_date = current_date;//from  w  ww. jav  a2s  .  com
        current_date = (String) dbObj.get("week");
        int[] count = new int[3];

        if (prev_date.equals(current_date)) { //current day is previous day so negative sentiment for sure
            count[0] = (Integer) dbObj.get("o_count");
            count[1] = prev_positive;
            count[2] = (Integer) dbObj.get("s_count");

            data.put(current_date, count);

        } else { //new day---- 2 cases positive or negative
            if (dbObj.get("sentiment").equals("positive")) {
                count[0] = (Integer) dbObj.get("o_count");
                count[1] = (Integer) dbObj.get("s_count");
                ;
                count[2] = 0;

                data.put(current_date, count);
                prev_positive = count[1];

            }

            if (dbObj.get("sentiment").equals("negative")) { //first date is negative
                count[0] = (Integer) dbObj.get("o_count");
                count[1] = 0;
                count[2] = (Integer) dbObj.get("s_count");

                data.put(current_date, count);

            }
        }
    }

    return data;

}

From source file:com.bigdid.scrap.model.Sentiment_Date.java

public HashMap<String, int[]> getSentiment() {
    DBCursor obj = coll.find();
    int i = 0;//from  w  w  w . j av  a 2s .c o  m

    String current_date = "0";
    String prev_date = "0";
    int[] count = new int[3];
    while (obj.hasNext()) {
        DBObject dbObj = obj.next();
        prev_date = current_date;
        current_date = (String) dbObj.get("date").toString().substring(4, 10) + " "
                + (String) dbObj.get("date").toString().substring(24);
        System.out.println("current date" + current_date);
        System.out.println("previous date :" + prev_date);
        int prev_positive = 0;
        int prev_orderValue = 0;
        String prev_sentiment = "0";

        if (prev_date.equals(current_date)) { //repeat date entry having negative count for sure 
            count[1] = prev_positive;
            count[2] = (Integer) dbObj.get("count");
            count[0] = (Integer) dbObj.get("order_count");
            data.put(current_date, count);
            prev_positive = 0;
            count[0] = 0;
            count[1] = 0;
            count[2] = 0;

        } else { //new date
            if (prev_sentiment.equals("positive") && dbObj.get("sentiment").equals("positive")) {
                count[0] = prev_orderValue;
                count[1] = prev_positive;
                count[2] = 0;
                data.put(prev_date, count);
                count[0] = 0;
                count[1] = 0;
                count[2] = 0;
                prev_sentiment = "0";
            }

            if (dbObj.get("Sentiment").equals("positive")) {
                prev_positive = (Integer) dbObj.get("count");
                prev_orderValue = (Integer) dbObj.get("order_count");
                prev_sentiment = "positive";

            } else { //new date with negative count
                prev_positive = 0;
                count[1] = prev_positive;
                count[2] = (Integer) dbObj.get("count");
                count[0] = (Integer) dbObj.get("order_count");
                data.put(current_date, count);

                count[0] = 0;
                count[1] = 0;
                count[2] = 0;
            }

        }

    }
    return data;

}

From source file:com.board.games.dao.nodebb.NodeBBJdbcDAOImpl.java

License:Open Source License

private PlayerProfile selectPlayerProfile(int id, String externalId, int accountId, boolean useExternalId)
        throws Exception {
    WalletAdapter walletAdapter = null;//ww w .  ja v  a2 s  . c  o  m

    if (getUseIntegrations().equals("Y")) {
        walletAdapter = new WalletAdapter();
    }

    String query = "";

    query = "select " + " n1.externalId, " + " n1.id,    " + " n3.id   " + " from " + getDbNetworkUserService()
            + "." + "User n1  " + " inner join " + getDbNetworkUserService() + "."
            + "UserAttribute n2 on n1.id=n2.user_id   " + " inner join " + getDbNetWorkWalletService() + "."
            + "Account n3 on n1.id=n3.userId   " + " where  "
            + (useExternalId ? " n1.id= ? " : " n1.externalId= ? ") + " and  " + " n3.name = n2.value ";

    log.warn("**** Query " + query);
    log.warn("User id to query " + (useExternalId ? externalId : id));
    /**
     * Define the connection, preparedStatement and resultSet parameters
     */
    Connection connection = null;
    PreparedStatement preparedStatement = null;
    ResultSet resultSet = null;
    try {
        /**
         * Open the connection
         */
        connection = dataSource.getConnection();
        /**
         * Prepare the statement
         */
        preparedStatement = connection.prepareStatement(query);
        /**
         * Bind the parameters to the PreparedStatement
         */
        // use ipb user id instead only the other for account balance
        log.warn("external id to look : " + Integer.parseInt(externalId));
        preparedStatement.setInt(1, (useExternalId ? Integer.parseInt(externalId) : id));
        /**
         * Execute the statement
         */
        resultSet = preparedStatement.executeQuery();
        PlayerProfile playerProfile = null;

        /**
         * Extract data from the result set
         */
        if (resultSet.next()) {
            playerProfile = new PlayerProfile();
            String avatar_location = "";

            //   playerProfile.setId(resultSet.getInt("t2.uid"));
            //         String imageUrl = resultSet.getString("t2.avatar");
            //      avatar_location = getSiteUrl() + "/" + imageUrl;

            //         String name = resultSet.getString("t2.username");
            //      int groupId = resultSet.getInt("t2.usergroup");
            //   playerProfile.setGroupId(groupId);
            //      log.warn("name " + name);
            //   playerProfile.setName(name);

            int externalRealId = resultSet.getInt("n1.externalId");
            // To connect to mongodb server
            MongoClient mongoClient = new MongoClient("localhost", 27017);
            // Now connect to your databases
            DB db = mongoClient.getDB("nodebb");
            //       log.debug("Connect to database successfully");
            log.debug("Execute query: authenticate");
            DBCursor cursor = null;
            try {

                DBCollection collection = db.getCollection("objects");
                log.warn("Collection find " + "user:" + String.valueOf(externalRealId));

                cursor = collection.find(new BasicDBObject("_key", "user:" + String.valueOf(externalRealId)),
                        new BasicDBObject("_id", 0));

                avatar_location = (String) cursor.next().get("picture");
                //Picture /uploads/profile/1-profileimg.png
                log.warn("url before " + avatar_location);
                if (avatar_location.indexOf("uploads") != -1) {
                    log.warn("avatar is an upload avatar");
                    avatar_location = getSiteUrl() + avatar_location;
                }
                log.warn("url after " + avatar_location);
                playerProfile.setAvatar_location(avatar_location);
            } finally {
                if (cursor != null) {
                    cursor.close();
                }
            }
            log.warn("calling wallet account balance");
            int walletAccountId = resultSet.getInt("n3.id");
            AccountBalanceResult accountBalance = walletAdapter
                    .getAccountBalance(new Long(String.valueOf(walletAccountId)));
            if (accountBalance != null) {
                Money playerMoney = (Money) accountBalance.getBalance();
                log.warn(walletAccountId + " has " + playerMoney.getAmount());
                playerProfile.setBalance(playerMoney.getAmount());
            }

            int userAccountId = resultSet.getInt("n1.id");
            log.warn("Getting user level for " + userAccountId);
            int level = walletAdapter.getUserLevel(new Long(String.valueOf(userAccountId)));
            log.warn("Level found : " + level);
            playerProfile.setLevel(level);
            log.warn("Level retrieved as # : " + playerProfile.getLevel());
            return playerProfile;
        } else {
            log.debug("Found no user");
        }

    } catch (SQLException e) {
        e.printStackTrace();
        log.error("SQLException : " + e.toString());
    } catch (Exception e) {
        log.error("Exception in selectPlayerProfile " + e.toString());
        throw e;
    } finally {
        try {
            /**
             * Close the resultSet
             */
            if (resultSet != null) {
                resultSet.close();
            }
            /**
             * Close the preparedStatement
             */
            if (preparedStatement != null) {
                preparedStatement.close();
            }
            /**
             * Close the connection
             */
            if (connection != null) {
                connection.close();
            }
        } catch (SQLException e) {
            /**
             * Handle any exception
             */
            e.printStackTrace();
        }
    }
    return null;
}