Java Code Examples for com.datastax.driver.core.ConsistencyLevel#valueOf()

The following examples show how to use com.datastax.driver.core.ConsistencyLevel#valueOf() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CassandraQueryOptions.java    From iotplatform with Apache License 2.0 5 votes vote down vote up
protected ConsistencyLevel getDefaultReadConsistencyLevel() {
    if (defaultReadConsistencyLevel == null) {
        if (readConsistencyLevel != null) {
            defaultReadConsistencyLevel = ConsistencyLevel.valueOf(readConsistencyLevel.toUpperCase());
        } else {
            defaultReadConsistencyLevel = ConsistencyLevel.ONE;
        }
    }
    return defaultReadConsistencyLevel;
}
 
Example 2
Source File: CassandraQueryOptions.java    From iotplatform with Apache License 2.0 5 votes vote down vote up
protected ConsistencyLevel getDefaultWriteConsistencyLevel() {
    if (defaultWriteConsistencyLevel == null) {
        if (writeConsistencyLevel != null) {
            defaultWriteConsistencyLevel = ConsistencyLevel.valueOf(writeConsistencyLevel.toUpperCase());
        } else {
            defaultWriteConsistencyLevel = ConsistencyLevel.ONE;
        }
    }
    return defaultWriteConsistencyLevel;
}
 
Example 3
Source File: ConsistencyLevelConverter.java    From graylog-plugin-metrics-reporter with GNU General Public License v3.0 5 votes vote down vote up
@Override
public ConsistencyLevel convertFrom(String value) {
    if (Strings.isNullOrEmpty(value)) {
        throw new ParameterException("Couldn't convert empty string to a Cassandra consistency level.");
    }

    try {
        return ConsistencyLevel.valueOf(value.toUpperCase(Locale.ENGLISH));
    } catch (Exception e) {
        throw new ParameterException(e.getMessage(), e);
    }
}
 
Example 4
Source File: DataSource.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * Parses consistency level provided as string.
 *
 * @param level consistency level string.
 *
 * @return consistency level.
 */
private ConsistencyLevel parseConsistencyLevel(String level) {
    if (level == null)
        return null;

    try {
        return ConsistencyLevel.valueOf(level.trim().toUpperCase());
    }
    catch (Throwable e) {
        throw new IgniteException("Incorrect consistency level '" + level + "' specified for Cassandra connection", e);
    }
}
 
Example 5
Source File: CassandraConnection.java    From cassandra-jdbc-wrapper with Apache License 2.0 5 votes vote down vote up
/**
 * Instantiates a new CassandraConnection.
 * @param sessionHolder
 * @throws SQLException
 */
public CassandraConnection(SessionHolder sessionHolder) throws SQLException
{
    this.sessionHolder = sessionHolder;
    Properties props = sessionHolder.properties;

    debugMode = props.getProperty(TAG_DEBUG, "").equals("true");
    hostListPrimary = new TreeSet<String>();
    hostListBackup = new TreeSet<String>();
    connectionProps = (Properties)props.clone();
    clientInfo = new Properties();
    url = PROTOCOL + createSubName(props);
    currentKeyspace = props.getProperty(TAG_DATABASE_NAME);
    username = props.getProperty(TAG_USER, "");
    String version = props.getProperty(TAG_CQL_VERSION, DEFAULT_CQL_VERSION);
    connectionProps.setProperty(TAG_ACTIVE_CQL_VERSION, version);
    majorCqlVersion = getMajor(version);
    defaultConsistencyLevel = ConsistencyLevel.valueOf(props.getProperty(TAG_CONSISTENCY_LEVEL, ConsistencyLevel.ONE.name()));

    cSession = sessionHolder.session;

    metadata = cSession.getCluster().getMetadata();
    logger.info("Connected to cluster: %s\n",
        metadata.getClusterName());
    for (Host aHost : metadata.getAllHosts()) {
    	logger.info("Datacenter: %s; Host: %s; Rack: %s\n",
            aHost.getDatacenter(), aHost.getAddress(), aHost.getRack());
    }

    Iterator<Host> hosts = metadata.getAllHosts().iterator();
    if (hosts.hasNext()) {
        Host firstHost = hosts.next();
        // TODO this is shared among all Connections, what if they belong to different clusters?
        CassandraConnection.DB_MAJOR_VERSION = firstHost.getCassandraVersion().getMajor();
        CassandraConnection.DB_MINOR_VERSION = firstHost.getCassandraVersion().getMinor();
        CassandraConnection.DB_REVISION = firstHost.getCassandraVersion().getPatch();
    }
}
 
Example 6
Source File: CassandraConnectorConfig.java    From debezium-incubator with Apache License 2.0 4 votes vote down vote up
public ConsistencyLevel snapshotConsistencyLevel() {
    String cl = this.getConfig().getString(SNAPSHOT_CONSISTENCY);
    return ConsistencyLevel.valueOf(cl);
}
 
Example 7
Source File: CqlCount.java    From cassandra-count with Apache License 2.0 4 votes vote down vote up
private boolean parseArgs(String[] args)
throws IOException, FileNotFoundException {
String tkey;
if (args.length == 0) {
    System.err.println("No arguments specified");
    return false;
}
if (0 != args.length % 2)
    return false;

Map<String, String> amap = new HashMap<String,String>();
for (int i = 0; i < args.length; i+=2) {
    amap.put(args[i], args[i+1]);
}

       if (null != (tkey = amap.remove("-configFile")))
           if (!processConfigFile(tkey, amap))
               return false;

host = amap.remove("-host");
if (null == host) { // host is required
    System.err.println("Must provide a host");
    return false;
}

keyspaceName = amap.remove("-keyspace");
if (null == keyspaceName) { // keyspace is required
    System.err.println("Must provide a keyspace name");
    return false;
}

tableName = amap.remove("-table");
if (null == tableName) { // table is required
    System.err.println("Must provide a table name");
    return false;
}

if (null != (tkey = amap.remove("-port")))          port = Integer.parseInt(tkey);
if (null != (tkey = amap.remove("-user")))          username = tkey;
if (null != (tkey = amap.remove("-pw")))            password = tkey;
       if (null != (tkey = amap.remove("-ssl-truststore-path"))) truststorePath = tkey;
       if (null != (tkey = amap.remove("-ssl-truststore-pwd")))  truststorePwd =  tkey;
       if (null != (tkey = amap.remove("-ssl-keystore-path")))   keystorePath = tkey;
       if (null != (tkey = amap.remove("-ssl-keystore-pwd")))    keystorePwd = tkey;
       if (null != (tkey = amap.remove("-consistencyLevel"))) consistencyLevel = ConsistencyLevel.valueOf(tkey);
if (null != (tkey = amap.remove("-numFutures")))    numFutures = Integer.parseInt(tkey);
if (null != (tkey = amap.remove("-numSplits")))    numSplits = Integer.parseInt(tkey);
if (null != (tkey = amap.remove("-splitSize")))    splitSize = Long.parseLong(tkey) * 1024 * 1024;
if (null != (tkey = amap.remove("-beginToken")))    beginTokenString = tkey;
if (null != (tkey = amap.remove("-endToken")))      endTokenString = tkey;
if (null != (tkey = amap.remove("-debug")))      debug = Integer.parseInt(tkey);

if (!amap.isEmpty()) {
    for (String k : amap.keySet())
	System.err.println("Unrecognized option: " + k);
    return false;
}
return validateArgs();
   }
 
Example 8
Source File: CassandraConfiguration.java    From conductor with Apache License 2.0 4 votes vote down vote up
default ConsistencyLevel getReadConsistencyLevel() {
    return ConsistencyLevel.valueOf(getProperty(CASSANDRA_READ_CONSISTENCY_LEVEL, CASSANDRA_READ_CONSISTENCY_LEVEL_DEFAULT_VALUE));
}
 
Example 9
Source File: CassandraConfiguration.java    From conductor with Apache License 2.0 4 votes vote down vote up
default ConsistencyLevel getWriteConsistencyLevel() {
    return ConsistencyLevel.valueOf(getProperty(CASSANDRA_WRITE_CONSISTENCY_LEVEL, CASSANDRA_WRITE_CONSISTENCY_LEVEL_DEFAULT_VALUE));
}
 
Example 10
Source File: ContextConfig.java    From newts with Apache License 2.0 4 votes vote down vote up
public ConsistencyLevel getReadConsistency() {
    return ConsistencyLevel.valueOf(m_readConsistency);
}
 
Example 11
Source File: ContextConfig.java    From newts with Apache License 2.0 4 votes vote down vote up
public ConsistencyLevel getWriteConsistency() {
    return ConsistencyLevel.valueOf(m_writeConsistency);
}