Prasad Saya

+ Follow
since Jun 05, 2009
Prasad likes ...
Notepad Java
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Rancher Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Prasad Saya

Hello. Just some thoughts on the error and its handling.

"errmsg":"E11000 duplicate key error collection: crypto.btc_ohlc_minute index: _id_ dup key: { _id: ObjectId('6255cce8bdfc280a8c8d6ee8') }"...

This error says that the unique index constraint on the _id field is violated. Every MongoDB collection document has this mandatory field, which functions as a "primary key", is of type ObjectId and is created by default. This value can be user supplied, optionally.

When doing a bulk insert (as using the insertMany method), when any error occurs the operation is aborted - as in this case. But, there is an option to continue with the bulk insert even when there is an error. And you can try to use it. The insertMany has an optional parameter ordered, and is by default True - the process aborts when there is an error. When set to False, the insert operation continues even when there is an error. This is useful when inserting many documents and do not need to stop the process in case of an error, like an "E11000". This kind of situation is quite common in MongoDB bulk operations.
1 month ago
The User and Address data is a one-to-many relationship. A user can have, in general, 1 to 3 ( a small number) addresses. In MongoDB, this is modeled by embedding the address data into the user data.

It is unusual, to create two collections one for each of the user and the address - especially when the addresses are going to be a very small number, and the kind of data being stored. The document structure would be something like this in a "user" collection:

Note the address is an array type field, with multiple address elements.

The two Java POJOs are the User and the Address. The User class will have a property called as address of type List<Address>. Using Spring-Data APIs for MongoDB, the CRUD operations can be performed on the "user" collection. For example, using MongoTemplate class:

  • Data Model Design
  • MongoTemplate

  • NOTE: One can also consider using MongoDB Java Driver APIs for the same application.

    2 years ago
    This is a post about the usage of PropertyChangeListener as an Observer using a Swing example. This can be used in place of the java.util.Observer and Observable (deprecated in Java 9).

    Read my post here: Java PropertyChangeListener as an Observer

    Closing a topic is not an end to anything really. George G. can always solve the way he perceives it. He can try to understand whats posted by the ranchers and figure the solution. May be there is another way. Sometimes pausing little bit can clear things up.

    Perhaps there are many thoughts and ideas to focus on. May be its little overwhelming (it can be sometimes when there is pressure to figure a solution on time, etc.). Can't say what are the factors affecting. Over years I have come to know that the most deterring factor in solving an issue in software field is human and his intervention; its never a technology or hardware or software.
    4 years ago
    Good to know you are finishing your code without any issues   . While posting the code make sure its properly indented (and do remove the commented code). Also, if code comments (saying what it does) are placed strategically helps others to read the code and respond with a comment or a suggestion.
    4 years ago
    RandomAccessFile has mechanism called file pointer which allows access to data from a known particular position in a file. But, I don't know if it can be used with a file with serialized objects.

    In case you choose to use a List collection to store and then retrieve objects from it, one can navigate thru a list using a ListIterator - an iterator for lists that allows traversal of the list in either direction.

    But what i want in my project is to get first object , last object, previous etc. ...

    4 years ago

    Prasad Saya wrote:I think, first you may have to write the code without streams API (functional-style programming) using pre-Java 8 constructs and find the solution. And, then translate or refactor it into using the streams API.

    Enthusiasm to do functional-style programming is not enough. It requires study and effort. Switching from OO style programming to functional-style requires understanding of why functional style, what are the differences, advantages and disadvantages, use cases, etc. Learning or browsing thru the API's is not sufficient, one needs to know how the provided features can be used and in the right situations.

    A way to learn (other than books, tutorials, tests, etc) is to actually take some non-functional code and convert it. One can immediately see the differences - like the compactness of the code, the self-documentation, the new features and the efficiency.
    4 years ago
    I think the GO command need to be studied and list out the use cases. Then, work how these cases can be handled within this application.
    4 years ago

    Stephan van Hulst wrote:

    Prasad Saya wrote:I think, first you may have to write the code without streams API (functional-style programming) using pre-Java 8 constructs and find the solution. And, then translate or refactor it into using the streams API.

    I don't agree with this advice. People don't learn functional programming by translating imperative programs. It's good to get into a functional mindset straight away.

    Then one should learn functional-style Java programming. One should put some effort, in a professional manner.
    4 years ago
    I think, first you may have to write the code without streams API (functional-style programming) using pre-Java 8 constructs and find the solution. And, then translate or refactor it into using the streams API.
    4 years ago
    I just used most of your code and refactored it like this (as I had explained earlier) and you may have to figure some details:

    4 years ago
    The main method does this:

    - from the original code: creates the Dictionary reader = ... using the two files Text.txt and Text2.txt (or more files)
    - create a list of your 10-12 input files (A, B, C,...)
    - process each file in a loop: processDocument
    4 years ago
    The GO command of sql server and its usage:

    You need to figure how to create batches of queries and how the GO affects the way the batched sql statements will be executed.
    4 years ago

    Would the dictionaries values be reset to 0 after each call?

    Yes. The value part of the map.

    But would that not overwrite the pre-existing vector(s)? If so, would this guarantee each vector would be different?

    Yes, it overwrites.

    You need to create another static variable List<Vector> myVectors = ....
    for each call store the vectors in that. So, at the end of processing all the 10-12 files you will be left with myVectors list with the output of those 10-12 input files/documents.
    4 years ago
    You can try this.

    Define "dictionary" as a static variable. Store the 10-12 file names to be processed in an ArrayList and process each file in a for-loop in a new function called processDocument or processInputFile:

    4 years ago