/** * 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 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)); } }
/** * 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)); }
/** * Gets the self-link for stored procedures in a collection. * * @return the stored procedures link. */ public String getStoredProceduresLink() { return String.format("%s/%s", StringUtils.stripEnd(super.getSelfLink(), "/"), super.getString(Constants.Properties.STORED_PROCEDURES_LINK)); }
null); } else { LOGGER.error("invalid Document to update {}", resource.getSelfLink()); throw new RuntimeException("invalid Document to update " + resource.getSelfLink());
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); } }
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); } }
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); } }