Package info.archinnov.achilles.schemabuilder

Examples of info.archinnov.achilles.schemabuilder.Create


    }

    private void createTable(Session session, EntityMeta entityMeta) {
        String qualifiedTableName = entityMeta.config().getQualifiedTableName();
        final List<String> indexes = new LinkedList<>();
        final Create createTable = SchemaBuilder.createTable(qualifiedTableName);
        for (PropertyMeta pm : entityMeta.getAllMetasExceptIdAndCounters()) {
            String cql3ColumnName = pm.getCQL3ColumnName();
            Class<?> valueClass = pm.config().getCQL3ValueType();
            final boolean staticColumn = pm.structure().isStaticColumn();
            switch (pm.type()) {
                case SIMPLE:
                    createTable.addColumn(cql3ColumnName, toCQLDataType(valueClass), staticColumn);
                    if (pm.structure().isIndexed()) {
                        indexes.add(pm.forTableCreation().createNewIndexScript(entityMeta.config().getTableName()));
                    }
                    break;
                case LIST:
                    createTable.addColumn(cql3ColumnName, DataType.list(toCQLDataType(valueClass)), staticColumn);
                    break;
                case SET:
                    createTable.addColumn(cql3ColumnName, DataType.set(toCQLDataType(valueClass)), staticColumn);
                    break;
                case MAP:
                    Class<?> keyClass = pm.config().getCQL3KeyType();
                    createTable.addColumn(cql3ColumnName, DataType.map(toCQLDataType(keyClass), toCQLDataType(valueClass)), staticColumn);
                    break;
                default:
                    break;
            }
        }
        final PropertyMeta idMeta = entityMeta.getIdMeta();
        buildPrimaryKey(idMeta, createTable);
        final Create.Options tableOptions = createTable.withOptions();
        idMeta.forTableCreation().addClusteringOrder(tableOptions);
        final String tableComment = entityMeta.config().getTableComment();
        if (StringUtils.isNotBlank(tableComment)) {
            tableOptions.comment(tableComment);
        }
View Full Code Here


    }

    private void createTableForClusteredCounter(Session session, EntityMeta meta) {
        log.debug("Creating table for clustered counter entity {}", meta.getClassName());

        final Create createTable = SchemaBuilder.createTable(meta.config().getQualifiedTableName());

        PropertyMeta idMeta = meta.getIdMeta();
        buildPrimaryKey(idMeta, createTable);
        for (PropertyMeta counterMeta : meta.getAllCounterMetas()) {
            createTable.addColumn(counterMeta.getCQL3ColumnName(), DataType.counter(),counterMeta.structure().isStaticColumn());
        }
        final Create.Options tableOptions = createTable.withOptions();
        idMeta.forTableCreation().addClusteringOrder(tableOptions);
        tableOptions.comment(meta.config().getTableComment());

        final String createTableScript = tableOptions.build();
        session.execute(createTableScript);
View Full Code Here

    }

    @Test
    public void should_add_partition_keys() throws Exception {
        //Given
        final Create create = mock(Create.class);
        PropertyMeta partitionMeta1 = mock(PropertyMeta.class, RETURNS_DEEP_STUBS);
        PropertyMeta partitionMeta2 = mock(PropertyMeta.class, RETURNS_DEEP_STUBS);
        when(embeddedIdProperties.getPartitionComponents()).thenReturn(new PartitionComponents(asList(partitionMeta1, partitionMeta2)));

        when(partitionMeta1.getCQL3ColumnName()).thenReturn("id");
View Full Code Here

    }

    @Test
    public void should_add_clustering_keys() throws Exception {
        //Given
        final Create create = mock(Create.class);
        PropertyMeta clusteringMeta1 = mock(PropertyMeta.class, RETURNS_DEEP_STUBS);
        PropertyMeta clusteringMeta2 = mock(PropertyMeta.class, RETURNS_DEEP_STUBS);
        when(embeddedIdProperties.getClusteringComponents()).thenReturn(new ClusteringComponents(asList(clusteringMeta1, clusteringMeta2), Arrays.<ClusteringOrder>asList()));

        when(clusteringMeta1.getCQL3ColumnName()).thenReturn("id");
View Full Code Here

TOP

Related Classes of info.archinnov.achilles.schemabuilder.Create

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.