All Downloads are FREE. Search and download functionalities are using the official Maven repository.

de.jaggl.sqlbuilder.columns.ColumnBuilder Maven / Gradle / Ivy

There is a newer version: 2.7.2
Show newest version
package de.jaggl.sqlbuilder.columns;

import static de.jaggl.sqlbuilder.schema.TableBuilderUtil.addColumnToTable;

import de.jaggl.sqlbuilder.schema.Table;
import lombok.RequiredArgsConstructor;

/**
 * @author Martin Schumacher
 *
 * @since 2.0.0
 */
@RequiredArgsConstructor
public abstract class ColumnBuilder, V>
{
    protected final Table table;
    protected final String name;

    protected boolean isNullable = true;
    protected boolean isDefaultNull = true;
    protected V defaultValue;

    protected abstract C getColumnInstance();

    public C build()
    {
        C columnInstance = getColumnInstance();
        addColumnToTable(columnInstance, table);
        return columnInstance;
    }

    @SuppressWarnings("unchecked")
    public B nullable(boolean nullable)
    {
        isNullable = nullable;
        return (B) this;
    }

    @SuppressWarnings("unchecked")
    public B defaultValue(V value)
    {
        isDefaultNull = false;
        defaultValue = value;
        return (B) this;
    }

    @SuppressWarnings("unchecked")
    public B defaultNull()
    {
        isNullable = true;
        defaultValue = null;
        isDefaultNull = true;
        return (B) this;
    }

    @SuppressWarnings("unchecked")
    public B noDefault()
    {
        defaultValue = null;
        isDefaultNull = false;
        return (B) this;
    }

    public B nullable()
    {
        return nullable(true);
    }

    public B notNull()
    {
        return nullable(false);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy