List of usage examples for org.springframework.data.mongodb.core User getClass
@HotSpotIntrinsicCandidate public final native Class<?> getClass();
From source file:de.steilerdev.myVerein.server.controller.init.InitController.java
License:asdf
/** * This function is establishing a connection to the new database and storing the new super user as well as the new root division. To correctly execute this function the {@link #mongoIsAvailable} function should be called first. * @param user The new super admin.// w w w . ja v a 2s . c om * @param division The new root division. * @return True if the operation was successfully, false otherwise. */ private boolean savingInitialSetup(User user, Division division, Settings settings) { if (mongoAddress != null && databaseName != null && !databaseName.isEmpty()) { logger.trace("Saving user and division using new MongoDB connection"); MongoClient mongoClient = new MongoClient(mongoAddress, mongoCredential); DB mongoDB = mongoClient.getDB(databaseName); if (mongoClient.getDatabaseNames().contains(databaseName)) { logger.warn("The database already contains the defined collection, dropping content."); mongoDB.dropDatabase(); } try { if (user != null) { logger.debug("Storing user"); DBObject userObject = (DBObject) mappingMongoConverter.convertToMongoType(user); userObject.put("_class", user.getClass().getCanonicalName()); mongoDB.getCollection(user.getClass().getSimpleName().toLowerCase()).insert(userObject); } if (division != null) { logger.debug("Storing division"); DBObject divisionObject = (DBObject) mappingMongoConverter.convertToMongoType(division); divisionObject.put("_class", division.getClass().getCanonicalName()); mongoDB.getCollection(division.getClass().getSimpleName().toLowerCase()).insert(divisionObject); } if (settings != null) { logger.debug("Storing settings"); settings.saveSettings(user, null); DBObject settingsObject = (DBObject) mappingMongoConverter.convertToMongoType(settings); settingsObject.put("_class", settings.getClass().getCanonicalName()); mongoDB.getCollection(settings.getClass().getSimpleName().toLowerCase()).insert(settingsObject); } logger.info("Successfully saved root division and super admin"); return true; } catch (MongoException e) { logger.warn("Unable to store root division and super admin in database"); return false; } finally { mongoClient.close(); } } else { logger.warn( "Unable to save super admin and new root division, because the new MongoDB connection is not available"); return false; } }