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;
27 import org.openecomp.sdc.be.dao.Account;
28 import org.openecomp.sdc.common.log.wrappers.Logger;
30 public class CassandraTest {
31 private static Logger log = Logger.getLogger(CassandraTest.class.getName());
32 private Cluster cluster;
35 public void testCrud() {
36 String node = "mtanjv9sdcg44";
38 cluster = Cluster.builder().addContactPoint(node).build();
41 String query = "CREATE KEYSPACE IF NOT EXISTS dstest WITH replication "
42 + "= {'class':'SimpleStrategy', 'replication_factor':1};";
44 String queryTable = "CREATE TABLE IF NOT EXISTS accounts(email varchar PRIMARY KEY, name varchar);";
46 Session session = cluster.connect();
47 // Executing the query
48 session.execute(query);
49 // //using the KeySpace
50 session.execute("USE dstest");
51 session.execute(queryTable);
53 Mapper<Account> mapper = new MappingManager(session).mapper(Account.class);
54 Account account = new Account("John Doe", "jd@example.com");
55 // Class<? extends Account> class1 = account.getClass();
56 // Class class2 = Account.class;
59 Account whose = mapper.get("jd@example.com");
60 log.debug("Account name: {}", whose.getName());
62 account.setName("Samanta Smit");
64 whose = mapper.get("jd@example.com");
65 log.debug("Account name: {}", whose.getName());
67 mapper.delete(account);
68 whose = mapper.get("jd@example.com");