Switching between MongoDB and JPA (Postgres) in the same project [closed] - java

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
In our current project we use MongoDB. Recently there was a request to switch to Postgres.
We don't want to drop MongoDB and just migrate to Postges right away. It would be great to have some sort of a switch in app config to use one or the other.
I know that is possible to have both in the same app (you can have Mongo config and JPA config). Usually it is done to store different domain objects (one type stored and retrieved from Mongo and the other one is stored and retrieved relational database). In these types of projects there are two domain models that serve corresponding persistence mechanisms.
Is there a way to have some sort of an abstract data model, two implementation for it and config switch that will either use MongoDB or Postgres?

Sounds like you should use an interface and then switch to the desired implementation. Not sure if for example Spring's autowiring is the "config switch" you expect, but it should work along those lines.

Related

Composite relationship in RESTful API using Spring Boot and Spring Data JPA [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 3 years ago.
Improve this question
What would be recommended way to implement composite relationship between two entities when building REST API using Spring Boot and Spring Data JPA?
As we have existence dependency between container and its contents, do we have to create, update and delete contents through container's API, or should it be handled through separate, specific content's API call?
In my opinion, this doesn't depend on the chosen framework (eg Spring) but depends on the chosen architecture.
If you, for example, adhere to DDD principles and your entities compose an aggregate, then you should work with them as a single whole.
Otherwise, if they are independent, you can work with them separately.

Java Data Base Overflow? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
My code is simple, it generates a Data Base to store certain data (obviously), but the problem resides in the fact that it would create an "overflow" of DBs becuase every time the class ran it would generate another Data Base, I heard of a command:
CREATE DATABASE IF NOT EXISTS insertYourFavoriteName;
But some people say that why should I need a DB for each computer, when I could just do a central one when users conect, but correct me if I'm wrong, that would make the app depend on internet, right?
So in resume here are the 2 questions:
Does the command mentioned above works? Or does a better version or way to work around it exists?
Data Bases where all users connect to it mean that you need a server, and as a consecuence your app would depend on internet?
If you want to learn about databases you practice basic CRUD operations on that database. After that do some sample applications on database
If you want to create a database if not exists in mysql simply use this CREATE DATABASE IF NOT EXISTS DBName;
Basically before checking all these things you have to have basic understanding of what is database and how it works, So, please go through some good resources and get good understanding on the concepts.

Best way for encapsulating the oracle and mysql [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
I have many kinds of db, some are oracle and some are MySQL ,
so when i have an operation about transaction , how can i know which db should be operated.
Have the ways to encapsulate for them to ensure the correct operation ?
what should i do to route these transaction to the correct db ? Do you have any ideas?
Database portability is a great goal to aim for, and is fully achievable for standard & even moderately complex business applications.
Practically, there are two main issues:
1) Some databases (Oracle) have non-standard DDL, especially data-types. This can be converted easily, with search-and-replace.
2) ID/ primary key generation has to be portable; this rules out sequences & auto-generated columns. Use an allocator table instead, which can be completely portable as well as significantly more performant.
Using a persistence layer (such as Hibernate) helps insulate over a few other differences. I've had very good success making even major & complex applications, coming from a major migration and re-engineering project, portable from Oracle to MySQL.

local databases for storing strings in java desktop application, currently using MongoDB [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
I am currently working on a project in which I am storing the name of program/application window titles and my knowledge of databases and datastores is fairly limited.
The idea is that I want to query the database with a string to see if it is present in the database. I am currently using MongoDB to do this but I have seen that MongoDB is mostly used to be run on a server which isn't what I'm looking for.
My question is - if I am just storing strings / searching for strings would a custom Array or HashMap be sufficient or would search times make it inefficient meaning that SQLite would be more ideal for this situation.
SQLite is perfect for this application. Firefox, for example, uses SQLite for storing its internal configuration settings (the about:config page). SQLite databases are single files, and it can be transparent to the user and requires very little in the way of system resources--unlike most server/client database solutions.
i would suggest to use java preferences api, if the data to be saved is not too much and if it needs to be available even when the application is terminated and restarted.,

Easiest way of getting third party database information into java objects [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I am making some small "business intelligence" applications/tools that need to talk to other systems. Primarily accounting systems that believe that databases are an integration layer (or are too lazy to provide an api).
What's the easiest way of getting specific data out of a third party database and into my Java objects?
Notes:
(I am now bolding the points below that have not been directly answered)
This is absolutely a read only situation. I would prefer a solution that cannot write.
Depending on speed and/or aggregation requirements, I may want/need to store these records at a future point. (This may or may not impact on solutions like hibernate which would have difficulty reading from one db and writing to another)
The first cut would be a very select partial object population (I have generated my objects from an xml schema, and the database will only need to supply 30% of the possible fields etc)
The first db integration target is (Visual?)FoxPro - hence point 2.
I am currently developing primarily in Java, but expect that to change to scala soonish (can LINQ help here?)
The standard of mapping db schema to objects (and vice versa) is the Java Persistence API. There are several implementation like Hibernate and EclipseLink (and others). I can't tell for all of them, but hibernate an eclipse plugin called hibernate tools, which can generate Java classes from the schema. You can find instructions here
JPA has its own query language called JPQL, Hibernate supports an extended version of it called HQL. Both looks like SQL, applied to objects.
I suggest you take a look at ScalaQuery, if you are doing Scala code.

Categories