All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.power4j.sequence.example.SequenceJdbcExampleApplication Maven / Gradle / Ivy

There is a newer version: 2.0.4
Show newest version
/*
 * Copyright 2020 ChenJun ([email protected])
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.power4j.sequence.example;

import com.power4j.kit.seq.core.Sequence;
import com.power4j.kit.seq.persistent.SeqSynchronizer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@SpringBootApplication
public class SequenceJdbcExampleApplication {

	@Autowired
	private Sequence sequence;

	@Autowired
	private SeqSynchronizer seqSynchronizer;

	public static void main(String[] args) {
		SpringApplication.run(SequenceJdbcExampleApplication.class, args);
	}

	@GetMapping("/seq")
	public Map getSequence(@RequestParam(required = false) Integer size) {
		size = (size == null || size <= 0) ? 10 : size;
		List list = new ArrayList<>(size);
		for (int i = 0; i < size; ++i) {
			list.add(sequence.nextStr());
		}
		Map data = new HashMap<>();
		data.put("query_count", Long.toString(seqSynchronizer.getQueryCounter()));
		data.put("update_count", Long.toString(seqSynchronizer.getUpdateCounter()));
		data.put("seq", list);
		return data;
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy