/** * Gets the self-link for collections in the database * * @return the collections link. */ public String getCollectionsLink() { return String.format("%s/%s", StringUtils.stripEnd(super.getSelfLink(), "/"), super.getString(Constants.Properties.COLLECTIONS_LINK)); }
/** * Gets the enableMulipleWritableLocations flag of the databaseAccount. * * @return the enableMulipleWritableLocations flag value. */ public boolean getEnableMultipleWritableLocations() { try { return super.getBoolean(Constants.Properties.ENABLE_MULTIPLE_WRITE_LOCATIONS); } catch (Exception e) {} return false; }
/** * Gets the collection's partition key statistics for each physical partition in the collection. * * @return the partition key statistics for each physical partition in the collection. */ public Collection<PartitionKeyRangeStatistics> getCollectionPartitionStatistics() { if (super.has(Constants.Properties.PARTITION_KEY_RANGE_STATISTICS)) { return super.getCollection(Constants.Properties.PARTITION_KEY_RANGE_STATISTICS, PartitionKeyRangeStatistics.class); } return null; }
null); } else { LOGGER.error("invalid Document to update {}", resource.getSelfLink()); throw new RuntimeException("invalid Document to update " + resource.getSelfLink());
/** * Gets the indexing policy. * * @return the indexing policy. */ public IndexingPolicy getIndexingPolicy() { if (this.indexingPolicy == null) { if (super.has(Constants.Properties.INDEXING_POLICY)) { this.indexingPolicy = super.getObject(Constants.Properties.INDEXING_POLICY, IndexingPolicy.class); } else { this.indexingPolicy = new IndexingPolicy(); } } return this.indexingPolicy; }
/** * Gets the content object that contains the details of the offer. * * @return the offer content. */ public JSONObject getContent() { return super.getObject(Constants.Properties.OFFER_CONTENT); }
/** * Gets the list of writable locations for this database account. * * @return the list of writable locations. */ public Iterable<DatabaseAccountLocation> getWritableLocations() { return super.getCollection(Constants.Properties.WRITABLE_LOCATIONS, DatabaseAccountLocation.class); }
static void validateResource(Resource resource) { if (!StringUtils.isEmpty(resource.getId())) { if (resource.getId().indexOf('/') != -1 || resource.getId().indexOf('\\') != -1 || resource.getId().indexOf('?') != -1 || resource.getId().indexOf('#') != -1) { throw new IllegalArgumentException("Id contains illegal chars."); } if (resource.getId().endsWith(" ")) { throw new IllegalArgumentException("Id ends with a space."); } } }
/** * Gets the resource partition key associated with this permission object. * * @return the partition key. */ public PartitionKey getResourcePartitionKey() { PartitionKey key = null; Object value = super.get(Constants.Properties.RESOURCE_PARTITION_KEY); if (value != null) { JSONArray arrayValue = (JSONArray) value; key = new PartitionKey(arrayValue.get(0)); } return key; }
private Database createDatabaseIfNotExists(String dbName) { try { final List<Database> dbList = documentDbFactory.getDocumentClient() .queryDatabases(new SqlQuerySpec("SELECT * FROM root r WHERE r.id=@id", new SqlParameterCollection(new SqlParameter("@id", dbName))), null) .getQueryIterable().toList(); if (!dbList.isEmpty()) { return dbList.get(0); } else { // create new database final Database db = new Database(); db.setId(dbName); if (LOGGER.isDebugEnabled()) { LOGGER.debug("execute createDatabase {}", dbName); } final Resource resource = documentDbFactory.getDocumentClient() .createDatabase(db, null).getResource(); if (resource instanceof Database) { return (Database) resource; } else { LOGGER.error("create database {} get unexpected result: {}" + resource.getSelfLink()); throw new RuntimeException("create database {} get unexpected result: " + resource.getSelfLink()); } } } catch (DocumentClientException ex) { throw new RuntimeException("createOrGetDatabase exception", ex); } }
/** * Gets the collection's partition key definition. * * @return the partition key definition. */ public PartitionKeyDefinition getPartitionKey() { if (super.has(Constants.Properties.PARTITION_KEY)) { return super.getObject(Constants.Properties.PARTITION_KEY, PartitionKeyDefinition.class); } this.setPartitionKey(new PartitionKeyDefinition()); return this.getPartitionKey(); }
/** * Gets the conflictResolutionPolicy that is used for resolving conflicting writes * on documents in different regions, in a collection in the Azure Cosmos DB service. * * @return ConflictResolutionPolicy */ public ConflictResolutionPolicy getConflictResolutionPolicy() { return super.getObject(Constants.Properties.CONFLICT_RESOLUTION_POLICY, ConflictResolutionPolicy.class); }
/** * Gets the list of readable locations for this database account. * * @return the list of readable locations. */ public Iterable<DatabaseAccountLocation> getReadableLocations() { return super.getCollection(Constants.Properties.READABLE_LOCATIONS, DatabaseAccountLocation.class); }
/** * Gets the self-link for users in the database. * * @return the users link. */ public String getUsersLink() { return String.format("%s/%s", StringUtils.stripEnd(super.getSelfLink(), "/"), super.getString(Constants.Properties.USERS_LINK)); } }
private Database createDatabaseIfNotExists(String dbName) { try { final List<Database> dbList = documentDbFactory.getDocumentClient() .queryDatabases(new SqlQuerySpec("SELECT * FROM root r WHERE r.id=@id", new SqlParameterCollection(new SqlParameter("@id", dbName))), null) .getQueryIterable().toList(); if (!dbList.isEmpty()) { return dbList.get(0); } else { // create new database final Database db = new Database(); db.setId(dbName); if (LOGGER.isDebugEnabled()) { LOGGER.debug("execute createDatabase {}", dbName); } final Resource resource = documentDbFactory.getDocumentClient() .createDatabase(db, null).getResource(); if (resource instanceof Database) { return (Database) resource; } else { final String errorMessage = MessageFormat.format( "create database {0} and get unexpected result: {1}", dbName, resource.getSelfLink()); LOGGER.error(errorMessage); throw new DatabaseCreationException(errorMessage); } } } catch (DocumentClientException ex) { throw new DocumentDBAccessException("createOrGetDatabase exception", ex); } }
/** * Sets the Uni that guarantees uniqueness of documents in collection in the Azure Cosmos DB service. * @return UniqueKeyPolicy */ public UniqueKeyPolicy getUniqueKeyPolicy() { // Thread safe lazy initialization for case when collection is cached (and is basically readonly). if (this.uniqueKeyPolicy == null) { this.uniqueKeyPolicy = super.getObject(Constants.Properties.UNIQUE_KEY_POLICY, UniqueKeyPolicy.class); if (this.uniqueKeyPolicy == null) { this.uniqueKeyPolicy = new UniqueKeyPolicy(); } } return this.uniqueKeyPolicy; }
/** * Gets the self-link for documents in a collection. * * @return the document link. */ public String getDocumentsLink() { return String.format("%s/%s", StringUtils.stripEnd(super.getSelfLink(), "/"), super.getString(Constants.Properties.DOCUMENTS_LINK)); }
private Database createDatabaseIfNotExists(String dbName) { try { final List<Database> dbList = getDocumentClient() .queryDatabases(new SqlQuerySpec("SELECT * FROM root r WHERE r.id=@id", new SqlParameterCollection(new SqlParameter("@id", dbName))), null) .getQueryIterable().toList(); if (!dbList.isEmpty()) { return dbList.get(0); } else { // create new database final Database db = new Database(); db.setId(dbName); log.debug("execute createDatabase {}", dbName); final Resource resource = getDocumentClient().createDatabase(db, null).getResource(); if (resource instanceof Database) { return (Database) resource; } else { final String errorMessage = MessageFormat.format( "create database {0} and get unexpected result: {1}", dbName, resource.getSelfLink()); log.error(errorMessage); throw new DatabaseCreationException(errorMessage); } } } catch (DocumentClientException ex) { throw new DocumentDBAccessException("createOrGetDatabase exception", ex); } }