Solved

Annotated Resource loading properties from database

Posted on 2013-01-13
3
170 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
java stored proc example 9 44
configure dependency in POM for new database 3 34
How do I remove an object from a 3 40
JavaFX TableView not displaying correctly 3 57
An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…

838 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