Ejemplo n.º 1
0
  /**
   * Test batched prepared statement concurrency. Batch prepares must not disappear between the
   * moment when they were created and when they are executed.
   */
  public void testConcurrentBatching() throws Exception {
    // Create a connection with a batch size of 1. This should cause prepares and actual batch
    // execution to become
    // interspersed (if correct synchronization is not in place) and greatly increase the chance of
    // prepares
    // being rolled back before getting executed.
    Properties props = new Properties();
    props.setProperty(Messages.get(net.sourceforge.jtds.jdbc.Driver.BATCHSIZE), "1");
    props.setProperty(
        Messages.get(net.sourceforge.jtds.jdbc.Driver.PREPARESQL),
        String.valueOf(TdsCore.TEMPORARY_STORED_PROCEDURES));
    Connection con = getConnection(props);

    try {
      Statement stmt = con.createStatement();
      stmt.execute(
          "create table #testConcurrentBatch (v1 int, v2 int, v3 int, v4 int, v5 int, v6 int)");
      stmt.close();

      Vector exceptions = new Vector();
      con.setAutoCommit(false);

      Thread t1 = new ConcurrentBatchingHelper(con, exceptions);
      Thread t2 = new ConcurrentBatchingHelper(con, exceptions);
      t1.start();
      t2.start();
      t1.join();
      t2.join();

      assertEquals(0, exceptions.size());
    } finally {
      con.close();
    }
  }
 public static void init() throws Exception {
   Properties props = new Properties();
   int pid = OSProcess.getId();
   String path = File.createTempFile("dunit-cachejta_", ".xml").getAbsolutePath();
   /** * Return file as string and then modify the string accordingly ** */
   String file_as_str = readFile(TestUtil.getResourcePath(CacheUtils.class, "cachejta.xml"));
   file_as_str = file_as_str.replaceAll("newDB", "newDB_" + pid);
   String modified_file_str = modifyFile(file_as_str);
   FileOutputStream fos = new FileOutputStream(path);
   BufferedWriter wr = new BufferedWriter(new OutputStreamWriter(fos));
   wr.write(modified_file_str);
   wr.flush();
   wr.close();
   props.setProperty("cache-xml-file", path);
   //    String tableName = "";
   //		  props.setProperty("mcast-port", "10339");
   try {
     //			   ds = DistributedSystem.connect(props);
     ds = (new ExceptionsDUnitTest("temp")).getSystem(props);
     cache = CacheFactory.create(ds);
   } catch (Exception e) {
     e.printStackTrace(System.err);
     throw new Exception("" + e);
   }
 }
Ejemplo n.º 3
0
 public static Connection getConnection(Connection c) throws Exception {
   Connection conn = c;
   if (c != null && !c.isClosed()) {
     return c;
   } else {
     Class clazz = Class.forName("org.luciddb.jdbc.LucidDbLocalDriver");
     LucidDbLocalDriver driver = (LucidDbLocalDriver) clazz.newInstance();
     String urlPrefix = driver.getUrlPrefix();
     Properties props = new Properties();
     props.setProperty("user", "sa");
     props.setProperty("password", "");
     props.setProperty("requireExistingEngine", "true");
     c = DriverManager.getConnection(urlPrefix, props);
   }
   return c;
 }
Ejemplo n.º 4
0
 /**
  * Parses connection options.
  *
  * @param options options
  * @return connection properties
  */
 private static Properties connProps(final HashMap<String, String> options) {
   final Properties props = new Properties();
   for (final Entry<String, String> entry : options.entrySet()) {
     props.setProperty(entry.getKey(), entry.getValue());
   }
   return props;
 }
  private synchronized void maybeConnect() throws BlockStoreException {
    try {
      if (conn.get() != null) return;

      Properties props = new Properties();
      props.setProperty("user", this.username);
      props.setProperty("password", this.password);

      conn.set(DriverManager.getConnection(connectionURL, props));

      Connection connection = conn.get();
      allConnections.add(conn.get());
      log.info("Made a new connection to database " + connectionURL);
    } catch (SQLException ex) {
      throw new BlockStoreException(ex);
    }
  }
