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.
Related
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
I need to build a desktop application for internal users for certain business. It also needs web based GUI for external users. I know, with web GUI both internal and external users can access it, but there are certain factors which are outside our control - due to which, desktop application is really unavoidable. For the purpose of this question, I would like to focus on the way to support both Desktop client (Swing) and Browser client.
Are there any best practices to be followed? I could think of below:
Expose service classes as web services and use these from both Swing client and web client
Expose service classes as EJB (business is into Java EE techs) and use Swing client as EJB client. Web client can use controller classes to interact with EJB
Are there any known benefits of using either approach, apart from technology agnosticism offered by web services?
Also, for swing client, I am thinking of using Java Web Start for easy distribution. I have never used it before, but from what I understood, it can support automatic version check at startup and update the client when required - is this correct?
If you need to avoid dependency to Java/JVM on the browser (which you most likely at least want to), you should definitely go with mixed Swing-Vaadin approach. Build the internal application with Swing or JavaFX and web part with Vaadin. The programming model in Vaadin is so close to typical desktop UI library that it is really easy for the same developers to work with both code base, and naturally you'll use exactly the same backend.
See the example application I recently built to demonstrate a setup like this.
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.
We have a desktop java application (image-processing) that is working great, now we have to add a client/server architecture using Java EE plateform.
We must use also MVC, and interacting with many other libraries like JDOM, JMatlink(MATLAB), and calling some exe files.
Based on your experience what is the best choice to do that (framworks, ... )
Correct, you must use an MVC framework to design a flexible and reusable web application on the Java EE platform.
I suggest the following design:
Use JSF (Java Server Faces) to design the front end. As you are migrating your desktop application then it will better suit you becuase it's Component and Event driven framework.
Middlware: EJB 3(or EJB3.1) This will provide best available flexibility, performance and security to call your Business components directy from JSF Beans or any other remote application.
Over here you can use various design pattern to encapsulate Library and database access i.e. DAO (Data Access Object).
Use DTO (Data Transfer Objects) to transfer your request/response.
Hope it will give base to start your research.
If you can abstract the layers that talk to the backends such that your frontend (Swing?) doesn't need to know where those service are located, you are half-way there.
The key should be a good module concept. Frameworks like the NetBeans platform help you with that, and they can easily integrate non-visual modules that handle the backend code.
I'm not sure what you mean with "We must use also MVC"
MVC is a design pattern not a library or framework.
But if you use something like the NetBeans platform, you'll be applying that pattern anyway, because it forces you to think in modules. Each module will have a defined responsibility and during startup it registers itself with the application.
Take an application that allows you to manage people (e.g. for a human resource department). One module is responsible for displaying a form where the user can look at a single employee. That module in turn looks for a provider that can load or list all employees. How that provider gets the data is invisible to the front end. It could use a flat file, a relational database or a call to a remote EJB server (this is were you could plug your JavaEE stuff in)
The application could even download the modules from the server if correctly configured.
The key is to make the modules independent from each other. This is true for any large scale application regardless of the technology used (web application, a server side daemon or a desktop application)
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?