diff --git a/docs/spring/cs4b17d13c-a90f-11ee-b0cd-acde48001122.java b/docs/spring/cs4b17d13c-a90f-11ee-b0cd-acde48001122.java new file mode 100644 index 00000000..6e582685 --- /dev/null +++ b/docs/spring/cs4b17d13c-a90f-11ee-b0cd-acde48001122.java @@ -0,0 +1,9 @@ +package dolores.oauthserver.config; + +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.context.annotation.Configuration; + +@Configuration +@EnableConfigurationProperties(OAuth2Properties.class) +public class OAuth2CoreConfig { +} diff --git a/docs/spring/cs4b508e0a-a90f-11ee-b0cd-acde48001122.java b/docs/spring/cs4b508e0a-a90f-11ee-b0cd-acde48001122.java new file mode 100644 index 00000000..1059332b --- /dev/null +++ b/docs/spring/cs4b508e0a-a90f-11ee-b0cd-acde48001122.java @@ -0,0 +1,40 @@ +/** + * Copyright 2009-2018 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.session; + +import java.sql.Connection; + +/** + * 事物级别, 封装 java.sql 的事物美剧 + * @author Clinton Begin + */ +public enum TransactionIsolationLevel { + NONE(Connection.TRANSACTION_NONE), + READ_COMMITTED(Connection.TRANSACTION_READ_COMMITTED), + READ_UNCOMMITTED(Connection.TRANSACTION_READ_UNCOMMITTED), + REPEATABLE_READ(Connection.TRANSACTION_REPEATABLE_READ), + SERIALIZABLE(Connection.TRANSACTION_SERIALIZABLE); + + private final int level; + + TransactionIsolationLevel(int level) { + this.level = level; + } + + public int getLevel() { + return level; + } +} diff --git a/docs/spring/cs4b881c6c-a90f-11ee-b0cd-acde48001122.java b/docs/spring/cs4b881c6c-a90f-11ee-b0cd-acde48001122.java new file mode 100644 index 00000000..8b0c22ce --- /dev/null +++ b/docs/spring/cs4b881c6c-a90f-11ee-b0cd-acde48001122.java @@ -0,0 +1,74 @@ +/** + * Copyright 2009-2018 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.jdbc; + +import org.apache.ibatis.type.*; + +/** + * 对于 null 不同类型的描述, {类型处理器,jdbc类型} + * @author Clinton Begin + * @author Adam Gent + */ +public enum Null { + BOOLEAN(new BooleanTypeHandler(), JdbcType.BOOLEAN), + + BYTE(new ByteTypeHandler(), JdbcType.TINYINT), + SHORT(new ShortTypeHandler(), JdbcType.SMALLINT), + INTEGER(new IntegerTypeHandler(), JdbcType.INTEGER), + LONG(new LongTypeHandler(), JdbcType.BIGINT), + FLOAT(new FloatTypeHandler(), JdbcType.FLOAT), + DOUBLE(new DoubleTypeHandler(), JdbcType.DOUBLE), + BIGDECIMAL(new BigDecimalTypeHandler(), JdbcType.DECIMAL), + + STRING(new StringTypeHandler(), JdbcType.VARCHAR), + CLOB(new ClobTypeHandler(), JdbcType.CLOB), + LONGVARCHAR(new ClobTypeHandler(), JdbcType.LONGVARCHAR), + + BYTEARRAY(new ByteArrayTypeHandler(), JdbcType.LONGVARBINARY), + BLOB(new BlobTypeHandler(), JdbcType.BLOB), + LONGVARBINARY(new BlobTypeHandler(), JdbcType.LONGVARBINARY), + + OBJECT(new ObjectTypeHandler(), JdbcType.OTHER), + OTHER(new ObjectTypeHandler(), JdbcType.OTHER), + TIMESTAMP(new DateTypeHandler(), JdbcType.TIMESTAMP), + DATE(new DateOnlyTypeHandler(), JdbcType.DATE), + TIME(new TimeOnlyTypeHandler(), JdbcType.TIME), + SQLTIMESTAMP(new SqlTimestampTypeHandler(), JdbcType.TIMESTAMP), + SQLDATE(new SqlDateTypeHandler(), JdbcType.DATE), + SQLTIME(new SqlTimeTypeHandler(), JdbcType.TIME); + + /** + * 类型处理器 + */ + private TypeHandler typeHandler; + /** + * jdbc 类型 + */ + private JdbcType jdbcType; + + Null(TypeHandler typeHandler, JdbcType jdbcType) { + this.typeHandler = typeHandler; + this.jdbcType = jdbcType; + } + + public TypeHandler getTypeHandler() { + return typeHandler; + } + + public JdbcType getJdbcType() { + return jdbcType; + } +} diff --git a/docs/spring/cs4bbe87d4-a90f-11ee-b0cd-acde48001122.java b/docs/spring/cs4bbe87d4-a90f-11ee-b0cd-acde48001122.java new file mode 100644 index 00000000..96a1f336 --- /dev/null +++ b/docs/spring/cs4bbe87d4-a90f-11ee-b0cd-acde48001122.java @@ -0,0 +1,35 @@ +package com.huifer.design.proxy.cglib; + +import net.sf.cglib.proxy.Enhancer; +import net.sf.cglib.proxy.MethodInterceptor; +import net.sf.cglib.proxy.MethodProxy; + +import java.lang.reflect.Method; + +/** + *

Title : CGLIBZhiLian

+ *

Description :

+ * + * @author huifer + * @date 2019-05-17 + */ +public class CGLIBZhiLian { + + public Object getInstance(Class clazz) throws Exception { + Enhancer enhancer = new Enhancer(); + enhancer.setSuperclass(clazz); + + enhancer.setCallback(new MethodInterceptor() { + @Override + public Object intercept(Object o, Method method, Object[] args, + MethodProxy methodProxy) throws Throwable { + System.out.println("CGLIB 代理智联"); + Object o1 = methodProxy.invokeSuper(o, args); + return o1; + } + }); + + return enhancer.create(); + + } +} diff --git a/docs/spring/cs4bf48604-a90f-11ee-b0cd-acde48001122.java b/docs/spring/cs4bf48604-a90f-11ee-b0cd-acde48001122.java new file mode 100644 index 00000000..72ddd356 --- /dev/null +++ b/docs/spring/cs4bf48604-a90f-11ee-b0cd-acde48001122.java @@ -0,0 +1,141 @@ +/** + * 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.logging; + +import java.lang.reflect.Constructor; + +/** + *

日志工厂,实现内容:

+ *
    + *
  1. org.slf4j.Logger 日志框架 slf4j
  2. + *
  3. org.apache.commons.logging.Log 日志框架 apache
  4. + *
  5. org.apache.logging.log4j.Logger 日志框架 log4j2
  6. + *
  7. org.apache.log4j.Logger 日志框架 log4j
  8. + *
  9. java.util.logging.Logger 日志框架,JDK的logger
  10. + * + *
+ * @author Clinton Begin + * @author Eduardo Macarron + */ +public final class LogFactory { + + /** + * Marker to be used by logging implementations that support markers. + */ + public static final String MARKER = "MYBATIS"; + + private static Constructor logConstructor; + + /** + * 日志的实现类的具体选择 + */ + static { + // slf4j 日志 + tryImplementation(LogFactory::useSlf4jLogging); + // apache 日志 + tryImplementation(LogFactory::useCommonsLogging); + // log4j2 日志 + tryImplementation(LogFactory::useLog4J2Logging); + // log4 日志 + tryImplementation(LogFactory::useLog4JLogging); + // JDK 日志 + tryImplementation(LogFactory::useJdkLogging); + // 空 日志 + tryImplementation(LogFactory::useNoLogging); + } + + /** + * 私有化构造方法,这是一个单例 + */ + private LogFactory() { + // disable construction + } + + public static Log getLog(Class aClass) { + return getLog(aClass.getName()); + } + + public static Log getLog(String logger) { + try { + return logConstructor.newInstance(logger); + } catch (Throwable t) { + throw new LogException("Error creating logger for logger " + logger + ". Cause: " + t, t); + } + } + + public static synchronized void useCustomLogging(Class clazz) { + setImplementation(clazz); + } + + public static synchronized void useSlf4jLogging() { + setImplementation(org.apache.ibatis.logging.slf4j.Slf4jImpl.class); + } + + public static synchronized void useCommonsLogging() { + setImplementation(org.apache.ibatis.logging.commons.JakartaCommonsLoggingImpl.class); + } + + public static synchronized void useLog4JLogging() { + setImplementation(org.apache.ibatis.logging.log4j.Log4jImpl.class); + } + + public static synchronized void useLog4J2Logging() { + setImplementation(org.apache.ibatis.logging.log4j2.Log4j2Impl.class); + } + + public static synchronized void useJdkLogging() { + setImplementation(org.apache.ibatis.logging.jdk14.Jdk14LoggingImpl.class); + } + + public static synchronized void useStdOutLogging() { + setImplementation(org.apache.ibatis.logging.stdout.StdOutImpl.class); + } + + public static synchronized void useNoLogging() { + setImplementation(org.apache.ibatis.logging.nologging.NoLoggingImpl.class); + } + + /** + * 选择具体的日志实现 + */ + private static void tryImplementation(Runnable runnable) { + if (logConstructor == null) { + try { + // run()? 似乎违背了代码的语义, 看静态方法.静态方法多行同类型的操作我认为是一个多线程 + runnable.run(); + } catch (Throwable t) { + // ignore + } + } + } + + /** + * 选择具体的日志实现 + */ + private static void setImplementation(Class implClass) { + try { + Constructor candidate = implClass.getConstructor(String.class); + Log log = candidate.newInstance(LogFactory.class.getName()); + if (log.isDebugEnabled()) { + log.debug("Logging initialized using '" + implClass + "' adapter."); + } + logConstructor = candidate; + } catch (Throwable t) { + throw new LogException("Error setting Log implementation. Cause: " + t, t); + } + } + +} diff --git a/docs/spring/cs4c2a4b40-a90f-11ee-b0cd-acde48001122.java b/docs/spring/cs4c2a4b40-a90f-11ee-b0cd-acde48001122.java new file mode 100644 index 00000000..d1f2a3f7 --- /dev/null +++ b/docs/spring/cs4c2a4b40-a90f-11ee-b0cd-acde48001122.java @@ -0,0 +1,34 @@ +package com.github.huifer.netty.learn.hello; + +import io.netty.bootstrap.ServerBootstrap; +import io.netty.channel.ChannelFuture; +import io.netty.channel.EventLoopGroup; +import io.netty.channel.nio.NioEventLoopGroup; +import io.netty.channel.socket.nio.NioServerSocketChannel; + +public class HelloNetty { + + public static void main(String[] args) { + EventLoopGroup boosGroup = new NioEventLoopGroup(); + EventLoopGroup workerGroup = new NioEventLoopGroup(); + + try { + ServerBootstrap serverBootstrap + = new ServerBootstrap() + .group(boosGroup, workerGroup) + .channel(NioServerSocketChannel.class) + .childHandler( + new HttpServerHandler() + ); + ChannelFuture sync = serverBootstrap.bind(1010).sync(); + sync.channel().closeFuture().sync(); + } catch (InterruptedException e) { + e.printStackTrace(); + } finally { + boosGroup.shutdownGracefully(); + workerGroup.shutdownGracefully(); + } + + } + +} diff --git a/docs/spring/cs4c5f653c-a90f-11ee-b0cd-acde48001122.java b/docs/spring/cs4c5f653c-a90f-11ee-b0cd-acde48001122.java new file mode 100644 index 00000000..5f0d68f4 --- /dev/null +++ b/docs/spring/cs4c5f653c-a90f-11ee-b0cd-acde48001122.java @@ -0,0 +1,21 @@ +/** + * Copyright 2009-2015 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. + *

+ * Hyper-simple Datasource. + */ +/** + * Hyper-simple Datasource. + */ +package org.apache.ibatis.datasource.unpooled; diff --git a/docs/spring/cs4c958d4c-a90f-11ee-b0cd-acde48001122.java b/docs/spring/cs4c958d4c-a90f-11ee-b0cd-acde48001122.java new file mode 100644 index 00000000..707887fa --- /dev/null +++ b/docs/spring/cs4c958d4c-a90f-11ee-b0cd-acde48001122.java @@ -0,0 +1,57 @@ +/** + * 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.ancestor_ref; + +import java.util.List; + +public class User { + private Integer id; + private String name; + private User friend; + private List friends; + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public User getFriend() { + return friend; + } + + public void setFriend(User friend) { + this.friend = friend; + } + + public List getFriends() { + return friends; + } + + public void setFriends(List friends) { + this.friends = friends; + } +} diff --git a/docs/spring/cs4ccbfcec-a90f-11ee-b0cd-acde48001122.java b/docs/spring/cs4ccbfcec-a90f-11ee-b0cd-acde48001122.java new file mode 100644 index 00000000..e623cd74 --- /dev/null +++ b/docs/spring/cs4ccbfcec-a90f-11ee-b0cd-acde48001122.java @@ -0,0 +1,21 @@ +/** + * Copyright 2009-2015 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 Datasources + */ +/** + * Base package for Datasources + */ +package org.apache.ibatis.datasource; diff --git a/docs/spring/cs4d03e800-a90f-11ee-b0cd-acde48001122.java b/docs/spring/cs4d03e800-a90f-11ee-b0cd-acde48001122.java new file mode 100644 index 00000000..4943128e --- /dev/null +++ b/docs/spring/cs4d03e800-a90f-11ee-b0cd-acde48001122.java @@ -0,0 +1,78 @@ +/** + * 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.SerializedCache; +import org.apache.ibatis.cache.decorators.WeakCache; +import org.apache.ibatis.cache.impl.PerpetualCache; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.*; + +class WeakCacheTest { + + @Test + void shouldDemonstrateObjectsBeingCollectedAsNeeded() { + final int N = 3000000; + WeakCache cache = new WeakCache(new PerpetualCache("default")); + for (int i = 0; i < N; i++) { + cache.putObject(i, i); + if (cache.getSize() < i + 1) { + // System.out.println("Cache exceeded with " + (i + 1) + " entries."); + break; + } + if ((i + 1) % 100000 == 0) { + // Try performing GC. + System.gc(); + } + } + assertTrue(cache.getSize() < N); + } + + @Test + void shouldDemonstrateCopiesAreEqual() { + Cache cache = new WeakCache(new PerpetualCache("default")); + cache = new SerializedCache(cache); + for (int i = 0; i < 1000; i++) { + cache.putObject(i, i); + Object value = cache.getObject(i); + assertTrue(value == null || value.equals(i)); + } + } + + @Test + void shouldRemoveItemOnDemand() { + WeakCache cache = new WeakCache(new PerpetualCache("default")); + cache.putObject(0, 0); + assertNotNull(cache.getObject(0)); + cache.removeObject(0); + assertNull(cache.getObject(0)); + } + + @Test + void shouldFlushAllItemsOnDemand() { + WeakCache cache = new WeakCache(new PerpetualCache("default")); + for (int i = 0; i < 5; i++) { + cache.putObject(i, i); + } + assertNotNull(cache.getObject(0)); + assertNotNull(cache.getObject(4)); + cache.clear(); + assertNull(cache.getObject(0)); + assertNull(cache.getObject(4)); + } + +}