Ejemplo n.º 6
0
  /**
   * Creates configuration properties object for new connection.
   *
   * <p>See GridGain client javadoc for more information: {@link GridClientConfiguration}.
   *
   * <p>All parameters are optional.
   *
   * @return Configuration.
   */
  private static Properties configuration() {
    Properties cfg = new Properties();

    // Node ID where to execute query. This property is useful when you have several
    // local caches with same name in topology and want to specify which of them to connect.
    //
    // Uncomment line below and provide correct ID if needed.
    //        cfg.setProperty(CONF_NODE_ID, "E0869485-512C-41F9-866D-BE906B591BEA");

    // Communication protocol (TCP or HTTP). Default is TCP.
    cfg.setProperty(CONF_PROTO, "TCP");

    // Socket timeout. Default is 0 which means infinite timeout.
    cfg.setProperty(CONF_TIMEOUT, "0");

    // Flag indicating whether TCP_NODELAY flag should be enabled for outgoing
    // connections. Default is true.
    cfg.setProperty(CONF_TCP_NO_DELAY, "true");

    // Flag indicating that SSL is needed for connection. Default is false.
    cfg.setProperty(CONF_SSL_ENABLED, "false");

    // SSL context factory class name. Class must extend
    // org.gridgain.client.ssl.GridSslContextFactory
    // interface, have default constructor and be available on classpath.
    // Ignored if SSL is disabled.
    cfg.setProperty(CONF_SSL_FACTORY, "org.gridgain.client.ssl.GridSslBasicContextFactory");

    // SSL pass-phrase.
    // Ignored is SSL is disabled.
    cfg.setProperty(CONF_CREDS, "s3cr3t");

    // Flag indicating that topology is cached internally. Cache will be refreshed
    // in the background with interval defined by CONF_TOP_REFRESH_FREQ property
    // (see below). Default is false.
    cfg.setProperty(CONF_TOP_CACHE_ENABLED, "false");

    // Topology cache refresh frequency. Default is 2000 ms.
    cfg.setProperty(CONF_TOP_REFRESH_FREQ, "2000");

    // Maximum amount of time that connection can be idle before it is closed.
    // Default is 30000 ms.
    cfg.setProperty(CONF_MAX_IDLE_TIME, "30000");

    return cfg;
  }
Ejemplo n.º 7
0
  @Override
  public Item item(final QueryContext qc, final InputInfo ii) throws QueryException {
    checkCreate(qc);
    // URL to relational database
    final String url = string(toToken(exprs[0], qc));
    final JDBCConnections jdbc = jdbc(qc);
    try {
      if (exprs.length > 2) {
        // credentials
        final String user = string(toToken(exprs[1], qc));
        final String pass = string(toToken(exprs[2], qc));
        if (exprs.length == 4) {
          // connection options
          final Options opts = toOptions(3, Q_OPTIONS, new Options(), qc);
          // extract auto-commit mode from options
          boolean ac = true;
          final HashMap<String, String> options = opts.free();
          final String commit = options.get(AUTO_COMM);
          if (commit != null) {
            ac = Strings.yes(commit);
            options.remove(AUTO_COMM);
          }
          // connection properties
          final Properties props = connProps(options);
          props.setProperty(USER, user);
          props.setProperty(PASS, pass);

          // open connection
          final Connection conn = getConnection(url, props);
          // set auto/commit mode
          conn.setAutoCommit(ac);
          return Int.get(jdbc.add(conn));
        }
        return Int.get(jdbc.add(getConnection(url, user, pass)));
      }
      return Int.get(jdbc.add(getConnection(url)));
    } catch (final SQLException ex) {
      throw BXSQ_ERROR_X.get(info, ex);
    }
  }
Ejemplo n.º 8
0
  private Connection openDB(final DBConfiguration dbConfiguration) throws DatabaseException {
    final String connectionURL = dbConfiguration.getConnectionString();
    final String jdbcClassName = dbConfiguration.getDriverClassname();

    try {
      final byte[] jdbcDriverBytes = dbConfiguration.getJdbcDriver();
      if (jdbcDriverBytes != null) {
        LOGGER.debug("loading JDBC database driver stored in configuration");
        final JarClassLoader jarClassLoader = new JarClassLoader();
        jarClassLoader.add(new ByteArrayInputStream(jdbcDriverBytes));
        final JclObjectFactory jclObjectFactory = JclObjectFactory.getInstance();

        // Create object of loaded class
        driver = (Driver) jclObjectFactory.create(jarClassLoader, jdbcClassName);

        LOGGER.debug(
            "successfully loaded JDBC database driver '"
                + jdbcClassName
                + "' from application configuration");
      }
    } catch (Throwable e) {
      final String errorMsg =
          "error registering JDBC database driver stored in configuration: " + e.getMessage();
      final ErrorInformation errorInformation =
          new ErrorInformation(PwmError.ERROR_DB_UNAVAILABLE, errorMsg);
      LOGGER.error(errorMsg, e);
      throw new DatabaseException(errorInformation);
    }

    if (driver == null) {
      try {
        LOGGER.debug("loading JDBC database driver from classpath: " + jdbcClassName);
        driver = (Driver) Class.forName(jdbcClassName).newInstance();

        LOGGER.debug("successfully loaded JDBC database driver from classpath: " + jdbcClassName);
      } catch (Throwable e) {
        final String errorMsg =
            e.getClass().getName()
                + " error loading JDBC database driver from classpath: "
                + e.getMessage();
        final ErrorInformation errorInformation =
            new ErrorInformation(PwmError.ERROR_DB_UNAVAILABLE, errorMsg);
        throw new DatabaseException(errorInformation);
      }
    }

    try {
      LOGGER.debug("opening connection to database " + connectionURL);
      final Properties connectionProperties = new Properties();
      if (dbConfiguration.getUsername() != null && !dbConfiguration.getUsername().isEmpty()) {
        connectionProperties.setProperty("user", dbConfiguration.getUsername());
      }
      if (dbConfiguration.getPassword() != null) {
        connectionProperties.setProperty(
            "password", dbConfiguration.getPassword().getStringValue());
      }
      final Connection connection = driver.connect(connectionURL, connectionProperties);

      final Map<PwmAboutProperty, String> debugProps = getConnectionDebugProperties(connection);
      ;
      LOGGER.debug(
          "successfully opened connection to database "
              + connectionURL
              + ", properties: "
              + JsonUtil.serializeMap(debugProps));

      connection.setAutoCommit(true);
      return connection;
    } catch (Throwable e) {
      final String errorMsg =
          "error connecting to database: " + Helper.readHostileExceptionMessage(e);
      final ErrorInformation errorInformation =
          new ErrorInformation(PwmError.ERROR_DB_UNAVAILABLE, errorMsg);
      if (e instanceof IOException) {
        LOGGER.error(errorInformation);
      } else {
        LOGGER.error(errorMsg, e);
      }
      throw new DatabaseException(errorInformation);
    }
  }
