Example usage for java.sql SQLDataException SQLDataException

List of usage examples for java.sql SQLDataException SQLDataException

Introduction

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

Prototype

public SQLDataException(Throwable cause) 

Source Link

Document

Constructs a SQLDataException object with a given cause.

Usage

From source file:org.neo4j.jdbc.http.HttpResultSet.java

/**
 * Retrieve the object that match the asked column.
 *
 * @param column Index of the column to retrieve
 * @return//from   w w w  .j  a v  a 2  s.c  o m
 * @throws SQLDataException
 */
private Object get(int column) throws SQLDataException {

    if (column < 1 || column > result.getColumns().size()) {
        throw new SQLDataException("Column " + column + " is invalid");
    }

    Object value = currentRow.get(column - 1);

    if (value == null) {
        wasNull = true;
    } else {
        wasNull = false;
    }
    return value;
}

From source file:it.larusba.neo4j.jdbc.http.HttpResultSet.java

/**
 * Retrieve the object that match the asked column.
 *
 * @param column Index of the column to retrieve
 * @return/*w w w.  j  ava 2  s  .  c o m*/
 * @throws SQLDataException
 */
private Object get(int column) throws SQLDataException {
    if (column < 1 || column > result.columns.size()) {
        throw new SQLDataException("Column " + column + " is invalid");
    }

    Object value = currentRow.get(column - 1);

    if (value == null) {
        wasNull = true;
    } else {
        wasNull = false;
    }
    return value;
}

From source file:org.neo4j.jdbc.http.HttpResultSet.java

/**
 * Retrieve a Numeric object from the currentRow that correspond to the column index.
 *
 * @param columnIndex Index of the column
 * @return 0 if null, otherwise a number
 * @throws SQLException If the object cannot be cast to Number
 *///from w  ww.  j ava  2  s .c o  m
private Number getNumber(int columnIndex) throws SQLException {

    Number num = null;
    Object value = get(columnIndex);

    if (value != null) {
        if (value instanceof Number) {
            num = (Number) value;
        } else {
            throw new SQLDataException("Value is not a number" + value);

        }
    }
    return num;
}

From source file:it.larusba.neo4j.jdbc.http.HttpResultSet.java

/**
 * Retrieve a Numeric object from the currentRow that correspond to the column index.
 *
 * @param columnIndex Index of the column
 * @return 0 if null, otherwise a number
 * @throws SQLException If the object cannot be cast to Number
 *//*from   ww w.  jav a2 s.c  om*/
private Number getNumber(int columnIndex) throws SQLException {
    Number num = null;
    Object value = get(columnIndex);

    if (value != null) {
        if (value instanceof Number) {
            num = (Number) value;
        } else {
            throw new SQLDataException("Value is not a number" + value);

        }
    }
    return num;
}

From source file:com.iksgmbh.sql.pojomemodb.sqlparser.SelectParser.java

/**
 * Parses a part of the SQL join statement that follows ANSI syntax
 * @param joinSqlPart // ww w .  j a  v a 2 s .  co m
 * @param whereConditions
 * @return List of JoinTables and join conditions in whereConditions 
 * @throws SQLException 
 */
private List<TableId> parseAnsiJoinStatement(final String joinSqlPart,
        final List<WhereCondition> whereConditions) throws SQLException {
    InterimParseResult parseResult = parseNextJoinTable(joinSqlPart);

    final List<TableId> toReturn = new ArrayList<TableId>();
    toReturn.add(new TableId(parseResult.parsedValue));

    try {
        while (parseResult.delimiter != null) {
            parseResult = parseJoinInstruction(parseResult.unparsedRest, whereConditions, toReturn);
        }
    } catch (SQLDataException e) {
        throw new SQLDataException(e.getMessage() + joinSqlPart);
    }

    return toReturn;
}

From source file:com.iksgmbh.sql.pojomemodb.sqlparser.SelectParser.java

private InterimParseResult parseJoinInstruction(final String unparsedRest,
        final List<WhereCondition> whereConditions, final List<TableId> toReturn) throws SQLException {
    InterimParseResult parseResult = parseNextJoinTable(unparsedRest);

    InterimParseResult tmpParseResult = parseNextValue(parseResult.parsedValue, ON);

    if (tmpParseResult.delimiter == null) {
        throw new SQLDataException("Missing " + ON.toUpperCase() + " keyword: ");
    }/* w ww.  j a va  2s .c om*/

    toReturn.add(new TableId(tmpParseResult.parsedValue));

    final String onClause = tmpParseResult.unparsedRest;
    List<WhereCondition> joinConditions = WhereConditionParser.doYourJob(onClause);
    whereConditions.addAll(joinConditions);

    return parseResult;
}

From source file:com.iksgmbh.sql.pojomemodb.sqlparser.SelectParser.java

private void checkForUnkownAliases(final String columnId, final List<String> tableNames)
        throws SQLDataException {
    if (columnId != null && columnId.contains(".") && !columnId.contains("'")
            && !columnId.endsWith("." + SQLKeyWords.NEXTVAL)) {
        boolean isKnown = false;

        for (String tableName : tableNames) {
            if (columnId.startsWith(tableName + ".")) {
                isKnown = true;/*from www .  ja va  2s  .co m*/
            }
        }

        if (!isKnown) {
            throw new SQLDataException("Unknown column id <" + columnId + "> detected.");
        }
    }

}

