Example usage for org.springframework.data.mongodb.core MongoTemplate getDb

List of usage examples for org.springframework.data.mongodb.core MongoTemplate getDb

Introduction

In this page you can find the example usage for org.springframework.data.mongodb.core MongoTemplate getDb.

Prototype

public MongoDatabase getDb() 

Source Link

Usage

From source file:com.sangupta.jerry.mongodb.MongoDBUtils.java

/**
 * Returns the MongoDB statistics for the database in use by this {@link MongoTemplate}.
 * //from ww w  . j av  a  2 s  . c o  m
 * @param template
 * 
 * @return
 * 
 * @throws NullPointerException if template instance provided is <code>null</code>.
 */
public static MongoDBStats getDatabaseStatistics(MongoTemplate template) {
    return getDatabaseStatistics(template.getDb());
}

From source file:com.epam.ta.reportportal.migration.ChangeSets_3_0.java

@ChangeSet(order = "3.0.0-1", id = "v3.0.0-Set STEP_BASED as default for all projects", author = "avarabyeu")
public void useStepBasedCalcStrategy(MongoTemplate mongoTemplate) throws IOException {
    mongoTemplate.getDb().doEval(asCharSource(getResource("migration/v3_0_0.js"), Charsets.UTF_8).read());
}

From source file:com.epam.ta.reportportal.migration.ChangeSets_3_0.java

@ChangeSet(order = "3.0.0-2", id = "v3.0.0-use classes with new names in server settings", author = "pbortnik")
public void useUpdatedClassesForSettings(MongoTemplate mongoTemplate) throws IOException {
    mongoTemplate.getDb().doEval(asCharSource(getResource("migration/v3_0_0_2.js"), Charsets.UTF_8).read());
}

From source file:com.epam.ta.reportportal.migration.ChangeSets_3_0.java

@ChangeSet(order = "3.0.0-3", id = "v3.0.0-Drop Favorites Resources collection", author = "avarabyeu")
public void dropFavoritesCollection(MongoTemplate mongoTemplate) throws IOException {
    mongoTemplate.getDb().doEval(asCharSource(getResource("migration/v3_0_0_3.js"), Charsets.UTF_8).read());
}

From source file:com.epam.ta.reportportal.migration.ChangeSets_2_7.java

@ChangeSet(order = "2.7-1", id = "v2.7-1-Description", author = "dkavalets")
public void initLoad(MongoTemplate mongoTemplate) {
    mongoTemplate.getDb().doEval("db.user.find({}).forEach(function(user){\n"
            + "        var userId = user._id\n" + "        var user = {\n" + "            userId : {\n"
            + "                    \"proposedRole\" : \"PROJECT_MANAGER\",\n"
            + "                    \"projectRole\" : \"PROJECT_MANAGER\"\n" + "                }\n"
            + "            }  \n" + "        var project = {\n"
            + "             \"_id\" : userId + \"_personal\",\n"
            + "             \"_class\" : \"com.epam.ta.reportportal.database.entity.Project\",\n"
            + "             \"addInfo\" : \"Personal project of \" + userId,\n"
            + "             \"configuration\" : {\n"
            + "                \"statisticsCalculationStrategy\" : \"TEST_BASED\",\n"
            + "                \"externalSystem\" : [],\n" + "                \"entryType\" : \"PERSONAL\",\n"
            + "                \"projectSpecific\" : \"DEFAULT\",\n"
            + "                \"interruptJobTime\" : \"1 day\",\n"
            + "                \"keepLogs\" : \"3 months\",\n"
            + "                \"keepScreenshots\" : \"1 month\",\n"
            + "                \"isAutoAnalyzerEnabled\" : false,\n" + "                \"subTypes\" : {\n"
            + "                    \"PRODUCT_BUG\" : [\n" + "                        {\n"
            + "                            \"locator\" : \"PB001\",\n"
            + "                            \"typeRef\" : \"PRODUCT_BUG\",\n"
            + "                            \"longName\" : \"Product Bug\",\n"
            + "                            \"shortName\" : \"PB\",\n"
            + "                            \"hexColor\" : \"#ec3900\"\n" + "                        }\n"
            + "                    ],\n" + "                    \"AUTOMATION_BUG\" : [\n"
            + "                        {\n" + "                            \"locator\" : \"AB001\",\n"
            + "                            \"typeRef\" : \"AUTOMATION_BUG\",\n"
            + "                            \"longName\" : \"Automation Bug\",\n"
            + "                            \"shortName\" : \"AB\",\n"
            + "                            \"hexColor\" : \"#f7d63e\"\n" + "                        }\n"
            + "                        ],\n" + "                    \"TO_INVESTIGATE\" : [\n"
            + "                        {\n" + "                            \"locator\" : \"TI001\",\n"
            + "                            \"typeRef\" : \"TO_INVESTIGATE\",\n"
            + "                            \"longName\" : \"To Investigate\",\n"
            + "                            \"shortName\" : \"TI\",\n"
            + "                            \"hexColor\" : \"#ffb743\"\n" + "                        }\n"
            + "                    ],\n" + "                    \"NO_DEFECT\" : [\n"
            + "                        {\n" + "                            \"locator\" : \"ND001\",\n"
            + "                            \"typeRef\" : \"NO_DEFECT\",\n"
            + "                            \"longName\" : \"No Defect\",\n"
            + "                            \"shortName\" : \"ND\",\n"
            + "                            \"hexColor\" : \"#777777\"\n" + "                        }\n"
            + "                    ],\n" + "                    \"SYSTEM_ISSUE\" : [\n"
            + "                        {\n" + "                            \"locator\" : \"SI001\",\n"
            + "                            \"typeRef\" : \"SYSTEM_ISSUE\",\n"
            + "                            \"longName\" : \"System Issue\",\n"
            + "                            \"shortName\" : \"SI\",\n"
            + "                            \"hexColor\" : \"#0274d1\"\n" + "                        }\n"
            + "                    ]\n" + "                },\n" + "                \"emailConfig\" : {\n"
            + "                    \"emailEnabled\" : false,\n"
            + "                    \"from\" : \"reportportal@example.com\",\n"
            + "                    \"emailCases\" : [\n" + "                        {\n"
            + "                            \"recipients\" : [\n" + "                                \"OWNER\"\n"
            + "                            ],\n" + "                            \"sendCase\" : \"ALWAYS\",\n"
            + "                            \"launchNames\" : [],\n"
            + "                            \"tags\" : []\n" + "                        }\n"
            + "                    ]\n" + "                }\n" + "             },\n"
            + "             \"users\" : {\n" + "            },\n"
            + "             \"creationDate\" : new ISODate()\n" + "            }\n"
            + "        project.users[userId] = {\n"
            + "                    \"proposedRole\" : \"PROJECT_MANAGER\",\n"
            + "                    \"projectRole\" : \"PROJECT_MANAGER\"\n" + "                }\n"
            + "        if (!db.project.findOne({\"_id\":project._id})){\n"
            + "             db.project.save(project)\n" + "        }\n" + "})");
    mongoTemplate.getDb()//  w  w  w.jav  a  2  s.  co m
            .doEval("db.projectSettings.find({}).forEach(\n" + "    function(doc) {\n"
                    + "            var project = db.project.findOne({'_id':doc._id})\n"
                    + "            if (project != null) {"
                    + "                project.configuration.subTypes = doc.subTypes\n"
                    + "                db.project.save(project)\n" + "            }\n" + "    }\n" + ")");
    mongoTemplate.getDb().doEval("db.projectSettings.drop()");
    mongoTemplate.getDb()
            .doEval("db.user.find({}).forEach(\n" + "    function(doc) {\n"
                    + "        doc.defaultProject = doc._id + '_personal'\n" + "        db.user.save(doc)   \n"
                    + "    }\n" + ")");
    mongoTemplate.getDb().doEval("db.userPreference.remove({})");
}

From source file:com.appleframework.monitor.service.ProjectService.java

public void create(Project project) throws IllegalArgumentException {
    Assert.isNull(findProject(project.getName()), "project  [" + project.getName() + "] has exist");
    MongoTemplate template = project.fetchMongoTemplate();
    Assert.notNull(template, "mongo uri is not access");
    Assert.notNull(template.getDb(), "mongo uri is not access");

    saveProject(project);//ww  w  .  j av a  2s.co m
}

From source file:org.slc.sli.dal.aspect.MongoTrackingAspect.java

@Around("call(* org.springframework.data.mongodb.core.MongoTemplate.*(..)) && !this(MongoTrackingAspect) && !within(org..*Test) && !within(org..*MongoPerfRepository)")
public Object track(ProceedingJoinPoint pjp) throws Throwable {

    long start = System.currentTimeMillis();
    Object result = pjp.proceed();
    long end = System.currentTimeMillis();

    if (isEnabled()) {
        MongoTemplate mt = (MongoTemplate) pjp.getTarget();
        String collection = determineCollectionName(pjp);
        proceedAndTrack(pjp, mt.getDb().getName(), pjp.getSignature().getName(), collection, start, end);
    }/* ww  w.java 2s  . c  o m*/
    if (Boolean.valueOf(dbCallTracking)) {
        dbCallTracker.incrementHitCount();
        // dbCallTracker.addMetric("t", pjp.getSignature().toShortString(), end-start);
    }

    return result;
}