2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.openecomp.sdc.be.resources;
23 import com.datastax.driver.core.Cluster;
24 import com.datastax.driver.core.Session;
25 import com.datastax.driver.mapping.Mapper;
26 import com.datastax.driver.mapping.MappingManager;
28 import org.openecomp.sdc.be.dao.Account;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
32 public class CassandraTest {
33 private static Logger log = LoggerFactory.getLogger(CassandraTest.class.getName());
34 private Cluster cluster;
37 public void testCrud() {
38 String node = "mtanjv9sdcg44";
40 cluster = Cluster.builder().addContactPoint(node).build();
43 String query = "CREATE KEYSPACE IF NOT EXISTS dstest WITH replication "
44 + "= {'class':'SimpleStrategy', 'replication_factor':1};";
46 String queryTable = "CREATE TABLE IF NOT EXISTS accounts(email varchar PRIMARY KEY, name varchar);";
48 Session session = cluster.connect();
49 // Executing the query
50 session.execute(query);
51 // //using the KeySpace
52 session.execute("USE dstest");
53 session.execute(queryTable);
55 Mapper<Account> mapper = new MappingManager(session).mapper(Account.class);
56 Account account = new Account("John Doe", "jd@example.com");
57 // Class<? extends Account> class1 = account.getClass();
58 // Class class2 = Account.class;
61 Account whose = mapper.get("jd@example.com");
62 log.debug("Account name: {}", whose.getName());
64 account.setName("Samanta Smit");
66 whose = mapper.get("jd@example.com");
67 log.debug("Account name: {}", whose.getName());
69 mapper.delete(account);
70 whose = mapper.get("jd@example.com");