I am making an inventory management program which has a Swing GUI as front end, with multiple users on LAN sharing a database.
I have successfully made my GUI components and a local DB and run the program as per my requirements on a standalone pc(without networking).
Now, I need some insight as to how to scale my application to a network environment. I have already tried the following and it fails:
Having MSACCESS on one of the computers, I make a connection to the db with DriverManager.getConnection("jdbc:ucanaccess:////COMPUTER-PC/admin/DB.accdb");
All works well, however when 2 users are simultaneously connecting to the database, after certain update queries from both users, the data does not remain consistent. I am stuck here. How to manage the data and maintain consistency.
You're describing a 2-tier architecture (client-db).
In most cases you want to have the business logic, consistency check etc. on the backend and thus a 3-tier architecture (client-backend-db).
You can e.g. use Spring Boot to create a simple backend.
Spring Initializr can get you started e.g. with Spring Web (MVC), Spring Data JPA and H2 Database (if you don't need to use MS Access) module selected.
The downsides are:
you need a server to run the Spring Boot JAR. But you can also run it on the machine currently running MS Access.
you need to think about client-backend communication, e.g. using REST. But there are many samples on the Internet, e.g. using Spring RestTemplate or Spring WebClient.
Your question seems little basic to me .
This book by Martin Fowler is little old but It will give you a solid foundation .
Patterns of Enterprise Application Architecture Hardcover
by Martin Fowler
Related
We are building a web portal based application with html5/javascript frontend and Play framework backend with mongodb.
I am an algorithm developer from the networking industry, we have to do design analysis of networks. This is done by complex algorithms in standalone java based application today. We are planning to move this standalone logic to the play application server with user logic and session management.
This would mean, we would have huge object cache and processing requirement everytime a user asks for analysis and we are planning for a 100+ user simultaneously. There is also lot of static data present today in the java cache model of the standalone application.
I am new to application server space, many people suggested that web application servers are not meant to manage this kind of usecase and the object cache is meant for volume query on a db and simpler rendering of db data, rather than running algorithms on it.
Question I have are :
Can Play or any other web application server manage such processing need?
Is there any design recommendation to convert heavy java based stand-alone tools to web-based, business logic and session managed and db persisted environment?
I'm creating a java desktop application using swing which requires some database persistance for which I'm planning to use Hibernate. I'm pretty new to desktop application development so I wanted to know if and how the database can be created on the client computer when installed.
Is there a script to be run or maybe a hibernate configuration which initiates database creation?
A sample tutorial or example illustrating this will be ideal (although I was not able to find one).
Thanks in advance for any help provided.
Hibernate is not an database server itself, it is a object-relational mapping framework so you need a either embedded or stanalone database server. Java DB that comes with the JDK will be sufficent for desktop applications.
http://hamidseta.blogspot.in/2008/05/install-mysql-server-50-silently.html
In your package installer scripts perform the steps of silent MySql installation. In the BAT file put the code you find in the above link before triggering your Java application installer.
As per free licensing terms, one should not package MySql bundle for free, just check about the licensing if you bother.
I think it would be better if you can start with javaDB or SQLite.
They are perferred embedded database technologies for desktop java applications.
You can download the jar for sqlite-jdbc from here.
Take a look at few tutorials on JDBC
If you making swing applications, make sure you learn to use swing worker well. It will
be important to perform background processing.
Hibernate is Framework used as middle layer in project which interact between database and Business layer logic.
Hibernate features
J2EE integration
Object/Relational mapping
Automatic primary key generation
Object-oriented query language
So my suggestion is to go with MySQL because
Handles large databases. We use MySQL Server with databases that contain 50 million records. We also know of users who use MySQL Server with 60,000 tables and about 5,000,000,000 rows.
A very fast thread-based memory allocation system.
Very fast joins using an optimized one-sweep multi-join.
The server can provide error messages to clients in many languages.
This is only few features but you go to official site for more detail. And most important it's open source.
And the post help to install and configure on client system.
After one year i have finished the development of my application.
Now when searching the internet i got a new knowledge about the 3tiers applications.
My Application running on 2tier Architecture (Standalone application connecting directly to database server).
My Application Developed using:
- Java SE (Swing).
- MySQL Server as database server.
I want to reconstruct my application to be 3tier application. (Client-Server)
- What technology i have to use?
- What I have to change within my current code?
- The application will run on network, there will be Many concurrent users who will use the application accessing the database (Insert,Update,Delete ... etc).
There are two main approaches. The first involves rewriting the client in HTML/JavaScript with help from one of the many available frameworks (Struts, Spring, Java Server Faces, etc.) Unless you specifically prefer a web application to a Swing application, or your user interface is a very thin layer on top of your business logic, then this is a costly approach.
The second approach involves inserting a server between your user interface and your database. Open source Java-based servers include Jetty, Tomcat, Spring, JBoss/WildFly and GlassFish.
If your code is structured in layers so that the user interface, the business logic and the data access code belong to separate layers, then converting from a two-tier system to a three-tier system should be straightforward once you understand the capabilities of your chosen mid-tier server and how to use them.
The basic technique is:
All user interface/Swing code remains on the client.
All business logic moves to the middle-tier server. The client talks to the business logic using a remote protocol.
All data access code is moved to the server.
Dependency Injection is useful to perform this refactoring step-by-step and also allow you to choose between working in two-tier or three-tier mode if that is needed.
The three main differences between a two-tier and three-tier application are:
Security - there is a new access point into your system. You need to be careful about the access rights it has to the database - do you have one server user that can do everything, or does each user need to use their own connection credentials. You also need to secure the server correctly and be careful not to add security holes in your mid-tier API.
Remote access - some method calls that were previously made within the same process are now made across the network. Server APIs generally need to support less fine-grained operations than local APIs, and the amount of data shipped as arguments and return values may also need to be managed.
The structure of your application becomes more important. The code isn't necessarily very different, but it will need to be organised into different layers.
Java EE is your answer.You could choose a framework like Hibernate/Spring/Struts to build a 3 tier architecture (MVC).You would also need to make a choice for a servlet container.Apache Tomcat should be a good choice.
It would be nice if you could post little more details like complexity , purpose etc. of your application.
I am dealing with quite an interesting challenge, we have an integration project that needs to interconnect the "in development" application with legacy applications. We developed a proxy that calls the legacy application from the new application and now we need to test or development against the code of a third company. I order to do that we setup a server with the same setup as the productive server and we will connect the client application to this server for testing purposes.
Application rough involved technologies: Java EE 6, Postgresql, java 7, JPA 2, Hibernate, Jboss 7
My issue is that we need to populate the DB with pseudo-real data. Meaning data that can be generated and is appropriate from the point of view of the application. The data must be somehow real as it reacts to different notifications sent by the legacy applications suite via JMS. The concerns are that it should be simple, quick to implement and somehow to create a mechanism for easy reusage - whenever I need new data, just run it once (maybe with parameters?!) and the magic is done.
Currently I try to find the best approach, I considered the following up to know:
plain SQL script
java application that inserts the needed things in DB
somehow exciting idea - use a scripting language to have the job done (which one - python, groovy)
Any idea, suggestion, question would be more than welcomed.
Maybe you should use DBUnit it has an XLSImporter. So you can maintain your test data in an Excel file.
I order to populate the DB I built a tool on top of the application's public API that creates the needed entities. To make it easier for our customer to add the needed data I exposed appropriate methods as WS that can be called as wanted by the client.
I wrote the application in java, for subjective reasons, even if I consider that a scripting language - I suppose groovy - would've been the best choice.
I have a project this year. It is about developing a Java application with a database for sharing and validating documents between the manager, secretary and head of finance.
My question is: How to make the database accessible by all, since the application will be installed on computers that I mentioned above, do I have to install it (the database) on these computers? The constraints of consistency and integrity of the database will be violated. The users will not have the same copy after each update!
Is there a possibility (or technology in Java) to put the database on the web and there will be accessible by all, or make it accessible from a computer that I realize as a server (client-server).
I would be grateful for your help or giving links for Tutorials.
How to make the database accessible by all, since the application will be installed on computers that I mentioned above, do I have to install it (the database) on these computers? The constraints of consistency and integrity of the database will be violated. The users will not have the same copy after each update!
Your question suggests that you will need one database on one computer. Let's call it a DB computer. I'd suggest this be a server, that no one from regular staff, such as secretary, manager, etc... can access.
Having one central database will eliminate your worries about integrity violation.
Now, you have two options. You can make a web application that your users will use to interact with your system. This is a more modern approach, since you'll have a 3 tier system:
users will access your application via a browser
the web application itself is stored on an application server, and it is accessing the database
the database is the backend part
The second option is making a desktop application and deploying it to everybody's computer that will use it; and afterwards making it connect to the database for interacting with it.
The first option is easier when you want to expose your application to a large number of users (and to the web), but know what you're doing when doing stuff like this, since you have to take security very seriously.
If you go the first route, you will need a few things:
First, a database. Use what you can, but if you need free and high quality databases, use PostgreSQL or MySQL.
Second, an application server. I suggest using Tomcat or GlassFish.
Now, you need to develop your application using JavaEE. There is a wealth of information about this, so I hope this will help you in the beginning and point you in the right direction.
Note that Tomcat doesn't support Java EE fully, but a subset of it. And this subset is surely more than enough for what you need to accomplish.
If I understand you correctly, you are looking for ways to implement a client-server system, where several clients on distinct computers each connect to a central server (or cluster of servers) hosting a DB. In Java, usually (but not necessarily) the DB is inside a web application, and the clients are lightweight web clients - in this case it is usually called an enterprise application.
Java has a whole dedicated SDK for this, called Java Enterprise Edition. You may find many questions dealing with this on SO, here are a few which I think may be especially helpful:
Is the offical Sun Java EE tutorial the best way to learn how to make Java web apps?
What to learn for making Java web applications in Java EE 6?