Solved

Annotated Resource loading properties from database

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

685 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