Different applications to the same database - java

I have 3 different applications
ASP.NET web application
Java Desktop application
Android Studio mobile application
These 3 applications have the same database and and they need to connect from any part of the world with an internet connection. They share almost all the information, so, if you move something in one application it has to update the information in the other 2 applications.
I have the database on a physical server and I want to know how best to make this connection.
I have searched but I couldn't find if I have to connect directly to the server with some SQL Server, using Web Service, or something like that.
I hope someone could help.
Thank you.

I believe the best way is to first create a Web API layer (REST/SOAP) that will be used to perform all the relative operations in the centralized DB. Once that is setup, any of your applications written in any language can use the exposed web API methods to manipulate the data of the same DB.

If you are looking at a global solution - will you have multiple copies of the applications in different parts of the world as well?
In this scenario you should be looking at a cloud-hosted database with some form of geo-replication so that you can keep latency to a minimum.
There are no restrictions on the number of applications that can connect to a specific database - you do not have to create a different database for each and you may be able to reuse Stored Procedures between applications if they perform the same task.
I would however look at the concept of schemas - any database objects that are specific to one app should be separated from other - so put them in a schema for "App1". Shared objects can be in a shared schema.

Related

Update data in two differents PostgreSQL database servers

I have 2 differents applications (Web app and Desktop app) with differents database servers but same structure.
I want to have the same data in all databases, no matter where the user insert/update/delete a record. This is the easiest for me but I don't think is the optimal.
So, for example, if I insert a record in the desktop app, this record must be inserted into the web app server ("cloud") and vice versa.
I'm using Spring+Hibernate+PostgreSQL for the web app and JavaFX+Hibernate+PostgreSQL for the desktop app.
I'm considering 2 options at the moment:
Use sockets to send messages between servers every time a record has been inserted/deleted/updated.
Use Triggers and Foreign Data Wrapper in PostgreSQL. I'm not too familiarize with this, so I don't know if I can make what I want with this option. Can they work together?
There is another option? What do you think is the best?
The simplest and maybe best solution is to have one central read-write database and several physical replication standbys.
The standby servers will be physical copies of the main database, and you can read from them (but not modify data).

Is it meaningful to create a own backend in java?

in my project I have different applications that all need a database connection (all "apps" are running on the same server) now my question is, what is better:
one "backend" that get requested from the apps through netty or something and has the one and only mongodb connection and cache with redis
or
all apps have mongodb connection and global cache with redis
Thanks in advance
TG
//edit
all applications are for the same project so they will need the same data
I would suggest you to write separate Backends for each Application as tomorrow you might want to have different connection requirements from each application. For eg : One application might decide it doesn't want to use Mongo DB at all . One application might want to use more connections and might be a noisy neighbour for others. Unless you are willing to write a Full Policy based server which can cater to the unique requirements of each application.

Java Embedded Database For a Few Computer Access

I just wonder if i can(or is it a good way to use it) set location of an embedded database on a server computer and run my desktop app on a computer which have access to server folders and get/insert data from database?
For example, i have one server machine and 3 computers accessing it. I want them to insert/update data of server database which is installed as embedded style.
If i can't which method is easier and free way of doing it?
EDIT: Actually that server is a not server.. it is just a computer others can access to.
It isn't a good idea to share the embedded database's files between different applications. For most embedded database implementations it is even not possible, because the embedded database engine needs exclusive access to the underlying data files. Furthermore it is a performance penalty to access the database files over a shared folder.
I know only two databases allowing shared database file access: SQLite and MS Access. Java and MS Access is not a good combination. Avoid it, use it only if you are forced to. For SQLite I don't know if it performs well for different processes on the same machine. But over a shared folder, I think this would work only for the simplest cases.
So if you have multiple client applications accessing the same database then you should install a database server. A database server is exactly made for such a sceanario. It manages the server local database files efficiently and can handle many clients at the same time. There are simple ones like Apache Derby or H2 which are Java only implementations and very easy to use. If you need more performance then you can go with MySQL or PostgreSQL, but these are more complex to administer.
The word "embedded" normally means running inside a given JVM. To access it from clients, as opposed to from other code running in the same JVM, an method of connecting will need to be supplied, such as a connection protocol + port. Well, by the time you do all that, you have in fact rolled your own server.
If you just want filesystem access, well normally databases lock the files they're using. And if they don't, you will anyway be missing all of the control and ACID constraints that a database normally gives you.
H2 database can be run in different modes: embedded, in-memory, standalone and mixed.
I think you are asking about the last one "mixed" mode.

Working with a cloud app and local private database

We are developing a cloud ERP product using java and want to provide the users to have an option to work either with a local database file or the database on the cloud. To some of our customers, their data is very sensitive and they do not want their data stored on web server, instead want to have the database on their own server/pc.
Will this kind of offering be technically viable, secure & effective to implement and maintain? If so, can anyone recommend the best work around for this kind of architecture where the application on our cloud server can work seamlessly with the local database?
Many Thanks
LJ
For your customers concerned with security, maybe using a local datastore such as MySQL running on a local server and a local instance of the ERP product, also running on a local server. And I would advise encrypting all sensitive columns using something like AES_ENCRYPT() -- even on this local database.
Otherwise I don't know of a way to run a hosted App with a secured local database without introducing all kinds of data vulnerabilities.

Can a second GAE application access the datastore of a primary application?

If I had an application that stored information in its datastore. Is there a way to access that same datastore from a second application?
Yes you can, with the Remote APIs.
For example, you can use Remote API to access a production datastore
from an app running on your local machine. You can also use Remote API
to access the datastore of one App Engine app from a different App
Engine app.
You need to configure the servlet (see documentation for that) and import the appengine-remote-api.jar in your project (You can find it ..\appengine-java-sdk\lib\)
Only remember that Ancestor Queries with Remote APIs are not working (See this)
You didn't mention why you wanted to access the datastore of one application from another, but depending on the nature of your situation, App Engine modules might be a solution. These are structurally similar to separate applications, but they run under the same application "umbrella" and can access a common datastore.
You can not directly access datastore of another application. Your application must actively serve that data in order for another application to be able to access it. The easiest way to achieve this is via Remote API, which needs a piece of code installed in order to serve the data.
If you would like to have two separate code bases (even serving different hostnames/urls), then see the new AppEngine Modules. They give you ability to run totally different code on separate urls and with different runtime settings (instances), while still being on one application sharing all stateful services (datastore, tasks queue, memcache..).

Categories