当前位置: 首页>>代码示例>>Java>>正文


Java Session.execute方法代码示例

本文整理汇总了Java中com.datastax.driver.core.Session.execute方法的典型用法代码示例。如果您正苦于以下问题:Java Session.execute方法的具体用法?Java Session.execute怎么用?Java Session.execute使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.datastax.driver.core.Session的用法示例。


在下文中一共展示了Session.execute方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: primeAndExecuteQueries

import com.datastax.driver.core.Session; //导入方法依赖的package包/类
private void primeAndExecuteQueries(String[] primed, String[] queries) throws Exception {
  SuccessResult result = getSampleSuccessResult();
  for (String primeQuery : primed) {
    server.prime(when(primeQuery).then(result));
  }

  try (com.datastax.driver.core.Cluster driverCluster =
      defaultBuilder(server.getCluster())
          .withRetryPolicy(FallthroughRetryPolicy.INSTANCE)
          .build()) {
    Session session = driverCluster.connect();
    server.getCluster().clearLogs();
    for (String executeQuery : queries) {
      SimpleStatement stmt = new SimpleStatement(executeQuery);
      stmt.setDefaultTimestamp(100);
      session.execute(stmt);
    }
  }
}
 
开发者ID:datastax,项目名称:simulacron,代码行数:20,代码来源:ActivityLogIntegrationTest.java

示例2: main

import com.datastax.driver.core.Session; //导入方法依赖的package包/类
public static void main(String[] args) {

		Session session = Connection.connect();		
		PreparedStatement preparedStatement = session.prepare("insert into user (id, name, age) values (?, ?, ?)");

		try {
			BoundStatement boundStatement = preparedStatement.bind(UUIDs.timeBased(), "Hector", 34);
			ResultSet rs = session.execute(boundStatement);
			System.out.println(rs);
		} catch (Exception ex) {
			ex.printStackTrace();
		}
		
		Connection.close();

	}
 
开发者ID:abulbasar,项目名称:cassandra-java-driver-examples,代码行数:17,代码来源:PreparedStatementExample.java

示例3: startServer

import com.datastax.driver.core.Session; //导入方法依赖的package包/类
@BeforeClass
public static void startServer() throws InterruptedException, TTransportException, ConfigurationException, IOException, URISyntaxException  {
    if (! started) {
        EmbeddedCassandraServerHelper.startEmbeddedCassandra(CASSANDRA_UNIT_RANDOM_PORT_YAML, CASSANDRA_TIMEOUT);
        Cluster cluster = new Cluster.Builder().addContactPoints("127.0.0.1").withPort(getNativeTransportPort()).build();
        Session session = cluster.connect();
        String createQuery = "CREATE KEYSPACE " + CASSANDRA_UNIT_KEYSPACE + " WITH replication={'class' : 'SimpleStrategy', 'replication_factor':1}";
        session.execute(createQuery);
        String useKeyspaceQuery = "USE " + CASSANDRA_UNIT_KEYSPACE;
        session.execute(useKeyspaceQuery);
        CQLDataLoader dataLoader = new CQLDataLoader(session);
        applyScripts(dataLoader, "config/cql/changelog/", "*.cql");
        started = true;
    }
}
 
开发者ID:xm-online,项目名称:xm-ms-timeline,代码行数:16,代码来源:AbstractCassandraTest.java

示例4: selectByDevice

import com.datastax.driver.core.Session; //导入方法依赖的package包/类
@Override
	public Status selectByDevice(TsPoint point, Date startTime, Date endTime) {
		long costTime = 0L;
		Cluster cluster = null;
		try {
//			cluster = Cluster.builder().addContactPoint(CASSADRA_URL).build();
//			Session session = cluster.connect(KEY_SPACE_NAME);
			Session session = SessionManager.getSession();
			String selectCql = "SELECT * FROM point WHERE device_code='" + point.getDeviceCode() + "' and timestamp>="
					+ startTime.getTime() + " and timestamp<=" + endTime.getTime() + " ALLOW FILTERING";
//			System.out.println(selectCql);
			long startTime1 = System.nanoTime();
			ResultSet rs = session.execute(selectCql);
			long endTime1 = System.nanoTime();
			costTime = endTime1 - startTime1;
		} finally {
			if (cluster != null)
				cluster.close();
		}
//		System.out.println("此次查询消耗时间[" + costTime / 1000 + "]s");
		return Status.OK(costTime);
	}
 
