Builds the alter ddl query.

@param tableInfo
the table info
@param newColumns
the new columns
@return the string
962733
private String buildAlterDDLQuery(TableInfo tableInfo, Map<String, String> newColumns)
    {
        String statement;
        StringBuilder builder = new StringBuilder();
        builder.append("ALTER TABLE ");
        builder.append(tableInfo.getTableName());
        builder.append(Constants.OPEN_ROUND_BRACKET);

        for (Map.Entry<String, String> entry : newColumns.entrySet())
        {
            builder.append("ADD ");
            builder.append(entry.getKey());
            builder.append(Constants.SPACE);
            String coulmnType = entry.getValue().toLowerCase();
            builder.append(OracleNoSQLValidationClassMapper.getValidType(coulmnType));
            builder.append(Constants.COMMA);
        }

        builder.deleteCharAt(builder.length() - 1);
        builder.append(Constants.CLOSE_ROUND_BRACKET);
        statement = builder.toString();
        return statement;
    }
1282435
private void createColumnFamilies(List<TableInfo> tableInfos, KsDef ksDef) throws Exception
    {
        for (TableInfo tableInfo : tableInfos)
        {
            if (isCql3Enabled(tableInfo))
            {
                createOrUpdateUsingCQL3(tableInfo, ksDef);
                createIndexUsingCql(tableInfo);
            }
            else
            {
                createOrUpdateColumnFamily(tableInfo, ksDef);
            }

            // Create Inverted Indexed Table if required.
            createInvertedIndexTable(tableInfo, ksDef);
        }
    }
18131
function(name, newname) {
				var act = new NobleMachine(function() {
					act.toNext(db.query("SHOW COLUMNS FROM `" + tablename + "`;"));
				});

				act.next(function(result) {
					var sql = "ALTER TABLE `" + tablename + "` CHANGE `" + name + "` `" + newname + "`";

					result.forEach(function(coldatum) {
						if (coldatum['Field'] == name) {
							sql += " " + coldatum['Type'];
							
							if (coldatum['Null'] == 'NO') {
								sql += " NOT NULL";
							}

							if (coldatum['Key'] == 'PRI') {
								sql += " PRIMARY KEY";
							}

							sql += coldatum['Extra'];

							if (coldatum['Default'] != 'NULL') {
								sql += " DEFAULT " + coldatum['Default'];
							}
						}
					});
					sql += ";";

					act.toNext(db.query(sql));
				});

				me.act.next(act);
			}
1204562
public static function changeColumn(
        $table,
        $oldColumn,
        $newColumn,
        $type = 'text',
        $signed = true,
        $allowNull = true,
        $default = null,
        $position = null,
        $comment = ''
    ) {
        $column = [$oldColumn, $newColumn];

        return static::alterColumn(
            'CHANGE',
            $table,
            $column,
            $type,
            $signed,
            $allowNull,
            $default,
            $position,
            $comment
        );
    }
125765
public Query<T> setColumnNames(Collection<N> columnNames) {
    if ( columnNames != null && columnNames.size() > 0) {
      slicePredicate.setColumnNames(columnNames);
    } else {
      slicePredicate.setKeysOnlyPredicate();
    }
    return this;
  }
