diff --git a/docs/spring/cs6beef402-4155-11ee-995c-acde48001122.java b/docs/spring/cs6beef402-4155-11ee-995c-acde48001122.java new file mode 100644 index 00000000..23207066 --- /dev/null +++ b/docs/spring/cs6beef402-4155-11ee-995c-acde48001122.java @@ -0,0 +1,37 @@ +/** + * Copyright 2009-2016 the original author or authors. + *

+ * 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 org.apache.ibatis.submitted.lazy_properties; + +import org.apache.ibatis.annotations.ResultMap; +import org.apache.ibatis.annotations.Select; + +import java.util.List; + +public interface Mapper { + User getUser(Integer id); + + @ResultMap("user") + @Select("select 11 id, 'lazy1' name from (values(0))") + User getLazy1(); + + @ResultMap("user") + @Select("select 12 id, 'lazy2' name from (values(0))") + User getLazy2(); + + @ResultMap("user") + @Select("select 13 id, 'lazy3' name from (values(0))") + List getLazy3(); +} diff --git a/docs/spring/cs6c39b41a-4155-11ee-995c-acde48001122.java b/docs/spring/cs6c39b41a-4155-11ee-995c-acde48001122.java new file mode 100644 index 00000000..aa1bc5cc --- /dev/null +++ b/docs/spring/cs6c39b41a-4155-11ee-995c-acde48001122.java @@ -0,0 +1,32 @@ +package com.huifer.data.list.circularLinkedList; + +/** + *

Title : CircularNode

+ *

Description : 循环链表结点

+ * + * @author huifer + * @date 2019-04-18 + */ +public class CircularNode { + + public Integer data; + public CircularNode next; + + public CircularNode(Integer data) { + this.data = data; + } + + public CircularNode() { + } + + @Override + public String toString() { + final StringBuilder sb = new StringBuilder("{"); + sb.append("\"data\":") + .append(data); + sb.append(",\"next\":") + .append(next); + sb.append('}'); + return sb.toString(); + } +} diff --git a/docs/spring/cs6c8068ce-4155-11ee-995c-acde48001122.java b/docs/spring/cs6c8068ce-4155-11ee-995c-acde48001122.java new file mode 100644 index 00000000..895bdd7d --- /dev/null +++ b/docs/spring/cs6c8068ce-4155-11ee-995c-acde48001122.java @@ -0,0 +1,21 @@ +/** + * Copyright 2009-2016 the original author or authors. + *

+ * 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. + *

+ * Base package for cursor feature + */ +/** + * Base package for cursor feature + */ +package org.apache.ibatis.cursor; diff --git a/docs/spring/cs6cc29a00-4155-11ee-995c-acde48001122.java b/docs/spring/cs6cc29a00-4155-11ee-995c-acde48001122.java new file mode 100644 index 00000000..96cebbd2 --- /dev/null +++ b/docs/spring/cs6cc29a00-4155-11ee-995c-acde48001122.java @@ -0,0 +1,111 @@ +package org.huifer.ztj.spring; + +import java.util.EnumSet; +import org.springframework.messaging.Message; +import org.springframework.messaging.support.MessageBuilder; +import org.springframework.statemachine.StateContext; +import org.springframework.statemachine.StateMachine; +import org.springframework.statemachine.action.Action; +import org.springframework.statemachine.config.StateMachineBuilder; +import org.springframework.statemachine.config.StateMachineBuilder.Builder; +import org.springframework.statemachine.guard.Guard; +import org.springframework.statemachine.state.State; + +public class Main { + + public static void main(String[] args) throws Exception { + StateMachine stateMachine = buildWithInternal(); + stateMachine.start(); + +// stateMachine.sendEvent(Events.EVENT1); + + Message user_id = MessageBuilder.withPayload(Events.EVENT1).setHeader("user_id", 100) + .build(); + stateMachine.sendEvent(user_id); +// stateMachine.sendEvent(Events.EVENT2); + + printState(stateMachine); + System.out.println(); + } + + private static void printState(StateMachine stateMachine) { + State state = stateMachine.getState(); + States id = state.getId(); + System.out.println("发送事件之后的状态"); + System.out.println(id); + } + + + public static StateMachine buildWithInternal() throws Exception { + Builder builder = StateMachineBuilder.builder(); + + builder.configureStates() + .withStates() + .initial(States.STATE1) + .end(States.STATE3) + .states(EnumSet.allOf(States.class)) + ; + builder.configureTransitions() + .withExternal() + .source(States.STATE1).target(States.STATE2).event(Events.EVENT1) + .guard(new Guard() { + @Override + public boolean evaluate( + StateContext context) { + return false; + } + }) + .and() + // 做了什么失败了并且吧状态还原 + .withInternal() + .source(States.STATE1).event(Events.EVENT1) + + ; + + return builder.build(); + } + + + public static StateMachine buildMachine() throws Exception { + Builder builder = StateMachineBuilder.builder(); + + builder.configureStates() + .withStates() + .initial(States.STATE1) + .states(EnumSet.allOf(States.class)) + ; + builder.configureTransitions() + .withExternal() + .source(States.STATE1).target(States.STATE2) + .event(Events.EVENT1) + .guard(new Guard() { + @Override + public boolean evaluate( + StateContext context) { + return false; + } + }) + + .action(new Action() { + @Override + public void execute( + StateContext context) { + // todo: 做状态变更的事情 + Object user_id = context.getMessageHeaders().get("user_id"); + System.out.println(user_id); + System.out.println(); + } + }) + ; + + return builder.build(); + } + + enum States { + STATE1, STATE2, STATE3 + } + + enum Events { + EVENT1, EVENT2 + } +} diff --git a/docs/spring/cs6d0ebbce-4155-11ee-995c-acde48001122.java b/docs/spring/cs6d0ebbce-4155-11ee-995c-acde48001122.java new file mode 100644 index 00000000..9bb895ad --- /dev/null +++ b/docs/spring/cs6d0ebbce-4155-11ee-995c-acde48001122.java @@ -0,0 +1,98 @@ +package dolores.oauthserver.service; + +import dolores.oauthserver.config.OAuth2ClientProperties; +import dolores.oauthserver.config.OAuth2Properties; +import org.apache.commons.lang.ArrayUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Qualifier; +import org.springframework.context.annotation.Configuration; +import org.springframework.security.authentication.AuthenticationManager; +import org.springframework.security.core.userdetails.UserDetailsService; +import org.springframework.security.crypto.password.PasswordEncoder; +import org.springframework.security.oauth2.config.annotation.builders.InMemoryClientDetailsServiceBuilder; +import org.springframework.security.oauth2.config.annotation.configurers.ClientDetailsServiceConfigurer; +import org.springframework.security.oauth2.config.annotation.web.configuration.AuthorizationServerConfigurerAdapter; +import org.springframework.security.oauth2.config.annotation.web.configuration.EnableAuthorizationServer; +import org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerEndpointsConfigurer; +import org.springframework.security.oauth2.config.annotation.web.configurers.AuthorizationServerSecurityConfigurer; +import org.springframework.security.oauth2.provider.token.TokenEnhancer; +import org.springframework.security.oauth2.provider.token.TokenEnhancerChain; +import org.springframework.security.oauth2.provider.token.TokenStore; +import org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter; + +import java.util.ArrayList; +import java.util.List; + +@Configuration +@EnableAuthorizationServer +public class GameAuthorizationServerConfig extends AuthorizationServerConfigurerAdapter { + + @Autowired + private OAuth2Properties oAuth2Properties; + + @Autowired + private UserDetailsService userDetailsService; + + @Autowired + private AuthenticationManager authenticationManager; + + @Autowired + private TokenStore tokenStore; + + @Autowired(required = false) + @Qualifier("jwtAccessTokenConverter") + private JwtAccessTokenConverter jwtAccessTokenConverter; + + @Autowired(required = false) + @Qualifier("jwtTokenEnhancer") + private TokenEnhancer jwtTokenEnhancer; + + @Autowired + private PasswordEncoder passwordEncoder; + + public GameAuthorizationServerConfig() { + super(); + } + + @Override + public void configure(AuthorizationServerSecurityConfigurer security) throws Exception { + security.tokenKeyAccess("permitAll()"); + security.checkTokenAccess("isAuthenticated()"); + } + + @Override + public void configure(ClientDetailsServiceConfigurer clients) throws Exception { + InMemoryClientDetailsServiceBuilder builder = clients.inMemory(); + + if (ArrayUtils.isNotEmpty(oAuth2Properties.getClients())) { + for (OAuth2ClientProperties config : oAuth2Properties.getClients()) { + builder.withClient(config.getClientId()) + .secret(passwordEncoder.encode(config.getClientSecret())) + .accessTokenValiditySeconds(config.getAccessTokenValiditySeconds()) + .refreshTokenValiditySeconds(60 * 60 * 24 * 15) + .authorizedGrantTypes("refresh_token", "password", "authorization_code")//OAuth2支持的验证模式 + .redirectUris("http://www.ixx.com") + .scopes("all"); + } + } + } + + @Override + public void configure(AuthorizationServerEndpointsConfigurer endpoints) throws Exception { + endpoints + .tokenStore(tokenStore) + .authenticationManager(authenticationManager) + .userDetailsService(userDetailsService); + + if (jwtAccessTokenConverter != null && jwtTokenEnhancer != null) { + TokenEnhancerChain tokenEnhancerChain = new TokenEnhancerChain(); + List enhancers = new ArrayList<>(); + enhancers.add(jwtTokenEnhancer); + enhancers.add(jwtAccessTokenConverter); + tokenEnhancerChain.setTokenEnhancers(enhancers); + endpoints + .tokenEnhancer(tokenEnhancerChain) + .accessTokenConverter(jwtAccessTokenConverter); + } + } +} diff --git a/docs/spring/cs6d5cdba6-4155-11ee-995c-acde48001122.java b/docs/spring/cs6d5cdba6-4155-11ee-995c-acde48001122.java new file mode 100644 index 00000000..c582e7eb --- /dev/null +++ b/docs/spring/cs6d5cdba6-4155-11ee-995c-acde48001122.java @@ -0,0 +1,59 @@ +/** + * Copyright 2009-2019 the original author or authors. + *

+ * 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 org.apache.ibatis.cache; + +import org.apache.ibatis.cache.decorators.TransactionalCache; + +import java.util.HashMap; +import java.util.Map; + +/** + * 缓存和事物管理器 + * @author Clinton Begin + */ +public class TransactionalCacheManager { + + private final Map transactionalCaches = new HashMap<>(); + + public void clear(Cache cache) { + getTransactionalCache(cache).clear(); + } + + public Object getObject(Cache cache, CacheKey key) { + return getTransactionalCache(cache).getObject(key); + } + + public void putObject(Cache cache, CacheKey key, Object value) { + getTransactionalCache(cache).putObject(key, value); + } + + public void commit() { + for (TransactionalCache txCache : transactionalCaches.values()) { + txCache.commit(); + } + } + + public void rollback() { + for (TransactionalCache txCache : transactionalCaches.values()) { + txCache.rollback(); + } + } + + private TransactionalCache getTransactionalCache(Cache cache) { + return transactionalCaches.computeIfAbsent(cache, TransactionalCache::new); + } + +} diff --git a/docs/spring/cs6da043dc-4155-11ee-995c-acde48001122.java b/docs/spring/cs6da043dc-4155-11ee-995c-acde48001122.java new file mode 100644 index 00000000..02fa3392 --- /dev/null +++ b/docs/spring/cs6da043dc-4155-11ee-995c-acde48001122.java @@ -0,0 +1,24 @@ +package com.huifer.jdk.jdk8.stearm; + +import java.util.stream.Stream; + +/** + * 描述: + * + * @author huifer + * @date 2019-06-16 + */ +public class Demo04 { + public static void main(String[] args) { +// Stream stringStream = Stream.generate(UUID.randomUUID()::toString); + Stream stringStream = null; + + stringStream.findFirst().get(); + + if (stringStream.findFirst().isPresent()) { + // TODO:..... + } + stringStream.findFirst().ifPresent(System.out::println); + + } +}