Package org.apache.avalon.excalibur.datasource

Examples of org.apache.avalon.excalibur.datasource.DataSourceComponent


    /**
     * Main invocation routine.
     */
    public Map act (Redirector redirector, SourceResolver resolver, Map objectModel, String src,
            Parameters parameters) throws Exception {
        DataSourceComponent datasource = null;
        Connection conn = null;
        PreparedStatement st = null;
        ResultSet rs = null;

        // read global parameter settings
        boolean reloadable = Constants.DESCRIPTOR_RELOADABLE_DEFAULT;

        if (this.settings.containsKey("reloadable")) {
            reloadable = Boolean.valueOf((String) this.settings.get("reloadable")).booleanValue();
        }

        // read local settings
        try {
            Configuration conf = this.getConfiguration (
                    parameters.getParameter ("descriptor", (String) this.settings.get("descriptor")),
            resolver,
            parameters.getParameterAsBoolean("reloadable",reloadable));
            boolean cs = true;
            String create_session = parameters.getParameter ("create-session",
                                 (String) this.settings.get("create-session"));
            if (create_session != null &&
                    ("no".equals (create_session.trim ()) || "false".equals (create_session.trim ()))) {
                cs = false;
            }

            datasource = this.getDataSource(conf);
            conn = datasource.getConnection();
            Request req = ObjectModelHelper.getRequest(objectModel);

            /* check request validity */
            if (req == null) {
                getLogger ().debug ("DBAUTH: no request object");
View Full Code Here


                JMeterContextService.getContext().getVariables().getObject(poolName);
        if (poolObject == null) {
            throw new SQLException("No pool found named: '" + poolName + "', ensure Variable Name matches Variable Name of JDBC Connection Configuration");
        } else {
            if(poolObject instanceof DataSourceComponent) {
                DataSourceComponent pool = (DataSourceComponent) poolObject;
                return pool.getConnection();   
            } else {
                String errorMsg = "Found object stored under variable:'"+poolName
                        +"' with class:"+poolObject.getClass().getName()+" and value: '"+poolObject+" but it's not a DataSourceComponent, check you're not already using this name as another variable";
                log.error(errorMsg);
                throw new SQLException(errorMsg);
View Full Code Here

     * Purpose:
     * - allows JDBCSampler to be entirely independent of the pooling classes
     * - allows the pool storage mechanism to be changed if necessary
     */
    public static Connection getConnection(String poolName) throws SQLException{
        DataSourceComponent pool = (DataSourceComponent)
            JMeterContextService.getContext().getVariables().getObject(poolName);
        if (pool == null) {
            throw new SQLException("No pool found named: '" + poolName + "'");
        }
        return pool.getConnection();
    }
View Full Code Here

    SampleResult res = new SampleResult();
    res.setSampleLabel(getName());
    res.setSamplerData(toString());

    res.sampleStart();
    DataSourceComponent pool = (DataSourceComponent) getThreadContext().getVariables().getObject(getDataSource());
    log.debug("DataSourceComponent: " + pool);
    Connection conn = null;
    Statement stmt = null;

    try {

      if (pool == null)
        throw new SQLException("No pool created");

      // TODO: Consider creating a sub-result with the time to get the
      // connection.
      conn = pool.getConnection();
      stmt = conn.createStatement();

      // Based on query return value, get results
      if (isQueryOnly()) {
        ResultSet rs = null;
View Full Code Here

        super( name );
    }

    public void testOverAllocation()
    {
        DataSourceComponent ds = null;
        m_isSuccessful = false;
        LinkedList connectionList = new LinkedList();

        try
        {
            ds = (DataSourceComponent)manager.lookup( DataSourceComponent.ROLE );

            for( int i = 0; i < 10; i++ )
            {
                connectionList.add( ds.getConnection() );
            }
            getLogger().info( "Testing overallocation of connections.  Should see a warning next." );
            connectionList.add( ds.getConnection() );
        }
        catch( SQLException se )
        {
            this.m_isSuccessful = true;
            getLogger().info( "The test was successful" );
View Full Code Here

        assertTrue( "Exception was not thrown when too many datasource components were retrieved.", this.m_isSuccessful );
    }

    public void testNormalUse()
    {
        DataSourceComponent ds = null;
        m_isSuccessful = true;

        try
        {
            ds = (DataSourceComponent)manager.lookup( DataSourceComponent.ROLE );
View Full Code Here

  public static JasperPrint createReport(String dataSourceName, String reportName, ModelRequest req, Class klass,
          Map parameters, String format) throws ModelException
  {
    try
    {
      DataSourceComponent dataSource = (DataSourceComponent) req.getService(DataSourceComponent.ROLE,
              dataSourceName);
      Connection connection = dataSource.getConnection();

      InputStream reportStream = klass.getResourceAsStream(reportName);

      if (reportStream == null)
      {
View Full Code Here

    PersistentFactory persistentFactory = (PersistentFactory) req.getService(PersistentFactory.ROLE, req
            .getDomain());

    ModelResponse res = req.createResponse();

    DataSourceComponent dataSourceComponent = (DataSourceComponent) req.getService(DataSourceComponent.ROLE,
            "keel-dbpool");

    List<Configuration> moduleConfigs = de.iritgo.aktera.base.module.ModuleInfo
            .moduleConfigsSortedByDependency(req);

    try
    {
      Connection connection = null;

      try
      {
        connection = dataSourceComponent.getConnection();

        for (Configuration moduleConfig : moduleConfigs)
        {
          String moduleId = moduleConfig.getAttribute("id", "unkown");
          String createHandlerClassName = moduleConfig.getChild("create").getAttribute("class", null);

          if (createHandlerClassName != null)
          {
            try
            {
              System.out.println("CreateDatabase: Creating tables of module '" + moduleId
                      + "' with handler '" + createHandlerClassName + "'");

              Class klass = Class.forName(createHandlerClassName);

              if (klass != null)
              {
                CreateHandler createHandler = (CreateHandler) klass.newInstance();
                createHandler.setConnection(connection);
                createHandler.createTables(req, persistentFactory, connection, log);
              }
              else
              {
                log
                        .error("CreateDatabase: Unable to find create handler for module '"
                                + moduleId + "'");
              }
            }
            catch (ClassNotFoundException x)
            {
              log.error("CreateDatabase: Unable call create handler for module '" + moduleId + "': " + x);
            }
            catch (Exception x)
            {
              res.addOutput("databaseError", x.getMessage());
              res.addOutput("databaseErrorStackTrace", StringTools.stackTraceToString(x).replaceAll("\n",
                      "<br>"));

              return res;
            }
          }
        }
      }
      catch (SQLException x)
      {
        log.error("Unable to create database connection", x);
      }
      finally
      {
        try
        {
          connection.close();
        }
        catch (SQLException x)
        {
        }
      }

      connection = null;

      try
      {
        connection = dataSourceComponent.getConnection();

        for (Configuration moduleConfig : moduleConfigs)
        {
          String moduleId = moduleConfig.getAttribute("id", "unkown");
          String createHandlerClassName = moduleConfig.getChild("create").getAttribute("class", null);
View Full Code Here

    response.add(outModuleList);

    PersistentFactory pf = (PersistentFactory) request.getService(PersistentFactory.ROLE, request.getDomain());

    DataSourceComponent dataSourceComponent = (DataSourceComponent) request.getService(DataSourceComponent.ROLE,
            "keel-dbpool");

    updatePreProcessing(request, dataSourceComponent);

    boolean needReboot = false;
    boolean newUserPreferences = false;

    List<Configuration> moduleConfigs = de.iritgo.aktera.base.module.ModuleInfo
            .moduleConfigsSortedByDependency(request);

    for (Configuration moduleConfig : moduleConfigs)
    {
      String moduleId = moduleConfig.getAttribute("id", "unkown");
      String moduleName = moduleConfig.getChild("name").getValue("unkown");
      ModuleVersion newVersion = new ModuleVersion(moduleConfig.getChild("version").getValue(null));

      Output outModule = response.createOutput("module_" + moduleConfig.getAttribute("id", "unknown"));

      outModuleList.add(outModule);
      outModule.setAttribute("name", moduleName);
      outModule.setAttribute("description", moduleConfig.getChild("description").getValue(""));
      outModule.setAttribute("newVersion", newVersion.toString());

      ModuleVersion currentVersion = new ModuleVersion();

      try
      {
        Persistent version = pf.create("aktera.Version");

        version.setField("type", "M");
        version.setField("name", moduleId);

        if (version.find())
        {
          currentVersion = new ModuleVersion(version.getFieldString("version"));
        }
        else
        {
          currentVersion = new ModuleVersion("0.0.0");
        }
      }
      catch (Exception x)
      {
        outModule.setAttribute("oldVersion", currentVersion.toString());
        outModule.setAttribute("error", "unableToRetrieveCurrentVersion");
        outModule.setAttribute("errorException", x.toString());

        response.addOutput("updateError", "Y");

        continue;
      }

      outModule.setAttribute("oldVersion", currentVersion.toString());

      String updateHandlerClassName = moduleConfig.getChild("update").getAttribute("class", null);

      if (updateHandlerClassName != null)
      {
        try
        {
          System.out.println("UpdateDatabase: Updating module '" + moduleId + "' with handler '"
                  + updateHandlerClassName + "'");

          Class klass = Class.forName(updateHandlerClassName);

          if (klass != null)
          {
            UpdateHandler updateHandler = (UpdateHandler) klass.newInstance();

            Connection con = null;

            try
            {
              con = dataSourceComponent.getConnection();
              updateHandler.setConnection(con);
              updateHandler.updateDatabase(request, logger, con, pf, (ModuleVersion) currentVersion
                      .clone(), newVersion);
            }
            finally
View Full Code Here

    Statement stmt = null;
    ResultSet res = null;

    try
    {
      DataSourceComponent dataSourceComponent = (DataSourceComponent) request.getService(
              DataSourceComponent.ROLE, "keel-dbpool");

      connection = dataSourceComponent.getConnection();
      stmt = connection.createStatement();
      res = stmt
              .executeQuery("SELECT value FROM systemconfig where name = 'databaseCreated' and category = 'system'");

      if (res.next())
View Full Code Here

TOP

Related Classes of org.apache.avalon.excalibur.datasource.DataSourceComponent

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.