All Downloads are FREE. Search and download functionalities are using the official Maven repository.
Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
shz.generator.DefaultGenerator Maven / Gradle / Ivy
package shz.generator;
import shz.core.*;
import shz.core.cl.ClassLoaderHelp;
import shz.generator.module.*;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.text.Collator;
import java.util.*;
public abstract class DefaultGenerator extends Generator {
protected final Properties properties;
protected DefaultGenerator(Properties properties) {
this.properties = properties;
}
@Override
protected final Connection conn() {
Properties prop = new Properties();
prop.putAll(properties);
prop.put("useInformationSchema", "true");
prop.put("remarksReporting", "true");
String url = prop.getProperty("url");
try {
return DriverManager.getConnection(url, prop);
} catch (SQLException e) {
ClassLoaderHelp.load(prop.getProperty("driverClassName"));
}
try {
return DriverManager.getConnection(url, prop);
} catch (SQLException e) {
throw PRException.of(e);
}
}
/**
* 拼接java文件内容
*/
private void append(Tgp tgp, GenInfo genInfo, List data, Class extends AppendData> cls) {
AppendData appendData = BeanHelp.of(cls);
appendData.generator = this;
data.add("package " + genInfo.packageName + ";\n");
Set imports = new HashSet<>();
List annotations = appendData.annotations(tgp, imports);
String classStr = appendData.cls(tgp, imports);
List content = appendData.content(tgp, imports);
if (!imports.isEmpty()) {
List sort = sort(imports);
sort.set(sort.size() - 1, sort.get(sort.size() - 1) + "\n");
data.addAll(sort);
}
String comment = appendData.comment(tgp.table);
if (NullHelp.nonBlank(comment)) data.add(comment);
data.addAll(annotations);
data.add(classStr + " {");
data.addAll(content);
data.add("}");
}
/**
* 对imports行进行排序
*/
private List sort(Collection collection) {
List list = ToList.explicitCollect(collection.stream(), collection.size());
list.sort(Collator.getInstance(Locale.ENGLISH));
return list;
}
@Override
protected final void appendEntityData(Tgp tgp, List data) {
append(tgp, tgp.entityGenInfo, data, appendEntityCls());
}
protected Class extends AppendEntityData> appendEntityCls() {
return AppendEntityData.class;
}
@Override
protected final void appendVoData(Tgp tgp, List data) {
append(tgp, tgp.voGenInfo, data, appendVoCls());
}
protected Class extends AppendVoData> appendVoCls() {
return AppendVoData.class;
}
@Override
protected final void appendApiData(Tgp tgp, List data) {
append(tgp, tgp.apiGenInfo, data, appendApiCls());
}
protected Class extends AppendApiData> appendApiCls() {
return AppendApiData.class;
}
@Override
protected final void appendServiceData(Tgp tgp, List data) {
append(tgp, tgp.serviceGenInfo, data, appendServiceCls());
}
protected Class extends AppendServiceData> appendServiceCls() {
return AppendServiceData.class;
}
@Override
protected final void appendServiceImplData(Tgp tgp, List data) {
append(tgp, tgp.serviceImplGenInfo, data, appendServiceImplCls());
}
protected Class extends AppendServiceImplData> appendServiceImplCls() {
return AppendServiceImplData.class;
}
@Override
protected final void appendRepositoryData(Tgp tgp, List data) {
append(tgp, tgp.repositoryGenInfo, data, appendRepositoryCls());
}
protected Class extends AppendRepositoryData> appendRepositoryCls() {
return AppendRepositoryData.class;
}
@Override
protected final void appendControllerData(Tgp tgp, List data) {
append(tgp, tgp.controllerGenInfo, data, appendControllerCls());
}
protected Class extends AppendControllerData> appendControllerCls() {
return AppendControllerData.class;
}
@Override
protected final void appendApiClientData(Tgp tgp, List data) {
append(tgp, tgp.apiClientGenInfo, data, appendApiClientCls());
}
protected Class extends AppendApiClientData> appendApiClientCls() {
return AppendApiClientData.class;
}
@Override
protected final void appendApiClientFallbackData(Tgp tgp, List data) {
append(tgp, tgp.apiClientFallbackGenInfo, data, appendApiClientFallbackCls());
}
protected Class extends AppendApiClientFallbackData> appendApiClientFallbackCls() {
return AppendApiClientFallbackData.class;
}
}