Solved

Annotated Resource loading properties from database

Posted on 2013-01-13
3
169 Views
Last Modified: 2013-05-30
I'm working on developing custom annotation which will pull values from datasource at runtime. I need immediate help on this task.

For e.g. Following class has defined annotated field pageTitle which will pull value for given parameter (rLable) from spring defined datasource at runtime i.e. getPageTitle() should return value for key "label.page.title" from database which is "My Page Title".

Class ResourceDataVO {

@myResources (rLabel = "lable.page.title")
String pageTitle;
....

public String getPageTitle(){
	return this.pageTitle;
}
}

Open in new window

0
Comment
Question by:sanjaykjadhav
  • 2
3 Comments
 
LVL 35

Expert Comment

by:mccarl
ID: 38772888
I need immediate help on this task
Perhaps, you should immediately ask your question then!
0
 

Author Comment

by:sanjaykjadhav
ID: 38772894
How to develop annotation accessing database? Please explain based on above usage of annotation.
0
 
LVL 35

Accepted Solution

by:
mccarl earned 500 total points
ID: 38772977
Firstly, you need to learn what Java Annotations are and what they are NOT!

They *are* a way to provide meta-data about a class/method/field/etc. And this meta-data can be accessed at compile time by compilers,etc or at runtime by your code or other code.

They are *NOT* of themselves active elements that can directly execute code, etc.


Therefore, to achieve what you are trying to do, you need some sort of annotation processor. This will look for your particular custom annotation and apply the desired behaviour that you are trying to achieve. How, and when and in what context this annotation processor runs is enitrely up to you, and it will depnd on exactly when you need this behaviour to have been applied.

You did mention Spring in the original problem statement, so one Spring like way of doing this would be with a BeanPostProcessor instance. Look at the code for say InitDestroyAnnotationBeanPostProcessor for an idea on what your code might have to do, in terms on scanning for an annotation on the bean that is being constructed. Obviously, your code would be different in terms of it needing to interface with the datasource to retrieve value(s) and populate them in the bean. You then just create an instance of your BeanPostProcessor within your appContext and then Spring takes care or running it for you when you instantiate your beans.
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question