1372674
private void addColumnToTableInfo(EntityMetadata entityMetadata, Type type, TableInfo tableInfo)
    {
        // Add columns to table info.

        Metamodel metaModel = kunderaMetadata.getApplicationMetadata()
                .getMetamodel(entityMetadata.getPersistenceUnit());
        EntityType entityType = metaModel.entity(entityMetadata.getEntityClazz());
        Map<String, PropertyIndex> columns = entityMetadata.getIndexProperties();

        // populate columnsToBeIndexed with composite indexes
        for (Entry<String, PropertyIndex> c : columns.entrySet())
        {
            PropertyIndex indexedColumn = c.getValue();
            if (indexedColumn.getIndexType() != null
                    && indexedColumn.getIndexType().toLowerCase().equals(Constants.COMPOSITE))
            {
                IndexInfo indexInfo = new IndexInfo(c.getKey(), indexedColumn.getMax(), indexedColumn.getMin(),
                        indexedColumn.getIndexType(), indexedColumn.getName());
                tableInfo.addToIndexedColumnList(indexInfo);
            }
        }

        Set attributes = entityType.getAttributes();

        Iterator<Attribute> iter = attributes.iterator();
        while (iter.hasNext())
        {
            Attribute attr = iter.next();

            if (!attr.isAssociation())
            {
                if (((MetamodelImpl) metaModel).isEmbeddable(attr.getJavaType()))
                {

                    EmbeddableType embeddable = metaModel.embeddable(attr.getJavaType());

                    EmbeddedColumnInfo embeddedColumnInfo = getEmbeddedColumn(tableInfo, embeddable, attr.getName(),
                            attr.getJavaType(), ((Field) ((Field) attr.getJavaMember())));

                    if (!tableInfo.getEmbeddedColumnMetadatas().contains(embeddedColumnInfo))
                    {
                        tableInfo.addEmbeddedColumnInfo(embeddedColumnInfo);
                    }
                }
                else if (!attr.isCollection() && !((SingularAttribute) attr).isId())
                {

                    if (((Field) attr.getJavaMember()).getAnnotation(Lob.class) != null)
                    {
                        tableInfo.addLobColumnInfo(((AbstractAttribute) attr).getJPAColumnName());
                    }

                    ColumnInfo columnInfo = getColumn(tableInfo, attr,
                            columns != null ? columns.get(((AbstractAttribute) attr).getJPAColumnName()) : null, null);
                    if (!tableInfo.getColumnMetadatas().contains(columnInfo))
                    {
                        tableInfo.addColumnInfo(columnInfo);
                    }
                }
                else if (attr.isCollection()
                        && MetadataUtils.isBasicElementCollectionField((Field) attr.getJavaMember()))
                {
                    CollectionColumnInfo cci = new CollectionColumnInfo();
                    cci.setCollectionColumnName(((AbstractAttribute) attr).getJPAColumnName());
                    cci.setType(attr.getJavaType());
                    cci.setGenericClasses(PropertyAccessorHelper.getGenericClasses((Field) attr.getJavaMember()));

                    tableInfo.addCollectionColumnMetadata(cci);
                    // add if collection column is indexed
                    String jpaName = ((AbstractAttribute) attr).getJPAColumnName();
                    PropertyIndex indexedColumn = columns.get(jpaName);
                    if (indexedColumn != null && indexedColumn.getName() != null)
                    {
                        IndexInfo indexInfo = new IndexInfo(jpaName, indexedColumn.getMax(), indexedColumn.getMin(),
                                indexedColumn.getIndexType(), indexedColumn.getName());
                        tableInfo.addToIndexedColumnList(indexInfo);
                        // Add more if required
                    }
                }
                else if (attr.isCollection()
                        && !MetadataUtils.isBasicElementCollectionField((Field) attr.getJavaMember()))
                {
                    CollectionColumnInfo eci = new CollectionColumnInfo();
                    eci.setCollectionColumnName(((AbstractAttribute) attr).getJPAColumnName());
                    eci.setType(attr.getJavaType());
                    eci.setGenericClasses(PropertyAccessorHelper.getGenericClasses((Field) attr.getJavaMember()));

                    tableInfo.addElementCollectionMetadata(eci);
                    // add if collection column is indexed
                    String jpaName = ((AbstractAttribute) attr).getJPAColumnName();
                    PropertyIndex indexedColumn = columns.get(jpaName);
                    if (indexedColumn != null && indexedColumn.getName() != null)
                    {
                        IndexInfo indexInfo = new IndexInfo(jpaName, indexedColumn.getMax(), indexedColumn.getMin(),
                                indexedColumn.getIndexType(), indexedColumn.getName());
                        tableInfo.addToIndexedColumnList(indexInfo);
                        // Add more if required
                    }
                }

            }
        }

        onInheritedProperty(tableInfo, entityType);
    }
