-
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
10 changed files
with
655 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,64 @@ | ||
/** | ||
* 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.mapping; | ||
|
||
import org.apache.ibatis.session.Configuration; | ||
|
||
import java.util.Collections; | ||
import java.util.Map; | ||
|
||
/** | ||
* @author Clinton Begin | ||
*/ | ||
public class Discriminator { | ||
|
||
private ResultMapping resultMapping; | ||
private Map<String, String> discriminatorMap; | ||
|
||
Discriminator() { | ||
} | ||
|
||
public ResultMapping getResultMapping() { | ||
return resultMapping; | ||
} | ||
|
||
public Map<String, String> getDiscriminatorMap() { | ||
return discriminatorMap; | ||
} | ||
|
||
public String getMapIdFor(String s) { | ||
return discriminatorMap.get(s); | ||
} | ||
|
||
public static class Builder { | ||
private Discriminator discriminator = new Discriminator(); | ||
|
||
public Builder(Configuration configuration, ResultMapping resultMapping, Map<String, String> discriminatorMap) { | ||
discriminator.resultMapping = resultMapping; | ||
discriminator.discriminatorMap = discriminatorMap; | ||
} | ||
|
||
public Discriminator build() { | ||
assert discriminator.resultMapping != null; | ||
assert discriminator.discriminatorMap != null; | ||
assert !discriminator.discriminatorMap.isEmpty(); | ||
//lock down map | ||
discriminator.discriminatorMap = Collections.unmodifiableMap(discriminator.discriminatorMap); | ||
return discriminator; | ||
} | ||
} | ||
|
||
} |
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,30 @@ | ||
package com.huifer.aop.advisor; | ||
|
||
import org.springframework.aop.ClassFilter; | ||
|
||
/** | ||
* 描述: | ||
* 类过滤器 | ||
* | ||
* @author huifer | ||
* @date 2019-03-03 | ||
*/ | ||
public class MyClassFilter implements ClassFilter { | ||
/*** | ||
* 判断当前实现类是否是我们的织入所相关的类 | ||
* 本次案例中 男性上厕所不需要带纸巾,女性上厕所需要带纸巾, | ||
* 那么BaseAopPointCut接口应该要对女性进行判断,完成此步骤后还需要一个方法匹配器 , | ||
* 再次我们只要对上厕所匹配 吃饭不需要匹配 | ||
* | ||
* @param aClass 当前被拦截的类 | ||
* @return boolean | ||
*/ | ||
@Override | ||
public boolean matches(Class<?> aClass) { | ||
if (aClass == WoMan.class) { | ||
|
||
return true; | ||
} | ||
return false; | ||
} | ||
} |
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,86 @@ | ||
/** | ||
* 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.submitted.use_actual_param_name; | ||
|
||
import org.apache.ibatis.BaseDataTest; | ||
import org.apache.ibatis.io.Resources; | ||
import org.apache.ibatis.session.SqlSession; | ||
import org.apache.ibatis.session.SqlSessionFactory; | ||
import org.apache.ibatis.session.SqlSessionFactoryBuilder; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.io.Reader; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
|
||
class UseActualParamNameTest { | ||
|
||
private static SqlSessionFactory sqlSessionFactory; | ||
|
||
@BeforeAll | ||
static void setUp() throws Exception { | ||
// create an SqlSessionFactory | ||
try (Reader reader = Resources.getResourceAsReader( | ||
"org/apache/ibatis/submitted/use_actual_param_name/mybatis-config.xml")) { | ||
sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader); | ||
} | ||
|
||
// populate in-memory database | ||
BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(), | ||
"org/apache/ibatis/submitted/use_actual_param_name/CreateDB.sql"); | ||
} | ||
|
||
@Test | ||
void shouldSingleParamBeReferencedByAnyName() { | ||
try (SqlSession sqlSession = sqlSessionFactory.openSession()) { | ||
Mapper mapper = sqlSession.getMapper(Mapper.class); | ||
User user = mapper.getUserById(1); | ||
assertNotNull(user); | ||
} | ||
} | ||
|
||
@Test | ||
void shouldMultipleParamsBeReferencedByActualNames() { | ||
try (SqlSession sqlSession = sqlSessionFactory.openSession()) { | ||
Mapper mapper = sqlSession.getMapper(Mapper.class); | ||
User user = mapper.getUserByIdAndName(1, "User1"); | ||
assertNotNull(user); | ||
} | ||
} | ||
|
||
@Test | ||
void shouldSoleListParamBeReferencedByImplicitName() { | ||
try (SqlSession sqlSession = sqlSessionFactory.openSession()) { | ||
Mapper mapper = sqlSession.getMapper(Mapper.class); | ||
List<User> users = mapper.getUsersByIdList(Arrays.asList(1, 2)); | ||
assertEquals(2, users.size()); | ||
} | ||
} | ||
|
||
@Test | ||
void shouldListParamBeReferencedByActualNameIfAnotherParamExists() { | ||
try (SqlSession sqlSession = sqlSessionFactory.openSession()) { | ||
Mapper mapper = sqlSession.getMapper(Mapper.class); | ||
List<User> users = mapper.getUsersByIdListAndName(Arrays.asList(1, 2), null); | ||
assertEquals(2, users.size()); | ||
} | ||
} | ||
|
||
} |
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,38 @@ | ||
/** | ||
* 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.submitted.duplicate_statements; | ||
|
||
public class User { | ||
|
||
private Integer id; | ||
private String name; | ||
|
||
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; | ||
} | ||
} |
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,24 @@ | ||
/** | ||
* 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.session; | ||
|
||
/** | ||
* 本地缓存作用域 | ||
* @author Eduardo Macarron | ||
*/ | ||
public enum LocalCacheScope { | ||
SESSION, STATEMENT | ||
} |
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,42 @@ | ||
/** | ||
* Copyright 2009-2016 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; | ||
|
||
/** | ||
* @author Clinton Begin | ||
*/ | ||
class ByteArrayUtils { | ||
|
||
private ByteArrayUtils() { | ||
// Prevent Instantiation | ||
} | ||
|
||
static byte[] convertToPrimitiveArray(Byte[] objects) { | ||
final byte[] bytes = new byte[objects.length]; | ||
for (int i = 0; i < objects.length; i++) { | ||
bytes[i] = objects[i]; | ||
} | ||
return bytes; | ||
} | ||
|
||
static Byte[] convertToObjectArray(byte[] bytes) { | ||
final Byte[] objects = new Byte[bytes.length]; | ||
for (int i = 0; i < bytes.length; i++) { | ||
objects[i] = bytes[i]; | ||
} | ||
return objects; | ||
} | ||
} |
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,47 @@ | ||
/** | ||
* 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.submitted.constructor_automapping; | ||
|
||
public class Article { | ||
|
||
private Integer id; | ||
private String title; | ||
private Author author; | ||
|
||
public Integer getId() { | ||
return id; | ||
} | ||
|
||
public void setId(Integer id) { | ||
this.id = id; | ||
} | ||
|
||
public String getTitle() { | ||
return title; | ||
} | ||
|
||
public void setTitle(String title) { | ||
this.title = title; | ||
} | ||
|
||
public Author getAuthor() { | ||
return author; | ||
} | ||
|
||
public void setAuthor(Author author) { | ||
this.author = author; | ||
} | ||
} |
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,38 @@ | ||
/** | ||
* Copyright 2009-2018 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.submitted.lazyload_proxyfactory_comparison; | ||
|
||
public class Group { | ||
|
||
private Integer id; | ||
private String name; | ||
|
||
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; | ||
} | ||
} |
Oops, something went wrong.