Package org.springframework.transaction.support

Examples of org.springframework.transaction.support.TransactionTemplate


    public SpringTransactionPolicy(TransactionTemplate template) {
        this.template = template;
    }

    public Processor wrap(Processor processor) {
        final TransactionTemplate transactionTemplate = getTemplate();
        if (transactionTemplate == null) {
            LOG.warn("No TransactionTemplate available so transactions will not be enabled!");
            return processor;
        }
View Full Code Here


    sfControl.replay();
    sessionControl.replay();
    queryControl.replay();

    JtaTransactionManager ptm = new JtaTransactionManager(ut);
    TransactionTemplate tt = new TransactionTemplate(ptm);
    tt.setReadOnly(readOnly);
    assertTrue("JTA synchronizations not active", !TransactionSynchronizationManager.isSynchronizationActive());
    assertTrue("Hasn't thread session", !TransactionSynchronizationManager.hasResource(sf));

    Object result = tt.execute(new TransactionCallback() {
      public Object doInTransaction(TransactionStatus status) {
        try {
          assertTrue("JTA synchronizations active", TransactionSynchronizationManager.isSynchronizationActive());
          assertTrue("Hasn't thread session", !TransactionSynchronizationManager.hasResource(sf));
          HibernateTemplate ht = new HibernateTemplate(sf);
View Full Code Here

    tmControl.replay();
    sfControl.replay();
    sessionControl.replay();

    JtaTransactionManager ptm = new JtaTransactionManager(ut);
    TransactionTemplate tt = new TransactionTemplate(ptm);
    final List l = new ArrayList();
    l.add("test");
    assertTrue("JTA synchronizations not active", !TransactionSynchronizationManager.isSynchronizationActive());
    assertTrue("Hasn't thread session", !TransactionSynchronizationManager.hasResource(sf));

    Object result = tt.execute(new TransactionCallback() {
      public Object doInTransaction(TransactionStatus status) {
        try {
          assertTrue("JTA synchronizations active", TransactionSynchronizationManager.isSynchronizationActive());
          assertTrue("Hasn't thread session", !TransactionSynchronizationManager.hasResource(sf));
          HibernateTemplate ht = new HibernateTemplate(sf);
View Full Code Here

    sessionControl.setReturnValue(true, 1);
    sfControl.replay();
    sessionControl.replay();

    JtaTransactionManager ptm = new JtaTransactionManager(ut);
    TransactionTemplate tt = new TransactionTemplate(ptm);
    final List l = new ArrayList();
    l.add("test");
    final HibernateException flushEx = new HibernateException("flush failure");
    assertTrue("JTA synchronizations not active", !TransactionSynchronizationManager.isSynchronizationActive());
    assertTrue("Hasn't thread session", !TransactionSynchronizationManager.hasResource(sf));

    try {
      tt.execute(new TransactionCallback() {
        public Object doInTransaction(TransactionStatus status) {
          try {
            assertTrue("JTA synchronizations active", TransactionSynchronizationManager.isSynchronizationActive());
            assertTrue("Hasn't thread session", !TransactionSynchronizationManager.hasResource(sf));
            HibernateTemplate ht = new HibernateTemplate(sf);
View Full Code Here

    sessionControl.setReturnValue(sf, 1);
    sfControl.replay();
    sessionControl.replay();

    JtaTransactionManager ptm = new JtaTransactionManager(ut);
    TransactionTemplate tt = new TransactionTemplate(ptm);
    final List l = new ArrayList();
    l.add("test");
    assertTrue("JTA synchronizations not active", !TransactionSynchronizationManager.isSynchronizationActive());

    Object result = tt.execute(new TransactionCallback() {
      public Object doInTransaction(TransactionStatus status) {
        try {
          assertTrue("JTA synchronizations active", TransactionSynchronizationManager.isSynchronizationActive());
          HibernateTemplate ht = new HibernateTemplate(sf);
          List htl = ht.executeFind(new HibernateCallback() {
View Full Code Here

    sessionControl.replay();

    TransactionSynchronizationManager.bindResource(sf, new SessionHolder(session));
    try {
      JtaTransactionManager ptm = new JtaTransactionManager(ut);
      TransactionTemplate tt = new TransactionTemplate(ptm);
      tt.setReadOnly(readOnly);
      final List l = new ArrayList();
      l.add("test");
      assertTrue("JTA synchronizations not active", !TransactionSynchronizationManager.isSynchronizationActive());
      assertTrue("Has thread session", TransactionSynchronizationManager.hasResource(sf));

      Object result = tt.execute(new TransactionCallback() {
        public Object doInTransaction(TransactionStatus status) {
          try {
            assertTrue("JTA synchronizations active", TransactionSynchronizationManager.isSynchronizationActive());
            assertTrue("Has thread session", TransactionSynchronizationManager.hasResource(sf));
            HibernateTemplate ht = new HibernateTemplate(sf);
View Full Code Here

    sessionControl.replay();

    TransactionSynchronizationManager.bindResource(sf, new SessionHolder(session));
    try {
      JtaTransactionManager ptm = new JtaTransactionManager(ut);
      final TransactionTemplate tt = new TransactionTemplate(ptm);
      assertTrue("JTA synchronizations not active", !TransactionSynchronizationManager.isSynchronizationActive());
      assertTrue("Has thread session", TransactionSynchronizationManager.hasResource(sf));

      tt.execute(new TransactionCallbackWithoutResult() {
        public void doInTransactionWithoutResult(TransactionStatus status) {
          tt.execute(new TransactionCallbackWithoutResult() {
            public void doInTransactionWithoutResult(TransactionStatus status) {
              status.setRollbackOnly();
              try {
                assertTrue("JTA synchronizations active", TransactionSynchronizationManager.isSynchronizationActive());
                assertTrue("Has thread session", TransactionSynchronizationManager.hasResource(sf));
View Full Code Here

    session2Control.replay();

    JtaTransactionManager ptm = new JtaTransactionManager();
    ptm.setUserTransaction(ut);
    ptm.setTransactionManager(tm);
    final TransactionTemplate tt = new TransactionTemplate(ptm);
    tt.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW);

    assertTrue("Hasn't thread session", !TransactionSynchronizationManager.hasResource(sf));
    try {
      tt.execute(new TransactionCallback() {
        public Object doInTransaction(TransactionStatus status) {
          org.hibernate.Session outerSession = SessionFactoryUtils.getSession(sf, false);
          assertSame(session1, outerSession);
          SessionHolder holder = (SessionHolder) TransactionSynchronizationManager.getResource(sf);
          assertTrue("Has thread session", holder != null);
          try {
            tt.execute(new TransactionCallback() {
              public Object doInTransaction(TransactionStatus status) {
                org.hibernate.Session innerSession = SessionFactoryUtils.getSession(sf, false);
                assertSame(session2, innerSession);
                HibernateTemplate ht = new HibernateTemplate(sf);
                ht.setFlushMode(HibernateTemplate.FLUSH_EAGER);
View Full Code Here

    session1Control.replay();

    JtaTransactionManager ptm = new JtaTransactionManager();
    ptm.setUserTransaction(ut);
    ptm.setTransactionManager(tm);
    final TransactionTemplate tt = new TransactionTemplate(ptm);
    tt.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW);

    assertTrue("Hasn't thread session", !TransactionSynchronizationManager.hasResource(sf));
    try {
      tt.execute(new TransactionCallback() {
        public Object doInTransaction(TransactionStatus status) {
          org.hibernate.Session outerSession = SessionFactoryUtils.getSession(sf, false);
          assertSame(session1, outerSession);
          SessionHolder holder = (SessionHolder) TransactionSynchronizationManager.getResource(sf);
          assertTrue("Has thread session", holder != null);
          tt.execute(new TransactionCallback() {
            public Object doInTransaction(TransactionStatus status) {
              return null;
            }
          });
          return null;
View Full Code Here

    session2Control.replay();

    JtaTransactionManager ptm = new JtaTransactionManager();
    ptm.setUserTransaction(ut);
    ptm.setTransactionManager(tm);
    final TransactionTemplate tt = new TransactionTemplate(ptm);
    tt.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW);

    assertTrue("Hasn't thread session", !TransactionSynchronizationManager.hasResource(sf));
    try {
      tt.execute(new TransactionCallback() {
        public Object doInTransaction(TransactionStatus status) {
          org.hibernate.Session outerSession = SessionFactoryUtils.getSession(sf, false);
          assertSame(session1, outerSession);
          SessionHolder holder = (SessionHolder) TransactionSynchronizationManager.getResource(sf);
          assertTrue("Has thread session", holder != null);
          try {
            tt.execute(new TransactionCallback() {
              public Object doInTransaction(TransactionStatus status) {
                org.hibernate.Session innerSession = SessionFactoryUtils.getSession(sf, false);
                assertSame(session2, innerSession);
                HibernateTemplate ht = new HibernateTemplate(sf);
                ht.setFlushMode(HibernateTemplate.FLUSH_EAGER);
View Full Code Here

TOP

Related Classes of org.springframework.transaction.support.TransactionTemplate

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.