Examples of ITransaction


Examples of com.alu.e3.common.transaction.ITransaction

    // Create, then begin a transaction
    TransactionContext transactionState1 = executor1.submit( new Callable<TransactionContext>() {
      @Override
      public TransactionContext call() throws Exception {
        ITransactionManager txMnger = new TransactionManager();
        ITransaction tx = txMnger.getNewTransaction();
        tx.begin();
        return txMnger.getTransactionContext();
      }
    }).get();

    assertNotNull(transactionState1);
    assertNotNull(transactionState1.getTransactionId());
   
    // Later, a method in the same thread stack should be able to deal with the same transaction context
    TransactionContext transactionState2 = executor1.submit( new Callable<TransactionContext>() {
      @Override
      public TransactionContext call() throws Exception {
        ITransactionManager txMnger = new TransactionManager();
        return txMnger.getTransactionContext();
      }
    }).get();
   
    assertNotNull(transactionState2);
    assertNotNull(transactionState2.getTransactionId());
    assertEquals(transactionState1.getTransactionId(), transactionState2.getTransactionId());

    // The transaction in a thread must not be viewable from another thread
    ExecutorService executor2 = Executors.newSingleThreadScheduledExecutor();
    TransactionContext transactionState3 = executor2.submit( new Callable<TransactionContext>() {
      @Override
      public TransactionContext call() throws Exception {
        ITransactionManager txMnger = new TransactionManager();
        return txMnger.getTransactionContext();
      }
    }).get();
    assertNull (transactionState3);
   
    transactionState3 = executor2.submit( new Callable<TransactionContext>() {
      @Override
      public TransactionContext call() throws Exception {
        ITransactionManager txMnger = new TransactionManager();
        ITransaction tx = txMnger.getNewTransaction();
        tx.begin();
        return txMnger.getTransactionContext();
      }
    }).get();
   
    assertNotNull (transactionState3);
View Full Code Here

Examples of com.alu.e3.common.transaction.ITransaction

  public void testTransactionInCurrentThread() throws Exception {
    ITransactionManager txMnger = new TransactionManager();
    assertNull(txMnger.getTransactionContext());

    // create, begin, commit, end
    ITransaction tx = txMnger.getNewTransaction();
    assertNotNull(tx);

    // Not transaction id until the transaction has begun
    assertNull(tx.getTransactionId());
    // Not transaction context until the transaction has begun
    assertNull(txMnger.getTransactionContext());


    tx.begin();
    assertNotNull (tx.getTransactionId());
    assertNotNull (txMnger.getTransactionContext().getTransactionId());
    assertEquals (txMnger.getTransactionContext().getTransactionId(), tx.getTransactionId());

    tx.commit();
    assertNotNull (tx.getTransactionId());
    assertNotNull (txMnger.getTransactionContext().getTransactionId());
    assertEquals (txMnger.getTransactionContext().getTransactionId(), tx.getTransactionId());

    tx.end();
    assertNull(tx.getTransactionId());
    assertNull(txMnger.getTransactionContext());

    // create, begin, rollback
    tx = txMnger.getNewTransaction();
    assertNull(tx.getTransactionId());
    assertNull(txMnger.getTransactionContext());

    tx.begin();
    assertNotNull (tx.getTransactionId());
    assertNotNull (txMnger.getTransactionContext().getTransactionId());
    assertEquals (txMnger.getTransactionContext().getTransactionId(), tx.getTransactionId());

    tx.rollback();
    assertNull(tx.getTransactionId());
    assertNull(txMnger.getTransactionContext());

    // begin, commit, rollback
    tx = txMnger.getNewTransaction();
    assertNull(tx.getTransactionId());
    assertNull(txMnger.getTransactionContext());

    tx.begin();
    assertNotNull (tx.getTransactionId());
    assertNotNull (txMnger.getTransactionContext().getTransactionId());
    assertEquals (txMnger.getTransactionContext().getTransactionId(), tx.getTransactionId());

    tx.commit();
    assertNotNull (tx.getTransactionId());
    assertNotNull (txMnger.getTransactionContext().getTransactionId());
    assertEquals (txMnger.getTransactionContext().getTransactionId(), tx.getTransactionId());

    tx.rollback();
    assertNull(tx.getTransactionId());
    assertNull(txMnger.getTransactionContext());
  }
