Example usage for org.springframework.data.mongodb.core.index Index Index

List of usage examples for org.springframework.data.mongodb.core.index Index Index

Introduction

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

Prototype

public Index() 

Source Link

Usage

From source file:com.harpatec.examples.Main.java

/**
 * Load the Spring Integration Application Context
 * // w w w  . j a v  a  2s .com
 * @param args - command line arguments
 * @throws InterruptedException
 * @throws IOException
 * @throws JsonMappingException
 * @throws JsonGenerationException
 */
public static void main(final String... args)
        throws InterruptedException, JsonGenerationException, JsonMappingException, IOException {

    final AbstractApplicationContext context = new ClassPathXmlApplicationContext(
            "classpath:META-INF/spring/integration/*-context.xml");

    context.registerShutdownHook();

    LOGGER.debug("Dropping the collection of MessageRecords");
    MongoTemplate mongoTemplate = context.getBean(MongoTemplate.class);
    mongoTemplate.dropCollection(MessageRecord.class);
    mongoTemplate.indexOps(MessageRecord.class).ensureIndex(new Index().on("key", Order.ASCENDING).unique());
    mongoTemplate.indexOps(MessageRecord.class).ensureIndex(new Index().on("completionTime", Order.ASCENDING));

    RabbitTemplate inboundTemplate = (RabbitTemplate) context.getBean("amqpTemplateInbound");
    Map<String, Object> messageMap = new HashMap<String, Object>();
    messageMap.put("count", "4");

    LOGGER.debug("Submitting first message which should pass DuplicateMessageFilter ok.");
    submitMessage(inboundTemplate, messageMap);

    Thread.sleep(5 * 1000);
    LOGGER.debug("Submitting a duplicate message which should get caught by the DuplicateMessageFilter.");
    submitMessage(inboundTemplate, messageMap);

    Thread.sleep(5 * 1000);
    messageMap.put("count", "0");
    LOGGER.debug("Submitting a message which will not go all the way through the message flow.");
    submitMessage(inboundTemplate, messageMap);

    Thread.sleep(5 * 1000);
    messageMap.put("count", "1");
    messageMap.put("fail", "true");
    LOGGER.debug("Submitting a message which should signal that an Exception should be thrown.");
    submitMessage(inboundTemplate, messageMap);

    Thread.sleep(6 * 60 * 1000);

    System.exit(0);

}

From source file:org.tylproject.data.mongo.MongoModelConfig.java

public static void createIndexes(MongoOperations mongoOps) {
    mongoOps.indexOps(Party.class).ensureIndex(new Index().on("code", Sort.Direction.ASC));
    mongoOps.indexOps(Party.class)
            .ensureIndex(new Index().on("partyIdentifier.identifier", Sort.Direction.ASC));
}

From source file:org.swarmcom.jsynapse.service.accesstoken.AccessTokenServiceImpl.java

@PostConstruct
    public void init() {
        this.mongoTemplate.indexOps(AccessToken.class)
                .ensureIndex(new Index().on("lastUsed", Sort.Direction.ASC).expire(expire, TimeUnit.SECONDS));
    }//from www . j  a  v  a2 s .c o  m

From source file:com.seajas.search.profiler.service.repository.RepositoryService.java

/**
 * Default constructor.//from  w w  w.j  a  v a  2 s .  com
 *
 * @param dbFactory
 */
@Autowired
public RepositoryService(final MongoDbFactory dbFactory, final MongoTemplate mongoTemplate) {
    this.gridFs = new GridFS(dbFactory.getDb());

    // Initialize the indexes only if there aren't too many documents in the store yet

    Long currentCount = mongoTemplate.count(new Query(), CompositeEntry.class);

    // Determine whether the given indexes have been created, and initialize them if necessary

    if (currentCount <= MAX_INDEX_CREATION_COUNT)
        for (String index : INDEXES)
            mongoTemplate.indexOps(CompositeEntry.class).ensureIndex(new Index().on(index, Order.ASCENDING));

    this.mongoTemplate = mongoTemplate;
}

From source file:se.inera.axel.shs.broker.messagestore.internal.AbstractMongoMessageLogTest.java

