Changes

Cassandra -NoSQL database

2,063 bytes added, 21:51, 16 February 2019
Partíció mérete
Minél szélesebb egy tábla annál egyszerűbb ezt a korlátot elérni még relatíve kevés adattal is.
 
 
=Java kliens=
 
 
 
<source lang="java">
public class CassandraConnector {
 
private static CassandraConnector instance;
 
private Cluster cluster = null;
 
private Session session = null;
 
private MappingManager manager = null;
 
private CassandraConnector() {
initConnection();
}
 
public static CassandraConnector getInstance() {
 
if (instance == null) {
 
synchronized (CassandraConnector.class) {
if (instance == null) {
// if instance is null, initialize
instance = new CassandraConnector();
}
}
}
 
return instance;
}
 
private void initConnection() {
 
String host = System.getProperty("cassandra.default.host", "localhost");
String port = System.getProperty("cassandra.default.port", "9042");
String keyspace = System.getProperty("cassandra.default.keyspace");
String username = System.getProperty("cassandra.user", "user");
String password = System.getProperty("cassandra.pwd", "pass");
boolean withSSL = Boolean.parseBoolean(System.getProperty("cassandra.needSSL", "false"));
 
connect(nodes, withSSL, username, password, keyspace);
}
 
private void connect(String host, String port, boolean withSSL, String username, String password, String keyspace) {
 
try {
 
Cluster.Builder b = Cluster.builder().withSocketOptions((new SocketOptions()).setReadTimeoutMillis(1800000))
.withQueryOptions((new QueryOptions()).setFetchSize(100000));
 
 
builder.addContactPoint(host).withPort(port);
 
if (withSSL) {
b.withSSL();
}
 
if (username != null && username.trim().length() > 0 && withSSL) {
b.withCredentials(username, password);
}
 
session = cluster.connect();
 
manager = new MappingManager(session);
 
} catch (Exception e) {
System.out.println(e);
throw e;
}
}
 
 
public Session getSession() {
 
return session;
}
 
public MappingManager getManager() {
 
return manager;
}
 
 
 
@Override
public void finalize() {
try {
session.close();
cluster.close();
} catch (Exception e) {
// ...
}
}
}
</source>