Ricardo Coto

Ranch Hand
+ Follow
since Feb 21, 2017
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 Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Ricardo Coto

I've just made an implementation using queues and I need to get some feedback to see if the solution I've taken is reliable...

I created a sqs implementation to replace a rest call, in this way, i won't loose any rest request, so, i insert requests in a queue, all that happens next is totally asynchronous, so the application send a message to a queue and imediately needs to wait a response which is inserted in another queue, but i need that wait to be synchronous, as the user need to wait an answer...

So to achieve that, after the app send the request message to the queue, it gets into a while true which continuosly reads the response queue, the wait is for 30 secs max, now it works, but i need to know what do you guys think of this approach.
Peter Rooke I don't get what you said, you said 'depend upon what's on the runtime classpath' ? by runtime you mean the application server ? do you mean the library classpath of the project, have no idea what you're talking about...

Dave Tolls, yes thanks, that's what i did, i changed it to return a string, and to modify the http status i injected HttpServletResponse and then modify the status from there, thanks.
1 year ago
mm nice Jeanne, that's a starting point to understand what to test... thanks.
1 year ago
Hi I'm beginning to work with mockito, i took some course in pluralsight and now that i know how to use mockito and how it works, i don't know what to begin to apply unit testing, for example, i begin with one service, is a pretty short one, see it below:

And this is the test code i wrote:

So this test looks useless to me, if i mock the returning query, why then should i make a test for this service, i know tests must be independent from data, but in this case i don' t know if remove this test, or what exactly should i test from this service...
I have this issue where I coded a controller and i returning a Response (endpoint consumes and produces json) as follows:

when i return something, controller is converting the whole response into json, i know is logical, but i have the same controller in another old project and as it is it works, i mean the controller returns the http status and only the json i'm returning

This is the code of one return

If test the endpoint through postman, it returns a huge json and just one child of the json, the entity is what i need to return, so what am i doing wrong...

This is the old controller that is currently working fine (i know there are a whole different libraries like swagger and version that behaves different)

1 year ago
I have two data sources (persistent contexts) one is Read Only, and one is for Read-Write, everyone pointing to a different database.

Read-Only is configured to be outside of JTA, as I going to only read from it.

So in this way, we're migrating all related to reads/fetch/gets from database to retrieve data from the read only DB.

Take a look at this code:

pEm is the entity manager, as you know the find searches for the ActionItem, then it updates with the LocalDateTime, then it use the 'merge' function...

Problem is, in pEm.find inside of the function (that i've overrided) i use the read only entity manager, so it fetch from the read DB, problem is with the merge, because it's giving me an ERROR saying:

Caused by: org.postgresql.util.PSQLException: ERROR: cannot execute UPDATE in a read-only transaction

And it's because inside of the merge, i use reflection to get the same object from the read-write entity manager, to enabled transaction to commit in the read-write, but for some reason it's not working, this is the merge function:

Thing is, if i perform the get reference outside the merge, it works, like this...

Any idea would be appreciated... (help help help)
I'm not saying it's not reliable by it self, i said is not reliable how invading this is, remember this is an optimization, there's a bunch of entities there, imagine you changing every entity present in the project adding an inferface to each one on them, that's what i say is not reliable, the change is huge, so i would take other paths before doing something like this...

Remember hibernate have a process of mapping, i tried in past time in other project, not this one, to implement an interface in hibernate entities and had weird errors...
1 year ago
remember these are entities, hibernate isn't going to let me i think, besides, remember this is an optimization, that is totally invasive, having cents of classes changed it's not reliable...
1 year ago
Yes we're sure objects are going to have getId, they are entities, and as a convention they will have it...

in what way we can achieve this through an interface ?
1 year ago
Hi, I'm questioning my self if there's a good idea, a professional idea to use reflection...

We're in the middle of an optimization change to get the DB response times lower..
In order to achieve this, we're using two persistent contexts, because we're using a Read Only database (to migrate all fetches/gets to read only db), so, as we have defined these two PC's in our code, there are some cases, specially in UPDATES and DELETES, where the code actually fetches for an item in Database through hibernate, then the same object is updated, and then committed, the thing is, we analyze what operation is performing before commit something, in order to know what PC to use, if the nature of the action is reading, we use PC Read Only, if not we use Write DB...

Thing is, when we fetch the object, it's fetched using PC-Read, and when it update/delete, the object belong to the Read PC, and it throws an error, so in order to avoid that, we use reflection, to update the reference of the object (I know it hits the DB twice, but the second hit is cheap as it is over an id)

As you can see, we're using reflection to get the object (o) id and then, create an object with the associated PC (write) then remove.

Is this right ? is this a good practice, if it's a not common used practice is it acceptable in some way, is it a workaround instead of reflection for this cases?

Thanks for your help....
1 year ago

Adjustment in Funding removing the order by gave one ms of optimization
Adjustment in paid removing last_payment gave me a little bit of time (less tan a ms)
Can't remove the ids you mentioned because they are use to link the joins...

Thanks, i'll go with the next tips...
that last query has a bunch of errors, i'm trying to correct them in order to see the numbers... i'm analyzing all comments though it will take some time, right now, the only optimization i made, from some miliseconds, was to materialized z...
if you notice, below there are some filters in the where clause with the column extracted from the inner queries in the left joins...
I just don't get it, in the first query i put, i created a materialized view for 'z' and it improves time, now that i need to grop by ap.id nad a.collections_category, the query running with the materialized view takes more time than without it, I'm loosing my patience...
I had to update the query, and now is taking more time, as there's one field that i needed :s

WITH actions AS
        SELECT   Rank() OVER(partition BY customer_account_id ORDER BY action_timestamp ASC),
                 Cast (ai.action_timestamp AS DATE)
        FROM     action_item ai
        JOIN     customer_account cac
        ON       ai.customer_account_id = cac.id
        WHERE    cac.status IN ('ACTIVE',
                                'CHARGE_OFF') ), account_attributes AS
        SELECT   customer_account_id,
        FROM     customer_account_attribute
        GROUP BY customer_account_id), sent_history AS
      SELECT ccnh.*
      FROM   command_center_configuration ccc
      JOIN   document_template dt
      ON     ccc.document_template_id = dt.id
      AND    ccc.id= 231489734
      JOIN   command_center_notification_history ccnh
      ON     ccnh.document_template_id = dt.id)
