-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
359 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.huifer.restsec; | ||
|
||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
|
||
@SpringBootApplication | ||
public class RestSecApplication { | ||
|
||
public static void main(String[] args) { | ||
SpringApplication.run(RestSecApplication.class, args); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package com.huifer.design.builder; | ||
|
||
/** | ||
* 基础对象 trek 自行车 | ||
*/ | ||
public class TrekBike { | ||
|
||
private Wheel wheel; | ||
private Frame frame; | ||
|
||
public Wheel getWheel() { | ||
return wheel; | ||
} | ||
|
||
public void setWheel(Wheel wheel) { | ||
this.wheel = wheel; | ||
} | ||
|
||
public Frame getFrame() { | ||
return frame; | ||
} | ||
|
||
public void setFrame(Frame frame) { | ||
this.frame = frame; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/** | ||
* Copyright 2009-2019 the original author or authors. | ||
* <p> | ||
* 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 | ||
* <p> | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* <p> | ||
* 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.jdbc; | ||
|
||
import org.apache.ibatis.logging.Log; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
|
||
import java.sql.Array; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.mockito.Mockito.when; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
class BaseJdbcLoggerTest { | ||
|
||
@Mock | ||
Log log; | ||
@Mock | ||
Array array; | ||
private BaseJdbcLogger logger; | ||
|
||
@BeforeEach | ||
void setUp() { | ||
logger = new BaseJdbcLogger(log, 1) { | ||
}; | ||
} | ||
|
||
@Test | ||
void shouldDescribePrimitiveArrayParameter() throws Exception { | ||
logger.setColumn("1", array); | ||
when(array.getArray()).thenReturn(new int[]{1, 2, 3}); | ||
assertThat(logger.getParameterValueString()).startsWith("[1, 2, 3]"); | ||
} | ||
|
||
@Test | ||
void shouldDescribeObjectArrayParameter() throws Exception { | ||
logger.setColumn("1", array); | ||
when(array.getArray()).thenReturn(new String[]{"one", "two", "three"}); | ||
assertThat(logger.getParameterValueString()).startsWith("[one, two, three]"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
/** | ||
* Copyright 2009-2019 the original author or authors. | ||
* <p> | ||
* 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 | ||
* <p> | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* <p> | ||
* 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.type; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.mockito.Mock; | ||
import org.mockito.Mockito; | ||
|
||
import java.io.Reader; | ||
import java.sql.Clob; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNull; | ||
import static org.mockito.Mockito.verify; | ||
import static org.mockito.Mockito.when; | ||
|
||
class NClobTypeHandlerTest extends BaseTypeHandlerTest { | ||
|
||
private static final TypeHandler<String> TYPE_HANDLER = new NClobTypeHandler(); | ||
|
||
@Mock | ||
protected Clob clob; | ||
|
||
@Override | ||
@Test | ||
public void shouldSetParameter() throws Exception { | ||
TYPE_HANDLER.setParameter(ps, 1, "Hello", null); | ||
verify(ps).setCharacterStream(Mockito.eq(1), Mockito.any(Reader.class), Mockito.eq(5)); | ||
} | ||
|
||
@Override | ||
@Test | ||
public void shouldGetResultFromResultSetByName() throws Exception { | ||
when(rs.getClob("column")).thenReturn(clob); | ||
when(clob.length()).thenReturn(3l); | ||
when(clob.getSubString(1, 3)).thenReturn("Hello"); | ||
assertEquals("Hello", TYPE_HANDLER.getResult(rs, "column")); | ||
} | ||
|
||
@Override | ||
@Test | ||
public void shouldGetResultNullFromResultSetByName() throws Exception { | ||
when(rs.getClob("column")).thenReturn(null); | ||
assertNull(TYPE_HANDLER.getResult(rs, "column")); | ||
} | ||
|
||
@Override | ||
@Test | ||
public void shouldGetResultFromResultSetByPosition() throws Exception { | ||
when(rs.getClob(1)).thenReturn(clob); | ||
when(clob.length()).thenReturn(3L); | ||
when(clob.getSubString(1, 3)).thenReturn("Hello"); | ||
assertEquals("Hello", TYPE_HANDLER.getResult(rs, 1)); | ||
} | ||
|
||
@Override | ||
@Test | ||
public void shouldGetResultNullFromResultSetByPosition() throws Exception { | ||
when(rs.getClob(1)).thenReturn(null); | ||
assertNull(TYPE_HANDLER.getResult(rs, 1)); | ||
} | ||
|
||
@Override | ||
@Test | ||
public void shouldGetResultFromCallableStatement() throws Exception { | ||
when(cs.getClob(1)).thenReturn(clob); | ||
when(clob.length()).thenReturn(3L); | ||
when(clob.getSubString(1, 3)).thenReturn("Hello"); | ||
assertEquals("Hello", TYPE_HANDLER.getResult(cs, 1)); | ||
} | ||
|
||
@Override | ||
@Test | ||
public void shouldGetResultNullFromCallableStatement() throws Exception { | ||
when(cs.getClob(1)).thenReturn(null); | ||
assertNull(TYPE_HANDLER.getResult(cs, 1)); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/** | ||
* Copyright 2009-2019 the original author or authors. | ||
* <p> | ||
* 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 | ||
* <p> | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* <p> | ||
* 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.type; | ||
|
||
import java.sql.*; | ||
|
||
/** | ||
* Convert <code>String</code> to/from <code>SQLXML</code>. | ||
* | ||
* @since 3.5.0 | ||
* @author Iwao AVE! | ||
*/ | ||
public class SqlxmlTypeHandler extends BaseTypeHandler<String> { | ||
|
||
@Override | ||
public void setNonNullParameter(PreparedStatement ps, int i, String parameter, JdbcType jdbcType) | ||
throws SQLException { | ||
SQLXML sqlxml = ps.getConnection().createSQLXML(); | ||
try { | ||
sqlxml.setString(parameter); | ||
ps.setSQLXML(i, sqlxml); | ||
} finally { | ||
sqlxml.free(); | ||
} | ||
} | ||
|
||
@Override | ||
public String getNullableResult(ResultSet rs, String columnName) throws SQLException { | ||
return sqlxmlToString(rs.getSQLXML(columnName)); | ||
} | ||
|
||
@Override | ||
public String getNullableResult(ResultSet rs, int columnIndex) throws SQLException { | ||
return sqlxmlToString(rs.getSQLXML(columnIndex)); | ||
} | ||
|
||
@Override | ||
public String getNullableResult(CallableStatement cs, int columnIndex) throws SQLException { | ||
return sqlxmlToString(cs.getSQLXML(columnIndex)); | ||
} | ||
|
||
protected String sqlxmlToString(SQLXML sqlxml) throws SQLException { | ||
if (sqlxml == null) { | ||
return null; | ||
} | ||
try { | ||
return sqlxml.getString(); | ||
} finally { | ||
sqlxml.free(); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.huifer.design.delegate.subordinate; | ||
|
||
/** | ||
* <p>Title : QD </p> | ||
* <p>Description : 前端</p> | ||
* | ||
* @author huifer | ||
* @date 2019-05-21 | ||
*/ | ||
public class QD implements Dev { | ||
|
||
@Override | ||
public void work(String s) { | ||
System.out.println("前端工程师开始工作"); | ||
System.out.println("前端任务 : " + s); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
//package com.huifer.design.proxy.cglib; | ||
// | ||
//import com.huifer.design.proxy.staticproxy.Person; | ||
////import sun.misc.ProxyGenerator; | ||
// | ||
//import java.io.FileOutputStream; | ||
// | ||
///** | ||
// * <p>Title : CglibProxyTest </p> | ||
// * <p>Description : </p> | ||
// * | ||
// * @author huifer | ||
// * @date 2019-05-17 | ||
// */ | ||
//public class CglibProxyTest { | ||
// | ||
// public static void main(String[] args) throws Exception { | ||
// | ||
// CGPerson instance = (CGPerson) new CGLIBZhiLian().getInstance(CGPerson.class); | ||
// instance.findWork(); | ||
// System.out.println(instance.getClass()); | ||
// | ||
// | ||
// try { | ||
// | ||
// byte[] proxyClass = ProxyGenerator | ||
// .generateProxyClass("CGPerson$$EnhancerByCGLIB$$a7024b7c", new Class[]{Person.class}); | ||
// FileOutputStream fos = new FileOutputStream( | ||
// "E:\\mck\\javaBook-src\\design\\src\\main\\resources\\proxy2.class"); | ||
// | ||
// fos.write(proxyClass); | ||
// fos.close(); | ||
// | ||
// } catch (Exception e) { | ||
// e.printStackTrace(); | ||
// | ||
// } | ||
// | ||
// } | ||
// | ||
//} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/** | ||
* Copyright 2009-2015 the original author or authors. | ||
* <p> | ||
* 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 | ||
* <p> | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* <p> | ||
* 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; | ||
|
||
/** | ||
* mybatis 的日志接口,提供日志级别 | ||
* <ol> | ||
* <li>error</li> | ||
* <li>debug</li> | ||
* <li>trace</li> | ||
* <li>warn</li> | ||
* </ol> | ||
* <p>通过自己定义的接口来实现各大日志框架的内容达到高可用</p> | ||
* | ||
* @author Clinton Begin | ||
*/ | ||
public interface Log { | ||
|
||
boolean isDebugEnabled(); | ||
|
||
boolean isTraceEnabled(); | ||
|
||
void error(String s, Throwable e); | ||
|
||
void error(String s); | ||
|
||
void debug(String s); | ||
|
||
void trace(String s); | ||
|
||
void warn(String s); | ||
|
||
} |