i have a spring boot Web application with Spring Data JPA and Hibernate and a want to write a Java handler to check in time intervals the fill level of my postgresql database and delete old data accordingly. for example if it reach a max of 10 GB the database has to delete the old data. Is there any Java Library or any suggestion for this purpose? I found only SELECT statements to perform directly on the PostgreSQL Database (https://wiki.postgresql.org/wiki/Disk_Usage)
Related
I have java vertx web application which uses mysql as database also take apache kafka in use. To increase the speed of search query i was thinking to add apache solr in my application and store few tables in it.
But i m not able to find a way to keep those few table stored in mysql data in sync with apache solr.
i try to read DIH documentation but didnt found any solution
I'm currently building a Spring Boot Service with a h2 in-memory database.
This Database acts as an cache for a part of the data on a central db2 database with a different database schema.
Now when the Spring boot service starts it needs to populate the h2 database with the latest data from the central database.
How can I do this in the best way performance wise?
I'm currently looking to create an different data-source in my service to first get the data and then save the data to the h2.
This doesn't feel like a good solution and it would take quite a long time to populate the database.
If you want to use H2 instead of your DB2 database ... and if you don't want to re-create the database each time you run your app ...
... then consider using an H2 file, instead of in-memory:
http://www.h2database.com/html/features.html
jdbc:h2:[file:][<path>]<databaseName>
jdbc:h2:~/test
jdbc:h2:file:/data/sample
jdbc:h2:file:C:/data/sample (Windows only)
You can "initialize" the file whenever you want (perhaps just once).
Performance should be excellent.
Per your update:
I still need to access the central db to get the latest data in the
fastest way possible. The central db needs to stay for other services
also accessing this
The "fastest" way to get the very latest data ... is to query the central db directly. Period - no ifs/ands/buts.
But, if for whatever reason, you want to "cache" a subset of "recent" data ... then H2 is an excellent choice.
And if you don't want to "rebuild" each time you start your H2 database, then save H2 to a file instead of making it in-memory.
The performance difference between H2:mem and H2:file is small, compared to the network overhead of querying your central db.
'Hope that helps...
I have to write an application (in server 1) that will generate a SQL. The SQL will be transferred to some different server (server 2). Another application which is deployed on server 2 will run the query on a database deployed in server 2.
Now there can be different types of database and the query will not be a simple one (may be 200 lines of query). Is there any third party application (like Hibernate) which I can use to create the query may be in a different format (like HQL), which can be transferred to server 2 and the application on server 2 will convert it to a DB specific SQL and run it?
I am using Spring & Java 8 to write the application.
Thanks in advance.
It is not possible for native sql query. But If you use any ORM technology like Hibernate then it is possible. Hibernate dailect will generate different database specific query for you. Though hibernate is an ORM technology it will defines relations with Objects that will represent your database table's. Popularly we call that objects as Entity. SO If you want to use different database then there will be no problem. But you have to change dailelect for different databases.
Why not use ORM - JPA or Hibernate and move queries to configurable different XML which works for each platform/DB? Deploy the XML based on DB...
No shortcut here but if you use ANSI SQL standards which is a platform-independent and is used as a base with most Database systems including Microsoft SQL Server, Oracle, MySQL, IBM DB2 etc you queries should work almost without any issues. Obviously you will loose on added features of DB's provide.
There is 6GB table (oracle 12), which changes approximately every 1 second (delete,insert,update).
I have restful application which uses hibernate to call database with some filters to get data from this DB table. there are cases when "user" wants 1GB data from table as csv or xlsx report, selecting and fetching data from database takes too long.
so I thought, maybe its better to take this whole DB table in to java object (in to heap) and make search and exports directly from this object.
but there is a problem:
my java object should be synchronized with oracle Db table.
What is the best way to listen/track to oracle table changes from java?
one way that I know is oracle util UTL_HTTP which can call web service directly from oracle, and using this util inform a service about data changes.
Can hibernate also listen to oracle table changes which is not initiated from the same service? I mean, is it possible that APP1 listen to some oracle table_1, and when APP2 changes some data in to oracle table_1, APP1 to know this automatically. if it can, please provide some examples.
also, I wonder what do you think about importing whole table data in to a service, and make filters in this object, will it be lightweight? (I know that ~6GB memory will always in use)
I want to migrate some data from an existing database to Cassandra DB.
Post migration, I want to verify whether all the data were migrated successfully or not.
I was wondering whether Cassandra Driver for JAVA provides any internal implementation feature to verify the same so that I can reduce the unnecessary overhead incurred during the interaction with Cassandra DB?
It all depends on the type of database that you are migrating from you can either check row per row in your previous database and then make queries against cassandra to see if the rows are there. That would be the safest approach imho.
Then you can do some very complex stuff like having spark jobs that do the comparisons.
Or you can iterate over all the rows in cassandra and check against the original database. Something like this: Fetch all rows in cassandra
The list could go on and on. For details you would have to tell more about the originating database, data model in cassandra and give some context what it means for a row to be verified ... other than it's there.