[JBoss AOP] - Re: Metadata Scope
by kabir.khanï¼ jboss.com
I'm not the original author, but storing things directly in the invocation is more lightweight, you are storing in a map and don't have to store things in a threadlocal (which underlies the ThreadMetaData). The original intent for the metadata is to be "short-lived", i.e. the span of the invocations.. If you want "long-lived" metadata then you need to set it the other way, and the invocation will check whether it exists.
invocation.getMetaData() checks all available scopes, but at setting time you explicitly add it
-directly to the invocation
-to the ThreadMetaData
-to the instance advisor
I guess a flag could be added to setMetaData() to specify the scope, but I think it is fine as it is?
BTW on your server side you probably want to do something like
| try{
| ThreadMetaData.instance().addMetaData(...);
| ...
| }
| finally{
| ThreadMetaData.instance().clear()
| }
|
to avoid polluting subsequent threads with non-relevant metadata
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4074502#4074502
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4074502
18Â years, 11Â months
[JBoss Seam] - inject into a non-component?
by laksu
I have a wrapper class called Node implementing TreeNode from RichFaces. I try to avoid recursively populating the whole tree and so have a mechanism in there to populate each node as they are referred. And in conjunction with the "ajax" property of the tree component, I expect the individual population of the nodes happening in the ajax calls.
The class "Node" basically keeps a Map (required to be a Map by the tree) of my Category objects that are children of the wrapped Category object when populated.
I provide these details because I could not figure out what kind of a component the Node should be.
My proof of concept does not even start by populating the root node. I try to inject the session (I use Hibernate/session instead of JPA/em) but it is injected null or not injected.
So the question is if my "Node" should be a Seam component to have the Hibernate session injected and if so what kind of a scope I should put it in?
Here follows my Node class:
| public class Node<E extends Treeable<E>> implements TreeNode {
|
| @In(create=true)
| private Session session;
|
| private E value;
| Node parent;
|
| public Node(E aValue, Node<E> parent) {
| value=aValue;
| this.parent=parent;
| System.out.println("initing Node with Treeable="+aValue.getName());
| }
|
| private Map<Long,Node<E>> dataMap;
|
| public Node(String className) {
| List<E> rooties;
| System.out.println("Expanding root. session is"+session);
| rooties=session.createQuery("from "+className+" where parent"+className+" is null")
| .list();
|
| System.out.println("Root has "+rooties.size()+" rooties");
| dataMap=new HashMap<Long,Node<E>>();
| for(E rootie:rooties){
| Node node=new Node(rootie,this);
| dataMap.put(rootie.getId(),node);
| System.out.println("Rootie :"+rootie.getName()+" was added to roots");
| }
|
| System.out.println("initing rooties done");
| }
|
|
| public Map<Long, Node<E>> getDataMap() {
| if (dataMap==null){
| List<E> children;
| System.out.println("Expanding Node:"+value);
| String className=value.getClass().getName();
| children=session.createQuery("from "+className+" where parent"+className+"= :parent")
| .setEntity("parent",value)
| .list();
|
| dataMap=new HashMap<Long,Node<E>>();
| for(E child:value.getChildren()){
| Node node=new Node(child,this);
| dataMap.put(child.getId(),node);
| }
| }
| return dataMap;
| }
|
| public Object getData() {
| return this;
| }
|
| public void setData(Object data) {
| }
|
| public boolean isLeaf() {
| return getDataMap().isEmpty();
| }
|
| public Iterator getChildren() {
| System.out.println("getChildren is called for:"+toString());
| return getDataMap().entrySet().iterator();
| }
|
| public TreeNode getChild(Object id) {
| return getDataMap().get(id);
| }
|
| public void addChild(Object identifier, TreeNode child) {
| }
|
| public void removeChild(Object id) {
| }
|
| public TreeNode getParent() {
| System.out.println("getParent is called for:"+toString());
| return parent;
| }
|
|
| public void setParent(TreeNode treeNode) {
| System.out.println("setParent is called with:"+treeNode);
| }
|
| public String getType(){
| return (value==null)?"root":value.getType();
| }
|
| public String toString(){
| ...
| }
|
| public String getName(){
| return value.getName();
| }
|
| public E getValue() {
| return value;
| }
|
| }
|
View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4074495#4074495
Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4074495
18Â years, 11Â months