当前位置: 首页>>代码示例>>Java>>正文


Java Greeting类代码示例

本文整理汇总了Java中org.example.ws.model.Greeting的典型用法代码示例。如果您正苦于以下问题:Java Greeting类的具体用法?Java Greeting怎么用?Java Greeting使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Greeting类属于org.example.ws.model包,在下文中一共展示了Greeting类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getGreeting

import org.example.ws.model.Greeting; //导入依赖的package包/类
/**
 * Web service endpoint to fetch a single Greeting entity by primary key
 * identifier.
 * 
 * If found, the Greeting is returned as JSON with HTTP status 200.
 * 
 * If not found, the service returns an empty response body with HTTP status
 * 404.
 * 
 * @param id A Long URL path variable containing the Greeting primary key
 *        identifier.
 * @return A ResponseEntity containing a single Greeting object, if found,
 *         and a HTTP status code as described in the method comment.
 */
@RequestMapping(
        value = "/api/greetings/{id}",
        method = RequestMethod.GET,
        produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<Greeting> getGreeting(@PathVariable("id") Long id) {
    logger.info("> getGreeting id:{}", id);

    Greeting greeting = greetingService.findOne(id);
    if (greeting == null) {
        return new ResponseEntity<Greeting>(HttpStatus.NOT_FOUND);
    }

    logger.info("< getGreeting id:{}", id);
    return new ResponseEntity<Greeting>(greeting, HttpStatus.OK);
}
 
开发者ID:leanstacks,项目名称:spring-data-fundamentals,代码行数:30,代码来源:GreetingController.java

示例2: send

import org.example.ws.model.Greeting; //导入依赖的package包/类
@Override
public Boolean send(Greeting greeting) {
    logger.info("> send");

    Boolean success = Boolean.FALSE;

    // Simulate method execution time
    long pause = 5000;
    try {
        Thread.sleep(pause);
    } catch (Exception e) {
        // do nothing
    }
    logger.info("Processing time was {} seconds.", pause / 1000);

    success = Boolean.TRUE;

    logger.info("< send");
    return success;
}
 
开发者ID:leanstacks,项目名称:spring-data-fundamentals,代码行数:21,代码来源:EmailServiceBean.java

示例3: sendAsyncWithResult

import org.example.ws.model.Greeting; //导入依赖的package包/类
@Async
@Override
public Future<Boolean> sendAsyncWithResult(Greeting greeting) {
    logger.info("> sendAsyncWithResult");

    AsyncResponse<Boolean> response = new AsyncResponse<Boolean>();

    try {
        Boolean success = send(greeting);
        response.complete(success);
    } catch (Exception e) {
        logger.warn("Exception caught sending asynchronous mail.", e);
        response.completeExceptionally(e);
    }

    logger.info("< sendAsyncWithResult");
    return response;
}
 
开发者ID:leanstacks,项目名称:spring-data-fundamentals,代码行数:19,代码来源:EmailServiceBean.java

示例4: testCreateWithId

import org.example.ws.model.Greeting; //导入依赖的package包/类
@Test
public void testCreateWithId() {

    Exception exception = null;

    Greeting entity = new Greeting();
    entity.setId(Long.MAX_VALUE);
    entity.setText("test");

    try {
        service.create(entity);
    } catch (EntityExistsException e) {
        exception = e;
    }

    Assert.assertNotNull("failure - expected exception", exception);
    Assert.assertTrue("failure - expected EntityExistsException",
            exception instanceof EntityExistsException);

}
 
开发者ID:leanstacks,项目名称:spring-data-fundamentals,代码行数:21,代码来源:GreetingServiceTest.java

示例5: testUpdate

import org.example.ws.model.Greeting; //导入依赖的package包/类
@Test
public void testUpdate() {

    Long id = new Long(1);

    Greeting entity = service.findOne(id);

    Assert.assertNotNull("failure - expected not null", entity);

    String updatedText = entity.getText() + " test";
    entity.setText(updatedText);
    Greeting updatedEntity = service.update(entity);

    Assert.assertNotNull("failure - expected not null", updatedEntity);
    Assert.assertEquals("failure - expected id attribute match", id,
            updatedEntity.getId());
    Assert.assertEquals("failure - expected text attribute match",
            updatedText, updatedEntity.getText());

}
 
开发者ID:leanstacks,项目名称:spring-data-fundamentals,代码行数:21,代码来源:GreetingServiceTest.java

示例6: testUpdateNotFound

import org.example.ws.model.Greeting; //导入依赖的package包/类
@Test
public void testUpdateNotFound() {

    Exception exception = null;

    Greeting entity = new Greeting();
    entity.setId(Long.MAX_VALUE);
    entity.setText("test");

    try {
        service.update(entity);
    } catch (NoResultException e) {
        exception = e;
    }

    Assert.assertNotNull("failure - expected exception", exception);
    Assert.assertTrue("failure - expected NoResultException",
            exception instanceof NoResultException);

}
 
开发者ID:leanstacks,项目名称:spring-data-fundamentals,代码行数:21,代码来源:GreetingServiceTest.java

示例7: getGreetings

import org.example.ws.model.Greeting; //导入依赖的package包/类
/**
 * Web service endpoint to fetch all Greeting entities. The service returns
 * the collection of Greeting entities as JSON.
 * 
 * @return A ResponseEntity containing a Collection of Greeting objects.
 */
@RequestMapping(
        value = "/api/greetings",
        method = RequestMethod.GET,
        produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<Collection<Greeting>> getGreetings() {
    logger.info("> getGreetings");

    Collection<Greeting> greetings = greetingService.findAll();

    logger.info("< getGreetings");
    return new ResponseEntity<Collection<Greeting>>(greetings,
            HttpStatus.OK);
}
 
开发者ID:leanstacks,项目名称:spring-data-fundamentals,代码行数:20,代码来源:GreetingController.java

示例8: sendGreeting

import org.example.ws.model.Greeting; //导入依赖的package包/类
/**
 * Web service endpoint to fetch a single Greeting entity by primary key
 * identifier and send it as an email.
 * 
 * If found, the Greeting is returned as JSON with HTTP status 200 and sent
 * via Email.
 * 
 * If not found, the service returns an empty response body with HTTP status
 * 404.
 * 
 * @param id A Long URL path variable containing the Greeting primary key
 *        identifier.
 * @param waitForAsyncResult A boolean indicating if the web service should
 *        wait for the asynchronous email transmission.
 * @return A ResponseEntity containing a single Greeting object, if found,
 *         and a HTTP status code as described in the method comment.
 */
@RequestMapping(
        value = "/api/greetings/{id}/send",
        method = RequestMethod.POST,
        produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<Greeting> sendGreeting(@PathVariable("id") Long id,
        @RequestParam(
                value = "wait",
                defaultValue = "false") boolean waitForAsyncResult) {

    logger.info("> sendGreeting id:{}", id);

    Greeting greeting = null;

    try {
        greeting = greetingService.findOne(id);
        if (greeting == null) {
            logger.info("< sendGreeting id:{}", id);
            return new ResponseEntity<Greeting>(HttpStatus.NOT_FOUND);
        }

        if (waitForAsyncResult) {
            Future<Boolean> asyncResponse = emailService
                    .sendAsyncWithResult(greeting);
            boolean emailSent = asyncResponse.get();
            logger.info("- greeting email sent? {}", emailSent);
        } else {
            emailService.sendAsync(greeting);
        }
    } catch (Exception e) {
        logger.error("A problem occurred sending the Greeting.", e);
        return new ResponseEntity<Greeting>(
                HttpStatus.INTERNAL_SERVER_ERROR);
    }

    logger.info("< sendGreeting id:{}", id);
    return new ResponseEntity<Greeting>(greeting, HttpStatus.OK);
}
 
开发者ID:leanstacks,项目名称:spring-data-fundamentals,代码行数:55,代码来源:GreetingController.java

示例9: sendAsync

import org.example.ws.model.Greeting; //导入依赖的package包/类
@Async
@Override
public void sendAsync(Greeting greeting) {
    logger.info("> sendAsync");

    try {
        send(greeting);
    } catch (Exception e) {
        logger.warn("Exception caught sending asynchronous mail.", e);
    }

    logger.info("< sendAsync");
}
 
开发者ID:leanstacks,项目名称:spring-data-fundamentals,代码行数:14,代码来源:EmailServiceBean.java

示例10: findAll

import org.example.ws.model.Greeting; //导入依赖的package包/类
@Override
public Collection<Greeting> findAll() {
    logger.info("> findAll");

    counterService.increment("method.invoked.greetingServiceBean.findAll");

    Collection<Greeting> greetings = greetingRepository.findAll();

    logger.info("< findAll");
    return greetings;
}
 
开发者ID:leanstacks,项目名称:spring-data-fundamentals,代码行数:12,代码来源:GreetingServiceBean.java

示例11: findOne

import org.example.ws.model.Greeting; //导入依赖的package包/类
@Override
@Cacheable(
        value = "greetings",
        key = "#id")
public Greeting findOne(Long id) {
    logger.info("> findOne id:{}", id);

    counterService.increment("method.invoked.greetingServiceBean.findOne");

    Greeting greeting = greetingRepository.findOne(id);

    logger.info("< findOne id:{}", id);
    return greeting;
}
 
开发者ID:leanstacks,项目名称:spring-data-fundamentals,代码行数:15,代码来源:GreetingServiceBean.java

示例12: create

import org.example.ws.model.Greeting; //导入依赖的package包/类
@Override
@Transactional(
        propagation = Propagation.REQUIRED,
        readOnly = false)
@CachePut(
        value = "greetings",
        key = "#result.id")
public Greeting create(Greeting greeting) {
    logger.info("> create");

    counterService.increment("method.invoked.greetingServiceBean.create");

    // Ensure the entity object to be created does NOT exist in the
    // repository. Prevent the default behavior of save() which will update
    // an existing entity if the entity matching the supplied id exists.
    if (greeting.getId() != null) {
        // Cannot create Greeting with specified ID value
        logger.error(
                "Attempted to create a Greeting, but id attribute was not null.");
        throw new EntityExistsException(
                "The id attribute must be null to persist a new entity.");
    }

    Greeting savedGreeting = greetingRepository.save(greeting);

    logger.info("< create");
    return savedGreeting;
}
 
开发者ID:leanstacks,项目名称:spring-data-fundamentals,代码行数:29,代码来源:GreetingServiceBean.java

示例13: update

import org.example.ws.model.Greeting; //导入依赖的package包/类
@Override
@Transactional(
        propagation = Propagation.REQUIRED,
        readOnly = false)
@CachePut(
        value = "greetings",
        key = "#greeting.id")
public Greeting update(Greeting greeting) {
    logger.info("> update id:{}", greeting.getId());

    counterService.increment("method.invoked.greetingServiceBean.update");

    // Ensure the entity object to be updated exists in the repository to
    // prevent the default behavior of save() which will persist a new
    // entity if the entity matching the id does not exist
    Greeting greetingToUpdate = findOne(greeting.getId());
    if (greetingToUpdate == null) {
        // Cannot update Greeting that hasn't been persisted
        logger.error(
                "Attempted to update a Greeting, but the entity does not exist.");
        throw new NoResultException("Requested entity not found.");
    }

    greetingToUpdate.setText(greeting.getText());
    Greeting updatedGreeting = greetingRepository.save(greetingToUpdate);

    logger.info("< update id:{}", greeting.getId());
    return updatedGreeting;
}
 
开发者ID:leanstacks,项目名称:spring-data-fundamentals,代码行数:30,代码来源:GreetingServiceBean.java

示例14: cronJob

import org.example.ws.model.Greeting; //导入依赖的package包/类
/**
 * Use a cron expression to execute logic on a schedule.
 * 
 * Expression: second minute hour day-of-month month weekday
 * 
 * @see http ://docs.spring.io/spring/docs/current/javadoc-api/org/
 *      springframework /scheduling/support/CronSequenceGenerator.html
 */
@Scheduled(
        cron = "${batch.greeting.cron}")
public void cronJob() {
    logger.info("> cronJob");

    // Add scheduled logic here
    Collection<Greeting> greetings = greetingService.findAll();
    logger.info("There are {} greetings in the data store.",
            greetings.size());

    logger.info("< cronJob");
}
 
开发者ID:leanstacks,项目名称:spring-data-fundamentals,代码行数:21,代码来源:GreetingBatchBean.java

示例15: health

import org.example.ws.model.Greeting; //导入依赖的package包/类
@Override
public Health health() {

    // Assess the application's Greeting health. If the application's
    // Greeting components have data to service user requests, the Greeting
    // component is considered 'healthy', otherwise it is not.

    Collection<Greeting> greetings = greetingService.findAll();

    if (greetings == null || greetings.size() == 0) {
        return Health.down().withDetail("count", 0).build();
    }

    return Health.up().withDetail("count", greetings.size()).build();
}
 
开发者ID:leanstacks,项目名称:spring-data-fundamentals,代码行数:16,代码来源:GreetingHealthIndicator.java


注:本文中的org.example.ws.model.Greeting类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。