Package java.sql

Examples of java.sql.SQLException


   * Assign an ID value to this field.
   */
  public Object assignIdValue(Object data, Number val) throws SQLException {
    Object idVal = dataPersister.convertIdNumber(val);
    if (idVal == null) {
      throw new SQLException("Invalid class " + dataPersister + " for sequence-id " + this);
    } else {
      assignField(data, idVal);
      return idVal;
    }
  }
View Full Code Here


    }
    @SuppressWarnings("unchecked")
    T converted = (T) fieldConverter.resultToJava(this, results, dbColumnPos);
    if (dataPersister.isPrimitive()) {
      if (fieldConfig.isThrowIfNull() && results.wasNull(dbColumnPos)) {
        throw new SQLException("Results value for primitive field '" + field.getName()
            + "' was an invalid null value");
      }
    } else if (!fieldConverter.isStreamType() && results.wasNull(dbColumnPos)) {
      // we can't check if we have a null if this is a stream type
      return null;
View Full Code Here

        }
      }
      throw new IllegalArgumentException(sb.toString());
    }
    if (fieldConfig.isThrowIfNull() && !dataPersister.isPrimitive()) {
      throw new SQLException("Field " + field.getName() + " must be a primitive if set with throwIfNull");
    }
    if (this.isId && !dataPersister.isAppropriateId()) {
      throw new SQLException("Field '" + field.getName() + "' is of data type " + dataPersister
          + " which cannot be the ID field");
    }
    this.dataTypeConfigObj = dataPersister.makeConfigObject(this);
    String defaultStr = fieldConfig.getDefaultValue();
    if (defaultStr == null || defaultStr.equals("")) {
      this.defaultValue = null;
    } else if (this.isGeneratedId) {
      throw new SQLException("Field '" + field.getName() + "' cannot be a generatedId and have a default value '"
          + defaultStr + "'");
    } else {
      this.defaultValue = this.fieldConverter.parseDefaultString(this, defaultStr);
    }
  }
View Full Code Here

      usedSpecialConnection = true;
      specialConnection.set(new NestedConnection(connection));
      return true;
    } else {
      if (currentSaved.connection != connection) {
        throw new SQLException("trying to save connection " + connection
            + " but already have saved connection " + currentSaved.connection);
      }
      // we must have a save call within another save
      currentSaved.increment();
      return false;
View Full Code Here

   * with the value escaped if necessary.
   */
  public StatementBuilder<T, ID> updateColumnValue(String columnName, Object value) throws SQLException {
    FieldType fieldType = verifyColumnName(columnName);
    if (fieldType.isForeignCollection()) {
      throw new SQLException("Can't update foreign colletion field: " + columnName);
    }
    addUpdateColumnToList(columnName, new SetValue(columnName, fieldType, value));
    return this;
  }
View Full Code Here

   * </p>
   */
  public StatementBuilder<T, ID> updateColumnExpression(String columnName, String expression) throws SQLException {
    FieldType fieldType = verifyColumnName(columnName);
    if (fieldType.isForeignCollection()) {
      throw new SQLException("Can't update foreign colletion field: " + columnName);
    }
    addUpdateColumnToList(columnName, new SetExpression(columnName, fieldType, expression));
    return this;
  }
View Full Code Here

    // find the id field
    FieldType findIdFieldType = null;
    for (FieldType fieldType : fieldTypes) {
      if (fieldType.isId() || fieldType.isGeneratedId() || fieldType.isGeneratedIdSequence()) {
        if (findIdFieldType != null) {
          throw new SQLException("More than 1 idField configured for class " + dataClass + " ("
              + findIdFieldType + "," + fieldType + ")");
        }
        findIdFieldType = fieldType;
      }
    }
    // if we just have 1 field and it is a generated-id then inserts will be blank which is not allowed.
    if (fieldTypes.length == 1 && findIdFieldType != null && findIdFieldType.isGeneratedId()) {
      throw new SQLException("Must have more than a single field which is a generated-id for class " + dataClass);
    }
    // can be null if there is no id field
    this.idField = findIdFieldType;
    this.constructor = tableConfig.getConstructor();
  }
View Full Code Here

    this.dao = dao;
  }

  private void checkForDao() throws SQLException {
    if (dao == null) {
      throw new SQLException("Dao has not been set on " + getClass() + " object: " + this);
    }
  }
View Full Code Here

  public QueryBuilder<T, ID> offset(Integer startRow) throws SQLException {
    if (databaseType.isOffsetSqlSupported()) {
      offset = startRow;
      return this;
    } else {
      throw new SQLException("Offset is not supported by this database");
    }
  }
View Full Code Here

    // call the query-next-sequence stmt to increment the sequence
    long seqVal = databaseConnection.queryForLong(queryNextSequenceStmt);
    logger.debug("queried for sequence {} using stmt: {}", seqVal, queryNextSequenceStmt);
    if (seqVal == 0) {
      // sanity check that it is working
      throw new SQLException("Should not have returned 0 for stmt: " + queryNextSequenceStmt);
    }
    assignIdValue(data, seqVal, "sequence");
  }
View Full Code Here

TOP

Related Classes of java.sql.SQLException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.