Package com.impetus.client.cassandra.thrift

Examples of com.impetus.client.cassandra.thrift.CQLTranslator$CQLKeywordMapper


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

        String query = "select count(*) from "
                + translator.ensureCase(new StringBuilder(), "PERSON", false).toString();
        Query q = entityManager.createNativeQuery(query, PersonCassandra.class);
        List noOfRows = q.getResultList();
        Assert.assertEquals(new Long(4),noOfRows.get(0));

        entityManager.clear();
View Full Code Here


        // Modify value in database directly, refresh and then check PC
        entityManager.clear();
        entityManager = emf.createEntityManager();
        Object o1 = entityManager.find(PersonCassandra.class, "1");
        CQLTranslator translator = new CQLTranslator();
        String query = "insert into \"PERSON\" (\"personId\",\"PERSON_NAME\",\"AGE\") values ('1','Amry',10 )";
        CassandraCli.client.execute_cql3_query(ByteBuffer.wrap(query.getBytes()), Compression.NONE,
                    ConsistencyLevel.ONE);
        entityManager.refresh(o1);
        Object oo1 = entityManager.find(PersonCassandra.class, "1");
View Full Code Here

    private StringBuilder createSelectQuery(Object rowId, EntityMetadata metadata, String tableName)
    {
        MetamodelImpl metaModel = (MetamodelImpl) kunderaMetadata.getApplicationMetadata().getMetamodel(
                metadata.getPersistenceUnit());

        CQLTranslator translator = new CQLTranslator();

        String select_Query = translator.SELECTALL_QUERY;
        select_Query = StringUtils.replace(select_Query, CQLTranslator.COLUMN_FAMILY,
                translator.ensureCase(new StringBuilder(), tableName, false).toString());
        StringBuilder builder = new StringBuilder(select_Query);

        builder.append(CQLTranslator.ADD_WHERE_CLAUSE);
        onWhereClause(metadata, rowId, translator, builder, metaModel, metadata.getIdAttribute());
        builder.delete(builder.lastIndexOf(CQLTranslator.AND_CLAUSE), builder.length());
View Full Code Here

                joinTableData.getEntityClass());

        // need to bring in an insert query for this
        // add columns & execute query

        CQLTranslator translator = new CQLTranslator();

        String batch_Query = CQLTranslator.BATCH_QUERY;

        String insert_Query = translator.INSERT_QUERY;

        StringBuilder builder = new StringBuilder();
        builder.append(CQLTranslator.DEFAULT_KEY_NAME);
        builder.append(CQLTranslator.COMMA_STR);
        builder.append(translator.ensureCase(new StringBuilder(), joinTableData.getJoinColumnName(), false));
        builder.append(CQLTranslator.COMMA_STR);
        builder.append(translator.ensureCase(new StringBuilder(), joinTableData.getInverseJoinColumnName(), false));

        insert_Query = StringUtils.replace(insert_Query, CQLTranslator.COLUMN_FAMILY,
                translator.ensureCase(new StringBuilder(), joinTableName, false).toString());

        insert_Query = StringUtils.replace(insert_Query, CQLTranslator.COLUMNS, builder.toString());

        StringBuilder columnValueBuilder = new StringBuilder();

        StringBuilder statements = new StringBuilder();

        // insert query for each row key and
        for (Object key : joinTableRecords.keySet())
        {
            PropertyAccessor accessor = PropertyAccessorFactory.getPropertyAccessor((Field) entityMetadata
                    .getIdAttribute().getJavaMember());

            Set<Object> values = joinTableRecords.get(key); // join column value

            for (Object value : values)
            {
                if (value != null)
                {
                    String insertQuery = insert_Query;
                    columnValueBuilder.append(CQLTranslator.QUOTE_STR);
                    columnValueBuilder.append(PropertyAccessorHelper.getString(key) + "\001"
                            + PropertyAccessorHelper.getString(value));
                    columnValueBuilder.append(CQLTranslator.QUOTE_STR);
                    columnValueBuilder.append(CQLTranslator.COMMA_STR);
                    translator.appendValue(columnValueBuilder, key.getClass(), key, true, false);
                    columnValueBuilder.append(CQLTranslator.COMMA_STR);
                    translator.appendValue(columnValueBuilder, value.getClass(), value, true, false);

                    insertQuery = StringUtils.replace(insertQuery, CQLTranslator.COLUMN_VALUES,
                            columnValueBuilder.toString());
                    statements.append(insertQuery);
                    statements.append(" ");
View Full Code Here

            Object pKeyColumnValue, Class columnJavaType)
    {
        // select columnName from tableName where pKeyColumnName =
        // pKeyColumnValue
        List results = new ArrayList();
        CQLTranslator translator = new CQLTranslator();
        String selectQuery = translator.SELECT_QUERY;
        selectQuery = StringUtils.replace(selectQuery, CQLTranslator.COLUMN_FAMILY,
                translator.ensureCase(new StringBuilder(), tableName, false).toString());
        selectQuery = StringUtils.replace(selectQuery, CQLTranslator.COLUMNS,
                translator.ensureCase(new StringBuilder(), columnName, false).toString());

        StringBuilder selectQueryBuilder = new StringBuilder(selectQuery);

        selectQueryBuilder.append(CQLTranslator.ADD_WHERE_CLAUSE);

        translator.buildWhereClause(selectQueryBuilder, columnJavaType, pKeyColumnName, pKeyColumnValue,
                CQLTranslator.EQ_CLAUSE, false);
        selectQueryBuilder
                .delete(selectQueryBuilder.lastIndexOf(CQLTranslator.AND_CLAUSE), selectQueryBuilder.length());

        ResultSet rSet = execute(selectQueryBuilder.toString(), null);
View Full Code Here

    @Override
    public void deleteByColumn(String schemaName, String tableName, String columnName, Object columnValue)
    {
        Session session = factory.getConnection();
        String rowKeyName = null;
        CQLTranslator translator = new CQLTranslator();
        try
        {
            List<ColumnMetadata> primaryKeys = session.getCluster().getMetadata().getKeyspace("\"" + schemaName + "\"")
                    .getTable("\"" + tableName + "\"").getPrimaryKey();
            rowKeyName = primaryKeys.get(0).getName();
        }
        finally
        {
            // factory.releaseConnection(session);
        }

        List rowKeys = getColumnsById(schemaName, tableName, columnName, rowKeyName, columnValue,
                columnValue.getClass());
        for (Object rowKey : rowKeys)
        {
            if (rowKey != null)
            {
                String deleteQuery = CQLTranslator.DELETE_QUERY;

                deleteQuery = StringUtils.replace(deleteQuery, CQLTranslator.COLUMN_FAMILY,
                        translator.ensureCase(new StringBuilder(), tableName, false).toString());
                StringBuilder deleteQueryBuilder = new StringBuilder(deleteQuery);
                deleteQueryBuilder.append(CQLTranslator.ADD_WHERE_CLAUSE);
                deleteQueryBuilder = translator.ensureCase(deleteQueryBuilder, rowKeyName, false);
                deleteQueryBuilder.append(CQLTranslator.EQ_CLAUSE);
                translator.appendValue(deleteQueryBuilder, rowKey.getClass(), rowKey, false, false);
                this.execute(deleteQueryBuilder.toString(), null);
            }
        }
    }
View Full Code Here

    @Override
    public List<Object> findByRelation(String colName, Object colValue, Class entityClazz)
    {
        EntityMetadata m = KunderaMetadataManager.getEntityMetadata(kunderaMetadata, entityClazz);
        CQLTranslator translator = new CQLTranslator();
        String selectQuery = translator.SELECTALL_QUERY;
        selectQuery = StringUtils.replace(selectQuery, CQLTranslator.COLUMN_FAMILY,
                translator.ensureCase(new StringBuilder(), m.getTableName(), false).toString());

        StringBuilder selectQueryBuilder = new StringBuilder(selectQuery);
        selectQueryBuilder.append(CQLTranslator.ADD_WHERE_CLAUSE);

        translator.buildWhereClause(selectQueryBuilder, colValue.getClass(), colName, colValue,
                CQLTranslator.EQ_CLAUSE, false);
        selectQueryBuilder
                .delete(selectQueryBuilder.lastIndexOf(CQLTranslator.AND_CLAUSE), selectQueryBuilder.length());

        ResultSet rSet = (ResultSet) this.execute(selectQueryBuilder.toString(), null);
View Full Code Here

    @Test
    public void testPrepareColumns()
    {
        logger.info("On prepare columns.");
        CQLTranslator translator = new CQLTranslator();
        UUID timeLineId = UUID.randomUUID();
        Date currentDate = new Date();
        UserTimeLine key = new UserTimeLine("mevivs", 1, timeLineId);
        PrimeUser user = new PrimeUser(key);
        user.setTweetBody("my first tweet");
        user.setTweetDate(currentDate);
        EntityMetadata entityMetadata = KunderaMetadataManager.getEntityMetadata(((EntityManagerFactoryImpl)emf).getKunderaMetadataInstance(), PrimeUser.class);
        Map<String, StringBuilder> translatedSql = translator
                .prepareColumnOrColumnValues(user, entityMetadata, TranslationType.VALUE, null, ((EntityManagerFactoryImpl)emf).getKunderaMetadataInstance()).get(
                        TranslationType.VALUE);
        String columnAsCsv = "'mevivs',1," + timeLineId /*+ ",'my first tweet','" + currentDate.getTime() + */ /*+ "'"*/;
       
        Assert.assertTrue(StringUtils.contains(translatedSql.get(entityMetadata.getTableName()).toString(), columnAsCsv));
View Full Code Here

    }
   
    @Test
    public void testGetKeyword()
    {
        CQLTranslator translator = new CQLTranslator();
        Assert.assertEquals("read_repair_chance", translator.getKeyword(CassandraConstants.READ_REPAIR_CHANCE));
        Assert.assertEquals("dclocal_read_repair_chance", translator.getKeyword(CassandraConstants.DCLOCAL_READ_REPAIR_CHANCE));
        Assert.assertEquals("bloom_filter_fp_chance", translator.getKeyword(CassandraConstants.BLOOM_FILTER_FP_CHANCE));
        Assert.assertEquals("compaction_strategy_class", translator.getKeyword(CassandraConstants.COMPACTION_STRATEGY));
        Assert.assertEquals("bloom_filter_fp_chance", translator.getKeyword(CassandraConstants.BLOOM_FILTER_FP_CHANCE));
        Assert.assertEquals("replicate_on_write", translator.getKeyword(CassandraConstants.REPLICATE_ON_WRITE));
        Assert.assertEquals("caching", translator.getKeyword(CassandraConstants.CACHING));
        Assert.assertEquals("comment", translator.getKeyword(CassandraConstants.COMMENT));
        Assert.assertEquals("gc_grace_seconds", translator.getKeyword(CassandraConstants.GC_GRACE_SECONDS));   
       
    }
View Full Code Here

    @Test
    public void testPrepareColumns()
    {
        logger.info("On prepare columns.");
        CQLTranslator translator = new CQLTranslator();
        UUID timeLineId = UUID.randomUUID();
        Date currentDate = new Date();
        CassandraCompoundKey key = new CassandraCompoundKey("mevivs", 1, timeLineId);
        CassandraPrimeUser user = new CassandraPrimeUser(key);
        user.setTweetBody("my first tweet");
        user.setTweetDate(currentDate);
        EntityMetadata entityMetadata = KunderaMetadataManager.getEntityMetadata(((EntityManagerFactoryImpl)emf).getKunderaMetadataInstance(), CassandraPrimeUser.class);
        Map<String, StringBuilder> translatedSql = translator
                .prepareColumnOrColumnValues(user, entityMetadata, TranslationType.VALUE, null, ((EntityManagerFactoryImpl)emf).getKunderaMetadataInstance()).get(
                        TranslationType.VALUE);
        String columnAsCsv = "'mevivs',1," + timeLineId /*+ ",'my first tweet','" + currentDate.getTime() + */ /*+ "'"*/;
       
        Assert.assertTrue(StringUtils.contains(translatedSql.get(entityMetadata.getTableName()).toString(), columnAsCsv));
View Full Code Here

TOP

Related Classes of com.impetus.client.cassandra.thrift.CQLTranslator$CQLKeywordMapper

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.