开发者ID:dbiir,项目名称:ts-benchmark,代码行数:23,代码来源:CassandraDB.java

示例5: selectByDeviceAndSensor

import com.datastax.driver.core.Session; //导入方法依赖的package包/类
@Override
	public Status selectByDeviceAndSensor(TsPoint point, Date startTime, Date endTime) {
		long costTime = 0L;
		Cluster cluster = null;
		try {
//			cluster = Cluster.builder().addContactPoint(CASSADRA_URL).build();
//			Session session = cluster.connect(KEY_SPACE_NAME);
			Session session = SessionManager.getSession();
			String selectCql = "SELECT * FROM point WHERE device_code='" + point.getDeviceCode() + "' and sensor_code='"
					+ point.getSensorCode() + "' and timestamp>=" + startTime.getTime() + " and timestamp<="
					+ endTime.getTime() + " ALLOW FILTERING";
//			System.out.println(selectCql);
			long startTime1 = System.nanoTime();
			ResultSet rs = session.execute(selectCql);
			long endTime1 = System.nanoTime();
			costTime = endTime1 - startTime1;
		} finally {
			if (cluster != null)
				cluster.close();
		}
//		System.out.println("此次查询消耗时间[" + costTime / 1000 + "]s");
		return Status.OK(costTime);
	}
 
开发者ID:dbiir,项目名称:ts-benchmark,代码行数:24,代码来源:CassandraDB.java

示例6: selectMinByDeviceAndSensor

import com.datastax.driver.core.Session; //导入方法依赖的package包/类
@Override
	public Status selectMinByDeviceAndSensor(String deviceCode, String sensorCode, Date startTime, Date endTime) {
		long costTime = 0L;
		Cluster cluster = null;
		try {
			cluster = Cluster.builder().addContactPoint(CASSADRA_URL).build();
			Session session = cluster.connect(KEY_SPACE_NAME);
			String selectCql = "SELECT MIN(value) FROM point WHERE device_code='" + deviceCode + "' and sensor_code='"
					+ sensorCode + "' and timestamp>=" + startTime.getTime() + " and timestamp<=" + endTime.getTime()
					+ " ALLOW FILTERING";
//			System.out.println(selectCql);
			long startTime1 = System.nanoTime();
			ResultSet rs = session.execute(selectCql);
			long endTime1 = System.nanoTime();
			costTime = endTime1 - startTime1;
		} finally {
			if (cluster != null)
				cluster.close();
		}
//		System.out.println("此次查询消耗时间[" + costTime / 1000 + "]s");
		return Status.OK(costTime);
	}
 
开发者ID:dbiir,项目名称:ts-benchmark,代码行数:23,代码来源:CassandraDB.java

示例7: selectAvgByDeviceAndSensor

import com.datastax.driver.core.Session; //导入方法依赖的package包/类
@Override
	public Status selectAvgByDeviceAndSensor(String deviceCode, String sensorCode, Date startTime, Date endTime) {
		long costTime = 0L;
		Cluster cluster = null;
		try {
			cluster = Cluster.builder().addContactPoint(CASSADRA_URL).build();
			Session session = cluster.connect(KEY_SPACE_NAME);
			String selectCql = "SELECT AVG(value) FROM point WHERE device_code='" + deviceCode + "' and sensor_code='"
					+ sensorCode + "' and timestamp>=" + startTime.getTime() + " and timestamp<=" + endTime.getTime()
					+ " ALLOW FILTERING";
//			System.out.println(selectCql);
			long startTime1 = System.nanoTime();
			ResultSet rs = session.execute(selectCql);
			long endTime1 = System.nanoTime();
			costTime = endTime1 - startTime1;
		} finally {
			if (cluster != null)
				cluster.close();
		}
//		System.out.println("此次查询消耗时间[" + costTime / 1000 + "]s");
		return Status.OK(costTime);
	}
 
开发者ID:dbiir,项目名称:ts-benchmark,代码行数:23,代码来源:CassandraDB.java

