Package com.impetus.client.cassandra.thrift

Examples of com.impetus.client.cassandra.thrift.ThriftClient


    private void testINClause()
    {
        if (USE_CQL)
        {
            Map<String, Client> clientMap = (Map<String, Client>) entityManager.getDelegate();
            ThriftClient tc = (ThriftClient) clientMap.get(SEC_IDX_CASSANDRA_TEST);
            tc.setCqlVersion(CassandraConstants.CQL_VERSION_3_0);

            Query findQuery;
            List<PersonCassandra> allPersons;
            findQuery = entityManager.createQuery("Select p from PersonCassandra p where p.personId IN :idList");
            List<String> idList = new ArrayList<String>();
            idList.add("1");
            idList.add("2");
            idList.add("3");

            findQuery.setParameter("idList", idList);
            allPersons = findQuery.getResultList();
            Assert.assertNotNull(allPersons);
            Assert.assertEquals(3, allPersons.size());

            findQuery = entityManager.createQuery("Select p from PersonCassandra p where p.personId IN ?1");
            findQuery.setParameter(1, idList);
            allPersons = findQuery.getResultList();
            Assert.assertNotNull(allPersons);
            Assert.assertEquals(3, allPersons.size());

            entityManager.close();

            entityManager = emf.createEntityManager();

            findQuery = entityManager.createQuery("Select p from PersonCassandra p where p.personId IN :idList");
            findQuery.setParameter("idList", new ArrayList<String>());
            allPersons = findQuery.getResultList();
            Assert.assertNotNull(allPersons);
            Assert.assertTrue(allPersons.isEmpty());

            findQuery = entityManager.createQuery("Select p from PersonCassandra p where p.personId IN ('1', '2')");
            allPersons = findQuery.getResultList();
            Assert.assertNotNull(allPersons);
            Assert.assertEquals(2, allPersons.size());

            entityManager.close();

            try
            {
                entityManager = emf.createEntityManager();
                findQuery = entityManager.createQuery("Select p from PersonCassandra p where p.age IN (10 , 20)");
                allPersons = findQuery.getResultList();
                Assert.fail();
            }
            catch (Exception e)
            {
                Assert.assertEquals(
                        "javax.persistence.PersistenceException: com.impetus.kundera.KunderaException: InvalidRequestException(why:IN predicates on non-primary-key columns (AGE) is not yet supported)",
                        e.getMessage());
            }

            tc.setCqlVersion(CassandraConstants.CQL_VERSION_2_0);
        }
        else
        {
            Query findQuery;
            List<PersonCassandra> allPersons;
View Full Code Here


    }

    private void testCountResult()
    {
        Map<String, Client> clientMap = (Map<String, Client>) entityManager.getDelegate();
        ThriftClient tc = (ThriftClient) clientMap.get(SEC_IDX_CASSANDRA_TEST);
        tc.setCqlVersion(CassandraConstants.CQL_VERSION_3_0);
        CQLTranslator translator = new CQLTranslator();

        String query = "select count(*) from "
                + translator.ensureCase(new StringBuilder(), "PERSONCASSANDRA", false).toString();
        Query q = entityManager.createNativeQuery(query, PersonCassandra.class);
        List noOfRows = q.getResultList();

        if (USE_CQL)
        {
            Assert.assertEquals(new Long(4),
                    PropertyAccessorHelper.getObject(Long.class, ((Column) noOfRows.get(0)).getValue()));
        }
        else
        {
            Assert.assertEquals(new Long(3),
                    PropertyAccessorHelper.getObject(Long.class, ((Column) noOfRows.get(0)).getValue()));
        }
        Assert.assertEquals("count",
                PropertyAccessorHelper.getObject(String.class, ((Column) noOfRows.get(0)).getName()));

        entityManager.clear();
        q = entityManager.createNamedQuery("q");
        noOfRows = q.getResultList();
        if (USE_CQL)
        {
            Assert.assertEquals(4, noOfRows.size());
        }
        else
        {
            Assert.assertEquals(3, noOfRows.size());
        }
        tc.setCqlVersion(CassandraConstants.CQL_VERSION_2_0);
    }
View Full Code Here

        String useNativeSql = "USE \"" + schema + "\"";
        EntityManager em = emf.createEntityManager();

        Map<String, Client> clientMap = (Map<String, Client>) em.getDelegate();
        ThriftClient pc = (ThriftClient) clientMap.get("cassandra");
        pc.setCqlVersion(CassandraConstants.CQL_VERSION_3_0);

        Query q = em.createNativeQuery(useNativeSql, CassandraEntity.class);
        q.executeUpdate();
        // create column family
        String colFamilySql = "CREATE COLUMNFAMILY users (key varchar PRIMARY KEY,full_name varchar, birth_date int,state varchar)";
View Full Code Here

        String batchOps = "BEGIN BATCH INSERT INTO CassandraBatchEntity (user_name, password, name) VALUES ('user2', 'ch@ngem3b', 'second user') UPDATE CassandraBatchEntity SET password = 'ps22dhds' WHERE user_name = 'user2' INSERT INTO CassandraBatchEntity (user_name, password) VALUES ('user3', 'ch@ngem3c') DELETE name FROM CassandraBatchEntity WHERE user_name = 'user2' INSERT INTO CassandraBatchEntity (user_name, password, name) VALUES ('user4', 'ch@ngem3c', 'Andrew') APPLY BATCH";

        EntityManager em = emf.createEntityManager();

        Map<String, Client> clientMap = (Map<String, Client>) em.getDelegate();
        ThriftClient pc = (ThriftClient) clientMap.get("cassandra");
        pc.setCqlVersion(CassandraConstants.CQL_VERSION_3_0);

        Query q = em.createNativeQuery(useNativeSql);
        // q.getResultList();
        q.executeUpdate();

        pc.setConsistencyLevel(ConsistencyLevel.QUORUM);
        q = em.createNativeQuery(createColumnFamily, CassandraBatchEntity.class);
        // q.getResultList();
        q.executeUpdate();

        pc.setConsistencyLevel(ConsistencyLevel.QUORUM);
        q = em.createNativeQuery(batchOps, CassandraBatchEntity.class);
        // q.getResultList();
        q.executeUpdate();

        q = em.createNativeQuery("select * from CassandraBatchEntity", CassandraBatchEntity.class);
View Full Code Here

TOP

Related Classes of com.impetus.client.cassandra.thrift.ThriftClient

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.