-
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
495 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,85 @@ | ||
/** | ||
* 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.array_type_handler; | ||
|
||
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.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.io.Reader; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNull; | ||
|
||
public class ArrayTypeHandlerTest { | ||
|
||
private SqlSessionFactory sqlSessionFactory; | ||
|
||
@BeforeEach | ||
public void setUp() throws Exception { | ||
try (Reader reader = Resources | ||
.getResourceAsReader("org/apache/ibatis/submitted/array_type_handler/mybatis-config.xml")) { | ||
sqlSessionFactory = new SqlSessionFactoryBuilder().build(reader); | ||
} | ||
|
||
BaseDataTest.runScript(sqlSessionFactory.getConfiguration().getEnvironment().getDataSource(), | ||
"org/apache/ibatis/submitted/array_type_handler/CreateDB.sql"); | ||
} | ||
|
||
@Test | ||
public void shouldInsertArrayValue() throws Exception { | ||
try (SqlSession sqlSession = sqlSessionFactory.openSession()) { | ||
User user = new User(); | ||
user.setId(1); | ||
user.setName("User 1"); | ||
user.setNicknames(new String[]{"User", "one"}); | ||
|
||
Mapper mapper = sqlSession.getMapper(Mapper.class); | ||
mapper.insert(user); | ||
sqlSession.commit(); | ||
|
||
int usersInDatabase = mapper.getUserCount(); | ||
assertEquals(1, usersInDatabase); | ||
|
||
Integer nicknameCount = mapper.getNicknameCount(); | ||
assertEquals(2, nicknameCount); | ||
} | ||
} | ||
|
||
@Test | ||
public void shouldInsertNullValue() throws Exception { | ||
try (SqlSession sqlSession = sqlSessionFactory.openSession()) { | ||
User user = new User(); | ||
user.setId(1); | ||
user.setName("User 1"); | ||
// note how the user does not have nicknames | ||
|
||
Mapper mapper = sqlSession.getMapper(Mapper.class); | ||
mapper.insert(user); | ||
sqlSession.commit(); | ||
|
||
int usersInDatabase = mapper.getUserCount(); | ||
assertEquals(1, usersInDatabase); | ||
|
||
Integer nicknameCount = mapper.getNicknameCount(); | ||
assertNull(nicknameCount); | ||
} | ||
} | ||
} |
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,22 @@ | ||
package com.github.huifer.ctrpluginexample.api; | ||
|
||
import com.github.huifer.ctrpluginexample.entity.AppEntity; | ||
import com.github.huifer.ctrpluginexample.req.AppAddParam; | ||
|
||
public class InsertOrUpdateConvertImpl implements | ||
InsertOrUpdateConvert<AppAddParam, AppAddParam, AppEntity> { | ||
|
||
@Override | ||
public AppEntity fromInsType(AppAddParam appAddParam) { | ||
AppEntity appEntity = new AppEntity(); | ||
appEntity.setName(appAddParam.getName() + "111"); | ||
return appEntity; | ||
} | ||
|
||
@Override | ||
public AppEntity fromUpType(AppAddParam appAddParam) { | ||
AppEntity appEntity = new AppEntity(); | ||
|
||
return appEntity; | ||
} | ||
} |
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,70 @@ | ||
package com.huifer.idgen.my.service.conv; | ||
|
||
import com.huifer.idgen.my.service.bean.Id; | ||
import com.huifer.idgen.my.service.bean.IdMeta; | ||
import com.huifer.idgen.my.service.bean.enums.IdType; | ||
import com.huifer.idgen.my.service.factory.IdMetaFactory; | ||
|
||
/** | ||
* @author: wang | ||
* @description: | ||
*/ | ||
public class IdConverterImpl implements IdConverter { | ||
|
||
private IdMeta idMeta; | ||
|
||
public IdConverterImpl(IdType idType) { | ||
this(IdMetaFactory.getIdMeta(idType)); | ||
} | ||
|
||
public IdConverterImpl(IdMeta idMeta) { | ||
this.idMeta = idMeta; | ||
} | ||
|
||
|
||
@Override | ||
public long converter(Id id) { | ||
return doConverter(id, this.idMeta); | ||
} | ||
|
||
@Override | ||
public Id converter(long id) { | ||
return doConvert(id, idMeta); | ||
} | ||
|
||
/** | ||
* 根据id生产,根据id元数据生产一个long类型的id | ||
* | ||
* @param id | ||
* @param idMeta | ||
* @return | ||
*/ | ||
protected long doConverter(Id id, IdMeta idMeta) { | ||
long res = 0; | ||
res |= id.getMachine(); | ||
res |= id.getSeq() << idMeta.getMachineBits(); | ||
res |= id.getTime() << idMeta.getTimeBitsStartPos(); | ||
res |= id.getGenMethod() << idMeta.getGenMethodBitsStartPos(); | ||
res |= id.getType() << idMeta.getTypeBitsStartPos(); | ||
res |= id.getVersion() << idMeta.getVersionBitsStartPos(); | ||
return res; | ||
} | ||
|
||
/** | ||
* 根据long类型id,根据id元数据返回这个id的意义 | ||
* | ||
* @param id | ||
* @param idMeta | ||
* @return | ||
*/ | ||
protected Id doConvert(long id, IdMeta idMeta) { | ||
Id res = new Id(); | ||
res.setMachine(id & idMeta.getMachineBitsMask()); | ||
res.setSeq((id >>> idMeta.getMachineBits()) & idMeta.getSeqBitsMask()); | ||
res.setTime((id >>> idMeta.getTimeBitsStartPos()) & idMeta.getTimeBitsMask()); | ||
res.setGenMethod((id >>> idMeta.getGenMethodBitsStartPos()) & idMeta.getGenMethodBitsMask()); | ||
res.setType((id >>> idMeta.getTypeBitsStartPos()) & idMeta.getTypeBitsMask()); | ||
res.setVersion((id >>> idMeta.getVersionBitsStartPos()) & idMeta.getVersionBitsMask()); | ||
return res; | ||
} | ||
} |
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,11 @@ | ||
package com.github.huifer.full.shiro.model.req.company; | ||
|
||
import lombok.Data; | ||
|
||
@Data | ||
public class CompanyCreateParam { | ||
private String name; | ||
|
||
private String address; | ||
|
||
} |
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,28 @@ | ||
/** | ||
* 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.resolution.javamethods; | ||
|
||
import org.apache.ibatis.annotations.CacheNamespace; | ||
import org.apache.ibatis.annotations.ResultMap; | ||
import org.apache.ibatis.annotations.Select; | ||
import org.apache.ibatis.submitted.resolution.User; | ||
|
||
@CacheNamespace | ||
public interface MapperC { | ||
@ResultMap("org.apache.ibatis.submitted.resolution.javamethods.MapperA.userRM") | ||
@Select("select * from users where id = #{id}") | ||
User getUser(Integer id); | ||
} |
117 changes: 117 additions & 0 deletions
117
docs/spring/csc492368e-68cb-11ef-9292-acde48001122.java
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,117 @@ | ||
/* | ||
* Copyright 2007-present 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 | ||
* | ||
* https://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. | ||
*/ | ||
import java.net.*; | ||
import java.io.*; | ||
import java.nio.channels.*; | ||
import java.util.Properties; | ||
|
||
public class MavenWrapperDownloader { | ||
|
||
private static final String WRAPPER_VERSION = "0.5.6"; | ||
/** | ||
* Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided. | ||
*/ | ||
private static final String DEFAULT_DOWNLOAD_URL = "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/" | ||
+ WRAPPER_VERSION + "/maven-wrapper-" + WRAPPER_VERSION + ".jar"; | ||
|
||
/** | ||
* Path to the maven-wrapper.properties file, which might contain a downloadUrl property to | ||
* use instead of the default one. | ||
*/ | ||
private static final String MAVEN_WRAPPER_PROPERTIES_PATH = | ||
".mvn/wrapper/maven-wrapper.properties"; | ||
|
||
/** | ||
* Path where the maven-wrapper.jar will be saved to. | ||
*/ | ||
private static final String MAVEN_WRAPPER_JAR_PATH = | ||
".mvn/wrapper/maven-wrapper.jar"; | ||
|
||
/** | ||
* Name of the property which should be used to override the default download url for the wrapper. | ||
*/ | ||
private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl"; | ||
|
||
public static void main(String args[]) { | ||
System.out.println("- Downloader started"); | ||
File baseDirectory = new File(args[0]); | ||
System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath()); | ||
|
||
// If the maven-wrapper.properties exists, read it and check if it contains a custom | ||
// wrapperUrl parameter. | ||
File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH); | ||
String url = DEFAULT_DOWNLOAD_URL; | ||
if(mavenWrapperPropertyFile.exists()) { | ||
FileInputStream mavenWrapperPropertyFileInputStream = null; | ||
try { | ||
mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile); | ||
Properties mavenWrapperProperties = new Properties(); | ||
mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream); | ||
url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url); | ||
} catch (IOException e) { | ||
System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'"); | ||
} finally { | ||
try { | ||
if(mavenWrapperPropertyFileInputStream != null) { | ||
mavenWrapperPropertyFileInputStream.close(); | ||
} | ||
} catch (IOException e) { | ||
// Ignore ... | ||
} | ||
} | ||
} | ||
System.out.println("- Downloading from: " + url); | ||
|
||
File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH); | ||
if(!outputFile.getParentFile().exists()) { | ||
if(!outputFile.getParentFile().mkdirs()) { | ||
System.out.println( | ||
"- ERROR creating output directory '" + outputFile.getParentFile().getAbsolutePath() + "'"); | ||
} | ||
} | ||
System.out.println("- Downloading to: " + outputFile.getAbsolutePath()); | ||
try { | ||
downloadFileFromURL(url, outputFile); | ||
System.out.println("Done"); | ||
System.exit(0); | ||
} catch (Throwable e) { | ||
System.out.println("- Error downloading"); | ||
e.printStackTrace(); | ||
System.exit(1); | ||
} | ||
} | ||
|
||
private static void downloadFileFromURL(String urlString, File destination) throws Exception { | ||
if (System.getenv("MVNW_USERNAME") != null && System.getenv("MVNW_PASSWORD") != null) { | ||
String username = System.getenv("MVNW_USERNAME"); | ||
char[] password = System.getenv("MVNW_PASSWORD").toCharArray(); | ||
Authenticator.setDefault(new Authenticator() { | ||
@Override | ||
protected PasswordAuthentication getPasswordAuthentication() { | ||
return new PasswordAuthentication(username, password); | ||
} | ||
}); | ||
} | ||
URL website = new URL(urlString); | ||
ReadableByteChannel rbc; | ||
rbc = Channels.newChannel(website.openStream()); | ||
FileOutputStream fos = new FileOutputStream(destination); | ||
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); | ||
fos.close(); | ||
rbc.close(); | ||
} | ||
|
||
} |
Oops, something went wrong.