Ejemplo n.º 9
0
  public ClientApplication() {
    //    ClientUtils.setObjectSender(new HessianObjectSender());

    clientFacade = new DemoClientFacade();

    Hashtable domains = new Hashtable();
    Domain sexDomain = new Domain("SEX");
    sexDomain.addDomainPair("M", "male");
    sexDomain.addDomainPair("F", "female");
    domains.put(sexDomain.getDomainId(), sexDomain);

    Properties props = new Properties();
    props.setProperty("deptCode", "Dept Code");
    props.setProperty("description", "Description");
    props.setProperty("address", "Address");
    props.setProperty("tasks", "Tasks");
    props.setProperty("departments", "departments");
    props.setProperty("taskCode", "Task Code");
    props.setProperty("firstName", "First Name");
    props.setProperty("lastName", "Last Name");
    props.setProperty("deptDescription", "Dept. Description");
    props.setProperty("tadkDescription", "Task Description");
    props.setProperty("hire date", "Hire Date");
    props.setProperty("sex", "Sex");
    props.setProperty("male", "Male");
    props.setProperty("female", "Female");
    props.setProperty("salary", "Salary");
    props.setProperty("empCode", "Employee Code");
    props.setProperty("task", "Task");
    props.setProperty("department", "Department");

    ClientSettings clientSettings =
        new ClientSettings(new EnglishOnlyResourceFactory("$", props, true), domains);

    ClientSettings.BACKGROUND = "background4.jpg";
    ClientSettings.TREE_BACK = "treeback2.jpg";
    ClientSettings.VIEW_BACKGROUND_SEL_COLOR = true;
    ClientSettings.VIEW_MANDATORY_SYMBOL = true;

    MDIFrame mdi = new MDIFrame(this);
  }
Ejemplo n.º 10
0
  public ClientApplication() {

    Hashtable domains = new Hashtable();
    Properties props = new Properties();
    props.setProperty("category", "Category");
    props.setProperty("subCategory", "Sub Category");
    props.setProperty("item", "Item");
    props.setProperty("sellQty", "Qty");
    props.setProperty("sellAmount", "Sell");
    props.setProperty("orderDate", "Order Date");
    props.setProperty("year", "Year");
    props.setProperty("quarter", "Quarter");
    props.setProperty("sells", "Sells");
    props.setProperty("agent", "Agent");
    props.setProperty("country", "Country");
    props.setProperty("region", "Region");

    ClientSettings clientSettings =
        new ClientSettings(new EnglishOnlyResourceFactory("£", props, true), domains);
    ClientSettings.FILTER_PANEL_ON_GRID = true;

    Domain orderStateDomain = new Domain("ORDERSTATE");
    orderStateDomain.addDomainPair(new Integer(0), "opened");
    orderStateDomain.addDomainPair(new Integer(1), "suspended");
    orderStateDomain.addDomainPair(new Integer(2), "delivered");
    orderStateDomain.addDomainPair(new Integer(3), "closed");
    domains.put(orderStateDomain.getDomainId(), orderStateDomain);
    ClientSettings.ALLOW_OR_OPERATOR = false;
    ClientSettings.INCLUDE_IN_OPERATOR = false;
    ClientSettings.GRID_PROFILE_MANAGER = new FileGridProfileManager();

    // createData();
    long t = System.currentTimeMillis();
    //    ArrayList vos = loadData();
    //    System.out.println("Loading data in "+(System.currentTimeMillis()-t)+"ms");
    //    ArrayList vos = null;
    //    new GridFrame(vos);

    new GridFrame();
  }