diff --git a/docs/spring/csba694812-55c3-11ee-9bca-acde48001122.java b/docs/spring/csba694812-55c3-11ee-9bca-acde48001122.java new file mode 100644 index 00000000..235628e4 --- /dev/null +++ b/docs/spring/csba694812-55c3-11ee-9bca-acde48001122.java @@ -0,0 +1,48 @@ +package com.huifer.concurrence.ch1; + +import java.util.ArrayList; +import java.util.List; + +/** + *
Title : ThreadYield
+ *Description : yield
+ * + * @author huifer + * @date 2019-03-27 + */ +public class ThreadYield { + + public static void main(String[] args) { + Task task1 = new Task(true); + Task task2 = new Task(false); + new Thread(task1).start(); + new Thread(task2).start(); + } + + + private static class Task implements Runnable { + + private final boolean isYield; + private List+ * 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.parsing;
+
+import org.apache.ibatis.builder.BuilderException;
+import org.apache.ibatis.io.Resources;
+import org.junit.jupiter.api.Test;
+import org.w3c.dom.Document;
+import org.xml.sax.InputSource;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Reader;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+class XPathParserTest {
+ private String resource = "resources/nodelet_test.xml";
+
+ // InputStream Source
+ @Test
+ void constructorWithInputStreamValidationVariablesEntityResolver() throws Exception {
+
+ try (InputStream inputStream = Resources.getResourceAsStream(resource)) {
+ XPathParser parser = new XPathParser(inputStream, false, null, null);
+ testEvalMethod(parser);
+ }
+ }
+
+ @Test
+ void constructorWithInputStreamValidationVariables() throws IOException {
+ try (InputStream inputStream = Resources.getResourceAsStream(resource)) {
+ XPathParser parser = new XPathParser(inputStream, false, null);
+ testEvalMethod(parser);
+ }
+ }
+
+ @Test
+ void constructorWithInputStreamValidation() throws IOException {
+ try (InputStream inputStream = Resources.getResourceAsStream(resource)) {
+ XPathParser parser = new XPathParser(inputStream, false);
+ testEvalMethod(parser);
+ }
+ }
+
+ @Test
+ void constructorWithInputStream() throws IOException {
+ try (InputStream inputStream = Resources.getResourceAsStream(resource)) {
+ XPathParser parser = new XPathParser(inputStream);
+ testEvalMethod(parser);
+ }
+ }
+
+ // Reader Source
+ @Test
+ void constructorWithReaderValidationVariablesEntityResolver() throws Exception {
+
+ try (Reader reader = Resources.getResourceAsReader(resource)) {
+ XPathParser parser = new XPathParser(reader, false, null, null);
+ testEvalMethod(parser);
+ }
+ }
+
+ @Test
+ void constructorWithReaderValidationVariables() throws IOException {
+ try (Reader reader = Resources.getResourceAsReader(resource)) {
+ XPathParser parser = new XPathParser(reader, false, null);
+ testEvalMethod(parser);
+ }
+ }
+
+ @Test
+ void constructorWithReaderValidation() throws IOException {
+ try (Reader reader = Resources.getResourceAsReader(resource)) {
+ XPathParser parser = new XPathParser(reader, false);
+ testEvalMethod(parser);
+ }
+ }
+
+ @Test
+ void constructorWithReader() throws IOException {
+ try (Reader reader = Resources.getResourceAsReader(resource)) {
+ XPathParser parser = new XPathParser(reader);
+ testEvalMethod(parser);
+ }
+ }
+
+ // Xml String Source
+ @Test
+ void constructorWithStringValidationVariablesEntityResolver() throws Exception {
+ XPathParser parser = new XPathParser(getXmlString(resource), false, null, null);
+ testEvalMethod(parser);
+ }
+
+ @Test
+ void constructorWithStringValidationVariables() throws IOException {
+ XPathParser parser = new XPathParser(getXmlString(resource), false, null);
+ testEvalMethod(parser);
+ }
+
+ @Test
+ void constructorWithStringValidation() throws IOException {
+ XPathParser parser = new XPathParser(getXmlString(resource), false);
+ testEvalMethod(parser);
+ }
+
+ @Test
+ void constructorWithString() throws IOException {
+ XPathParser parser = new XPathParser(getXmlString(resource));
+ testEvalMethod(parser);
+ }
+
+ // Document Source
+ @Test
+ void constructorWithDocumentValidationVariablesEntityResolver() {
+ XPathParser parser = new XPathParser(getDocument(resource), false, null, null);
+ testEvalMethod(parser);
+ }
+
+ @Test
+ void constructorWithDocumentValidationVariables() {
+ XPathParser parser = new XPathParser(getDocument(resource), false, null);
+ testEvalMethod(parser);
+ }
+
+ @Test
+ void constructorWithDocumentValidation() {
+ XPathParser parser = new XPathParser(getDocument(resource), false);
+ testEvalMethod(parser);
+ }
+
+ @Test
+ void constructorWithDocument() {
+ XPathParser parser = new XPathParser(getDocument(resource));
+ testEvalMethod(parser);
+ }
+
+ private Document getDocument(String resource) {
+ try {
+ InputSource inputSource = new InputSource(Resources.getResourceAsReader(resource));
+ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+ factory.setNamespaceAware(false);
+ factory.setIgnoringComments(true);
+ factory.setIgnoringElementContentWhitespace(false);
+ factory.setCoalescing(false);
+ factory.setExpandEntityReferences(true);
+ DocumentBuilder builder = factory.newDocumentBuilder();
+ return builder.parse(inputSource);// already closed resource in builder.parse method
+ } catch (Exception e) {
+ throw new BuilderException("Error creating document instance. Cause: " + e, e);
+ }
+ }
+
+ private String getXmlString(String resource) throws IOException {
+ try (BufferedReader bufferedReader = new BufferedReader(Resources.getResourceAsReader(resource))) {
+ StringBuilder sb = new StringBuilder();
+ String temp;
+ while ((temp = bufferedReader.readLine()) != null) {
+ sb.append(temp);
+ }
+ return sb.toString();
+ }
+ }
+
+ private void testEvalMethod(XPathParser parser) {
+ assertEquals((Long) 1970L, parser.evalLong("/employee/birth_date/year"));
+ assertEquals((short) 6, (short) parser.evalShort("/employee/birth_date/month"));
+ assertEquals((Integer) 15, parser.evalInteger("/employee/birth_date/day"));
+ assertEquals((Float) 5.8f, parser.evalFloat("/employee/height"));
+ assertEquals((Double) 5.8d, parser.evalDouble("/employee/height"));
+ assertEquals("${id_var}", parser.evalString("/employee/@id"));
+ assertEquals(Boolean.TRUE, parser.evalBoolean("/employee/active"));
+ assertEquals("
+ * 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.annotations; + +import java.lang.annotation.*; + +/** + * The annotation that specify the parameter name. + * + *
+ * How to use:
+ *
+ * public interface UserMapper { + * @Select("SELECT id, name FROM users WHERE name = #{name}") + * User selectById(@Param("name") String value); + * } + *+ * 参数注解 + * @author Clinton Begin + */ +@Documented +@Retention(RetentionPolicy.RUNTIME) +@Target(ElementType.PARAMETER) +public @interface Param { + /** + * Returns the parameter name. + * + * @return the parameter name + */ + String value(); +} diff --git a/docs/spring/csbb3cf1ee-55c3-11ee-9bca-acde48001122.java b/docs/spring/csbb3cf1ee-55c3-11ee-9bca-acde48001122.java new file mode 100644 index 00000000..62f06f9a --- /dev/null +++ b/docs/spring/csbb3cf1ee-55c3-11ee-9bca-acde48001122.java @@ -0,0 +1,32 @@ +/** + * 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.array_result_type; + +import org.apache.ibatis.annotations.Select; + +public interface Mapper { + + @Select("select * from users") + User[] getUsers(); + + User[] getUsersXml(); + + @Select("select id from users") + Integer[] getUserIds(); + + @Select("select id from users") + int[] getUserIdsPrimitive(); +} diff --git a/docs/spring/csbb88eb4e-55c3-11ee-9bca-acde48001122.java b/docs/spring/csbb88eb4e-55c3-11ee-9bca-acde48001122.java new file mode 100644 index 00000000..a84fd8e7 --- /dev/null +++ b/docs/spring/csbb88eb4e-55c3-11ee-9bca-acde48001122.java @@ -0,0 +1,67 @@ +package com.huifer.hystrix.aop; + +import com.huifer.hystrix.annotation.Fusing; +import org.aspectj.lang.ProceedingJoinPoint; +import org.aspectj.lang.annotation.Around; +import org.aspectj.lang.annotation.Aspect; +import org.springframework.stereotype.Component; + +import java.util.concurrent.*; + +/** + *
Title : MyHystrixControllerAspect
+ *Description :
+ * + * @author huifer + * @date 2019-05-30 + */ +@Aspect +@Component +public class MyHystrixControllerAspect { + + private final ExecutorService executorService = Executors.newSingleThreadScheduledExecutor(); + + + @Around(" execution(* com.huifer.hystrix.controller.MyHystrixController.v3(..) ) && args(msg)") + public Object timeout(ProceedingJoinPoint joinPoint, String msg) throws Throwable { + String s = doInvoke(joinPoint, msg, 100, msg); + return s; + + } + + + @Around("execution(* com.huifer.hystrix.controller.MyHystrixController.v4(..) ) && args(msg) && @annotation( fusing )") + public Object versionFour(ProceedingJoinPoint joinPoint, String msg, Fusing fusing) + throws Throwable { + int timeout = fusing.timeout(); + String s = doInvoke(joinPoint, msg, timeout, "注解形式 " + msg); + return s; + + } + + private String doInvoke(ProceedingJoinPoint joinPoint, String msg, int timeout, String s2) + throws InterruptedException, java.util.concurrent.ExecutionException { + Future