Java Code Examples for java.sql.CallableStatement#wasNull()

The following examples show how to use java.sql.CallableStatement#wasNull() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractCopySQLData.java    From CloverETL-Engine with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public void setJetel(CallableStatement statement) throws SQLException {
	Array fieldVal = statement.getArray(fieldSQL);
	Object obj = fieldVal.getArray();

      	Object [] objectArray = (Object []) obj;   // cast it to an array of objects
      	
      	StringBuffer buffer = new StringBuffer("{");
      	buffer.append(String.valueOf(objectArray[0]));
      	for (int j=1; j < objectArray.length; j++)
      	   {
      			buffer.append(", ").append(String.valueOf(objectArray[j]));
      	   }
      	buffer.append("}");
	if (statement.wasNull()) {
		((StringDataField) field).setValue((Object)null);
	} else {
		((StringDataField) field).setValue(buffer.toString());
	}
}
 
Example 2
Source File: DAOFactory.java    From uavstack with Apache License 2.0 5 votes vote down vote up
public Object getResult(CallableStatement cs, int columnIndex) throws SQLException {

            Object obj = cs.getObject(columnIndex);
            if (cs.wasNull()) {
                return null;
            }
            else {
                return obj;
            }
        }
 
Example 3
Source File: DAOFactory.java    From uavstack with Apache License 2.0 5 votes vote down vote up
public Object getResult(CallableStatement cs, int columnIndex) throws SQLException {

            Object sqlTime = cs.getTime(columnIndex);
            if (cs.wasNull()) {
                return null;
            }
            else {
                return sqlTime;
            }
        }
 
Example 4
Source File: DAOFactory.java    From uavstack with Apache License 2.0 5 votes vote down vote up
public Object getResult(CallableStatement cs, int columnIndex) throws SQLException {

            Object sqlTimestamp = cs.getTimestamp(columnIndex);
            if (cs.wasNull()) {
                return null;
            }
            else {
                return sqlTimestamp;
            }
        }
 
Example 5
Source File: PostgreSQLNodeFunctions.java    From binnavi with Apache License 2.0 5 votes vote down vote up
/**
 * Deletes a local function node comment from the list of local function node comments associated
 * with the given function node.
 *
 * @param provider THe provider to access the database.
 * @param functionNode The function node to which the comment is associated.
 * @param commentId The id of the comment which will be deleted.
 * @param userId The id of the user of the currently active user.
 *
 * @throws CouldntDeleteException if the comment could not be deleted from the database.
 */
public static void deleteLocalFunctionNodeComment(final SQLProvider provider,
    final INaviFunctionNode functionNode, final Integer commentId, final Integer userId)
    throws CouldntDeleteException {

  Preconditions.checkNotNull(provider, "IE02477: provider argument can not be null");
  Preconditions.checkNotNull(functionNode, "IE02478: functionNode argument can not be null");
  Preconditions.checkNotNull(commentId, "IE02479: comment argument can not be null");
  Preconditions.checkNotNull(userId, "IE02480: userId argument can not be null");

  final String function = " { ? = call delete_function_node_comment(?, ?, ?, ?) } ";

  try {
    final CallableStatement deleteCommentStatement =
        provider.getConnection().getConnection().prepareCall(function);

    try {
      deleteCommentStatement.registerOutParameter(1, Types.INTEGER);

      deleteCommentStatement.setInt(2,
          functionNode.getFunction().getModule().getConfiguration().getId());
      deleteCommentStatement.setInt(3, functionNode.getId());
      deleteCommentStatement.setInt(4, commentId);
      deleteCommentStatement.setInt(5, userId);

      deleteCommentStatement.execute();

      deleteCommentStatement.getInt(1);
      if (deleteCommentStatement.wasNull()) {
        throw new IllegalArgumentException(
            "Error: the comment id returned from the database was null");
      }
    } finally {
      deleteCommentStatement.close();
    }

  } catch (final SQLException exception) {
    throw new CouldntDeleteException(exception);
  }
}
 
Example 6
Source File: AbstractCopySQLData.java    From CloverETL-Engine with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void setJetel(CallableStatement statement) throws SQLException {
	String fieldVal = statement.getString(fieldSQL);
	// CL-949, CL-2748: use setValue() instead of fromString()
	if (statement.wasNull()) {
		field.setValue(null);
	} else {
		field.setValue(fieldVal);
	}
}
 
Example 7
Source File: AbstractCopySQLData.java    From CloverETL-Engine with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void setJetel(CallableStatement statement) throws SQLException {
	BigDecimal i = statement.getBigDecimal(fieldSQL);
	if (statement.wasNull()) {
		((DecimalDataField) field).setValue((Object)null);
	} else {
		((DecimalDataField) field).setValue(new HugeDecimal(i, Integer.parseInt(field.getMetadata().getProperty(DataFieldMetadata.LENGTH_ATTR)), Integer.parseInt(field.getMetadata().getProperty(DataFieldMetadata.SCALE_ATTR)), false));
	}
}
 
Example 8
Source File: PostgreSQLNodeFunctions.java    From binnavi with Apache License 2.0 5 votes vote down vote up
/**
 * Appends a comment to the list of comments associated with the group node in the database.
 *
 * @param provider The provider to access the database.
 * @param groupNode The group node to which the comment is associated.
 * @param commentText The comment text of the comment.
 * @param userId The user id of the currently active user.
 *
 * @return The generated comment id from the database.
 *
 * @throws CouldntSaveDataException if the comment could not be saved to the database.
 */
public static Integer appendGroupNodeComment(final SQLProvider provider,
    final INaviGroupNode groupNode, final String commentText, final Integer userId)
    throws CouldntSaveDataException {

  Preconditions.checkNotNull(provider, "IE02449: provider argument can not be null");
  Preconditions.checkNotNull(groupNode, "IE02450: groupNode argument can not be null");
  Preconditions.checkNotNull(commentText, "IE02451: commentText argument can not be null");
  Preconditions.checkNotNull(userId, "IE02452: userId argument can not be null");
  Preconditions.checkArgument(groupNode.getId() > 0, "Error: group node is not saved.");


  final String function = " { ? = call append_group_node_comment(?, ?, ?) } ";

  try {
    final CallableStatement appendCommentFunction =
        provider.getConnection().getConnection().prepareCall(function);

    try {
      appendCommentFunction.registerOutParameter(1, Types.INTEGER);
      appendCommentFunction.setInt(2, groupNode.getId());
      appendCommentFunction.setInt(3, userId);
      appendCommentFunction.setString(4, commentText);

      appendCommentFunction.execute();
      final Integer commentId = appendCommentFunction.getInt(1);
      if (appendCommentFunction.wasNull()) {
        throw new CouldntSaveDataException("Error: Got an comment id of null from the database");
      }
      return commentId;

    } finally {
      appendCommentFunction.close();
    }
  } catch (final SQLException exception) {
    throw new CouldntSaveDataException(exception);
  }
}
 
Example 9
Source File: AbstractCopySQLData.java    From CloverETL-Engine with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void setJetel(CallableStatement statement) throws SQLException {
	Date time = statement.getTime(fieldSQL);
	if (statement.wasNull()) {
		((DateDataField) field).setValue((Object)null);
	}else{
		((DateDataField) field).setValue(time);
	}
	
}
 
Example 10
Source File: AbstractCopySQLData.java    From CloverETL-Engine with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void setJetel(CallableStatement statement) throws SQLException {
	String fieldVal = statement.getString(fieldSQL);
	// uses fromString - field should _not_ be a StringDataField
	if (statement.wasNull()) {
		field.fromString(null);
	} else {
		field.fromString(fieldVal);
	}
}
 
Example 11
Source File: EnumOrdinalTypeHandler.java    From tangyuan2 with GNU General Public License v3.0 5 votes vote down vote up
@Override
public E getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
	int i = cs.getInt(columnIndex);
	if (cs.wasNull()) {
		return null;
	} else {
		try {
			return enums[i];
		} catch (Exception ex) {
			throw new IllegalArgumentException("Cannot convert " + i + " to " + type.getSimpleName() + " by ordinal value.", ex);
		}
	}
}
 
Example 12
Source File: AbstractCopySQLData.java    From CloverETL-Engine with GNU Lesser General Public License v2.1 5 votes vote down vote up
@Override
public void setJetel(CallableStatement statement) throws SQLException {
	Timestamp timestamp = statement.getTimestamp(fieldSQL);
	if (statement.wasNull()) {
		((DateDataField) field).setValue((Object)null);
	}else{
		((DateDataField) field).setValue(timestamp);
	}
	
}
 
Example 13
Source File: BaseTypeHandler.java    From mybaties with Apache License 2.0 5 votes vote down vote up
@Override
 public T getResult(CallableStatement cs, int columnIndex) throws SQLException {
   T result = getNullableResult(cs, columnIndex);
//通过CallableStatement.wasNull判断是否为NULL
   if (cs.wasNull()) {
     return null;
   } else {
     return result;
   }
 }
 
Example 14
Source File: PostgreSQLInstructionFunctions.java    From binnavi with Apache License 2.0 5 votes vote down vote up
/**
 * This function deletes a global instruction comment associated with the
 * given instruction from the database.
 *
 * @param provider The provider used to access the database.
 * @param instruction The instruction to which the comment is associated.
 * @param commentId The comment id of the comment to be deleted.
 * @param userId The id of the currently active user.
 *
 * @throws CouldntDeleteException if the comment could not be deleted from the
 *         database.
 */
public static void deleteGlobalInstructionComment(final SQLProvider provider,
    final INaviInstruction instruction, final Integer commentId, final Integer userId)
        throws CouldntDeleteException {

  Preconditions.checkNotNull(provider, "IE02428: provider argument can not be null");
  Preconditions.checkNotNull(instruction, "IE02429: instruction argument can not be null");
  Preconditions.checkNotNull(commentId, "IE02430: comment argument can not be null");
  Preconditions.checkNotNull(userId, "IE02431: userId argument can not be null");

  final String function = " { ? = call delete_global_instruction_comment(?, ?, ?, ?) } ";

  try {

    final CallableStatement deleteCommentStatement =
        provider.getConnection().getConnection().prepareCall(function);

    try {
      deleteCommentStatement.registerOutParameter(1, Types.INTEGER);
      deleteCommentStatement.setInt(2, instruction.getModule().getConfiguration().getId());
      deleteCommentStatement.setObject(3, instruction.getAddress().toBigInteger(), Types.BIGINT);
      deleteCommentStatement.setInt(4, commentId);
      deleteCommentStatement.setInt(5, userId);

      deleteCommentStatement.execute();

      deleteCommentStatement.getInt(1);
      if (deleteCommentStatement.wasNull()) {
        throw new IllegalArgumentException(
            "Error: The comment id returned from the database was null.");
      }

    } finally {
      deleteCommentStatement.close();
    }

  } catch (final SQLException exception) {
    throw new CouldntDeleteException(exception);
  }
}
 
Example 15
Source File: ListTypeHandler.java    From joyqueue with Apache License 2.0 5 votes vote down vote up
@Override
public List<T> getNullableResult(CallableStatement cs, int columnIndex) throws SQLException {
    if (cs==null || cs.wasNull()) {
        return null;
    }
    String columnValue = cs.getString(columnIndex);
    if (StringUtils.isBlank(columnValue)) {
        return null;
    }
    return JSONArray.parseArray(columnValue, type);

}
 
Example 16
Source File: PostgreSQLEdgeFunctions.java    From binnavi with Apache License 2.0 4 votes vote down vote up
/**
 * This function deletes a global edge comment from the database.
 *
 * @param provider The provider to access the database.
 * @param edge The edge to which the comment is associated.
 * @param commentId The comment id of the comment to be deleted.
 * @param userId The user id of the currently active user.
 *
 * @throws CouldntDeleteException if the comment could not be deleted from the database.
 */
