Package avrobase

Examples of avrobase.AvroBaseException


    Connection c = null;
    try {
      c = ds.getConnection();
      PreparedStatement insertRow = c.prepareStatement("INSERT INTO " + tableName + " () VALUES ()");
      int insert = insertRow.executeUpdate();
      if (insert != 1) throw new AvroBaseException("Could not get new key: " + insert + " rows updated");
      insertRow.close();
      PreparedStatement getRow = c.prepareStatement("SELECT LAST_INSERT_ID()");
      ResultSet resultSet = getRow.executeQuery();
      if (resultSet.next()) {
        Long query = resultSet.getLong(1);
        int deleted = c.prepareStatement("DELETE FROM " + tableName + " WHERE id = LAST_INSERT_ID()").executeUpdate();
        if (deleted != 1) throw new AvroBaseException("Failed to delete row");
        byte[] row = String.valueOf(query).getBytes();
        int length = row.length;
        for (int i = 0; i < length / 2; i++) {
          byte tmp = row[i];
          row[i] = row[length - i - 1];
          row[length - i - 1] = tmp;
        }
        return row;
      }
      throw new AvroBaseException("Failed to find last insert id");
    } catch (Exception e) {
      throw new AvroBaseException("Failed to get key", e);
    } finally {
      try {
        c.close();
      } catch (SQLException e) {
        // ignore
View Full Code Here


    if (row == null) return null;
    byte[] bytes = transformer == null ? (byte[]) row : transformer.apply(row);
    try {
      return new String(base32hex.encode(bytes));
    } catch (IOException e) {
      throw new AvroBaseException("Could not encode");
    }
  }
View Full Code Here

  public Row<T, K> get(K row) throws AvroBaseException {
    Lock lock = readLock(row);
    try {
      return _get(row);
    } catch (Exception e) {
      throw new AvroBaseException("Failed to get row: " + row, e);
    } finally {
      lock.unlock();
    }
  }
View Full Code Here

      if (schema == null) {
        File schemaFile = new File(schemaDir, hash);
        try {
          schema = Schema.parse(new FileInputStream(schemaFile));
        } catch (IOException ioe) {
          throw new AvroBaseException("Failed to read schema for hash: " + hash + " row: " + row, ioe);
        }
        schemaCache.put(hash, schema);
        hashCache.put(schema, hash);
      }
      try {
        DecoderFactory decoderFactory = new DecoderFactory();
        Decoder d;
        switch (format) {
          case JSON:
            d = decoderFactory.jsonDecoder(schema, is);
            break;
          case BINARY:
          default:
            d = decoderFactory.binaryDecoder(is, null);
            break;
        }
        // Read the data
        SpecificDatumReader<T> sdr = new SpecificDatumReader<T>(schema);
        sdr.setExpected(actualSchema);
        return new Row<T, K>(sdr.read(null, d), row, version);
      } catch (IOException e) {
        throw new AvroBaseException("Failed to read file: " + schema, e);
      } catch (AvroTypeException e) {
        throw new AvroBaseException("Failed to read value: " + schema, e);
      }
    } finally {
      channel.close();
      is.close();
    }
View Full Code Here

    return readWriteLock;
  }

  @Override
  public K create(T value) throws AvroBaseException {
    if (supplier == null) throw new AvroBaseException("No key generator provided");
    K row = supplier.get();
    put(row, value);
    return row;
  }
View Full Code Here

        fileLock.release();
        channel.close();
        raf.close();
      }
    } catch (Exception e) {
      throw new AvroBaseException("Failed to get row: " + row, e);
    } finally {
      lock.unlock();
    }
  }
View Full Code Here

        fileLock.release();
        channel.close();
        raf.close();
      }
    } catch (Exception e) {
      throw new AvroBaseException("Failed to get row: " + row, e);
    } finally {
      lock.unlock();
    }
  }
View Full Code Here

        raf.close();
      }
    } catch (FileNotFoundException e) {
      // Already deleted
    } catch (IOException e) {
      throw new AvroBaseException("Failed to delete: " + row, e);
    } finally {
      writeLock.unlock();
    }
  }
View Full Code Here

                try {
                  byte[] decode = base32hex.decode(sb.toString().toCharArray());
                  current = get(transformer == null ? (K) decode : transformer.unapply(decode));
                  return current != null || hasNext();
                } catch (IOException e) {
                  throw new AvroBaseException("Corrupt file system: " + file, e);
                }
              }
            } while (true);
          }
View Full Code Here

        fis.close();
      }
    } catch (FileNotFoundException e) {
      return null;
    } catch (IOException e) {
      throw new AvroBaseException("Failed to delete: " + row, e);
    } finally {
      writeLock.unlock();
    }
  }
View Full Code Here

TOP

Related Classes of avrobase.AvroBaseException

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.