From source file:com.iksgmbh.sql.pojomemodb.sqlparser.SelectParser.java

private void removeTableIdFromColumnNamesIfPresent(final TableId tableId, final List<String> selectedColumns)
        throws SQLDataException {
    if (selectedColumns == null)
        return;//from  w  ww  .  j  a  v a 2  s . co m

    for (int i = 0; i < selectedColumns.size(); i++) {
        final String oldColumnName = selectedColumns.get(i);
        final String alias = tableId.getAlias();

        if (alias != null && oldColumnName.startsWith(alias + ".")) {
            // remove alias
            String newColumnName = oldColumnName.substring(alias.length() + 1);
            selectedColumns.set(i, newColumnName);
        } else if (oldColumnName.toUpperCase().startsWith(tableId.getTableName() + ".")) {
            // remove table name
            String newColumnName = oldColumnName.substring(tableId.getTableName().length() + 1);
            selectedColumns.set(i, newColumnName);

        } else if (!StringUtils.isEmpty(alias)) {
            throw new SQLDataException("Column name <" + oldColumnName + "> misses table alias.");
        }
    }
}

From source file:com.iksgmbh.sql.pojomemodb.sqlparser.CreateTableParser.java

private void parseDefaultValue(ColumnInitData columnInitData) throws SQLException {
    if (columnInitData.columnType.toUpperCase().contains(SQLKeyWords.DEFAULT.toUpperCase())) {
        if (columnInitData.columnType.toUpperCase().contains(SQLKeyWords.PRIMARY_KEY.toUpperCase())) {
            throw new SQLException(
                    "Primary Key column '" + columnInitData.columnName + "' must not define a default value!");
        }/*from   ww w . j a va  2s  .c  o m*/

        InterimParseResult parseResult = parseNextValue(columnInitData.columnType, SQLKeyWords.DEFAULT);
        columnInitData.defaultValue = parseResult.unparsedRest;
        columnInitData.columnType = parseResult.parsedValue;
        if (StringUtils.isEmpty(columnInitData.defaultValue) && !StringUtils.isEmpty(parseResult.delimiter))
            throw new SQLDataException("Missing default value for column '" + columnInitData.columnName + "'!");
    }
}

From source file:org.apache.nifi.processors.standard.PutDatabaseRecord.java

SqlAndIncludedColumns generateInsert(final RecordSchema recordSchema, final String tableName,
        final TableSchema tableSchema, final DMLSettings settings)
        throws IllegalArgumentException, SQLException {

    final Set<String> normalizedFieldNames = getNormalizedColumnNames(recordSchema,
            settings.translateFieldNames);

    for (final String requiredColName : tableSchema.getRequiredColumnNames()) {
        final String normalizedColName = normalizeColumnName(requiredColName, settings.translateFieldNames);
        if (!normalizedFieldNames.contains(normalizedColName)) {
            String missingColMessage = "Record does not have a value for the Required column '"
                    + requiredColName + "'";
            if (settings.failUnmappedColumns) {
                getLogger().error(missingColMessage);
                throw new IllegalArgumentException(missingColMessage);
            } else if (settings.warningUnmappedColumns) {
                getLogger().warn(missingColMessage);
            }/*from  w  ww  . j  a v  a 2  s . c  o m*/
        }
    }

    final StringBuilder sqlBuilder = new StringBuilder();
    sqlBuilder.append("INSERT INTO ");
    if (settings.quoteTableName) {
        sqlBuilder.append(tableSchema.getQuotedIdentifierString()).append(tableName)
                .append(tableSchema.getQuotedIdentifierString());
    } else {
        sqlBuilder.append(tableName);
    }
    sqlBuilder.append(" (");

    // iterate over all of the fields in the record, building the SQL statement by adding the column names
    List<String> fieldNames = recordSchema.getFieldNames();
    final List<Integer> includedColumns = new ArrayList<>();
    if (fieldNames != null) {
        int fieldCount = fieldNames.size();
        AtomicInteger fieldsFound = new AtomicInteger(0);

        for (int i = 0; i < fieldCount; i++) {
            RecordField field = recordSchema.getField(i);
            String fieldName = field.getFieldName();

            final ColumnDescription desc = tableSchema.getColumns()
                    .get(normalizeColumnName(fieldName, settings.translateFieldNames));
            if (desc == null && !settings.ignoreUnmappedFields) {
                throw new SQLDataException(
                        "Cannot map field '" + fieldName + "' to any column in the database");
            }

            if (desc != null) {
                if (fieldsFound.getAndIncrement() > 0) {
                    sqlBuilder.append(", ");
                }

                if (settings.escapeColumnNames) {
                    sqlBuilder.append(tableSchema.getQuotedIdentifierString()).append(desc.getColumnName())
                            .append(tableSchema.getQuotedIdentifierString());
                } else {
                    sqlBuilder.append(desc.getColumnName());
                }
                includedColumns.add(i);
            }
        }

        // complete the SQL statements by adding ?'s for all of the values to be escaped.
        sqlBuilder.append(") VALUES (");
        sqlBuilder.append(StringUtils.repeat("?", ",", includedColumns.size()));
        sqlBuilder.append(")");

        if (fieldsFound.get() == 0) {
            throw new SQLDataException("None of the fields in the record map to the columns defined by the "
                    + tableName + " table");
        }
    }
    return new SqlAndIncludedColumns(sqlBuilder.toString(), includedColumns);
}