示例8: selectCountByDeviceAndSensor

import com.datastax.driver.core.Session; //导入方法依赖的package包/类
@Override
	public Status selectCountByDeviceAndSensor(String deviceCode, String sensorCode, Date startTime, Date endTime) {
		long costTime = 0L;
		Cluster cluster = null;
		try {
			cluster = Cluster.builder().addContactPoint(CASSADRA_URL).build();
			Session session = cluster.connect(KEY_SPACE_NAME);
			String selectCql = "SELECT COUNT(*) FROM point WHERE device_code='" + deviceCode + "' and sensor_code='"
					+ sensorCode + "' and timestamp>=" + startTime.getTime() + " and timestamp<=" + endTime.getTime()
					+ " ALLOW FILTERING";
//			System.out.println(selectCql);
			long startTime1 = System.nanoTime();
			ResultSet rs = session.execute(selectCql);
			long endTime1 = System.nanoTime();
			costTime = endTime1 - startTime1;
		} finally {
			if (cluster != null)
				cluster.close();
		}
//		System.out.println("此次查询消耗时间[" + costTime / 1000 + "]s");
		return Status.OK(costTime);
	}
 
开发者ID:dbiir,项目名称:ts-benchmark,代码行数:23,代码来源:CassandraDB.java

示例9: listPackages

import com.datastax.driver.core.Session; //导入方法依赖的package包/类
@Override
public List<DataPackage> listPackages() {
    List<DataPackage> dataPacks = new ArrayList<>();
    try {
        Session session;
        Cluster cluster;
        cluster = Cluster.builder().addContactPoint("127.0.0.1").build();
        session = cluster.connect();
        Statement statement = QueryBuilder.select()
                .all()
                .from(DATABASE, MAIN_TABLE);
        ResultSet results = session.execute(statement);
        for(Row row : results) {
            DataPackage dataPack = new DataPackage();
            dataPack.setId(row.getLong(COL_ID));
            dataPack.setDescription(row.getString(COL_DESC));
            dataPacks.add(dataPack);
        }
    } catch (Exception ex) {
        System.out.println(ex.getMessage());
    }
    return dataPacks;
}
 
开发者ID:roscisz,项目名称:KernelHive,代码行数:24,代码来源:CassandraManager.java

示例10: createTable

import com.datastax.driver.core.Session; //导入方法依赖的package包/类
static boolean createTable(Session client, String appid) {
	if (StringUtils.isBlank(appid) || StringUtils.containsWhitespace(appid) ||
			existsTable(appid) || client == null) {
		return false;
	}
	try {
		String table = getTableNameForAppid(appid);
		client.execute("CREATE KEYSPACE IF NOT EXISTS " + DBNAME +
				" WITH replication = {'class': 'SimpleStrategy', 'replication_factor': " + REPLICATION + "};");
		client.execute("USE " + DBNAME + ";");
		client.execute("CREATE TABLE IF NOT EXISTS " + table + " (id text PRIMARY KEY, json text);");
		logger.info("Created Cassandra table '{}'.", table);
	} catch (Exception e) {
		logger.error(null, e);
		return false;
	}
	return true;
}
 
开发者ID:Erudika,项目名称:para-dao-cassandra,代码行数:19,代码来源:CassandraUtils.java

示例11: create

import com.datastax.driver.core.Session; //导入方法依赖的package包/类
/**
 * Creates a session and ensures schema if configured. Closes the cluster and session if any
 * exception occurred.
 */
@Override public Session create(Cassandra3Storage cassandra) {
  Closer closer = Closer.create();
  try {
    Cluster cluster = closer.register(buildCluster(cassandra));
    cluster.register(new QueryLogger.Builder().build());
    Session session;
    if (cassandra.ensureSchema) {
      session = closer.register(cluster.connect());
      Schema.ensureExists(cassandra.keyspace, session);
      session.execute("USE " + cassandra.keyspace);
    } else {
      session = cluster.connect(cassandra.keyspace);
    }

    initializeUDTs(session);

    return session;
  } catch (RuntimeException e) {
    try {
      closer.close();
    } catch (IOException ignored) {
    }
    throw e;
  }
}
 
