private void createTable(EntityMeta entityMeta, String tableName) { CQLTableBuilder builder = CQLTableBuilder.createTable(tableName); for (PropertyMeta pm : entityMeta.getAllMetasExceptIdMeta()) { String propertyName = pm.getPropertyName(); Class<?> keyClass = pm.getKeyClass(); Class<?> valueClass = pm.getValueClass(); switch (pm.type()) { case SIMPLE: case LAZY_SIMPLE: builder.addColumn(propertyName, valueClass); break; case LIST: case LAZY_LIST: builder.addList(propertyName, valueClass); break; case SET: case LAZY_SET: builder.addSet(propertyName, valueClass); break; case MAP: case LAZY_MAP: builder.addMap(propertyName, keyClass, pm.getValueClass()); break; case JOIN_SIMPLE: builder.addColumn(propertyName, pm.joinIdMeta().getValueClass()); break; case JOIN_LIST: builder.addList(propertyName, pm.joinIdMeta().getValueClass()); break; case JOIN_SET: builder.addSet(propertyName, pm.joinIdMeta().getValueClass()); break; case JOIN_MAP: builder.addMap(propertyName, keyClass, pm.joinIdMeta().getValueClass()); break; default: break; } } buildPrimaryKeys(entityMeta.getIdMeta(), builder); builder.addComment("Create table for entity '" + entityMeta.getClassName() + "'"); session.execute(builder.generateDDLScript()); }
private void createTableForClusteredCounter(EntityMeta meta) { PropertyMeta pm = meta.getFirstMeta(); log.debug( "Creating table for counter property {} for entity {}", pm.getPropertyName(), meta.getClassName()); CQLTableBuilder builder = CQLTableBuilder.createCounterTable(meta.getTableName()); PropertyMeta idMeta = meta.getIdMeta(); buildPrimaryKeys(idMeta, builder); builder.addColumn(pm.getPropertyName(), pm.getValueClass()); builder.addComment( "Create table for counter property '" + pm.getPropertyName() + "' of entity '" + meta.getClassName() + "'"); session.execute(builder.generateDDLScript()); }
@Override protected void validateOrCreateTableForCounter(boolean forceColumnFamilyCreation) { if (tableMetas.containsKey(CQL_COUNTER_TABLE)) { validator.validateAchillesCounter(); } else { if (forceColumnFamilyCreation) { CQLTableBuilder builder = CQLTableBuilder.createTable(CQL_COUNTER_TABLE); builder.addColumn(CQL_COUNTER_FQCN, String.class); builder.addColumn(CQL_COUNTER_PRIMARY_KEY, String.class); builder.addColumn(CQL_COUNTER_PROPERTY_NAME, String.class); builder.addColumn(CQL_COUNTER_VALUE, Counter.class); builder.addPrimaryKeys( Arrays.asList(CQL_COUNTER_FQCN, CQL_COUNTER_PRIMARY_KEY, CQL_COUNTER_PROPERTY_NAME)); builder.addComment("Create default Achilles counter table '" + CQL_COUNTER_TABLE + "'"); session.execute(builder.generateDDLScript()); } else { throw new AchillesInvalidTableException( "The required generic table '" + CQL_COUNTER_TABLE + "' does not exist"); } } }