Tabnine Logo
FieldValidator.validatePrimaryKeys
Code IndexAdd Tabnine to your IDE (free)

How to use
validatePrimaryKeys
method
in
co.cask.cdap.spi.data.table.field.FieldValidator

Best Java code snippets using co.cask.cdap.spi.data.table.field.FieldValidator.validatePrimaryKeys (Showing top 8 results out of 315)

origin: cdapio/cdap

@Override
public void delete(Collection<Field<?>> keys) throws InvalidFieldException, IOException {
 LOG.trace("Table {}: Delete with keys {}", tableSchema.getTableId(), keys);
 fieldValidator.validatePrimaryKeys(keys, false);
 String sqlQuery = getDeleteQuery(keys);
 try (PreparedStatement statement = connection.prepareStatement(sqlQuery)) {
  int index = 1;
  for (Field<?> key : keys) {
   setField(statement, key, index);
   index++;
  }
  LOG.trace("SQL statement: {}", statement);
  statement.executeUpdate();
 } catch (SQLException e) {
  throw new IOException(String.format("Failed to delete the row from table %s with fields %s",
                    tableSchema.getTableId().getName(), keys), e);
 }
}
origin: cdapio/cdap

Collection<Field<?>> keys, @Nullable Collection<String> columns) throws InvalidFieldException, IOException {
LOG.trace("Table {}: Read with keys {} and columns {}", tableSchema.getTableId(), keys, columns);
fieldValidator.validatePrimaryKeys(keys, false);
String readQuery = getReadQuery(keys, columns, false);
try (PreparedStatement statement = connection.prepareStatement(readQuery);) {
origin: cdapio/cdap

 throw new IllegalArgumentException("Cannot use increment on a primary key field");
fieldValidator.validatePrimaryKeys(keys, false);
origin: cdapio/cdap

@Override
public void deleteAll(Range keyRange) throws InvalidFieldException, IOException {
 LOG.trace("Table {}: DeleteAll with range {}", tableSchema.getTableId(), keyRange);
 fieldValidator.validatePrimaryKeys(keyRange.getBegin(), true);
 fieldValidator.validatePrimaryKeys(keyRange.getEnd(), true);
 String sql = getDeleteAllStatement(keyRange);
 try (PreparedStatement statement = connection.prepareStatement(sql)) {
  int index = 1;
  if (keyRange.getBegin() != null) {
   for (Field<?> key : keyRange.getBegin()) {
    setField(statement, key, index);
    index++;
   }
  }
  if (keyRange.getEnd() != null) {
   for (Field<?> key : keyRange.getEnd()) {
    setField(statement, key, index);
    index++;
   }
  }
  LOG.trace("SQL statement: {}", statement);
  statement.executeUpdate();
 } catch (SQLException e) {
  throw new IOException(String.format("Failed to delete the rows from table %s with range %s",
                    tableSchema.getTableId().getName(), keyRange), e);
 }
}
origin: cdapio/cdap

@Override
public CloseableIterator<StructuredRow> scan(Range keyRange, int limit) throws InvalidFieldException, IOException {
 LOG.trace("Table {}: Scan range {} with limit {}", tableSchema.getTableId(), keyRange, limit);
 fieldValidator.validatePrimaryKeys(keyRange.getBegin(), true);
 fieldValidator.validatePrimaryKeys(keyRange.getEnd(), true);
 String scanQuery = getScanQuery(keyRange, limit);
 // We don't close the statement here because once it is closed, the result set is also closed.
 try {
  PreparedStatement statement = connection.prepareStatement(scanQuery);
  int index = 1;
  if (keyRange.getBegin() != null) {
   for (Field<?> key : keyRange.getBegin()) {
    setField(statement, key, index);
    index++;
   }
  }
  if (keyRange.getEnd() != null) {
   for (Field<?> key : keyRange.getEnd()) {
    setField(statement, key, index);
    index++;
   }
  }
  LOG.trace("SQL statement: {}", statement);
  ResultSet resultSet = statement.executeQuery();
  return new ResultSetIterator(statement, resultSet, tableSchema);
 } catch (SQLException e) {
  throw new IOException(String.format("Failed to scan from table %s with range %s",
                    tableSchema.getTableId().getName(), keyRange), e);
 }
}
origin: cdapio/cdap

LOG.trace("Table {}: CompareAndSwap with keys {}, oldValue {}, newValue {}", tableSchema.getTableId(), keys,
     oldValue, newValue);
fieldValidator.validatePrimaryKeys(keys, false);
fieldValidator.validateField(oldValue);
if (oldValue.getFieldType() != newValue.getFieldType()) {
origin: cdapio/cdap

/**
 * Convert the keys to corresponding byte array. The keys can either be a prefix or complete primary keys depending
 * on the value of allowPrefix. The method will always prepend the table name as a prefix for the row keys.
 *
 * @param keys keys to convert
 * @param allowPrefix true if the keys can be prefix false if the keys have to contain all the primary keys.
 * @return the byte array converted
 * @throws InvalidFieldException if the key are not prefix or complete primary keys
 */
private byte[] convertKeyToBytes(Collection<Field<?>> keys, boolean allowPrefix) throws InvalidFieldException {
 fieldValidator.validatePrimaryKeys(keys, allowPrefix);
 MDSKey.Builder mdsKey = new MDSKey.Builder(keyPrefix);
 for (Field<?> key : keys) {
  addKey(mdsKey, key, schema.getType(key.getName()));
 }
 return mdsKey.build().getKey();
}
origin: caskdata/cdap

validator.validatePrimaryKeys(Arrays.asList(Fields.intField(KEY, 10), Fields.longField(KEY2, 100L),
                      Fields.stringField(KEY3, "s")), false);
validator.validatePrimaryKeys(Arrays.asList(Fields.intField(KEY, 10), Fields.longField(KEY2, 100L)),
                      true);
validator.validatePrimaryKeys(Collections.singletonList(Fields.intField(KEY, 10)), true);
 validator.validatePrimaryKeys(Arrays.asList(Fields.floatField(KEY, 10.0f), Fields.longField(KEY2, 100L),
                       Fields.stringField(KEY3, "s")), false);
 Assert.fail("Expected InvalidFieldException");
 validator.validatePrimaryKeys(Arrays.asList(Fields.intField(KEY, 10), Fields.longField(KEY2, 100L)),
                false);
 Assert.fail("Expected InvalidFieldException");
co.cask.cdap.spi.data.table.fieldFieldValidatorvalidatePrimaryKeys

Javadoc

Validate if the given keys are prefix or complete primary keys.

Popular methods of FieldValidator

  • <init>
  • validateField
    Validate if the given field matches the schema. The given field is invalid if: it is not present in

Popular in Java

  • Creating JSON documents from java classes using gson
  • notifyDataSetChanged (ArrayAdapter)
  • onCreateOptionsMenu (Activity)
  • getExternalFilesDir (Context)
  • BufferedImage (java.awt.image)
    The BufferedImage subclass describes an java.awt.Image with an accessible buffer of image data. All
  • Selector (java.nio.channels)
    A controller for the selection of SelectableChannel objects. Selectable channels can be registered w
  • Date (java.sql)
    A class which can consume and produce dates in SQL Date format. Dates are represented in SQL as yyyy
  • Collections (java.util)
    This class consists exclusively of static methods that operate on or return collections. It contains
  • Set (java.util)
    A Set is a data structure which does not allow duplicate elements.
  • StringUtils (org.apache.commons.lang)
    Operations on java.lang.String that arenull safe. * IsEmpty/IsBlank - checks if a String contains
  • CodeWhisperer alternatives
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now