@Override public UUID findFirst(JobAuthorization.State jobState) { try { String partitionFilter = generateFilterCondition( "PartitionKey", TableQuery.QueryComparisons.EQUAL, configuration.getPartitionKey()); String stateFilter = generateFilterCondition( "State", TableQuery.QueryComparisons.EQUAL, jobState.name()); // properties are converted to capitalized by the storage API String combinedFilter = TableQuery.combineFilters(partitionFilter, TableQuery.Operators.AND, stateFilter); TableQuery<DataWrapper> query = TableQuery.from(DataWrapper.class).where(combinedFilter).take(1); CloudTable table = tableClient.getTableReference(JOB_TABLE); Iterator<DataWrapper> iter = table.execute(query).iterator(); if (!iter.hasNext()) { return null; } return UUID.fromString(iter.next().getRowKey()); } catch (StorageException | URISyntaxException e) { throw new MicrosoftStorageException("Error finding first job", e); } }
/** * Generates a property filter condition string for a <code>String</code> value. Creates a formatted string to use * in a filter expression that uses the specified operation to compare the property with the value, formatted as * a string value, as in the following example: * <p> * <code>String condition = generateFilterCondition("Platform", QueryComparisons.EQUAL, "Azure");</code> * <p> * This statement sets <code>condition</code> to the following value: * <p> * <code>Platform eq 'Azure'</code> * * @param propertyName * A <code>String</code> which specifies the name of the property to compare. * @param operation * A <code>String</code> which specifies the comparison operator to use. * @param value * A <code>String</code> which specifies the value to compare with the property. * @return * A <code>String</code> which represents the formatted filter condition. */ public static String generateFilterCondition(String propertyName, String operation, final String value) { return generateFilterCondition(propertyName, operation, value, EdmType.STRING); }
/** * Generates a property filter condition string for a <code>boolean</code> value. Creates a formatted string to use * in a filter expression that uses the specified operation to compare the property with the value, formatted as a * boolean, as in the following example: * <p> * <code>String condition = generateFilterCondition("BooleanProperty", QueryComparisons.EQUAL, false);</code> * <p> * This statement sets <code>condition</code> to the following value: * <p> * <code>BooleanProperty eq false</code> * * @param propertyName * A <code>String</code> which specifies the name of the property to compare. * @param operation * A <code>String</code> which specifies the comparison operator to use. * @param value * A <code>boolean</code> which specifies the value to compare with the property. * @return * A <code>String</code> which represents the formatted filter condition. */ public static String generateFilterCondition(String propertyName, String operation, final boolean value) { return generateFilterCondition(propertyName, operation, value ? Constants.TRUE : Constants.FALSE, EdmType.BOOLEAN); }
/** * Generates a property filter condition string for a <code>String</code> value. Creates a formatted string to use * in a filter expression that uses the specified operation to compare the property with the value, formatted as * a string value, as in the following example: * <p> * <code>String condition = generateFilterCondition("Platform", QueryComparisons.EQUAL, "Azure");</code> * <p> * This statement sets <code>condition</code> to the following value: * <p> * <code>Platform eq 'Azure'</code> * * @param propertyName * A <code>String</code> which specifies the name of the property to compare. * @param operation * A <code>String</code> which specifies the comparison operator to use. * @param value * A <code>String</code> which specifies the value to compare with the property. * @return * A <code>String</code> which represents the formatted filter condition. */ public static String generateFilterCondition(String propertyName, String operation, final String value) { return generateFilterCondition(propertyName, operation, value, EdmType.STRING); }
private static String timestampEquals(long timestamp) { return TableQuery.generateFilterCondition( ROW_KEY, TableQuery.QueryComparisons.EQUAL, String.valueOf(timestamp) ); }
/** * Generates a property filter condition string for a <code>double</code> value. Creates a formatted string to use * in a filter expression that uses the specified operation to compare the property with the value, formatted as * a double value, as in the following example: * <p> * <code>String condition = generateFilterCondition("Circumference", QueryComparisons.EQUAL, 2 * 3.141592);</code> * <p> * This statement sets <code>condition</code> to the following value: * <p> * <code>Circumference eq 6.283184</code> * * @param propertyName * A <code>String</code> which specifies the name of the property to compare. * @param operation * A <code>String</code> which specifies the comparison operator to use. * @param value * A <code>double</code> which specifies the value to compare with the property. * @return * A <code>String</code> which represents the formatted filter condition. */ public static String generateFilterCondition(String propertyName, String operation, final double value) { return generateFilterCondition(propertyName, operation, Double.toString(value), EdmType.DOUBLE); }
/** * Generates a property filter condition string for a <code>long</code> value. Creates a formatted string to use * in a filter expression that uses the specified operation to compare the property with the value, formatted as * a numeric value, as in the following example: * <p> * <code>String condition = generateFilterCondition("StellarMass", QueryComparisons.GREATER_THAN, 7000000000L);</code> * <p> * This statement sets <code>condition</code> to the following value: * <p> * <code>StellarMass gt 7000000000</code> * * @param propertyName * A <code>String</code> which specifies the name of the property to compare. * @param operation * A <code>String</code> which specifies the comparison operator to use. * @param value * A <code>long</code> which specifies the value to compare with the property. * @return * A <code>String</code> which represents the formatted filter condition. */ public static String generateFilterCondition(String propertyName, String operation, final long value) { return generateFilterCondition(propertyName, operation, Long.toString(value), EdmType.INT64); }
/** * Generates a property filter condition string for a <code>UUID</code> value. Creates a formatted string to use * in a filter expression that uses the specified operation to compare the property with the value, formatted as * a UUID value, as in the following example: * <p> * <code>String condition = generateFilterCondition("Identity", QueryComparisons.EQUAL, UUID.fromString(</code> * <code>"c9da6455-213d-42c9-9a79-3e9149a57833"));</code> * <p> * This statement sets <code>condition</code> to the following value: * <p> * <code>Identity eq guid'c9da6455-213d-42c9-9a79-3e9149a57833'</code> * * @param propertyName * A <code>String</code> which specifies the name of the property to compare. * @param operation * A <code>String</code> which specifies the comparison operator to use. * @param value * A <code>UUID</code> which specifies the value to compare with the property. * @return * A <code>String</code> which represents the formatted filter condition. */ public static String generateFilterCondition(String propertyName, String operation, final UUID value) { return generateFilterCondition(propertyName, operation, value.toString(), EdmType.GUID); }
/** * Generates a property filter condition string for a <code>UUID</code> value. Creates a formatted string to use * in a filter expression that uses the specified operation to compare the property with the value, formatted as * a UUID value, as in the following example: * <p> * <code>String condition = generateFilterCondition("Identity", QueryComparisons.EQUAL, UUID.fromString(</code> * <code>"c9da6455-213d-42c9-9a79-3e9149a57833"));</code> * <p> * This statement sets <code>condition</code> to the following value: * <p> * <code>Identity eq guid'c9da6455-213d-42c9-9a79-3e9149a57833'</code> * * @param propertyName * A <code>String</code> which specifies the name of the property to compare. * @param operation * A <code>String</code> which specifies the comparison operator to use. * @param value * A <code>UUID</code> which specifies the value to compare with the property. * @return * A <code>String</code> which represents the formatted filter condition. */ public static String generateFilterCondition(String propertyName, String operation, final UUID value) { return generateFilterCondition(propertyName, operation, value.toString(), EdmType.GUID); }
/** * Generates a property filter condition string for an <code>int</code> value. Creates a formatted string to use * in a filter expression that uses the specified operation to compare the property with the value, formatted as * a numeric value, as in the following example: * <p> * <code>String condition = generateFilterCondition("Population", QueryComparisons.GREATER_THAN, 1000);</code> * <p> * This statement sets <code>condition</code> to the following value: * <p> * <code>Population gt 1000</code> * * @param propertyName * A <code>String</code> which specifies the name of the property to compare. * @param operation * A <code>String</code> which specifies the comparison operator to use. * @param value * An <code>int</code> which specifies the value to compare with the property. * @return * A <code>String</code> which represents the formatted filter condition. */ public static String generateFilterCondition(String propertyName, String operation, final int value) { return generateFilterCondition(propertyName, operation, Integer.toString(value), EdmType.INT32); }
private static String serviceIdEquals(ServiceId serviceId) { return TableQuery.generateFilterCondition( "ServiceName", TableQuery.QueryComparisons.EQUAL, serviceId.getId()); }
private static String partitionEquals(DependencyId dependencyId) { return TableQuery.generateFilterCondition( PARTITION_KEY, TableQuery.QueryComparisons.EQUAL, dependencyId.getId()); } }
private static String partitionKeyEquals(ServiceId serviceId) { return TableQuery .generateFilterCondition( PARTITION_KEY, TableQuery.QueryComparisons.EQUAL, serviceId.getId()); }
public Iterable<BlobDataTracker> getBlobDataTrackers(long msBack,String volid) { long tm = System.currentTimeMillis() - msBack; String partitionFilter = TableQuery.combineFilters(TableQuery.generateFilterCondition( PARTITION_KEY, QueryComparisons.EQUAL, volid), TableQuery.Operators.AND,TableQuery.generateFilterCondition( TIMESTAMP, QueryComparisons.LESS_THAN, new Date((long)(tm)))); TableQuery<BlobDataTracker> partitionQuery = TableQuery.from(BlobDataTracker.class) .where(partitionFilter); Iterable<BlobDataTracker> iter = cloudTable.execute(partitionQuery); return iter; }
/** * Retrieve all rows in a table with the given partition key. * @param partitionKey Job model version of the processors to be retrieved. * @return Iterable list of processor entities. */ public Iterable<ProcessorEntity> getEntitiesWithPartition(String partitionKey) { String partitionFilter = TableQuery.generateFilterCondition(PARTITION_KEY, TableQuery.QueryComparisons.EQUAL, partitionKey); TableQuery<ProcessorEntity> partitionQuery = TableQuery.from(ProcessorEntity.class).where(partitionFilter); return table.execute(partitionQuery); }
@Override public void clearCheckpoints() { LOG.debug("Clearing all checkpoints in Azure table"); for (TaskName taskName : taskNames) { String partitionQueryKey = taskName.toString(); // Generate table query String partitionFilter = TableQuery.generateFilterCondition( PARTITION_KEY, TableQuery.QueryComparisons.EQUAL, partitionQueryKey); TableQuery<TaskCheckpointEntity> partitionQuery = TableQuery.from(TaskCheckpointEntity.class) .where(partitionFilter); // All entities in a given batch must have the same partition key deleteEntities(cloudTable.execute(partitionQuery).iterator()); } }
public String generateCombinedFilterConditions() { String filter = ""; if (isValidFilterExpession()) { for (int idx = 0; idx < column.getValue().size(); idx++) { String c = column.getValue().get(idx); String cfn = function.getValue().get(idx); String cop = predicate.getValue().get(idx); String typ = fieldType.getValue().get(idx); String f = Comparison.getQueryComparisons(cfn); String v = operand.getValue().get(idx); String p = Predicate.getOperator(cop); EdmType t = SupportedFieldType.getEdmType(typ); String flt = TableQuery.generateFilterCondition(c, f, v, t); if (!filter.isEmpty()) { filter = TableQuery.combineFilters(filter, p, flt); } else { filter = flt; } } } return filter; }
public String generateCombinedFilterConditions() { String filter = ""; if (isValidFilterExpession()) { for (int idx = 0; idx < column.getValue().size(); idx++) { String c = column.getValue().get(idx); String cfn = function.getValue().get(idx); String cop = predicate.getValue().get(idx); String typ = fieldType.getValue().get(idx); String f = Comparison.getQueryComparisons(cfn); String v = operand.getValue().get(idx); String p = Predicate.getOperator(cop); EdmType t = SupportedFieldType.getEdmType(typ); String flt = TableQuery.generateFilterCondition(c, f, v, t); if (!filter.isEmpty()) { filter = TableQuery.combineFilters(filter, p, flt); } else { filter = flt; } } } return filter; }
@Override public void deleteVreAuthorizations(String vreId) throws AuthorizationUnavailableException { String condition = TableQuery.generateFilterCondition( "PartitionKey", TableQuery.QueryComparisons.EQUAL, vreId ); TableBatchOperation deletes = new TableBatchOperation(); for (DynamicTableEntity entity : table.execute(TableQuery.from(DynamicTableEntity.class).where(condition))) { deletes.delete(entity); } try { table.execute(deletes); } catch (StorageException e) { LOG.error("deleteVreAuthorizations failed", e); throw new AuthorizationUnavailableException("Could not delete authorizations"); } }
private void testTableQueryWithSpecialChars(char charToTest, CloudTable table) throws StorageException, URISyntaxException { String partitionKey = "partition" + charToTest + "key"; String rowKey = "row" + charToTest + "key"; EmptyClass ref = new EmptyClass(); ref.setPartitionKey(partitionKey); ref.setRowKey(rowKey); table.execute(TableOperation.insert(ref)); String condition = TableQuery.generateFilterCondition(TableConstants.PARTITION_KEY, QueryComparisons.EQUAL, partitionKey); ResultSegment<EmptyClass> seg = table.executeSegmented(TableQuery.from(EmptyClass.class).where(condition), null); assertEquals(1, seg.getLength()); assertEquals(partitionKey, seg.getResults().get(0).getPartitionKey()); }