Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
Locally I attach to my DAO from my client like so;
try {
AssetsDao _dao = getAssetsDao();
Assets _result[] = _dao.findAll();
for (int i=0; i<_result.length; i++ ) {
display( _result[i] );
}
}
catch (Exception _e) {
_e.printStackTrace();
}
If my DAO tier is on another server, what are the methods that I can use to access this tier? I know I can create a web service and have heard I can use RMI but what is the most common method?
The question leaves lots of room for speculation. So you may want to expand quite a bit.
E.g. if the current implementation of your DAOs is using a database, you may as well already be able to use a different computer (i.e. server) by just adjusting your database's configuration.
Update (taking OP's clarification into account):
You have to come up with or (better) use an existing technique to let your client talk with your server; this has nothing to do with DAOs, though, as remotely accessing the service of DAOs is the same as accessing any other service remotely. Look at Remoting and web services using Spring. Although this is part of the spring framework documentation, it will give you a first start.
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed last month.
Improve this question
I have a Spring Boot application connected to a PostgreSQL database.
This server will be receiving HTTP requests such as POST from another software to store some statistics, but I want to avoid having to undergo the process of acquiring all of those statistics again if an entry that matches some of the identifiers that the statistics has already exists in the database.
How can I do this check from the software-side, instead of server-side?
That is, without an usual GET method, because that will possibly return a very large list, to the point where it becomes too expensive to find a matching entry and to make this check in the application.
I hope I understood you correctly!
There are several options to launch some functionality without waiting for external requests.
One option is to use the #Scheduled functionality of spring
#Configuration
#EnableScheduling
public class SpringConfig {
...
}
#Scheduled(fixedDelay = 1000)
public void scheduleFixedDelayTask() {
daoSevice.execute();
}
https://www.baeldung.com/spring-scheduled-tasks
Good luck!
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 1 year ago.
Improve this question
First of all, this is what I mean by good practice :
code that is easy to maintain / fix
code that can be scaled
an architecture that is not going to cause security issues
With this out of the way, here is my problem :
I have a User class, currently it extends the UserDetails and has additional data attached to it not relevant to security ( for example purposes, let's say I added a user description / a profile page and data ). It works well and I can log in using it.
I, however, have seen tutorials and colleagues separate the data from the user details. They have a MyUserDetails class that only does the bare bones and encapsulates a User class that is used as a data container and nothing more.
Here is a good example of what I mean ( user related classes are roughly
in the middle )
Currently my implementation "works" but I am unsure if it's good practice and am unsure if I should separate the elements contained in my own user class as I don't know if it's any better.
Any help is most appreciated.
If by UserDetails you mean org.springframework.security.core.userdetails.UserDetails class - then it's definitely good idea to separate it from your application model. Single responsibility - one of key stones of good software architecture.
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 7 years ago.
Improve this question
My back-end calls for a dynamic datasource and topology, and my front-end calls for a bunch of app coding that queries the RDBMS. My idea is to walk away from the JDBC API altogether, as it turns out, for any API the app coding couples itself to.
Here's the design idea... On queries, the app code passes in SQL, and receives DefaultTableModel as a result. On updates, the app code passes in SQL (even batches of it), and receives success/failure code (plus error message) as a result.
Would you couple all of your app code to class DefaultTableModel? Would there be a better class for generic, decoupled query result handling? (If I ever need metadata, I can subclass/encapsulate that in with the result) Are there examples out there of this already being done? I do not need more than the above for this application. I don't have extravagant RDBMS needs.
What standard non-JDBC options does the Java API have for holding the kind of data in a ResultSet? I am aware of AbstractTableModel and DefaultTableModel. In any event, it has to be smart enough to associate a class with each column in terms of datatype.
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
In Java I have the abstract class Place, with two concrete subclasses Area and Level; a Level must have a parent Area. But in trying to make unit tests for Level, I don't want to have create a full-fledged instance of Area. I see two ways of dealing with this:
1) Create an interface IPlace, extended by interface IArea, which Place and Area implement. Then create a MockArea class which implements IArea, and pass that to Level when testing it.
2) Use a mocking framework which will automatically create mock objects for me.
Which way is better? Or is there a third way to do it?
You're not giving us the reason why you don't want to create a full-fledged Area, but lets assume it does something difficult to test, like connect to a DB or read a file or something. Those are dependencies that it has. Dependency Injection is the answer.
For example, let's say Area does this in its constructor:
public Area() {
//get db connection
//do something with db connection
}
Now when you create a Level, it'll connect to a DB. Here's how you'd rewrite the constructor to use Dependency Injection:
public Area(Connection con) {
//do something with db connection
}
Now, when you create a Level, you can give it a fake Connection and are able to test your Level.
Now you can use a mocking framework to make a fake Connection. I recommend Mockito.
As you've written it, I'd suggest using a mocking framework.
Dependency Injection is great. Using it lets your classes state in an obvious way what types of things they need to interact with. If done properly, the need for mocked objects is often unavoidable. Get used to working with a mocking framework. I like Mockito personally.
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 4 years ago.
Improve this question
I have played a bit with Spring Roo, now I am asking myself what is the Roo suggested way or best practice way to trigger an action after an object update.
Let me explain it with an example:
Assume I want to implement a web based Bug Tracker (I don’t want to do this, it is only an example). A bug tracker, is about Issues. Each Issue has a state (New, Confirmed, Assigned, In Progress, Resolved.), a title and some other fields.
The user has a web form where it can enter and update all fields (state, title, …). When the state of an issue switches from ‘In Progress’ to ‘Resolved’, the system should send an email to all persons that are interested in the bug (How this list of interested persons is maintained, is out of scope for this problem).
The problem that I have is: How to trigger the email sending process when the state is changed (in a Roo application)? Because there are several problems:
How to determine if the issue state is changed?
We need to make sure, that the message send after the issue is complete updated (for example it would not work, to put the trigger in the setState() method of the Issue, because it is not guaranteed that the other values from the form (title…) are updated before the state is changed.
The mail must only be sended if the form was valid and the Issue is likely to be saved (I do not facing the problem that the transaction cannot be committed – this will be another problem)
Does anybody have a good, testable (unit tests) and maintainable solution? Maintainable means especially that the code to handle this should not be placed in the controller, because it will be used in several controllers and someday somebody will implement an new controller and he will likely forget to handle this email concern.
You can use the #PostUpdate annotation, a JPA life cycle callback listener.
class Issue{
#PostUpdate
protected void onPostUpdate(){
//This method wil run after the update
if(this.state == Resolved){
//...
}
}
Here is more information about the available callbacks.