Sun River
          Topics about Java SE, Servlet/JSP, JDBC, MultiThread, UML, Design Pattern, CSS, JavaScript, Maven, JBoss, Tomcat, ...
          posts - 78,comments - 0,trackbacks - 0
           

          1. How someone can define that a method should be execute inside read-only transaction semantics?

            A

          It is not possible

            B

          No special action should be taken, default transaction semantics is read-only

            C

          It is possible using the following snippet:
          <tx:methodname="some-method"semantics="read-only"/>

          D

          It is possible using the following snippet:
          <tx:methodname="some-method"read-only="true"/>  

          explanation

          Default semantics in Spring is read/write, and someone should use read-only attribute to define read-only semantics for the method.

          2.      What is the correct way to execute some code inside transaction using programmatic transaction management?

           A

          Extend TransactionTemplate class and put all the code inside execute() method.

            B

          Implement class containing business code inside the method. Inject this class into TransactionManager.

          C

          Extend TransactionCallback class. Put all the code inside doInTransaction() method. Pass the object of created class as parameter to transactionTemplate.execute() method. 

            D

          Extend TransactionCallback class. Put all the code inside doInTransaction() method. Create the instance of TransactionCallback, call transactionCallback.doInTransaction method and pass TransactionManager as a parameter.

          3. Select all statements that are correct.

          Spring provides a consistent programming model across different transaction APIs such as JTA, JDBC, Hibernate, JPA, and JDO.

          The Spring Framework supports declarative transaction management.

          Spring provides a simpler API for programmatic transaction management than a number of complex transaction APIs such as JTA.

          The transaction management integrates very well with Spring's various data access abstractions.

          4. Does this method guarantee that all of its invocations will process data with ISOLATION_SERIALIZABLE?
          Assume
          txManager to be valid and only existing PlatformTransactionManager .
          publicvoid query(){
                 DefaultTransactionDefinition txDef =newDefaultTransactionDefinition();
                 txDef.setIsolationLevel(TransactionDefinition.ISOLATION_SERIALIZABLE);
                 txDef.setReadOnly(true);
                 txDef.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRED);
                 TransactionStatus txStat = txManager.getTransaction(txDef);
                 // ...
                 txManager.commit(txStat);
          }

          explanation

          If this method executes within an existing transaction context, it's isolation level will reflect the existing isolation level. For example JDBC does not specify what happens when one tries to change isolation level during existing transaction. PROPAGATION_REQUIRES_NEW will assure that transaction isolation is set to serializable.

          5. You would like to implement class with programmatic transaction management.
          How can you get TransactionTemplate instance?

          It is necessary to implement a certain interface in this class and then use getTransactionTemplate() call.

           

          It is possible to declare TransactionTemplate object in configuration file and inject it in this class.

          It is possible to declare PlatformTransactionManager object in configuration file, inject the manager in this class and then create TransactionTemplate like
          TransactionTemplate transactionTemplate =newTransactionTemplate(platformTransactionManager);

          It's possible to inject either PlatformTransactionManager or TransactionTemplate in this class.
          Option one is obviously wrong.

          6. Check the correct default values for the @Transactional annotation.

          PROPAGATION_REQUIRED

          The isolation level defaults to the default level of the underlying transaction system.

          readOnly="true"

           

          Only the Runtime Exceptions will trigger rollback.

          The transaction timeout defaults to the default timeout of the underlying transaction system, or none if timeouts are not supported.

          7. To make a method transactional in a concrete class it's enough to use @Transactional annotation before the method name (in Java >=5.0).

          correct answer

          FALSE

          explanation

          No, @Transactional annotation only marks a method as transactional. To make it transactional it is necessary to include the <tx:annotation-driven/> element in XML configuration file.

          8. The JtaTransactionManager allows us to use distributed transactions. (t)
          posted on 2007-12-01 15:20 Sun River 閱讀(856) 評論(0)  編輯  收藏 所屬分類: Spring
          主站蜘蛛池模板: 乐安县| 思茅市| 元阳县| 佛坪县| 英山县| 澳门| 屯留县| 天水市| 柘荣县| 商河县| 许昌市| 无棣县| 抚松县| 敦煌市| 泸州市| 阿荣旗| 邵阳市| 淄博市| 高陵县| 沾化县| 承德县| 兰溪市| 斗六市| 呼和浩特市| 利辛县| 平乐县| 绥德县| 西青区| 阳曲县| 莱州市| 濮阳县| 丹阳市| 瑞金市| 湖州市| 许昌市| 池州市| 保定市| 海南省| 邛崃市| 启东市| 闻喜县|