@BeforeMethod
public void setupTestDB() throws IOException {
    mongoDbFactory.getDb().dropDatabase();

    Maker<se.inera.axel.shs.mime.ShsMessage> asynchMessage = a(ShsMessage,
            with(ShsMessage.label, a(ShsLabel, with(transferType, TransferType.ASYNCH))));

    messageLogService.saveMessage(make(asynchMessage));

    messageLogService.saveMessage(make(asynchMessage));

    messageLogService.messageSent(messageLogService.saveMessage(make(asynchMessage)));

    messageLogService.messageReceived(messageLogService.saveMessage(
            make(a(ShsMessage, with(ShsMessage.label, a(ShsLabel, with(transferType, TransferType.SYNCH)))))));

    messageLogService.messageReceived(messageLogService.saveMessage(make(asynchMessage)));

    messageLogService.messageReceived(messageLogService.saveMessage(make(a(ShsMessage,
            with(ShsMessage.label, a(ShsLabel, with(to, a(To, with(To.value, ShsLabelMaker.DEFAULT_TEST_FROM))),
                    with(transferType, TransferType.ASYNCH)))))));

    messageLogService.messageReceived(messageLogService.saveMessage(make(a(ShsMessage,
            with(ShsMessage.label, a(ShsLabel, with(product, a(Product, with(Product.value, "error"))),
                    with(sequenceType, SequenceType.ADM), with(transferType, TransferType.ASYNCH)))))));

    messageLogService.messageReceived(messageLogService.saveMessage(make(a(ShsMessage,
            with(ShsMessage.label, a(ShsLabel, with(product, a(Product, with(Product.value, "confirm"))),
                    with(sequenceType, SequenceType.ADM), with(transferType, TransferType.ASYNCH)))))));

    messageLogService.messageReceived(messageLogService.saveMessage(make(a(ShsMessage, with(ShsMessage.label,
            a(ShsLabel, with(transferType, TransferType.ASYNCH), with(status, Status.TEST)))))));

    messageLogService.messageAcknowledged(
            messageLogService.messageReceived(messageLogService.saveMessage(make(asynchMessage))));

    messageLogService.messageReceived(messageLogService.saveMessage(make(a(ShsMessage,
            with(ShsMessage.label, a(ShsLabel, with(to, a(To, with(To.value, ShsLabelMaker.DEFAULT_TEST_FROM))),
                    with(endRecipient,// w  w  w . j ava  2 s  . com
                            a(EndRecipient, with(EndRecipient.value, ShsLabelMaker.DEFAULT_TEST_ENDRECIPIENT))),
                    with(transferType, TransferType.ASYNCH)))))));

    messageLogService.messageReceived(messageLogService.saveMessage(make(a(ShsMessage,
            with(ShsMessage.label, a(ShsLabel, with(to, a(To, with(To.value, ShsLabelMaker.DEFAULT_TEST_FROM))),
                    with(corrId, "testing-corrid"), with(transferType, TransferType.ASYNCH)))))));

    messageLogService.messageReceived(messageLogService.saveMessage(make(a(ShsMessage,
            with(ShsMessage.label,
                    a(ShsLabel, with(to, a(To, with(To.value, ShsLabelMaker.DEFAULT_TEST_FROM))),
                            with(transferType, TransferType.ASYNCH),
                            with(content, a(Content, with(Content.contentId, "testing-contentid")))))))));

    messageLogService.messageReceived(messageLogService.saveMessage(make(a(ShsMessage,
            with(ShsMessage.label, a(ShsLabel, with(to, a(To, with(To.value, ShsLabelMaker.DEFAULT_TEST_FROM))),
                    with(transferType, TransferType.ASYNCH),
                    with(meta, listOf(a(Meta, with(Meta.name, "namn"), with(Meta.value, "varde"))))))))));

    messageLogService.messageReceived(messageLogService.saveMessage(make(a(ShsMessage,
            with(ShsMessage.label, a(ShsLabel, with(originatorOrFrom,
                    listOf(a(Originator, with(Originator.value, ShsLabelMaker.DEFAULT_TEST_ORIGINATOR)))),
                    with(to, a(To, with(To.value, ShsLabelMaker.DEFAULT_TEST_FROM))),
                    with(transferType, TransferType.ASYNCH)))))));

    ShsMessageEntry entry = messageLogService.messageReceived(messageLogService.saveMessage(make(a(ShsMessage,
            with(ShsMessage.label, a(ShsLabel, with(to, a(To, with(To.value, ShsLabelMaker.DEFAULT_TEST_FROM))),
                    with(subject, "lastWeeksMessage"), with(transferType, TransferType.ASYNCH)))))));

    //config for message "entry"

    GregorianCalendar lastWeek = new GregorianCalendar();
    lastWeek.add(GregorianCalendar.DAY_OF_MONTH, -7);

    entry.setStateTimeStamp(lastWeek.getTime());
    messageLogService.update(entry);

    entry = messageLogService.saveMessage(make(asynchMessage));

    messageLogService.update(entry);

    mongoOperations.indexOps(ShsMessageEntry.class)
            .ensureIndex(new Index().on("label.txId", Sort.Direction.ASC).unique());
}

From source file:org.springframework.data.mongodb.repository.support.IndexEnsuringQueryCreationListener.java

public void onCreation(PartTreeMongoQuery query) {

    PartTree tree = query.getTree();//from  w ww .j  av  a  2 s  .c om
    Index index = new Index();
    index.named(query.getQueryMethod().getName());
    Sort sort = tree.getSort();

    for (Part part : tree.getParts()) {
        if (GEOSPATIAL_TYPES.contains(part.getType())) {
            return;
        }
        String property = part.getProperty().toDotPath();
        Order order = toOrder(sort, property);
        index.on(property, order);
    }

    // Add fixed sorting criteria to index
    if (sort != null) {
        for (Sort.Order order : sort) {
            index.on(order.getProperty(), QueryUtils.toOrder(order));
        }
    }

    MongoEntityInformation<?, ?> metadata = query.getQueryMethod().getEntityInformation();
    operations.indexOps(metadata.getCollectionName()).ensureIndex(index);
    LOG.debug(String.format("Created %s!", index));
}