1038087
private void alterMySqlCommitDateColumn() {
        ColumnType commitDateColType = getTypeOf(getCommitTableNameWithSchema(), "commit_date");

        if (commitDateColType.typeName.equals("TIMESTAMP") &&
            commitDateColType.precision == 19) {
            logger.info("migrating db schema from JaVers 3.9.2 to 3.9.3 (MySql only) ...");
            executeSQL("ALTER TABLE " + getCommitTableNameWithSchema() + " MODIFY commit_date TIMESTAMP(3)");
        }
    }
736571
private ColumnInfo getColumn(TableInfo tableInfo, Attribute column, PropertyIndex indexedColumn,
            String[] orderByColumns)
    {
        ColumnInfo columnInfo = new ColumnInfo();

        if (column.getJavaType().isAnnotationPresent(OrderBy.class))
        {
            OrderBy order = (OrderBy) column.getJavaType().getAnnotation(OrderBy.class);
            orderByColumns = order.value().split("\\s*,\\s*");

        }
        columnInfo.setOrderBy(getOrderByColumn(orderByColumns, column));

        if (column.getJavaType().isEnum())
        {
            columnInfo.setType(String.class);
        }
        else
        {
            columnInfo.setType(column.getJavaType());
        }
        columnInfo.setColumnName(((AbstractAttribute) column).getJPAColumnName());
        if (indexedColumn != null && indexedColumn.getName() != null)
        {
            columnInfo.setIndexable(true);
            IndexInfo indexInfo = new IndexInfo(((AbstractAttribute) column).getJPAColumnName(), indexedColumn.getMax(),
                    indexedColumn.getMin(), indexedColumn.getIndexType(), indexedColumn.getName());
            tableInfo.addToIndexedColumnList(indexInfo);
            // Add more if required
        }

        return columnInfo;
    }
542981
private void createIndexOnTable(TableInfo tableInfo)
    {

        List<IndexInfo> indexColumns = tableInfo.getColumnsToBeIndexed();
        for (IndexInfo indexInfo : indexColumns)
        {
            if (indexInfo.getIndexType() != null && indexInfo.getIndexType().toLowerCase().equals(Constants.COMPOSITE))
            {
                String[] columnNames = indexInfo.getColumnName().split(Constants.COMMA);
                createIndex(tableInfo.getTableName(), indexInfo.getIndexName(), columnNames);
            }
            else
            {
                createIndex(tableInfo.getTableName(), indexInfo.getIndexName(), indexInfo.getColumnName());
            }
        }
    }
687960
public static StandardTableSliceGroup create(Table original, String... columnsNames) {
        List<CategoricalColumn<?>> columns = original.categoricalColumns(columnsNames);
        return new StandardTableSliceGroup(original, columns.toArray(new CategoricalColumn<?>[0]));
    }
918040
private void createOrUpdateKeyspace(List<TableInfo> tableInfos) throws Exception
    {
        KsDef ksDef = onCreateKeyspace(); // create keyspace event.
        createColumnFamilies(tableInfos, ksDef); // create column family event.
    }
814403
private String alterColumnSetNotNull(String tableName, List<String> columnNames) {
        List<String> statement = new ArrayList<>();
        statement.add("ALTER TABLE");
        statement.add(quotize(tableName));

        for (String columnName : columnNames) {
            statement.add("ALTER COLUMN");
            statement.add(quotize(columnName));
            statement.add("SET NOT NULL");
        }

        return join(statement, " ");
    }
