org.apache.cassandra.cql3.QueryProcessor.executeOnceInternal()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(13.2k)|赞(0)|评价(0)|浏览(71)

本文整理了Java中org.apache.cassandra.cql3.QueryProcessor.executeOnceInternal方法的一些代码示例,展示了QueryProcessor.executeOnceInternal的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。QueryProcessor.executeOnceInternal方法的具体详情如下:
包路径:org.apache.cassandra.cql3.QueryProcessor
类名称:QueryProcessor
方法名:executeOnceInternal

QueryProcessor.executeOnceInternal介绍

[英]Same than executeInternal, but to use for queries we know are only executed once so that the created statement object is not cached.
[中]与executeInternal相同,但用于我们知道的查询,只执行一次,这样创建的语句对象就不会被缓存。

代码示例

代码示例来源:origin: jsevellec/cassandra-unit

private static UntypedResultSet query(String query, Object... values)
{
  return QueryProcessor.executeOnceInternal(query, values);
}

代码示例来源:origin: org.apache.cassandra/cassandra-all

private static UntypedResultSet query(String query, Object... values)
{
  return QueryProcessor.executeOnceInternal(query, values);
}

代码示例来源:origin: com.strapdata.cassandra/cassandra-all

private static UntypedResultSet query(String query, Object... values)
{
  return QueryProcessor.executeOnceInternal(query, values);
}

代码示例来源:origin: org.apache.cassandra/cassandra-all

@VisibleForTesting
  static Optional<String> checkLegacyAuthTablesMessage()
  {
    List<String> existing = new ArrayList<>(LEGACY_AUTH_TABLES).stream().filter((legacyAuthTable) ->
      {
        UntypedResultSet result = QueryProcessor.executeOnceInternal(String.format("SELECT table_name FROM %s.%s WHERE keyspace_name='%s' AND table_name='%s'",
                                              SchemaConstants.SCHEMA_KEYSPACE_NAME,
                                              "tables",
                                              SchemaConstants.AUTH_KEYSPACE_NAME,
                                              legacyAuthTable));
        return result != null && !result.isEmpty();
      }).collect(Collectors.toList());

    if (!existing.isEmpty())
      return Optional.of(String.format("Legacy auth tables %s in keyspace %s still exist and have not been properly migrated.",
            Joiner.on(", ").join(existing), SchemaConstants.AUTH_KEYSPACE_NAME));
    else
      return Optional.empty();
  };
}

代码示例来源:origin: com.strapdata.cassandra/cassandra-all

@VisibleForTesting
  static Optional<String> checkLegacyAuthTablesMessage()
  {
    List<String> existing = new ArrayList<>(LEGACY_AUTH_TABLES).stream().filter((legacyAuthTable) ->
      {
        UntypedResultSet result = QueryProcessor.executeOnceInternal(String.format("SELECT table_name FROM %s.%s WHERE keyspace_name='%s' AND table_name='%s'",
                                              SchemaConstants.SCHEMA_KEYSPACE_NAME,
                                              "tables",
                                              SchemaConstants.AUTH_KEYSPACE_NAME,
                                              legacyAuthTable));
        return result != null && !result.isEmpty();
      }).collect(Collectors.toList());

    if (!existing.isEmpty())
      return Optional.of(String.format("Legacy auth tables %s in keyspace %s still exist and have not been properly migrated.",
            Joiner.on(", ").join(existing), SchemaConstants.AUTH_KEYSPACE_NAME));
    else
      return Optional.empty();
  };
}

代码示例来源:origin: jsevellec/cassandra-unit

@VisibleForTesting
  static Optional<String> checkLegacyAuthTablesMessage()
  {
    List<String> existing = new ArrayList<>(LEGACY_AUTH_TABLES).stream().filter((legacyAuthTable) ->
      {
        UntypedResultSet result = QueryProcessor.executeOnceInternal(String.format("SELECT table_name FROM %s.%s WHERE keyspace_name='%s' AND table_name='%s'",
                                              SchemaConstants.SCHEMA_KEYSPACE_NAME,
                                              "tables",
                                              SchemaConstants.AUTH_KEYSPACE_NAME,
                                              legacyAuthTable));
        return result != null && !result.isEmpty();
      }).collect(Collectors.toList());

    if (!existing.isEmpty())
      return Optional.of(String.format("Legacy auth tables %s in keyspace %s still exist and have not been properly migrated.",
            Joiner.on(", ").join(existing), SchemaConstants.AUTH_KEYSPACE_NAME));
    else
      return Optional.empty();
  };
}