View Full Code Here

Examples of it.eng.qbe.datasource.transaction.ITransaction

    String responseType = null;
    boolean writeBackResponseInline = false;
    String mimeType = null;
    String fileExtension = null;
    IStatement statement = null;
    ITransaction transaction = null
    Connection connection = null;
    //HQL2SQLStatementRewriter queryRewriter = null;
    String jpaQueryStr = null;
    String sqlQuery = null;
    SQLFieldsReader fieldsReader = null;
    Vector extractedFields = null;
    Map params = null;
    TemplateBuilder templateBuilder = null;
    String templateContent = null;
    File reportFile = null;
    ReportRunner runner = null;
    boolean isFormEngineInstance = false;
   
    logger.debug("IN");
   
    try {
      super.service(request, response)
     
      mimeType = getAttributeAsString( MIME_TYPE );
      logger.debug(MIME_TYPE + ": " + mimeType);   
      responseType = getAttributeAsString( RESPONSE_TYPE );
      logger.debug(RESPONSE_TYPE + ": " + responseType);
         
      Assert.assertNotNull(getEngineInstance(), "It's not possible to execute " + this.getActionName() + " service before having properly created an instance of EngineInstance class");
     
      transaction = (getEngineInstance().getDataSource()).getTransaction()
      transaction.open();
     
      fileExtension = MimeUtils.getFileExtension( mimeType );
      writeBackResponseInline = RESPONSE_TYPE_INLINE.equalsIgnoreCase(responseType);
     
      isFormEngineInstance = getEngineInstance().getTemplate().getProperty("formJSONTemplate") != null;
      if (!isFormEngineInstance) {
        // case of standard QBE
       
        Assert.assertNotNull(getEngineInstance().getActiveQuery(), "Query object cannot be null in oder to execute " + this.getActionName() + " service");
        Assert.assertTrue(getEngineInstance().getActiveQuery().isEmpty() == false, "Query object cannot be empty in oder to execute " + this.getActionName() + " service");
           
        Assert.assertNotNull(mimeType, "Input parameter [" + MIME_TYPE + "] cannot be null in oder to execute " + this.getActionName() + " service");   
        Assert.assertTrue( MimeUtils.isValidMimeType( mimeType ) == true, "[" + mimeType + "] is not a valid value for " + MIME_TYPE + " parameter");
       
        Assert.assertNotNull(responseType, "Input parameter [" + RESPONSE_TYPE + "] cannot be null in oder to execute " + this.getActionName() + " service");   
        Assert.assertTrue( RESPONSE_TYPE_INLINE.equalsIgnoreCase(responseType) || RESPONSE_TYPE_ATTACHMENT.equalsIgnoreCase(responseType), "[" + responseType + "] is not a valid value for " + RESPONSE_TYPE + " parameter");
       
        statement = getEngineInstance().getDataSource().createStatement( getEngineInstance().getActiveQuery() );   
        //logger.debug("Parametric query: [" + statement.getQueryString() + "]");
       
        statement.setParameters( getEnv() );
        jpaQueryStr = statement.getQueryString();
        logger.debug("Executable HQL/JPQL query: [" + jpaQueryStr + "]");
       
        sqlQuery = statement.getSqlQueryString();
        Assert.assertNotNull(sqlQuery, "The SQL query is needed while exporting results.");
       
      } else {
        // case of FormEngine
       
        sqlQuery = this.getAttributeFromSessionAsString(ExecuteDetailQueryAction.LAST_DETAIL_QUERY);
        Assert.assertNotNull(sqlQuery, "The detail query was not found, maybe you have not execute the detail query yet.");
      }
      logger.debug("Executable SQL query: [" + sqlQuery + "]");
     
      logger.debug("Exctracting fields ...");
      fieldsReader = new SQLFieldsReader(sqlQuery, transaction.getSQLConnection());
      try {
        extractedFields = fieldsReader.readFields();
      } catch (Exception e) {
        logger.debug("Impossible to extract fields from query");
        throw new SpagoBIEngineException("Impossible to extract fields from query: " + jpaQueryStr, e);
      }
      logger.debug("Fields extracted succesfully");
     
      Assert.assertTrue(getEngineInstance().getActiveQuery().getDataMartSelectFields(true).size()+getEngineInstance().getActiveQuery().getInLineCalculatedSelectFields(true).size() == extractedFields.size(),
          "The number of fields extracted from query resultset cannot be different from the number of fields specified into the query select clause");
     
      decorateExtractedFields( extractedFields );
     
      params = new HashMap();
      params.put("pagination", getPaginationParamVaue(mimeType) );
     
     
      SourceBean config = (SourceBean)ConfigSingleton.getInstance();   
      SourceBean baseTemplateFileSB = (SourceBean)config.getAttribute("QBE.TEMPLATE-BUILDER.BASE-TEMPLATE");
      String baseTemplateFileStr = null;
      if(baseTemplateFileSB != null) baseTemplateFileStr = baseTemplateFileSB.getCharacters();
      File baseTemplateFile = null;
      if(baseTemplateFileStr != null) baseTemplateFile = new File(baseTemplateFileStr);
     
      templateBuilder = new TemplateBuilder(sqlQuery, extractedFields, params, baseTemplateFile);
      templateContent = templateBuilder.buildTemplate();
     
      if( !"text/jrxml".equalsIgnoreCase( mimeType ) ) {
        if( "application/vnd.ms-excel".equalsIgnoreCase( mimeType ) ) {
         
          IDataStore dataStore = null;
         
          if (!isFormEngineInstance) {
            // case of standard QBE
           
            IDataSet dataSet = null;
           
            Integer limit = 0;
            Integer start = 0;
            Integer maxSize = QbeEngineConfig.getInstance().getResultLimit()
            boolean isMaxResultsLimitBlocking = QbeEngineConfig.getInstance().isMaxResultLimitBlocking();
            dataSet = QbeDatasetFactory.createDataSet(statement);
            dataSet.setAbortOnOverflow(isMaxResultsLimitBlocking);
           
            Map userAttributes = new HashMap();
            UserProfile profile = (UserProfile)this.getEnv().get(EngineConstants.ENV_USER_PROFILE);
            Iterator it = profile.getUserAttributeNames().iterator();
            while(it.hasNext()) {
              String attributeName = (String)it.next();
              Object attributeValue = profile.getUserAttribute(attributeName);
              userAttributes.put(attributeName, attributeValue);
            }
            dataSet.addBinding("attributes", userAttributes);
            dataSet.addBinding("parameters", this.getEnv());
            logger.debug("Executing query ...");
            dataSet.loadData(start, limit, (maxSize == null? -1: maxSize.intValue()));
           
            dataStore = dataSet.getDataStore();
         
          } else {
            // case of FormEngine
           
            JDBCDataSet dataset = new JDBCDataSet();
            IDataSource datasource = (IDataSource) this.getEnv().get( EngineConstants.ENV_DATASOURCE );
            dataset.setDataSource(datasource);
            dataset.setUserProfileAttributes(UserProfileUtils.getProfileAttributes( (UserProfile) this.getEnv().get(EngineConstants.ENV_USER_PROFILE)));
            dataset.setQuery(sqlQuery);
            logger.debug("Executing query ...");
            dataset.loadData();
            dataStore = dataset.getDataStore();
          }
         
          Exporter exp = new Exporter(dataStore);
          exp.setExtractedFields(extractedFields);
         
          Workbook wb = exp.exportInExcel();
         
          File file = File.createTempFile("workbook", ".xls");
          FileOutputStream stream = new FileOutputStream(file);
          wb.write(stream);
          stream.flush();
          stream.close();
          try {       
            writeBackToClient(file, null, writeBackResponseInline, "workbook.xls", mimeType);
          } catch (IOException ioe) {
            throw new SpagoBIEngineException("Impossible to write back the responce to the client", ioe);
          finally{
            if(file != null && file.exists()) {
              try {
                file.delete();
              } catch (Exception e) {
                logger.warn("Impossible to delete temporary file " + file, e);
              }
            }
          }
     
        }else{
          try {
            reportFile = File.createTempFile("report", ".rpt");
          } catch (IOException ioe) {
            throw new SpagoBIEngineException("Impossible to create a temporary file to store the template generated on the fly", ioe);
          }
         
          setJasperClasspath();
          connection = transaction.getSQLConnection();
         
          runner = new ReportRunner( );
          Locale locale = this.getLocale();
          try {
            runner.run( templateContent, reportFile, mimeType, connection, locale);
          catch (Exception e) {
            throw new SpagoBIEngineException("Impossible compile or to export the report", e);
          }
         
          try {       
            writeBackToClient(reportFile, null, writeBackResponseInline, "report." + fileExtension, mimeType);
          } catch (IOException ioe) {
            throw new SpagoBIEngineException("Impossible to write back the responce to the client", ioe);
         
        }
      } else {
        try {       
          writeBackToClient(200, templateContent, writeBackResponseInline, "report." + fileExtension, mimeType);
        } catch (IOException e) {
          throw new SpagoBIEngineException("Impossible to write back the responce to the client", e);
        }
      }
    } catch (Throwable t) {     
      throw SpagoBIEngineServiceExceptionHandler.getInstance().getWrappedException(getActionName(), getEngineInstance(), t);
    } finally {
     
      try {
        // closing session will close also all connection created into this section
        transaction.close();
      } catch (Exception e) {
        logger.warn("Impossible to close the connection used to execute the report in " + getActionName() + " service", e);
      }
     
      if(reportFile != null && reportFile.exists()) {
View Full Code Here

Examples of net.sf.webdav.ITransaction

    }

    public ITransaction begin(final Principal principal) {
        tlRepo.set(RestAPIServlet.getRepository());

        return new ITransaction() {
            public Principal getPrincipal() {
                return principal;
            }
        };
    }
View Full Code Here

Examples of net.sf.webdav.ITransaction

    @Inject
    protected AssetValidator                 assetValidator;

    public ITransaction begin(final Principal principal) {
        return new ITransaction() {
            public Principal getPrincipal() {
                return principal;
            }
        };
    }
View Full Code Here

Examples of net.sf.webdav.ITransaction

    @Inject
    protected Identity                       identity;

    public ITransaction begin(final Principal principal) {
        return new ITransaction() {
            public Principal getPrincipal() {
                return principal;
            }
        };
    }
View Full Code Here

Examples of net.sf.webdav.ITransaction

    @Inject
    protected Identity identity;

    public ITransaction begin(final Principal principal) {
        return new ITransaction() {
            public Principal getPrincipal() {
                return principal;
            }
        };
    }
View Full Code Here

Examples of net.sf.webdav.ITransaction

    }

    public ITransaction begin(final Principal pr) {
        tlRepo.set( RestAPIServlet.getRepository() );

        return new ITransaction() {
            public Principal getPrincipal() {
                return pr;
            }
        };
    }
View Full Code Here

Examples of net.sf.webdav.ITransaction

    }

    public ITransaction begin(final Principal pr) {
        tlRepo.set( RestAPIServlet.getRepository() );

        return new ITransaction() {
            public Principal getPrincipal() {
                return pr;
            }
        };
    }
View Full Code Here

Examples of net.sf.webdav.ITransaction

    }

    public ITransaction begin(final Principal principal) {
        tlRepo.set( RestAPIServlet.getRepository() );

        return new ITransaction() {
            public Principal getPrincipal() {
                return principal;
            }
        };
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.