• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Method splittinga time_range in separate

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,
I have three materialized views in my project
MV_MSG_EXC_REC_HISTORY : Summarizes message data for the past two years up to the beginning of the current year.
MV_MSG_EXC_REC_RECENT : Summarizes message data from the beginning of the current year up to the current day.
MV_MSG_EXC_REC_CURRENT_DAY : Summarizes messages for the current day, grouping by minute-level timestamps and updating based on the nearest half-hour.

From the ui of the application I have two criteria, let it be "From" and "To"
I want when user adds these criteria to translate it to Java in a Map<String, Pair<LocalDateTime, LocalDateTime>> which contains the name of the MV, the start_date and end_date in order to construct queries like below :
eg.


I want to have 4 cases :
1. Both dates are filled then -> where min_date >= start_date and min_date <= end_date
2. Left date is null then  -> where min_date <= end_date
3. Right date is null then -> where min_date >= start_date
4. Both dates null then -> no where clause

Examples :
Supposing I have the below ranges for all the cases
MV_MSG_EXC_REC_HISTORY: 2022-01-01T00:00 - 2023-12-31T23:59:59.999
MV_MSG_EXC_REC_RECENT: 2024-01-01T00:00 - 2024-11-04T23:59:59.999
MV_MSG_EXC_REC_CURRENT_DAY: 2024-11-05T00:00 - 2024-11-05T07:30:00
====================
Case 1
And user selects the below from UI
From: 2023-01-01T00:00:03
To: 2024-10-10T03:56:04.235

I want to make a Map<String, Pair<LocalDateTime, LocalDateTime>> like

(the left date should be floored in minute level and the right date to be ceiled to next minute)

Case 2
And user selects the below from UI
From: 2023-01-01T00:00:03
To: 2024-12-31T03:56:04.235 (larger than current_date)
====================


Case 3
I have the below ranges
MV_MSG_EXC_REC_HISTORY: 2022-01-01T00:00 - 2023-12-31T23:59:59.999
MV_MSG_EXC_REC_RECENT: 2024-01-01T00:00 - 2024-11-04T23:59:59.999
MV_MSG_EXC_REC_CURRENT_DAY: 2024-11-05T00:00 - 2024-11-05T07:30:00
====================
And user selects the below from UI
From: 2023-01-01T00:00:03
To: 2024-11-03T03:56:04.235 (smaller than current_date)
====================



My code is below :




can you help me please to do the getMvNames to works as expected ?
as now it works with MV ranges

Thanks a lot
 
Marshal
Posts: 79956
396
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What sort of views? Are they views of a database?
Why are you giving that class a public constructor? If you are using the of() method it might be better not to allow the constructor to be used directly: give it private access.
Why are you using getClass() in the equals() method in a non‑final class? That will mean that instances of subtypes of Pair would not return true from equals(). That problem will disappear if Pair has a private constructor.
Unless L and R are always immutable, which LocalDateTime and String are, I think you should consider taking defensive copies of your fields.
Don't write your own null tests in equals(). Not when you can use Objects#equals() instead.
Why are you allowing nulls into your Pair in the first place? Have you considered a very early date or a very late date instead of the nulls? Have you considered using an Optional<LocalDateTime>? The ofNullable() method will allow you to create empty Optionals as appropriate, then you can use orElse(LocalDateTime.now()) if right is null, or something analogous if left is null.
 
peter petros
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There are materialised views in db.
The code is just a demo class for explaining what is the issue.
 
Saloon Keeper
Posts: 28319
210
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Like Campbell, I'm confused. Are you saying that you're simply illustrating how you want to create your views using Java code as an example?

SQL has a very trivial operation for capturing a date range. It's the BETWEEN operator.

Also note the difference between an ordinary view and a materialized view. An ordinary view is created based on the current contents of the database. A materialized view is a snapshot view taken when the few was created and thereafter immutable. Any view that is based on a sliding value such as current date or time should not be a materialized view.
 
Campbell Ritchie
Marshal
Posts: 79956
396
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please don't quote the whole of the preceding post; that adds nothing ot the discussion and is liable to removal without notice.

It sounds like something you should be doing on the database directly, as Tim said. The code you showed doesn't help us understand the problem.
 
Marshal
Posts: 8960
646
Mac OS X Spring VI Editor BSD Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@OP

You are failing to explain the problem and the task you have at hand at this very moment. Potentially you are trying to do too much at this stage.
Those cryptic names of tables, that later get transferred to code, i.e. variable names - don't help either to visualise problem in a head (at least mine).

Ignore cases 2, 3 and 4 to cover, unless you got case 1 working.
Can you explain, what is the relation between queries in DB you need to create (?) and the Java classes you created?
 
So you made a portal in time and started grabbing people. This tiny ad thinks that's rude:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic