private void insert(
     final Record object, final PathName typePath, final RecordDefinition recordDefinition)
     throws SQLException {
   PreparedStatement statement = this.typeInsertStatementMap.get(typePath);
   if (statement == null) {
     final String sql = getInsertSql(recordDefinition, false);
     try {
       statement = this.connection.prepareStatement(sql);
       this.typeInsertStatementMap.put(typePath, statement);
     } catch (final SQLException e) {
       LOG.error(sql, e);
     }
   }
   int parameterIndex = 1;
   for (final FieldDefinition fieldDefinition : recordDefinition.getFields()) {
     final JdbcFieldDefinition jdbcFieldDefinition = (JdbcFieldDefinition) fieldDefinition;
     parameterIndex =
         jdbcFieldDefinition.setInsertPreparedStatementValue(statement, parameterIndex, object);
   }
   statement.addBatch();
   Integer batchCount = this.typeInsertBatchCountMap.get(typePath);
   if (batchCount == null) {
     batchCount = 1;
     this.typeInsertBatchCountMap.put(typePath, 1);
   } else {
     batchCount += 1;
     this.typeInsertBatchCountMap.put(typePath, batchCount);
   }
   if (batchCount >= this.batchSize) {
     final String sql = getInsertSql(recordDefinition, false);
     processCurrentBatch(typePath, sql, statement, this.typeInsertBatchCountMap);
   }
 }
 private void update(final Record object) throws SQLException {
   final RecordDefinition objectType = object.getRecordDefinition();
   final PathName typePath = objectType.getPathName();
   final RecordDefinition recordDefinition = getRecordDefinition(typePath);
   flushIfRequired(recordDefinition);
   PreparedStatement statement = this.typeUpdateStatementMap.get(typePath);
   if (statement == null) {
     final String sql = getUpdateSql(recordDefinition);
     try {
       statement = this.connection.prepareStatement(sql);
       this.typeUpdateStatementMap.put(typePath, statement);
     } catch (final SQLException e) {
       LOG.error(sql, e);
     }
   }
   int parameterIndex = 1;
   final List<FieldDefinition> idFields = recordDefinition.getIdFields();
   for (final FieldDefinition fieldDefinition : recordDefinition.getFields()) {
     if (!idFields.contains(fieldDefinition)) {
       final JdbcFieldDefinition jdbcFieldDefinition = (JdbcFieldDefinition) fieldDefinition;
       parameterIndex =
           jdbcFieldDefinition.setInsertPreparedStatementValue(statement, parameterIndex, object);
     }
   }
   for (final FieldDefinition idField : idFields) {
     final JdbcFieldDefinition jdbcFieldDefinition = (JdbcFieldDefinition) idField;
     parameterIndex =
         jdbcFieldDefinition.setInsertPreparedStatementValue(statement, parameterIndex, object);
   }
   statement.addBatch();
   Integer batchCount = this.typeUpdateBatchCountMap.get(typePath);
   if (batchCount == null) {
     batchCount = 1;
     this.typeUpdateBatchCountMap.put(typePath, 1);
   } else {
     batchCount += 1;
     this.typeUpdateBatchCountMap.put(typePath, batchCount);
   }
   if (batchCount >= this.batchSize) {
     final String sql = getUpdateSql(recordDefinition);
     processCurrentBatch(typePath, sql, statement, this.typeUpdateBatchCountMap);
   }
   this.recordStore.addStatistic("Update", object);
 }
  private void delete(final Record object) throws SQLException {
    final RecordDefinition objectType = object.getRecordDefinition();
    final PathName typePath = objectType.getPathName();
    final RecordDefinition recordDefinition = getRecordDefinition(typePath);
    flushIfRequired(recordDefinition);
    PreparedStatement statement = this.typeDeleteStatementMap.get(typePath);
    if (statement == null) {
      final String sql = getDeleteSql(recordDefinition);
      try {
        statement = this.connection.prepareStatement(sql);
        this.typeDeleteStatementMap.put(typePath, statement);
      } catch (final SQLException e) {
        LOG.error(sql, e);
      }
    }
    int parameterIndex = 1;
    final JdbcFieldDefinition idField = (JdbcFieldDefinition) recordDefinition.getIdField();
    parameterIndex = idField.setInsertPreparedStatementValue(statement, parameterIndex, object);
    statement.addBatch();
    Integer batchCount = this.typeDeleteBatchCountMap.get(typePath);
    if (batchCount == null) {
      batchCount = 1;
      this.typeDeleteBatchCountMap.put(typePath, 1);
    } else {
      batchCount += 1;
      this.typeDeleteBatchCountMap.put(typePath, batchCount);
    }
    this.recordStore.addStatistic("Delete", object);

    // TODO this locks code tables which prevents insert
    // if (batchCount >= batchSize) {
    // final String sql = getDeleteSql(recordDefinition);
    // processCurrentBatch(typePath, sql, statement, typeDeleteBatchCountMap,
    // getDeleteStatistics());
    // }
  }