public static void deleteGlobalEdgeComment(final AbstractSQLProvider provider,
    final INaviEdge edge, final Integer commentId, final Integer userId)
    throws CouldntDeleteException {

  Preconditions.checkNotNull(provider, "IE00505: provider argument can not be null");
  Preconditions.checkNotNull(edge, "IE00506: codeNode argument can not be null");
  Preconditions.checkNotNull(commentId, "IE00507: comment argument can not be null");
  Preconditions.checkNotNull(userId, "IE00508: userId argument can not be null");

  final String function = " { ? = call delete_global_edge_comment(?, ?, ?, ?, ?, ?) } ";

  try {
    final CallableStatement deleteCommentFunction =
        provider.getConnection().getConnection().prepareCall(function);

    try {
      deleteCommentFunction.registerOutParameter(1, Types.INTEGER);
      deleteCommentFunction.setInt(2, getModuleId(edge.getSource()));
      deleteCommentFunction.setInt(3, getModuleId(edge.getTarget()));
      deleteCommentFunction.setObject(
          4, ((INaviCodeNode) edge.getSource()).getAddress().toBigInteger(), Types.BIGINT);
      deleteCommentFunction.setObject(
          5, ((INaviCodeNode) edge.getTarget()).getAddress().toBigInteger(), Types.BIGINT);
      deleteCommentFunction.setInt(6, commentId);
      deleteCommentFunction.setInt(7, userId);

      deleteCommentFunction.execute();

      deleteCommentFunction.getInt(1);
      if (deleteCommentFunction.wasNull()) {
        throw new IllegalArgumentException(
            "Error: the comment id returned from the database was null");
      }
    } finally {
      deleteCommentFunction.close();
    }

  } catch (SQLException | MaybeNullException exception) {
    throw new CouldntDeleteException(exception);
  }
}
 
Example 17
Source File: PostgreSQLTypeFunctions.java    From binnavi with Apache License 2.0 4 votes vote down vote up
/**
 * Creates a new type instance in the database.
 *
 * @param connection The connection used to access the database.
 * @param moduleId The id of the module the type instance is associated to.
 * @param name The name of the type instance.
 * @param commentId The id of the comment associated with the type instance.
 * @param typeId The id of the type which is the base type for this type instance.
 * @param sectionId The id of the section where this type instance is located in.
 * @param sectionOffset The offset in the section at which the type instance starts.
 *
 * @return The id of the generated type instance in the database.
 *
 * @throws CouldntSaveDataException if the type instance could not be generated in the database.
 */
public static int createTypeInstance(final Connection connection,
    final int moduleId,
    final String name,
    final Integer commentId,
    final int typeId,
    final int sectionId,
    final long sectionOffset) throws CouldntSaveDataException {

  Preconditions.checkNotNull(connection, "Error: connection argument can not be null");
  Preconditions.checkArgument(moduleId > 0, "Error: module id must be greater than zero");
  Preconditions.checkNotNull(name, "Error: name argument can not be null");
  Preconditions.checkArgument(typeId >= 0, "Error: type id must be greater than zero");
  Preconditions.checkArgument(sectionId >= 0, "Error: section id must be larger than zero");
  Preconditions.checkArgument(sectionOffset >= 0,
      "Error: section offset must be larger or equal to zero");

  try {
    final String query = " { ? = call create_type_instance(?, ?, ?, ?, ?, ?) } ";
    final CallableStatement procedure = connection.prepareCall(query);
    try {
      procedure.registerOutParameter(1, Types.INTEGER);
      procedure.setInt(2, moduleId);
      procedure.setString(3, name);
      if (commentId == null) {
        procedure.setNull(4, Types.INTEGER);
      } else {
        procedure.setInt(4, commentId);
      }
      procedure.setInt(5, typeId);
      procedure.setInt(6, sectionId);
      procedure.setLong(7, sectionOffset);
      procedure.execute();

      final int typeInstanceId = procedure.getInt(1);
      if (procedure.wasNull()) {
        throw new CouldntSaveDataException(
            "Error: the type instance id returned from the database was null");
      }
      return typeInstanceId;
    } finally {
      procedure.close();
    }
  } catch (final SQLException exception) {
    throw new CouldntSaveDataException(exception);
  }
}
 
Example 18
Source File: AbstractCopySQLData.java    From CloverETL-Engine with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
public Object getDbValue(CallableStatement statement)
		throws SQLException {
          byte[] i = statement.getBytes(fieldSQL);
	return statement.wasNull() ? null : i;
}
 
Example 19
Source File: SQLiteSpecific.java    From CloverETL-Engine with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
public Object getDbValue(CallableStatement statement) throws SQLException {
	double d = statement.getDouble(fieldSQL);
	return statement.wasNull() ? null : d;
}
 
Example 20
Source File: AbstractCopySQLData.java    From CloverETL-Engine with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
public Object getDbValue(CallableStatement statement)
		throws SQLException {
	Timestamp timestamp = statement.getTimestamp(fieldSQL);
	return statement.wasNull() ? null : timestamp;
}