Merge pull request #554 from mercyblitz/master
Polish spring-cloud-incubator/spring-cloud-alibaba#553 : Dubbo Spring…pull/555/head
commit
fb8ebf99da
@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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 org.springframework.cloud.alibaba.dubbo.service;
|
||||
|
||||
import org.apache.dubbo.config.annotation.Service;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* In-Memory {@link UserService} implementation
|
||||
*/
|
||||
@Service(protocol = "dubbo")
|
||||
public class InMemoryUserService implements UserService {
|
||||
|
||||
private Map<Long, User> usersRepository = new HashMap<>();
|
||||
|
||||
@Override
|
||||
public boolean save(User user) {
|
||||
return usersRepository.put(user.getId(), user) == null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean remove(Long userId) {
|
||||
return usersRepository.remove(userId) != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<User> findAll() {
|
||||
return usersRepository.values();
|
||||
}
|
||||
}
|
@ -0,0 +1,47 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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 org.springframework.cloud.alibaba.dubbo.service;
|
||||
|
||||
import org.apache.dubbo.config.annotation.Service;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* In-Memory {@link UserService} implementation
|
||||
*/
|
||||
@Service(protocol = "dubbo")
|
||||
public class InMemoryUserService implements UserService {
|
||||
|
||||
private Map<Long, User> usersRepository = new HashMap<>();
|
||||
|
||||
@Override
|
||||
public boolean save(User user) {
|
||||
return usersRepository.put(user.getId(), user) == null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean remove(Long userId) {
|
||||
return usersRepository.remove(userId) != null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<User> findAll() {
|
||||
return usersRepository.values();
|
||||
}
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership.
|
||||
* The ASF licenses this file to You 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 org.springframework.cloud.alibaba.dubbo.service;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* {@link User} Service
|
||||
*
|
||||
* @author <a href="mailto:mercyblitz@gmail.com">Mercy</a>
|
||||
*/
|
||||
public interface UserService {
|
||||
|
||||
boolean save(User user);
|
||||
|
||||
boolean remove(Long userId);
|
||||
|
||||
Collection<User> findAll();
|
||||
}
|
Loading…
Reference in New Issue