代码示例来源:origin: org.apache.cassandra/cassandra-all

public static List<Pair<String, String>> loadPreparedStatements()
  {
    String query = String.format("SELECT logged_keyspace, query_string FROM %s.%s", SchemaConstants.SYSTEM_KEYSPACE_NAME, PREPARED_STATEMENTS);
    UntypedResultSet resultSet = executeOnceInternal(query);
    List<Pair<String, String>> r = new ArrayList<>();
    for (UntypedResultSet.Row row : resultSet)
      r.add(Pair.create(row.has("logged_keyspace") ? row.getString("logged_keyspace") : null,
               row.getString("query_string")));
    return r;
  }
}

代码示例来源:origin: jsevellec/cassandra-unit

public static List<Pair<String, String>> loadPreparedStatements()
  {
    String query = String.format("SELECT logged_keyspace, query_string FROM %s.%s", SchemaConstants.SYSTEM_KEYSPACE_NAME, PREPARED_STATEMENTS);
    UntypedResultSet resultSet = executeOnceInternal(query);
    List<Pair<String, String>> r = new ArrayList<>();
    for (UntypedResultSet.Row row : resultSet)
      r.add(Pair.create(row.has("logged_keyspace") ? row.getString("logged_keyspace") : null,
               row.getString("query_string")));
    return r;
  }
}

代码示例来源:origin: com.strapdata.cassandra/cassandra-all

public static List<Pair<String, String>> loadPreparedStatements()
  {
    String query = String.format("SELECT logged_keyspace, query_string FROM %s.%s", SchemaConstants.SYSTEM_KEYSPACE_NAME, PREPARED_STATEMENTS);
    UntypedResultSet resultSet = executeOnceInternal(query);
    List<Pair<String, String>> r = new ArrayList<>();
    for (UntypedResultSet.Row row : resultSet)
      r.add(Pair.create(row.has("logged_keyspace") ? row.getString("logged_keyspace") : null,
               row.getString("query_string")));
    return r;
  }
}

代码示例来源:origin: com.facebook.presto.cassandra/cassandra-server

/** Migrates index_interval values to min_index_interval and sets index_interval to null */
private static void migrateIndexInterval()
{
  for (UntypedResultSet.Row row : executeOnceInternal(String.format("SELECT * FROM system.%s", SCHEMA_COLUMNFAMILIES_CF)))
  {
    if (!row.has("index_interval"))
      continue;
    logger.debug("Migrating index_interval to min_index_interval");
    CFMetaData table = CFMetaData.fromSchema(row);
    String query = String.format("SELECT writetime(type) FROM system.%s WHERE keyspace_name = ? AND columnfamily_name = ?", SCHEMA_COLUMNFAMILIES_CF);
    long timestamp = executeOnceInternal(query, table.ksName, table.cfName).one().getLong("writetime(type)");
    try
    {
      table.toSchema(timestamp).apply();
    }
    catch (ConfigurationException e)
    {
      // shouldn't happen
    }
  }
}

代码示例来源:origin: com.strapdata.elasticsearch/elasticsearch

public static MapType<?,?> getMapType(final String ksName, final String cfName, final String colName) {
  try {
    UntypedResultSet result = QueryProcessor.executeOnceInternal("SELECT validator FROM system.schema_columns WHERE keyspace_name = ? AND columnfamily_name = ? AND column_name = ?", 
        new Object[] { ksName, cfName, colName });
    Row row = result.one();
    if ((row != null) && row.has("validator")) {
      AbstractType<?> type = TypeParser.parse(row.getString("validator"));
      if (type instanceof MapType) {
        return (MapType<?,?>)type;
      }
    }
  } catch (Exception e) {
  }
  return null;
}

代码示例来源:origin: com.facebook.presto.cassandra/cassandra-server

private static void setupVersion()
{
  String req = "INSERT INTO system.%s (key, release_version, cql_version, thrift_version, native_protocol_version, data_center, rack, partitioner, rpc_address, broadcast_address, listen_address) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
  IEndpointSnitch snitch = DatabaseDescriptor.getEndpointSnitch();
  executeOnceInternal(String.format(req, LOCAL_CF),
            LOCAL_KEY,
            FBUtilities.getReleaseVersionString(),
            QueryProcessor.CQL_VERSION.toString(),
            cassandraConstants.VERSION,
            String.valueOf(Server.CURRENT_VERSION),
            snitch.getDatacenter(FBUtilities.getBroadcastAddress()),
            snitch.getRack(FBUtilities.getBroadcastAddress()),
            DatabaseDescriptor.getPartitioner().getClass().getName(),
            DatabaseDescriptor.getRpcAddress(),
            FBUtilities.getBroadcastAddress(),
            FBUtilities.getLocalAddress());
}

代码示例来源:origin: com.facebook.presto.cassandra/cassandra-server

private static void migrateCachingOption()
{
  for (UntypedResultSet.Row row : executeOnceInternal(String.format("SELECT * FROM system.%s", SCHEMA_COLUMNFAMILIES_CF)))
  {
    if (!row.has("caching"))
      continue;
    if (!CachingOptions.isLegacy(row.getString("caching")))
      continue;
    try
    {
      CachingOptions caching = CachingOptions.fromString(row.getString("caching"));
      CFMetaData table = CFMetaData.fromSchema(row);
      logger.info("Migrating caching option {} to {} for {}.{}", row.getString("caching"), caching.toString(), table.ksName, table.cfName);
      String query = String.format("SELECT writetime(type) FROM system.%s WHERE keyspace_name = ? AND columnfamily_name = ?", SCHEMA_COLUMNFAMILIES_CF);
      long timestamp = executeOnceInternal(query, table.ksName, table.cfName).one().getLong("writetime(type)");
      table.toSchema(timestamp).apply();
    }
    catch (ConfigurationException e)
    {
      // shouldn't happen
    }
  }
}

代码示例来源:origin: com.facebook.presto.cassandra/cassandra-server

public static void finishStartup()
{
  setupVersion();
  migrateIndexInterval();
  migrateCachingOption();
  // add entries to system schema columnfamilies for the hardcoded system definitions
  KSMetaData ksmd = Schema.instance.getKSMetaData(Keyspace.SYSTEM_KS);
  long timestamp = FBUtilities.timestampMicros();
  // delete old, possibly obsolete entries in schema columnfamilies
  for (String cfname : Arrays.asList(SystemKeyspace.SCHEMA_KEYSPACES_CF,
                    SystemKeyspace.SCHEMA_COLUMNFAMILIES_CF,
                    SystemKeyspace.SCHEMA_COLUMNS_CF,
                    SystemKeyspace.SCHEMA_TRIGGERS_CF,
                    SystemKeyspace.SCHEMA_USER_TYPES_CF))
  {
    executeOnceInternal(String.format("DELETE FROM system.%s USING TIMESTAMP ? WHERE keyspace_name = ?", cfname),
              timestamp,
              ksmd.name);
  }
  // (+1 to timestamp to make sure we don't get shadowed by the tombstones we just added)
  ksmd.toSchema(timestamp + 1).apply();
}

代码示例来源:origin: com.strapdata.elasticsearch/elasticsearch

public static Pair<List<String>, List<String>> getUDTInfo(final String ksName, final String typeName) {
  try {
    UntypedResultSet result = QueryProcessor.executeOnceInternal("SELECT field_names, field_types FROM system_schema.types WHERE keyspace_name = ? AND type_name = ?", 
        new Object[] { ksName, typeName });
    Row row = result.one();
    if ((row != null) && row.has("field_names")) {
      List<String> field_names = row.getList("field_names", UTF8Type.instance);
      List<String> field_types = row.getList("field_types", UTF8Type.instance);
      return Pair.<List<String>, List<String>> create(field_names, field_types);
    }
  } catch (Exception e) {
  }
  return null;
}

代码示例来源:origin: jsevellec/cassandra-unit

") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
IEndpointSnitch snitch = DatabaseDescriptor.getEndpointSnitch();
executeOnceInternal(String.format(req, LOCAL),
          LOCAL,
          DatabaseDescriptor.getClusterName(),

代码示例来源:origin: org.apache.cassandra/cassandra-all

") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
IEndpointSnitch snitch = DatabaseDescriptor.getEndpointSnitch();
executeOnceInternal(String.format(req, LOCAL),
          LOCAL,
          DatabaseDescriptor.getClusterName(),

代码示例来源:origin: org.apache.cassandra/cassandra-all

/**
 * Add entries to system_schema.* for the hardcoded system keyspaces
 */
public static void saveSystemKeyspacesSchema()
{
  KeyspaceMetadata system = Schema.instance.getKSMetaData(SchemaConstants.SYSTEM_KEYSPACE_NAME);
  KeyspaceMetadata schema = Schema.instance.getKSMetaData(SchemaConstants.SCHEMA_KEYSPACE_NAME);
  long timestamp = FBUtilities.timestampMicros();
  // delete old, possibly obsolete entries in schema tables
  for (String schemaTable : ALL)
  {
    String query = String.format("DELETE FROM %s.%s USING TIMESTAMP ? WHERE keyspace_name = ?", SchemaConstants.SCHEMA_KEYSPACE_NAME, schemaTable);
    for (String systemKeyspace : SchemaConstants.LOCAL_SYSTEM_KEYSPACE_NAMES)
      executeOnceInternal(query, timestamp, systemKeyspace);
  }
  // (+1 to timestamp to make sure we don't get shadowed by the tombstones we just added)
  makeCreateKeyspaceMutation(system, timestamp + 1).build().apply();
  makeCreateKeyspaceMutation(schema, timestamp + 1).build().apply();
}

代码示例来源:origin: jsevellec/cassandra-unit

/**
 * Add entries to system_schema.* for the hardcoded system keyspaces
 */
public static void saveSystemKeyspacesSchema()
{
  KeyspaceMetadata system = Schema.instance.getKSMetaData(SchemaConstants.SYSTEM_KEYSPACE_NAME);
  KeyspaceMetadata schema = Schema.instance.getKSMetaData(SchemaConstants.SCHEMA_KEYSPACE_NAME);
  long timestamp = FBUtilities.timestampMicros();
  // delete old, possibly obsolete entries in schema tables
  for (String schemaTable : ALL)
  {
    String query = String.format("DELETE FROM %s.%s USING TIMESTAMP ? WHERE keyspace_name = ?", SchemaConstants.SCHEMA_KEYSPACE_NAME, schemaTable);
    for (String systemKeyspace : SchemaConstants.LOCAL_SYSTEM_KEYSPACE_NAMES)
      executeOnceInternal(query, timestamp, systemKeyspace);
  }
  // (+1 to timestamp to make sure we don't get shadowed by the tombstones we just added)
  makeCreateKeyspaceMutation(system, timestamp + 1).build().apply();
  makeCreateKeyspaceMutation(schema, timestamp + 1).build().apply();
}

代码示例来源:origin: com.strapdata.cassandra/cassandra-all

/**
 * Add entries to system_schema.* for the hardcoded system keyspaces
 */
public static void saveSystemKeyspacesSchema()
{
  KeyspaceMetadata system = Schema.instance.getKSMetaData(SchemaConstants.SYSTEM_KEYSPACE_NAME);
  KeyspaceMetadata schema = Schema.instance.getKSMetaData(SchemaConstants.SCHEMA_KEYSPACE_NAME);
  long timestamp = FBUtilities.timestampMicros();
  // delete old, possibly obsolete entries in schema tables
  for (String schemaTable : ALL)
  {
    String query = String.format("DELETE FROM %s.%s USING TIMESTAMP ? WHERE keyspace_name = ?", SchemaConstants.SCHEMA_KEYSPACE_NAME, schemaTable);
    for (String systemKeyspace : SchemaConstants.LOCAL_SYSTEM_KEYSPACE_NAMES)
      executeOnceInternal(query, timestamp, systemKeyspace);
  }
  // (+1 to timestamp to make sure we don't get shadowed by the tombstones we just added)
  makeCreateKeyspaceMutation(system, timestamp + 1).build().apply();
  makeCreateKeyspaceMutation(schema, timestamp + 1).build().apply();
}

相关文章

微信公众号

最新文章

更多