diff --git a/docs/spring/cs6236709a-6bf0-11ef-8b3e-acde48001122.java b/docs/spring/cs6236709a-6bf0-11ef-8b3e-acde48001122.java new file mode 100644 index 00000000..fac73ea2 --- /dev/null +++ b/docs/spring/cs6236709a-6bf0-11ef-8b3e-acde48001122.java @@ -0,0 +1,55 @@ +package com.huifer.security.properties; + +/** + * 描述: + * + * @author: huifer + * @date: 2019-11-17 + */ +public class ImageCodeProperties { + private int width = 67; + private int height = 23; + private int length = 4; + private int expireIn = 60; + private String url; + + public String getUrl() { + return url; + } + + public void setUrl(String url) { + this.url = url; + } + + public int getWidth() { + return width; + } + + public void setWidth(int width) { + this.width = width; + } + + public int getHeight() { + return height; + } + + public void setHeight(int height) { + this.height = height; + } + + public int getLength() { + return length; + } + + public void setLength(int length) { + this.length = length; + } + + public int getExpireIn() { + return expireIn; + } + + public void setExpireIn(int expireIn) { + this.expireIn = expireIn; + } +} diff --git a/docs/spring/cs628af4a8-6bf0-11ef-8b3e-acde48001122.java b/docs/spring/cs628af4a8-6bf0-11ef-8b3e-acde48001122.java new file mode 100644 index 00000000..d164048f --- /dev/null +++ b/docs/spring/cs628af4a8-6bf0-11ef-8b3e-acde48001122.java @@ -0,0 +1,146 @@ +package com.huifer.idgen.my.service; + +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.conv.IdConverter; +import com.huifer.idgen.my.service.conv.IdConverterImpl; +import com.huifer.idgen.my.service.factory.IdMetaFactory; +import com.huifer.idgen.my.service.provider.MachineIdProvider; +import lombok.extern.slf4j.Slf4j; + +import java.util.Date; + +/** + * @author: wang + * @description: Id生产策略父类 + */ +@Slf4j +public abstract class AbstractIdService implements GenIdService { + + + protected long machineId = -1; + protected long genMethod = 0; + protected long type = 0; + protected long version = 0; + + protected IdMeta idMeta; + protected IdType idType; + protected IdConverter idConverter; + protected MachineIdProvider machineIdProvider; + + public AbstractIdService() { + this.idType = IdType.TYPE_ONE; + } + + public AbstractIdService(String type) { + this.idType = IdType.parse(type); + } + + public AbstractIdService(IdType type) { + this.idType = type; + } + + + public void init() { + this.machineId = machineIdProvider.getMachineId(); + if (this.machineId < 0) { + throw new IllegalArgumentException("machinId > 0 "); + } + if (this.idMeta == null) { + this.idMeta = IdMetaFactory.getIdMeta(this.idType); + this.type = this.idType.value(); + } else { + if (this.idMeta.getTimeBits() == 30) { + this.type = 1L; + } else if (this.idMeta.getTimeBits() == 40) { + this.type = 0L; + } else { + throw new IdGenException("时间位在30-40之间"); + } + } + this.idConverter = new IdConverterImpl(this.idMeta); + } + + protected abstract void populateId(Id id); + + public long genId() { + Id id = new Id(); + id.setMachine(machineId); + id.setGenMethod(genMethod); + id.setType(type); + id.setVersion(version); + populateId(id); + long res = idConverter.converter(id); + log.info("id={}-->{}", id, res); + return res; + } + + public Id expId(long id) { + return idConverter.converter(id); + } + + public long makeId(long time, long seq) { + return makeId(time, seq, machineId); + } + + public long makeId(long time, long seq, long machine) { + return makeId(genMethod, time, seq, machine); + } + + public long makeId(long genMethod, long time, long seq, long machine) { + return makeId(type, genMethod, time, seq, machine); + } + + public long makeId(long type, long genMethod, long time, long seq, long machine) { + return makeId(version, type, genMethod, time, seq, machine); + } + + public long makeId(long version, long type, long genMethod, long time, long seq, long machine) { + IdType _idType = IdType.parse(type); + Id _id = new Id(machine, seq, time, genMethod, type, version); + IdConverter _idConverter = new IdConverterImpl(_idType); + return _idConverter.converter(_id); + } + + public Date transTime(long time) { + if (idType == IdType.TYPE_ONE) { + return new Date(time * 1000 + 1420041600000L); + } else if (idType == IdType.TYPE_TWO) { + return new Date(time + 1420041600000L); + } + return null; + } + + public void setMachineId(long machineId) { + this.machineId = machineId; + } + + public void setGenMethod(long genMethod) { + this.genMethod = genMethod; + } + + public void setType(long type) { + this.type = type; + } + + public void setVersion(long version) { + this.version = version; + } + + public void setIdMeta(IdMeta idMeta) { + this.idMeta = idMeta; + } + + public void setIdType(IdType idType) { + this.idType = idType; + } + + public void setIdConverter(IdConverter idConverter) { + this.idConverter = idConverter; + } + + public void setMachineIdProvider(MachineIdProvider machineIdProvider) { + this.machineIdProvider = machineIdProvider; + } +} \ No newline at end of file diff --git a/docs/spring/cs62dbf074-6bf0-11ef-8b3e-acde48001122.java b/docs/spring/cs62dbf074-6bf0-11ef-8b3e-acde48001122.java new file mode 100644 index 00000000..b6477680 --- /dev/null +++ b/docs/spring/cs62dbf074-6bf0-11ef-8b3e-acde48001122.java @@ -0,0 +1,23 @@ +package com.huifer.dubbo.server.provider; + +import org.springframework.context.support.ClassPathXmlApplicationContext; + +import java.io.IOException; + +/** + *

Title : Bootstrap

+ *

Description :

+ * + * @author huifer + * @date 2019-06-13 + */ +public class Bootstrap { + + public static void main(String[] args) throws IOException { + ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( + "META-INF/spring/dubbo-server.xml"); + context.start(); + System.in.read(); + } + +} diff --git a/docs/spring/cs6337e06e-6bf0-11ef-8b3e-acde48001122.java b/docs/spring/cs6337e06e-6bf0-11ef-8b3e-acde48001122.java new file mode 100644 index 00000000..d06731ab --- /dev/null +++ b/docs/spring/cs6337e06e-6bf0-11ef-8b3e-acde48001122.java @@ -0,0 +1,19 @@ +/** + * 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. + */ +package org.apache.ibatis.domain.blog; + +public class DraftPost extends Post { +} diff --git a/docs/spring/cs63906b80-6bf0-11ef-8b3e-acde48001122.java b/docs/spring/cs63906b80-6bf0-11ef-8b3e-acde48001122.java new file mode 100644 index 00000000..3757e5ff --- /dev/null +++ b/docs/spring/cs63906b80-6bf0-11ef-8b3e-acde48001122.java @@ -0,0 +1,73 @@ +/** + * 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.type; + +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.mockito.Mockito.*; + +class StringTypeHandlerTest extends BaseTypeHandlerTest { + + private static final TypeHandler TYPE_HANDLER = new StringTypeHandler(); + + @Override + @Test + public void shouldSetParameter() throws Exception { + TYPE_HANDLER.setParameter(ps, 1, "Hello", null); + verify(ps).setString(1, "Hello"); + } + + @Override + @Test + public void shouldGetResultFromResultSetByName() throws Exception { + when(rs.getString("column")).thenReturn("Hello"); + assertEquals("Hello", TYPE_HANDLER.getResult(rs, "column")); + verify(rs, never()).wasNull(); + } + + @Override + public void shouldGetResultNullFromResultSetByName() throws Exception { + // Unnecessary + } + + @Override + @Test + public void shouldGetResultFromResultSetByPosition() throws Exception { + when(rs.getString(1)).thenReturn("Hello"); + assertEquals("Hello", TYPE_HANDLER.getResult(rs, 1)); + verify(rs, never()).wasNull(); + } + + @Override + public void shouldGetResultNullFromResultSetByPosition() throws Exception { + // Unnecessary + } + + @Override + @Test + public void shouldGetResultFromCallableStatement() throws Exception { + when(cs.getString(1)).thenReturn("Hello"); + assertEquals("Hello", TYPE_HANDLER.getResult(cs, 1)); + verify(cs, never()).wasNull(); + } + + @Override + public void shouldGetResultNullFromCallableStatement() throws Exception { + // Unnecessary + } + +} \ No newline at end of file