use of org.mybatis.generator.api.IntrospectedTable in project mybatis-generator-gui-extension by spawpaw.
the class SCVXGeneratorPlugin method contextGenerateAdditionalJavaFiles.
@Override
public List<GeneratedJavaFile> contextGenerateAdditionalJavaFiles(IntrospectedTable introspectedTable) {
log.info(">>>> generating extra files...");
// : 2018/3/22 将 introspectedTable 转化为对象
Map<String, String> map = new HashMap<>();
for (Object o : properties.keySet()) {
map.put(o.toString(), properties.getProperty(o.toString()));
}
Table table = new Table(context, introspectedTable, map);
// : 2018/3/22 初始化context
VelocityContext templateContext = new VelocityContext();
templateContext.put("table", table);
templateContext.put("projectDir.ss", projectDir);
// 输出测试数据
String content = renderTemplateAsString("test.vm", templateContext);
log.info("hierarchical table structure: {}", content);
// : 2018/3/22 保存到指定目录
List<TemplateConfig> configs = new Yaml().loadAs(Thread.currentThread().getContextClassLoader().getResourceAsStream("config.yml"), ConfigWrapper.class).getTemplateConfig();
for (TemplateConfig config : configs) {
String template = config.getTemplate();
String destDir = config.getDestDir().replaceAll("\\.", "/");
String destPackage = config.getDestPackage();
String destFileName = config.getDestFileName();
String absPath = (projectDir == null || projectDir.isEmpty() ? "" : projectDir) + destDir + "/" + destPackage.replace(".", "/") + "/" + destFileName;
absPath = absPath.replace("//", "/");
absPath = absPath.replace("${entityName}", table.getEntityName());
absPath = absPath.replace("${basePackage}", basePackage.replace(".", "/"));
log.info("generate file `{}` from template `{}`", absPath, template);
content = renderTemplateAsString(config.getTemplate(), templateContext);
// 写入文件
try {
FileUtil.writeStringToFile(absPath, content);
} catch (IOException e) {
log.error(e.getMessage());
}
log.info("content: {}", content);
}
log.info("<<< generated extra files.");
return null;
}
use of org.mybatis.generator.api.IntrospectedTable in project generator by mybatis.
the class Context method validate.
/**
* This method does a simple validate, it makes sure that all required fields have been filled in. It does not do
* any more complex operations such as validating that database tables exist or validating that named columns exist
*
* @param errors
* the errors
*/
public void validate(List<String> errors) {
if (!stringHasValue(id)) {
//$NON-NLS-1$
errors.add(getString("ValidationError.16"));
}
if (jdbcConnectionConfiguration == null && connectionFactoryConfiguration == null) {
// must specify one
//$NON-NLS-1$
errors.add(getString("ValidationError.10", id));
} else if (jdbcConnectionConfiguration != null && connectionFactoryConfiguration != null) {
// must not specify both
//$NON-NLS-1$
errors.add(getString("ValidationError.10", id));
} else if (jdbcConnectionConfiguration != null) {
jdbcConnectionConfiguration.validate(errors);
} else {
connectionFactoryConfiguration.validate(errors);
}
if (javaModelGeneratorConfiguration == null) {
//$NON-NLS-1$
errors.add(getString("ValidationError.8", id));
} else {
javaModelGeneratorConfiguration.validate(errors, id);
}
if (javaClientGeneratorConfiguration != null) {
javaClientGeneratorConfiguration.validate(errors, id);
}
IntrospectedTable it = null;
try {
it = ObjectFactory.createIntrospectedTableForValidation(this);
} catch (Exception e) {
//$NON-NLS-1$
errors.add(getString("ValidationError.25", id));
}
if (it != null && it.requiresXMLGenerator()) {
if (sqlMapGeneratorConfiguration == null) {
//$NON-NLS-1$
errors.add(getString("ValidationError.9", id));
} else {
sqlMapGeneratorConfiguration.validate(errors, id);
}
}
if (tableConfigurations.size() == 0) {
//$NON-NLS-1$
errors.add(getString("ValidationError.3", id));
} else {
for (int i = 0; i < tableConfigurations.size(); i++) {
TableConfiguration tc = tableConfigurations.get(i);
tc.validate(errors, i);
}
}
for (PluginConfiguration pluginConfiguration : pluginConfigurations) {
pluginConfiguration.validate(errors, id);
}
}
use of org.mybatis.generator.api.IntrospectedTable in project generator by mybatis.
the class DatabaseIntrospector method calculateIntrospectedTables.
/**
* Calculate introspected tables.
*
* @param tc
* the tc
* @param columns
* the columns
* @return the list
*/
private List<IntrospectedTable> calculateIntrospectedTables(TableConfiguration tc, Map<ActualTableName, List<IntrospectedColumn>> columns) {
boolean delimitIdentifiers = tc.isDelimitIdentifiers() || stringContainsSpace(tc.getCatalog()) || stringContainsSpace(tc.getSchema()) || stringContainsSpace(tc.getTableName());
List<IntrospectedTable> answer = new ArrayList<IntrospectedTable>();
for (Map.Entry<ActualTableName, List<IntrospectedColumn>> entry : columns.entrySet()) {
ActualTableName atn = entry.getKey();
// we only use the returned catalog and schema if something was
// actually
// specified on the table configuration. If something was returned
// from the DB for these fields, but nothing was specified on the
// table
// configuration, then some sort of DB default is being returned
// and we don't want that in our SQL
FullyQualifiedTable table = new FullyQualifiedTable(stringHasValue(tc.getCatalog()) ? atn.getCatalog() : null, stringHasValue(tc.getSchema()) ? atn.getSchema() : null, atn.getTableName(), tc.getDomainObjectName(), tc.getAlias(), isTrue(tc.getProperty(PropertyRegistry.TABLE_IGNORE_QUALIFIERS_AT_RUNTIME)), tc.getProperty(PropertyRegistry.TABLE_RUNTIME_CATALOG), tc.getProperty(PropertyRegistry.TABLE_RUNTIME_SCHEMA), tc.getProperty(PropertyRegistry.TABLE_RUNTIME_TABLE_NAME), delimitIdentifiers, context);
IntrospectedTable introspectedTable = ObjectFactory.createIntrospectedTable(tc, table, context);
for (IntrospectedColumn introspectedColumn : entry.getValue()) {
introspectedTable.addColumn(introspectedColumn);
}
calculatePrimaryKey(table, introspectedTable);
enhanceIntrospectedTable(introspectedTable);
answer.add(introspectedTable);
}
return answer;
}
Aggregations