Example usage for java.sql DatabaseMetaData columnNullableUnknown

List of usage examples for java.sql DatabaseMetaData columnNullableUnknown

Introduction

In this page you can find the example usage for java.sql DatabaseMetaData columnNullableUnknown.

Prototype

int columnNullableUnknown

To view the source code for java.sql DatabaseMetaData columnNullableUnknown.

Click Source Link

Document

Indicates that the nullability of columns is unknown.

Usage

From source file:com.jaxio.celerio.configuration.database.support.MetadataExtractor.java

private boolean isNullable(int nullable) {
    switch (nullable) {
    case DatabaseMetaData.columnNoNulls:
        return false;
    case DatabaseMetaData.columnNullableUnknown:
    case DatabaseMetaData.columnNullable:
    default://from w  w w .j  a v  a2s.  c om
        return true;
    }
}

From source file:ca.sqlpower.sqlobject.TestSQLColumn.java

public void testIsDefinitelyNullable() throws Exception {
    SQLColumn tmpCol = new SQLColumn();
    assertEquals(false, tmpCol.isDefinitelyNullable());
    tmpCol.setNullable(DatabaseMetaData.columnNullable);
    assertEquals(true, tmpCol.isDefinitelyNullable());
    tmpCol.setNullable(DatabaseMetaData.columnNoNulls);
    assertEquals(false, tmpCol.isDefinitelyNullable());
    tmpCol.setNullable(DatabaseMetaData.columnNullableUnknown);
    assertEquals(false, tmpCol.isDefinitelyNullable());

    SQLColumn cowCol = table1pk.getColumn(0);

    assertEquals(false, cowCol.isDefinitelyNullable());
    cowCol.setNullable(DatabaseMetaData.columnNullable);
    assertEquals(true, cowCol.isDefinitelyNullable());
    cowCol.setNullable(DatabaseMetaData.columnNoNulls);
    assertEquals(false, cowCol.isDefinitelyNullable());
    cowCol.setNullable(DatabaseMetaData.columnNullableUnknown);
    assertEquals(false, cowCol.isDefinitelyNullable());

}

From source file:ca.sqlpower.sqlobject.TestSQLColumn.java

public void testGetNullable() throws Exception {
    SQLColumn tmpCol = new SQLColumn();
    assertEquals(DatabaseMetaData.columnNoNulls, tmpCol.getNullable());
    tmpCol.setNullable(DatabaseMetaData.columnNullable);
    assertEquals(DatabaseMetaData.columnNullable, tmpCol.getNullable());
    tmpCol.setNullable(DatabaseMetaData.columnNullableUnknown);
    assertEquals(DatabaseMetaData.columnNullableUnknown, tmpCol.getNullable());
    tmpCol.setNullable(DatabaseMetaData.columnNoNulls);
    assertEquals(DatabaseMetaData.columnNoNulls, tmpCol.getNullable());

    SQLColumn cowCol = table1pk.getColumn(0);
    assertEquals(DatabaseMetaData.columnNoNulls, cowCol.getNullable());
    cowCol.setNullable(DatabaseMetaData.columnNullable);
    assertEquals(DatabaseMetaData.columnNullable, cowCol.getNullable());
    cowCol.setNullable(DatabaseMetaData.columnNullableUnknown);
    assertEquals(DatabaseMetaData.columnNullableUnknown, cowCol.getNullable());
    cowCol.setNullable(DatabaseMetaData.columnNoNulls);
    assertEquals(DatabaseMetaData.columnNoNulls, cowCol.getNullable());
}

From source file:ca.sqlpower.sqlobject.TestSQLColumn.java

/**
 * Tests the SQLColumn and {@link UserDefinedSQLType} at the same time. If
 * you set the column's type through its setter the persister should see the
 * events come through correctly and not throw an exception. Previously the
 * old value of the last property change was not matching the new value of
 * the first property change when persisting the object.
 *//*from   www. ja va  2 s . com*/
public void testSetNullabilityAfterCreation() throws Exception {
    final CountingSPPersister persister = new CountingSPPersister();
    SPPersisterListener listener = new SPPersisterListener(persister, getConverter());
    SQLTable table = (SQLTable) createNewValueMaker(getRootObject(), new PlDotIni())
            .makeNewValue(SQLTable.class, null, "");
    table.addSPListener(listener);

    UserDefinedSQLType underlyingType = new UserDefinedSQLType();
    underlyingType.setMyAutoIncrement(false);
    underlyingType.setMyNullability(DatabaseMetaData.columnNullableUnknown);
    underlyingType.setType(Types.VARCHAR);

    table.begin("Transaction for testing");
    SQLColumn col = new SQLColumn(underlyingType);
    table.addColumn(col);

    int nullable = col.getNullable();
    if (nullable == DatabaseMetaData.columnNullable) {
        nullable = DatabaseMetaData.columnNullableUnknown;
    } else {
        nullable = DatabaseMetaData.columnNullable;
    }
    col.setNullable(nullable);

    table.commit();

}

From source file:org.apache.drill.jdbc.MetaImpl.java

public ResultSet getColumns(String catalog, Pat schemaPattern, Pat tableNamePattern, Pat columnNamePattern) {

    StringBuilder sb = new StringBuilder();
    sb.append("select " + "TABLE_CATALOG as TABLE_CAT, " + "TABLE_SCHEMA as TABLE_SCHEM, " + "TABLE_NAME, "
            + "COLUMN_NAME, " + "DATA_TYPE, " + "CHARACTER_MAXIMUM_LENGTH as BUFFER_LENGTH, "
            + "NUMERIC_PRECISION as DECIMAL_PRECISION, " + "NUMERIC_PRECISION_RADIX as NUM_PREC_RADIX, "
            + DatabaseMetaData.columnNullableUnknown + " as NULLABLE, " + "'' as REMARKS, "
            + "'' as COLUMN_DEF, " + "0 as SQL_DATA_TYPE, " + "0 as SQL_DATETIME_SUB, "
            + "4 as CHAR_OCTET_LENGTH, " + "1 as ORDINAL_POSITION, " + "'YES' as IS_NULLABLE, "
            + "'' as SCOPE_CATALOG," + "'' as SCOPE_SCHEMA, " + "'' as SCOPE_TABLE, "
            + "'' as SOURCE_DATA_TYPE, " + "'' as IS_AUTOINCREMENT, " + "'' as IS_GENERATEDCOLUMN "
            + "FROM INFORMATION_SCHEMA.COLUMNS " + "WHERE 1=1 ");

    if (catalog != null) {
        sb.append(" AND TABLE_CATALOG = '" + StringEscapeUtils.escapeSql(catalog) + "' ");
    }//from  w  ww  . j av a 2s .c  o m
    if (schemaPattern.s != null) {
        sb.append(" AND TABLE_SCHEMA like '" + StringEscapeUtils.escapeSql(schemaPattern.s) + "'");
    }

    if (tableNamePattern.s != null) {
        sb.append(" AND TABLE_NAME like '" + StringEscapeUtils.escapeSql(tableNamePattern.s) + "'");
    }

    if (columnNamePattern.s != null) {
        sb.append(" AND COLUMN_NAME like '" + StringEscapeUtils.escapeSql(columnNamePattern.s) + "'");
    }

    sb.append(" ORDER BY TABLE_CATALOG, TABLE_SCHEMA, TABLE_NAME, COLUMN_NAME");

    return s(sb.toString());
}

From source file:org.apache.openjpa.jdbc.schema.Column.java

/**
 * Sets nullability of this receiver by the given flag.
 * @param flag one of the JDBC nullability flag namely
 * <LI> {@link DatabaseMetaData#columnNullableUnknown} : not known if the column can be set to null value
 * <LI> {@link DatabaseMetaData#columnNullable} : the column can be set to null value
 * <LI> {@link DatabaseMetaData#columnNoNulls} : the column can not be set to null value
 *///from w  w  w.j a  v a 2 s .  c o  m
public void setNullability(short flag) {
    switch (flag) {
    case DatabaseMetaData.columnNullableUnknown:
        _notNull = null;
        break;
    case DatabaseMetaData.columnNullable:
        _notNull = false;
        break;
    case DatabaseMetaData.columnNoNulls:
        _notNull = true;
        break;

    }
}