/**
   * @param cacheName Cache name.
   * @param key Key.
   * @return Data key.
   * @throws Exception In case of error.
   */
  private Object key(String cacheName, int key) throws Exception {
    Class<?> cls = Class.forName(GridSpringDynamicCacheManager.class.getName() + "$DataKey");

    Constructor<?> cons = cls.getDeclaredConstructor(String.class, Object.class);

    cons.setAccessible(true);

    return cons.newInstance(cacheName, key);
  }
Ejemplo n.º 2
0
  /**
   * Runs JDBC example.
   *
   * @param args Command line arguments.
   * @throws Exception In case of error.
   */
  public static void main(String[] args) throws Exception {
    Grid grid = G.start("examples/config/spring-cache.xml");

    Connection conn = null;

    try {
      // Populate cache with data.
      populate(grid.cache(CACHE_NAME));

      // Register JDBC driver.
      Class.forName("org.gridgain.jdbc.GridJdbcDriver");

      // Open JDBC connection.
      conn =
          DriverManager.getConnection("jdbc:gridgain://localhost/" + CACHE_NAME, configuration());

      X.println(">>>");

      // Query all persons.
      queryAllPersons(conn);

      X.println(">>>");

      // Query person older than 30 years.
      queryPersons(conn, 30);

      X.println(">>>");

      // Query persons working in GridGain.
      queryPersonsInOrganization(conn, "GridGain");

      X.println(">>>");
    } finally {
      // Close JDBC connection.
      if (conn != null) conn.close();

      G.stop(true);
    }
  }