|
@@ -19,45 +19,48 @@ import com.yonge.toolset.crud.core.db.model.Table;
|
|
|
@SpringBootApplication
|
|
|
public class CodegenApplication {
|
|
|
|
|
|
- public static void main(String[] args) throws JAXBException {
|
|
|
- //SpringApplication.run(CodegenApplication.class, args);
|
|
|
-
|
|
|
- /*
|
|
|
- * Configuration config = new Configuration("oracle.jdbc.driver.OracleDriver", "jdbc:oracle:thin:@192.168.10.134:1521:orcl", "margin_gy",
|
|
|
- * "margin_gy", null, "margin_gy");
|
|
|
- */
|
|
|
-
|
|
|
- // "src/generateConfigration.xml"
|
|
|
- GenerateConfiguration genConfig = toObject("src/main/resources/generateConfigration.xml", GenerateConfiguration.class);
|
|
|
-
|
|
|
- Configuration config = genConfig.getDbConfiguration();
|
|
|
-
|
|
|
- CrudSessionFactory sessionFactory = config.buildCrudSessionFactory();
|
|
|
- CrudSession session = sessionFactory.openSession();
|
|
|
- List<Table> tables = session.getTables();
|
|
|
- String srcBase = genConfig.getSrcBase();
|
|
|
- String pojoPackageName = genConfig.getPojoPackageName();
|
|
|
- String daoPackageName = genConfig.getDaoPackageName();
|
|
|
- String servicePackageName = genConfig.getServicePackageName();
|
|
|
- String sqlmapPackageName = genConfig.getSqlmapPackageName();
|
|
|
- String sqlmapConfigPackageName = genConfig.getSqlmapConfigPackageName();
|
|
|
- for (Table table : tables) {
|
|
|
- try {
|
|
|
- session.reverse(table, srcBase, pojoPackageName, sqlmapPackageName, daoPackageName, servicePackageName);
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- }
|
|
|
- // 生成sqlmapConfig
|
|
|
- session.generateSqlmapConfig(tables, srcBase, sqlmapConfigPackageName, sqlmapPackageName);
|
|
|
- session.closeSession();
|
|
|
- }
|
|
|
-
|
|
|
- public static <T> T toObject(String systemId, Class<T> clazz) throws JAXBException {
|
|
|
- JAXBContext jc = JAXBContext.newInstance(clazz);
|
|
|
- Unmarshaller unmarshaller = jc.createUnmarshaller();
|
|
|
- StreamSource xml = new StreamSource(systemId);
|
|
|
- JAXBElement<T> je = unmarshaller.unmarshal(xml, clazz);
|
|
|
- return je.getValue();
|
|
|
- }
|
|
|
+ public static void main(String[] args) throws JAXBException {
|
|
|
+ String path = Thread.currentThread().getContextClassLoader().getResource("").getPath();
|
|
|
+
|
|
|
+ //SpringApplication.run(CodegenApplication.class, args);
|
|
|
+
|
|
|
+ /*
|
|
|
+ * Configuration config = new Configuration("oracle.jdbc.driver.OracleDriver", "jdbc:oracle:thin:@192.168.10.134:1521:orcl", "margin_gy",
|
|
|
+ * "margin_gy", null, "margin_gy");
|
|
|
+ */
|
|
|
+
|
|
|
+ // "src/generateConfigration.xml"
|
|
|
+ //GenerateConfiguration genConfig = toObject("src/main/resources/generateConfigration.xml", GenerateConfiguration.class);
|
|
|
+ GenerateConfiguration genConfig = toObject(path + "/generateConfigration.xml", GenerateConfiguration.class);
|
|
|
+
|
|
|
+ Configuration config = genConfig.getDbConfiguration();
|
|
|
+
|
|
|
+ CrudSessionFactory sessionFactory = config.buildCrudSessionFactory();
|
|
|
+ CrudSession session = sessionFactory.openSession();
|
|
|
+ List<Table> tables = session.getTables();
|
|
|
+ String srcBase = genConfig.getSrcBase();
|
|
|
+ String pojoPackageName = genConfig.getPojoPackageName();
|
|
|
+ String daoPackageName = genConfig.getDaoPackageName();
|
|
|
+ String servicePackageName = genConfig.getServicePackageName();
|
|
|
+ String sqlmapPackageName = genConfig.getSqlmapPackageName();
|
|
|
+ String sqlmapConfigPackageName = genConfig.getSqlmapConfigPackageName();
|
|
|
+ for (Table table : tables) {
|
|
|
+ try {
|
|
|
+ session.reverse(table, srcBase, pojoPackageName, sqlmapPackageName, daoPackageName, servicePackageName);
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 生成sqlmapConfig
|
|
|
+ session.generateSqlmapConfig(tables, srcBase, sqlmapConfigPackageName, sqlmapPackageName);
|
|
|
+ session.closeSession();
|
|
|
+ }
|
|
|
+
|
|
|
+ public static <T> T toObject(String systemId, Class<T> clazz) throws JAXBException {
|
|
|
+ JAXBContext jc = JAXBContext.newInstance(clazz);
|
|
|
+ Unmarshaller unmarshaller = jc.createUnmarshaller();
|
|
|
+ StreamSource xml = new StreamSource(systemId);
|
|
|
+ JAXBElement<T> je = unmarshaller.unmarshal(xml, clazz);
|
|
|
+ return je.getValue();
|
|
|
+ }
|
|
|
}
|