Announcement Announcement Module
Collapse
No announcement yet.
Spring is Right? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring is Right?

    I have the following architecture requirements:

    1. Use JPA (hibernate), Spring, AOP (compile-time weaving), and @Transactional

    2. [Service Objects] <-> [Data Access Objects] <-> [Data Sources]

    The problem is that the targeted data sources are dynamic and determined at run time depending on which "client" makes use of Service Objects.

    I've read up on various techniques and I think I can solve it except for requirements 3.

    3. Add data sources dynamically with no service down-time. That is, bring online a new datasource and change the application context to add extra data source wirings at run time.

    JMX seems to be the way to go, BUT can the ApplicationContext be changed dynamically? Ie. can new beans be added, etc...?

    Thanks,

  • #2
    You have a number of options then:
    • check spring source, perform necessary downcasting and register beans within the context via the mechanisms used by spring internally (not good approach imho);
    • perform necessary dependency change by hand at runtime. I.e. if you want to change datasource used by particular DAO, you can manually inject new datasource to it;
    • if your 'used resource dependes on client' is consistent between all resources you can implement custom bean scope that provides necessary resource based on available client information (the best approach from my point of view);

    Comment


    • #3
      So, the idea is that use custom scope in combination of some custom factory managing data sources. The custom factory can then be modified at runtime to manage additional or less data sources.

      Sounds right?

      Comment


      • #4
        Only the custom exists at the higher level of abstraction. Custom scope factory belongs to implementation. So, the answer is to use custom scope and scoped proxies for dependency configuration, expose necessary services for underlying mechanisms runtime configuration.

        Comment


        • #5
          I am thinking that

          1. Scoped proxy
          2. AbstractRoutingDataSource

          ought to do the trick. I can manipulate the AbstractRoutingDataSource at runtime to add/remove data sources.

          One key issue is how to link JPA EntityManagerFactory/EntityManager (Hibernate impl.) to the whole thing. I don't mind using one EntityManager per data source.

          What are your thoughts?

          Thanks...

          Comment


          • #6
            Refining

            <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close" scope="myScope">
            <aop:scoped-proxy/>
            </bean>

            <bean id="entityManagerFactory"
            class="org.springframework.orm.jpa.LocalContainerE ntityManagerFactoryBean" scope="myScope">
            <aop:scoped-proxy/>
            </bean>

            <bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionM anager" scope="myScope">
            <aop:scoped-proxy/>
            </bean>

            "myScope" will handle the instantiation of transactionManager, entityManagerFactory and dataSource as per some specific values...

            sounds right?

            Thanks...

            Comment


            • #7
              Seems ok to me

              Comment


              • #8
                I am hesitating over the part where my "scope handler" instantiates the beans. Is there a way to delegate the "new" to Spring along with appropriate dependencies so Spring can wire up the objects?

                I am hesitating is I wonder if a plain old "new" is sufficient for all the beans in question.

                Comment


                • #10
                  Wouldn't it be nice to be able to pass in a snippet of "<beans></beans" at runtime to Spring and have Spring add it to its application context?

                  That would be cool...I think...

                  Comment


                  • #11
                    Either a snippet or an object graph reflecting the same...

                    Originally posted by Coder View Post
                    Wouldn't it be nice to be able to pass in a snippet of "<beans></beans" at runtime to Spring and have Spring add it to its application context?

                    That would be cool...I think...

                    Comment

                    Working...
                    X