mirror of
https://gitee.com/easii/mapstruct-plus.git
synced 2025-12-07 17:48:35 +08:00
adapterClassName、mapAdapterClassName、autoMapperConfigClassName、autoMapMapperConfigClassName 默认生成规则增加自增后缀
This commit is contained in:
parent
17b94de8d7
commit
bc6a6be078
@ -1,5 +1,7 @@
|
|||||||
package io.github.linpeilie.processor;
|
package io.github.linpeilie.processor;
|
||||||
|
|
||||||
|
import io.github.linpeilie.processor.utils.FileUtils;
|
||||||
|
import io.github.linpeilie.processor.utils.IncrementMarkUtils;
|
||||||
import org.mapstruct.NullValueMappingStrategy;
|
import org.mapstruct.NullValueMappingStrategy;
|
||||||
import org.mapstruct.NullValuePropertyMappingStrategy;
|
import org.mapstruct.NullValuePropertyMappingStrategy;
|
||||||
import org.mapstruct.ReportingPolicy;
|
import org.mapstruct.ReportingPolicy;
|
||||||
@ -16,7 +18,8 @@ public class AutoMapperProperties {
|
|||||||
|
|
||||||
private static NullValueMappingStrategy nullValueMappingStrategy = NullValueMappingStrategy.RETURN_NULL;
|
private static NullValueMappingStrategy nullValueMappingStrategy = NullValueMappingStrategy.RETURN_NULL;
|
||||||
|
|
||||||
private static NullValuePropertyMappingStrategy nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.SET_TO_NULL;
|
private static NullValuePropertyMappingStrategy nullValuePropertyMappingStrategy =
|
||||||
|
NullValuePropertyMappingStrategy.SET_TO_NULL;
|
||||||
|
|
||||||
private static String buildMethod = "build";
|
private static String buildMethod = "build";
|
||||||
|
|
||||||
@ -34,6 +37,15 @@ public class AutoMapperProperties {
|
|||||||
|
|
||||||
private static String autoMapMapperConfigClassName = ContextConstants.AutoConfig.autoMapMapperConfigClassName;
|
private static String autoMapMapperConfigClassName = ContextConstants.AutoConfig.autoMapMapperConfigClassName;
|
||||||
|
|
||||||
|
static {
|
||||||
|
// load increment mark
|
||||||
|
Integer mark = IncrementMarkUtils.incrementAndGet();
|
||||||
|
adapterClassName = adapterClassName + "$" + mark;
|
||||||
|
mapAdapterClassName = mapAdapterClassName + "$" + mark;
|
||||||
|
autoMapperConfigClassName = autoMapperConfigClassName + "$" + mark;
|
||||||
|
autoMapMapperConfigClassName = autoMapMapperConfigClassName + "$" + mark;
|
||||||
|
}
|
||||||
|
|
||||||
/* ******************** getter/setter ******************** */
|
/* ******************** getter/setter ******************** */
|
||||||
|
|
||||||
public static String getMapperPackage() {
|
public static String getMapperPackage() {
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
package io.github.linpeilie.processor;
|
package io.github.linpeilie.processor;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
import org.mapstruct.MappingConstants;
|
import org.mapstruct.MappingConstants;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -94,6 +95,10 @@ public interface ContextConstants {
|
|||||||
String enumMappers = "enumMappers";
|
String enumMappers = "enumMappers";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface AutoIncrementFile {
|
||||||
|
String file = System.getProperty("user.home") + File.separator + ".msp" + File.separator + "incrementMark";
|
||||||
|
}
|
||||||
|
|
||||||
interface Map {
|
interface Map {
|
||||||
String packageName = "java.util";
|
String packageName = "java.util";
|
||||||
String className = "Map";
|
String className = "Map";
|
||||||
|
|||||||
@ -0,0 +1,66 @@
|
|||||||
|
package io.github.linpeilie.processor.utils;
|
||||||
|
|
||||||
|
import io.github.linpeilie.processor.ContextConstants;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.RandomAccessFile;
|
||||||
|
import java.io.UncheckedIOException;
|
||||||
|
import java.nio.channels.FileChannel;
|
||||||
|
import java.nio.channels.FileLock;
|
||||||
|
|
||||||
|
public class IncrementMarkUtils {
|
||||||
|
|
||||||
|
public static Integer incrementAndGet() {
|
||||||
|
int mark = 0;
|
||||||
|
RandomAccessFile randomAccessFile = null;
|
||||||
|
FileChannel channel = null;
|
||||||
|
FileLock lock = null;
|
||||||
|
try {
|
||||||
|
File file = FileUtils.touch(new File(ContextConstants.AutoIncrementFile.file));
|
||||||
|
|
||||||
|
randomAccessFile = new RandomAccessFile(file, "rw");
|
||||||
|
|
||||||
|
channel = randomAccessFile.getChannel();
|
||||||
|
|
||||||
|
// 获取文件锁
|
||||||
|
lock = channel.lock();
|
||||||
|
|
||||||
|
String line = randomAccessFile.readLine();
|
||||||
|
if (line != null && !line.isEmpty()) {
|
||||||
|
mark = Integer.parseInt(line);
|
||||||
|
mark ++;
|
||||||
|
}
|
||||||
|
|
||||||
|
randomAccessFile.setLength(0);
|
||||||
|
randomAccessFile.seek(0);
|
||||||
|
randomAccessFile.writeBytes(String.valueOf(mark));
|
||||||
|
|
||||||
|
return mark;
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new UncheckedIOException(e);
|
||||||
|
} finally {
|
||||||
|
if (lock != null && lock.isValid()) {
|
||||||
|
try {
|
||||||
|
lock.release();
|
||||||
|
} catch (IOException e) {
|
||||||
|
// ignore
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (channel != null) {
|
||||||
|
try {
|
||||||
|
channel.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
// ignore
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (randomAccessFile != null) {
|
||||||
|
try {
|
||||||
|
randomAccessFile.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
// ignore
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user