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.
* 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 com.mybatisflex.codegen;
import com.mybatisflex.codegen.config.GlobalConfig;
import com.mybatisflex.codegen.config.StrategyConfig;
import com.mybatisflex.codegen.dialect.IDialect;
import com.mybatisflex.codegen.entity.Table;
import com.mybatisflex.codegen.generator.GeneratorFactory;
import com.mybatisflex.codegen.generator.IGenerator;
import javax.sql.DataSource;
import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;
/**
* 代码生成器。
*
* @author michael
*/
public class Generator {
protected DataSource dataSource;
protected GlobalConfig globalConfig;
protected IDialect dialect = IDialect.DEFAULT;
public Generator(DataSource dataSource, GlobalConfig globalConfig) {
this.dataSource = dataSource;
this.globalConfig = globalConfig;
}
public Generator(DataSource dataSource, GlobalConfig globalConfig, IDialect dialect) {
this.dataSource = dataSource;
this.globalConfig = globalConfig;
this.dialect = dialect;
}
public void generate() {
generate(getTables());
}
public void generate(List
tables) {
if (tables == null || tables.isEmpty()) {
System.err.printf("table %s not found.%n", globalConfig.getGenerateTables());
return;
} else {
System.out.printf("find tables: %s%n", tables.stream().map(Table::getName).collect(Collectors.toSet()));
}
for (Table table : tables) {
Collection generators = GeneratorFactory.getGenerators();
for (IGenerator generator : generators) {
generator.generate(table, globalConfig);
}
}
System.out.println("Code is generated successfully.");
}
public List