Package javax.sql

Examples of javax.sql.DataSource


      if ( initialContext == null ) {
        fLogger.severe(
          "DataSource problem. InitialContext is null. Db : " + Util.quote(dbConnString)
        );
      }
      DataSource datasource = (DataSource)initialContext.lookup(dbConnString);
      if ( datasource == null ){
        fLogger.severe("Datasource is null for : " + dbConnString);
      }
      result = datasource.getConnection();
    }
    catch (NamingException ex){
      throw new DAOException(
        "Config error with JNDI and datasource, for db " + Util.quote(dbConnString), ex
      );
View Full Code Here


    throws Exception
  {
    if (jdbcDriver != null) {
      Class.forName(jdbcDriver);
    }
    DataSource ds = lookupDataSource(url, user, password);
    Connection con;
    if (user == null || url.startsWith("jdbc:")) {
      con = ds.getConnection();
    }
    else {
      con = ds.getConnection(user, password);
    }
    try {
      DatabaseMetaData metaData = con.getMetaData();
      RdbmsConnectionFactory factory = newFactory(metaData);
      factory.setSail(this);
View Full Code Here

    }   
    
    public void testLDAPConnection() throws SQLException {
        // setup
        String dbName = TestConfiguration.getCurrent().getDefaultDatabaseName();
        DataSource ds = JDBCDataSource.getDataSource();
        Connection conn = ds.getConnection("system", "admin");
        // set the ldap properties
        setDatabaseProperty("derby.connection.requireAuthentication", "true", conn);
        setDatabaseProperty("derby.authentication.provider", "LDAP", conn);
        setDatabaseProperty("derby.authentication.server", ldapServer, conn);
        setDatabaseProperty("derby.authentication.ldap.searchBase", "o=" + dnString, conn);
        setDatabaseProperty("derby.authentication.ldap.searchFilter","(&(objectClass=inetOrgPerson)(uid=%USERNAME%))", conn);
        // java.naming.factory.initial is Context.INITIAL_CONTEXT_FACTORY
        // but using literal string here to avoid unnecessary import.
        // If the initial context factory is not provided it'll default to
        // com.sun.jndi.ldap.LdapCtxFactory in LDAPAuthenticationSchemeImpl.
        if ((ldapContextFactory != null) && (ldapContextFactory.length() > 0))
            setDatabaseProperty("java.naming.factory.initial", ldapContextFactory, conn);
        commit();
        // shutdown the database as system, so the properties take effect
        TestConfiguration.getCurrent().shutdownDatabase();
        conn.close();

        // actual test.
        // first attempt simple connection that should succeed
        ds = JDBCDataSource.getDataSource(dbName);
        assertLDAPDSConnectionOK(ds, ldapUser, ldapPassword);
        assertLDAPDrvMgrConnectionOK(dbName, ldapUser, ldapPassword);
        // try to get a connection for a user that has been added, but who
        // should *not* be on the ldap server; should fail
        assertInvalidLDAPDSConnectionFails(ds, "Jamie", "theHooligan");
        assertInvalidLDAPDrvMgrConnectionFails(dbName, "Jamie", "thHooligan");
        // try to get a connection using the valid ldapuser, but incorrect pwd
        assertInvalidLDAPDSConnectionFails(ds, ldapUser, ldapPassword + "ish");
        assertInvalidLDAPDrvMgrConnectionFails(dbName, ldapUser, ldapPassword + "ish");

        // set the users DN locally
        Connection conn3 = ds.getConnection(ldapUser, ldapPassword);
        String tmpString1 = "derby.user." + ldapUser;
        String tmpString2 = "uid=" + ldapUser + ",ou=People,o=" + dnString;
        setDatabaseProperty(tmpString1, tmpString2, conn3);
        conn3.commit();
        // restart to let setting take effect
        JDBCDataSource.setBeanProperty(ds, "shutdownDatabase", "shutdown");
        // shutdown really only happens on next attempt to connect
        try {
            ds.getConnection(ldapUser, ldapPassword);
            fail("expected system shutdown resulting in 08006 error.");
        } catch (SQLException e) {
            assertSQLState("08006", e);
        }
        conn3.close();
View Full Code Here

    }

    protected void assertDSSystemShutdownOK(
            String user, String password)
    throws SQLException {
        DataSource ds;
        if (usingEmbedded())
        {
            // we cannot use JDBCDataSource.getDataSource() (which uses the
            // default database name), unless we specifically clear the
            // databaseName. Otherwise, only the database will be shutdown.
            // The alternative is to use jDBCDataSource.getDatasource(dbName),
            // where dbName is an empty string - this will in the current code
            // be interpreted as a system shutdown.
            ds = JDBCDataSource.getDataSource();
            JDBCDataSource.clearStringBeanProperty(ds, "databaseName");
        }
        else
        {
            // With client, we cannot user clearStringBeanProperty on the 
            // databaseName, that will result in error 08001 -
            // Required DataSource property databaseName not set.
            // So, we pass an empty string as databaseName, which the current
            // code interprets as a system shutdown.
            ds = JDBCDataSource.getDataSource("");
        }

        JDBCDataSource.setBeanProperty(ds, "shutdownDatabase", "shutdown");
        try {
            ds.getConnection(user, password);
            fail("expected system shutdown resulting in XJ015 error");
        } catch (SQLException e) {
            // expect XJ015, system shutdown, on successful shutdown
            assertSQLState("XJ015", e);
        }
View Full Code Here

            // analyze jta datasource
            String jtaDsName = jPersistenceunitInfo.getJtaDataSourceName();

            // try to get this datasource (if not null)
            if (jtaDsName != null && !jtaDsName.equals("")) {
                DataSource ds = null;
                try {
                    ds = (DataSource) new InitialContext().lookup(jtaDsName);
                } catch (NamingException e) {
                    // TODO: Remove
                    // try with jdbc_1
                    try {
                        logger.warn("Datasource named '" + jtaDsName
                                + "' was not found, use instead the default jndi name jdbc_1");
                        ds = (DataSource) new InitialContext().lookup("jdbc_1");
                    } catch (NamingException ne) {
                        throw new JPersistenceUnitInfoException("Cannot get jta DataSource with the JNDI name '"
                                + jtaDsName + "'.", ne);
                    }
                }
                jPersistenceunitInfo.setJtaDataSource(ds);
            }

            // analyze non jta datasource
            String nonJtaDsName = jPersistenceunitInfo.getNonJtaDataSourceName();
            // try to get this datasource (if not null)
            if (nonJtaDsName != null && !nonJtaDsName.equals("")) {
                DataSource ds = null;
                try {
                    ds = (DataSource) new InitialContext().lookup(nonJtaDsName);
                } catch (NamingException e) {
                    // TODO: Remove
                    // try with jdbc_1
View Full Code Here

        } catch (JMSException e) {
            logger.debug("Error getting operation type: {0}", e);
        }

        if (isEqual(RESOURCE_MANAGER, op)) {
            DataSource ds = (DataSource) ctx.lookup("jdbc/ds01");
            checkResource(ds);
            log(MDBListenerMethodAccess.class, ON_MESSAGE, MDBListenerMethodAccess.class, RESOURCE_MANAGER);

        } else if (isEqual(ENTERPRISE_BEAN, op)) {
            ItfOneMethod01 bean = (ItfOneMethod01) ctx.lookup("ejb/bean01");
View Full Code Here

      sc.start();

      InitialContext ic = new InitialContext();

      TransactionManager tm = (TransactionManager)ic.lookup("java:/TransactionManager");
      DataSource ds = (DataSource)ic.lookup("java:/DefaultDS");
      Connection c;


      tm.begin();

      c = ds.getConnection();
      c.createStatement().executeUpdate("CREATE TABLE SOME_TABLE (SOME_FIELD VARCHAR)");

      tm.commit();

      tm.begin();
      c = ds.getConnection();
      c.createStatement().executeUpdate("INSERT INTO SOME_TABLE VALUES ('this shouldnt get into db')");

      tm.rollback();

      tm.begin();
      c = ds.getConnection();
      c.createStatement().executeUpdate("INSERT INTO SOME_TABLE VALUES ('some value')");

      tm.commit();


      c = ds.getConnection();
      ResultSet rs = c.createStatement().executeQuery("SELECT SOME_FIELD FROM SOME_TABLE");
      while (rs.next())
      {
         String a = rs.getString("SOME_FIELD");
         System.out.println(a);
View Full Code Here

      log.debug(this + " stopped");
   }

   public DataSource getDataSource()
   {
      DataSource ds = null;
      try
      {
         InitialContext ic = new InitialContext();
         ds = (DataSource)ic.lookup(DATA_SOURCE_JNDI_NAME);
         ic.close();
View Full Code Here

     
      // We need to execute each drop in its own transaction otherwise postgresql will not execute
      // further commands after one fails

      TransactionManager mgr = (TransactionManager)ctx.lookup(TransactionManagerService.JNDI_NAME);
      DataSource ds = (DataSource)ctx.lookup("java:/DefaultDS");

      javax.transaction.Transaction txOld = mgr.suspend();
                 
      executeStatement(mgr, ds, "DROP TABLE JBM_POSTOFFICE");
     
View Full Code Here

        if (info != null){
            op = info.toString();
        }

        if (isEqual(RESOURCE_MANAGER, op)) {
            DataSource ds = (DataSource) ctx.lookup("jdbc/ds01");
            checkResource(ds);
            log(getName(), TIMEOUT, getName(), RESOURCE_MANAGER);

        } else if (isEqual(ENTERPRISE_BEAN, op)) {
            ItfOneMethod01 bean = (ItfOneMethod01) ctx.lookup("ejb/bean01");
View Full Code Here

TOP

Related Classes of javax.sql.DataSource

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.