SELECT    ap.id,
FROM      customer_account a
JOIN      customer_agreement ag
ON        a.customer_agreement_id =ag.id
JOIN      customer_application ap
ON        ap.id = ag.customer_application_id
JOIN      customer_application_customer cac
ON        ap.id=cac.customer_application_id
JOIN      customer c
ON        c.id=cac.customer_id
JOIN      merchant m
ON        m.id=ap.merchant_id
LEFT JOIN sent_history ccnh
ON        ccnh.application_id = ap.id
LEFT JOIN actions ac
ON        ac.customer_account_id = a.id
AND       ac.rank = 1
LEFT JOIN account_attributes att
ON        a.id = att.customer_account_id
                    SELECT     cp_f.id ,
                                          WHEN fr_f.type = 'FUNDING' THEN amount
                                          ELSE amount*(-1)
                               END) AS funded_amt
                    FROM       funding_record fr_f
                    INNER JOIN customer_agreement cg_f
                    ON         fr_f.customer_agreement_id = cg_f.id
                    INNER JOIN customer_application cp_f
                    ON         cp_f.id = cg_f.customer_application_id
                    AND        cp_f.status NOT IN ('WITHDRAWN',
                    INNER JOIN customer_account cap_f
                    ON         cg_f.id = cap_f.customer_agreement_id
                    WHERE      funding_record_batch_id IS NOT NULL
                    AND        cap_f.status IN ('ACTIVE',
                    GROUP BY   cp_f.id
                    ORDER BY   cp_f.id ) fundings
ON        ap.id = fundings.id
                  SELECT   acc.id,
                           Sum( COALESCE( t.credit_amount, 0 ) ) -Sum( COALESCE( t.debit_amount, 0 ) ) AS amount_paid,
                           Max(effective_dt)                                                           AS last_payment
                  FROM     snapdata.customer_account_transaction t
                  JOIN     snapdata.customer_account acc
                  ON       t.account_id = acc.id
                  WHERE    acc.status IN ( 'ACTIVE',
                                          'CHARGE_OFF' )
                  AND      t.type NOT IN ('MINIMUM_PAYMENT',
                  AND      t.voided_ts IS NULL
                  AND      t.is_recovery = false
                  AND      t.is_surrender = false
                  AND      t.is_surrender = false
                  AND      t.effective_dt <= CURRENT_DATE
                  GROUP BY acc.id ) paid
ON        a.id = paid.id
                  SELECT   acc.id,
                           Sum(COALESCE(t.credit_amount, 0)) - Sum(COALESCE(t.debit_amount, 0)) AS amount_paid
                  FROM     snapdata.customer_account_transaction t
                  JOIN     snapdata.customer_account acc
                  ON       t.account_id = acc.id
                  WHERE    acc.status IN ( 'ACTIVE',
                                          'CHARGE_OFF' )
                  AND      t.type IN ('REGULAR_PAYMENT',
                  AND      t.voided_ts IS NULL
                  AND      t.is_recovery = false
                  AND      t.is_surrender = false
                  AND      t.is_surrender = false
                  AND      t.effective_dt <= CURRENT_DATE
                  GROUP BY acc.id) paid2
ON        a.id = paid2.id
                    SELECT     account_id,
                               Min(effective_dt) AS mindate
                    FROM       customer_account_transaction
                    INNER JOIN customer_account cac
                    ON         cac.id = account_id
                    WHERE      type IN ( 'REGULAR_PAYMENT',
                    AND        cac.status IN ('ACTIVE',
                    AND        ((
                                                     account_payment_batch_id IS NOT NULL)
                               OR         (
                                                     payment_method IN ('CREDIT_CARD',
                                          AND        account_payment_batch_id IS NULL))
                    GROUP BY   account_id
                    HAVING     Min(effective_dt) BETWEEN ( CURRENT_DATE - 15 ) AND        (
                                          CURRENT_DATE )) z
ON        a.id = z.account_id
WHERE     ccnh.return_reason IS NULL
AND       a.collections_category IN ('QUEUE_RETURNS',
AND       a.status IN ('ACTIVE')
AND       ccnh.sent_dt IS NULL
AND       (
                   action_timestamp < (CURRENT_DATE)
         OR        ( (
                                       action_timestamp >= (CURRENT_DATE) )
                   AND       ac.action NOT IN ('BANKRUPTCY',
         OR        ac.id IS NULL )
AND       att.customer_account_id IS NULL
AND       fundings.funded_amt > 0
                   WHEN paid2.amount_paid IS NULL THEN true
                   ELSE paid2.amount_paid / fundings.funded_amt < 1.90
AND       (
                   paid.amount_paid * -1) > 100
AND       a.days_past_due >= 14
AND       z.mindate IS NULL
GROUP BY  ap.id,