727049
public void addColumnInfo(ColumnInfo columnInfo)
    {
        if (this.columnMetadatas == null)
        {
            this.columnMetadatas = new ArrayList<ColumnInfo>();
        }
        if (!columnMetadatas.contains(columnInfo) && !this.getIdColumnName().equals(columnInfo.getColumnName()))
        {
            columnMetadatas.add(columnInfo);
        }
    }
593759
private ColumnDef getColumnMetadata(ColumnInfo columnInfo, TableInfo tableInfo)
    {
        ColumnDef columnDef = new ColumnDef();
        columnDef.setName(columnInfo.getColumnName().getBytes());
        columnDef.setValidation_class(CassandraValidationClassMapper.getValidationClass(columnInfo.getType(),
                isCql3Enabled(tableInfo)));

        if (columnInfo.isIndexable())
        {
            IndexInfo indexInfo = tableInfo.getColumnToBeIndexed(columnInfo.getColumnName());
            columnDef.setIndex_type(CassandraIndexHelper.getIndexType(indexInfo.getIndexType()));
            // if (!indexInfo.getIndexName().equals(indexInfo.getColumnName()))
            // {
            // columnDef.setIndex_name(indexInfo.getIndexName());
            // }
        }
        return columnDef;
    }
637571
@Override
    protected void update(List<TableInfo> tableInfos)
    {
        for (TableInfo tableInfo : tableInfos)
        {
            try
            {
                if (!client.tableExists(tableInfo.getTableName()))
                {
                    createKuduTable(tableInfo);
                }
                else
                {
                    List<String> entityColumns = new ArrayList<String>();
                    KuduTable table = client.openTable(tableInfo.getTableName());
                    AlterTableOptions alterTableOptions = new AlterTableOptions();
                    AtomicBoolean updated = new AtomicBoolean(false);
                    Schema schema = table.getSchema();
                    // add modify columns
                    for (ColumnInfo columnInfo : tableInfo.getColumnMetadatas())
                    {
                        entityColumns.add(columnInfo.getColumnName());
                        alterColumn(alterTableOptions, schema, columnInfo, updated);
                    }
                    // update for embeddables logic
                    for (EmbeddedColumnInfo embColumnInfo : tableInfo.getEmbeddedColumnMetadatas())
                    {
                        for (ColumnInfo columnInfo : embColumnInfo.getColumns())
                        {
                            entityColumns.add(columnInfo.getColumnName());
                            alterColumn(alterTableOptions, schema, columnInfo, updated);
                        }
                    }

                    // delete columns
                    for (ColumnSchema columnSchema : schema.getColumns())
                    {
                        // if not in tableInfo and not a key then delete
                        if (!entityColumns.contains(columnSchema.getName()) && !columnSchema.isKey())
                        {
                            alterTableOptions.dropColumn(columnSchema.getName());
                            updated.set(true);
                        }
                    }

                    if (updated.get())
                    {
                        client.alterTable(tableInfo.getTableName(), alterTableOptions);
                    }
                }
            }
            catch (Exception e)
            {
                logger.error("Error while updating tables, Caused by: " + e.getMessage());
                throw new KunderaException("Error while updating tables, Caused by: " + e.getMessage());
            }
        }
    }
524561
private ColumnInfo getJoinColumn(TableInfo tableInfo, String joinColumnName, Class columnType)
    {
        ColumnInfo columnInfo = new ColumnInfo();
        columnInfo.setColumnName(joinColumnName);
        columnInfo.setIndexable(true);

        IndexInfo indexInfo = new IndexInfo(joinColumnName);
        tableInfo.addToIndexedColumnList(indexInfo);

        columnInfo.setType(columnType);
        return columnInfo;
    }
490844
Index createIndexForColumns(int[] columns) {

        HsqlName indexName = database.nameManager.newAutoName("IDX_T",
            getSchemaName(), getName(), SchemaObject.INDEX);

        try {
            Index index = createAndAddIndexStructure(indexName, columns, null,
                null, false, false, false, false);

            return index;
        } catch (Throwable t) {
            return null;
        }
    }