开发者ID:liaominghua,项目名称:zipkin,代码行数:30,代码来源:DefaultSessionFactory.java

示例12: create

import com.datastax.driver.core.Session; //导入方法依赖的package包/类
/**
 * Creates a session and ensures schema if configured. Closes the cluster and session if any
 * exception occurred.
 */
@Override public Session create(CassandraStorage cassandra) {
  Closer closer = Closer.create();
  try {
    Cluster cluster = closer.register(buildCluster(cassandra));
    cluster.register(new QueryLogger.Builder().build());
    if (cassandra.ensureSchema) {
      Session session = closer.register(cluster.connect());
      Schema.ensureExists(cassandra.keyspace, session);
      session.execute("USE " + cassandra.keyspace);
      return session;
    } else {
      return cluster.connect(cassandra.keyspace);
    }
  } catch (RuntimeException e) {
    try {
      closer.close();
    } catch (IOException ignored) {
    }
    throw e;
  }
}
 
开发者ID:liaominghua,项目名称:zipkin,代码行数:26,代码来源:SessionFactory.java

示例13: testNoDelayOnPreparedStatementWhenIgnoreOnPrepareIsFalse

import com.datastax.driver.core.Session; //导入方法依赖的package包/类
@Test
public void testNoDelayOnPreparedStatementWhenIgnoreOnPrepareIsFalse() throws Exception {
  Prime prime =
      PrimeDsl.when("select * from table where c1=?")
          .then(noRows())
          .delay(2, TimeUnit.SECONDS)
          .ignoreOnPrepare()
          .build();
  HttpTestResponse response = server.prime(prime.getPrimedRequest());
  assertNotNull(response);
  RequestPrime responseQuery = om.readValue(response.body, RequestPrime.class);
  assertThat(responseQuery).isEqualTo(prime.getPrimedRequest());

  String contactPoint = HttpTestUtil.getContactPointString(server.getCluster(), 0);
  try (com.datastax.driver.core.Cluster cluster =
      defaultBuilder().addContactPoint(contactPoint).build()) {
    Session session = cluster.connect();
    long start = System.currentTimeMillis();
    PreparedStatement prepared = session.prepare("select * from table where c1=?");
    long duration = System.currentTimeMillis() - start;
    // should not have applied delay to prepare.
    assertThat(duration).isLessThan(2000);
    start = System.currentTimeMillis();
    session.execute(prepared.bind());
    duration = System.currentTimeMillis() - start;
    // should have taken longer than 2 seconds as delay is applied to execute.
    assertThat(duration).isGreaterThan(2000);
  }
}
 
开发者ID:datastax,项目名称:simulacron,代码行数:30,代码来源:HttpPrimeQueryIntegrationTest.java

示例14: intiateKernelHiveManager

import com.datastax.driver.core.Session; //导入方法依赖的package包/类
@Override
    public void intiateKernelHiveManager() {
//        try {
        Session session;
        Cluster cluster;
        cluster = Cluster.builder().addContactPoint("127.0.0.1").build();
        session = cluster.connect();
        
        session.execute("CREATE KEYSPACE " + DATABASE + " WITH replication "
            + "= {'class':'SimpleStrategy', 'replication_factor':3};");

        session.execute("CREATE TABLE " + DATABASE + "." + MAIN_TABLE + " (" + COL_ID + " bigint PRIMARY KEY,"
            + COL_DESC + " text," + COL_DATA + " blob" + ");");
    }
 
开发者ID:roscisz,项目名称:KernelHive,代码行数:15,代码来源:CassandraManager.java

示例15: prepareAndQuery

import com.datastax.driver.core.Session; //导入方法依赖的package包/类
private ResultSet prepareAndQuery() throws Exception {
  try (com.datastax.driver.core.Cluster driverCluster =
      defaultBuilder(server.getCluster())
          .withRetryPolicy(FallthroughRetryPolicy.INSTANCE)
          .build()) {
    Session session = driverCluster.connect();
    PreparedStatement prepared = session.prepare(query);
    return session.execute(prepared.bind());
  }
}
 
开发者ID:datastax,项目名称:simulacron,代码行数:11,代码来源:ErrorResultIntegrationTest.java


注:本文中的com.datastax.driver.core.Session.execute方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。