Search in sources :

Example 6 with TableModelDVO

use of kyj.Fx.dao.wizard.core.model.vo.TableModelDVO in project Gargoyle by callakrsos.

the class VoEditorController method setFromFile.

/********************************
	 * 작성일 : 2016. 7. 4. 작성자 : KYJ
	 *
	 *
	 * @param voFile
	 * @throws IOException
	 * @throws FileNotFoundException
	 ********************************/
public void setFromFile(File voFile) {
    if (voFile == null || !voFile.exists())
        return;
    if (voFile.isFile()) {
        CompilationUnit cu;
        try (FileInputStream in = new FileInputStream(voFile)) {
            // parse the file
            cu = JavaParser.parse(in);
            PackageDeclaration packageDeclaration = cu.getPackage();
            txtPackageName.setText(packageDeclaration.getName().toString());
            txtClassName.setText(voFile.getName().substring(0, voFile.getName().indexOf('.')));
            txtLocation.setText(voFile.getAbsolutePath());
            MethodVisitor methodVisitor = new MethodVisitor();
            methodVisitor.visit(cu, null);
            List<TableModelDVO> valideFieldMeta = methodVisitor.getValideFieldMeta(t -> {
                TableModelDVO tableModelDVO = new TableModelDVO();
                tableModelDVO.setName(t.getName());
                tableModelDVO.setType(t.getFieldType().getSimpleName());
                return tableModelDVO;
            });
            this.tbVoEditor.getItems().addAll(valideFieldMeta);
        } catch (IOException | ParseException e) {
            LOGGER.error(ValueUtil.toString(e));
        }
    } else {
        txtLocation.setText(voFile.getAbsolutePath());
    }
}
Also used : CompilationUnit(com.github.javaparser.ast.CompilationUnit) TableModelDVO(kyj.Fx.dao.wizard.core.model.vo.TableModelDVO) IOException(java.io.IOException) ParseException(com.github.javaparser.ParseException) FileInputStream(java.io.FileInputStream) PackageDeclaration(com.github.javaparser.ast.PackageDeclaration)

Example 7 with TableModelDVO

use of kyj.Fx.dao.wizard.core.model.vo.TableModelDVO in project Gargoyle by callakrsos.

the class VoWizardUtil method listColumns.

/**
	 * 테이블컬럼모델생성
	 *
	 * @param selectedItem
	 * @return
	 * @throws Exception
	 */
public static List<TableModelDVO> listColumns(TableMasterDVO selectedItem) throws Exception {
    DatabaseTypeMappingFunction databaseTypeMappingFunction = new DatabaseTypeMappingFunction();
    String tableName = selectedItem.getTableName();
    List<String> pks = DbUtil.pks(tableName, rs -> {
        try {
            return rs.getString(4).toLowerCase();
        } catch (SQLException e) {
            LOGGER.error(ValueUtil.toString(e));
        }
        return "";
    });
    return DbUtil.columns(tableName, rs -> {
        TableModelDVO dvo = new TableModelDVO();
        try {
            String columnName = rs.getString(4);
            String dataType = rs.getString(5);
            String typeName = rs.getString(6);
            String size = rs.getString(7);
            String remark = rs.getString(12);
            dvo.setName(ValueUtil.getPrefixLowerTextMyEdit(columnName));
            dvo.setDatabaseColumnName(columnName);
            dvo.setDabaseTypeName(typeName);
            dvo.setType(databaseTypeMappingFunction.apply(typeName));
            dvo.setPk(pks.contains(columnName.toLowerCase()) ? "Y" : "N");
            dvo.setDesc(remark);
            dvo.setSize(size);
        } catch (Exception e) {
            LOGGER.error(ValueUtil.toString(e));
        }
        return dvo;
    });
//
//		String tableName = selectedItem.getTableName();
//		String sql = ConfigResourceLoader.getInstance().get(ConfigResourceLoader.SQL_COLUMN);
//
//		/*
//		 * 2016-08-11 by kyj.
//		 *
//		 * 설정에 대한 sql항목이 없는경우 순수 jdbc 라이브러리를 이용하는 방안으로 구성.
//		 */
//		if (sql == null || sql.isEmpty()) {
//
//			List<String> pks = DbUtil.pks(tableName, rs -> {
//
//				try {
//					return rs.getString(4).toLowerCase();
//				} catch (SQLException e) {
//					LOGGER.error(ValueUtil.toString(e));
//				}
//				return "";
//			});
//
//			return DbUtil.columns(tableName, rs -> {
//
//				TableModelDVO dvo = new TableModelDVO();
//				try {
//
//					String columnName = rs.getString(4);
//					String dataType = rs.getString(5);
//					String typeName = rs.getString(6);
//					String size = rs.getString(7);
//					String remark = rs.getString(12);
//					dvo.setName(ValueUtil.getPrefixLowerTextMyEdit(columnName));
//					dvo.setDatabaseColumnName(columnName);
//					dvo.setDabaseTypeName(typeName);
//
//					dvo.setType(databaseTypeMappingFunction.apply(typeName));
//
//					dvo.setPk(pks.contains(columnName.toLowerCase()) ? "Y" : "N");
//					dvo.setDesc(remark);
//					dvo.setSize(size);
//
//				} catch (Exception e) {
//					LOGGER.error(ValueUtil.toString(e));
//				}
//
//				return dvo;
//			});
//
//		} else {
//
//			Map<String, Object> hashMap = new HashMap<String, Object>();
//			hashMap.put("tableName", tableName);
//
//			String convertedSql = ValueUtil.getVelocityToText(sql, hashMap);
//			return DbUtil.select(convertedSql, hashMap, new RowMapper<TableModelDVO>() {
//
//				@Override
//				public TableModelDVO mapRow(ResultSet rs, int rowNum) throws SQLException {
//					TableModelDVO dvo = new TableModelDVO();
//
//					String columnName = rs.getString(COLUMN_NAME);
//					dvo.setName(ValueUtil.getPrefixLowerTextMyEdit(columnName));
//					dvo.setDatabaseColumnName(columnName);
//
//					String typeName = rs.getString(TYPE);
//					dvo.setDabaseTypeName(typeName);
//
//					//				rs.getInt(columnLabel)
//					//				rs.getMetaData().getColumnTypeName()
//					dvo.setType(databaseTypeMappingFunction.apply(typeName));
//					dvo.setPk(rs.getString(PK));
//					dvo.setDesc(rs.getString(COMMENTS));
//					dvo.setSize(rs.getString(DATA_LENGTH));
//					return dvo;
//				}
//			});
//		}
}
Also used : SQLException(java.sql.SQLException) TableModelDVO(kyj.Fx.dao.wizard.core.model.vo.TableModelDVO) GargoyleFileAlreadyExistException(com.kyj.fx.voeditor.visual.exceptions.GargoyleFileAlreadyExistException) SQLException(java.sql.SQLException) DatabaseTypeMappingFunction(com.kyj.fx.voeditor.visual.functions.DatabaseTypeMappingFunction)

Example 8 with TableModelDVO

use of kyj.Fx.dao.wizard.core.model.vo.TableModelDVO in project Gargoyle by callakrsos.

the class VoWizardUtil method createExcelFile.

/**
	 * 엑셀파일생성
	 *
	 * @param pathDir
	 * @param _fileName
	 * @param models
	 * @return 생성된 엑셀파일에 대한 파일 객체
	 * @throws GargoyleFileAlreadyExistException
	 */
public static File createExcelFile(File pathDir, String _fileName, List<TableModelDVO> models, boolean isOverWrite) throws GargoyleFileAlreadyExistException {
    File saveFile = null;
    if (!pathDir.exists() || !pathDir.isDirectory())
        return saveFile;
    String fileName = _fileName;
    String createFilePathName = pathDir.getAbsolutePath() + File.separator + fileName;
    if (!_fileName.endsWith(".xlsx")) {
        createFilePathName.concat(".xlsx");
    }
    saveFile = new File(createFilePathName);
    if (saveFile.exists() && !isOverWrite) {
        throw new GargoyleFileAlreadyExistException("already exists. file");
    }
    // 로우번호 채번링
    AtomicInteger atomicInteger = new AtomicInteger(2);
    List<ExcelDataDVO> collect = models.stream().map(vo -> {
        List<ExcelDataDVO> list = new ArrayList<ExcelDataDVO>();
        String columnName = vo.getDatabaseColumnName();
        String dataType = vo.getType();
        String dataSize = vo.getSize();
        String desc = vo.getDesc();
        int row = atomicInteger.getAndIncrement();
        list.add(new ExcelDataDVO(row, 0, ValueUtil.toCamelCase(ValueUtil.decode(columnName, columnName, vo.getName()).toString())));
        list.add(new ExcelDataDVO(row, 1, dataType));
        list.add(new ExcelDataDVO(row, 2, dataSize));
        list.add(new ExcelDataDVO(row, 3, desc));
        return list;
    }).collect(() -> {
        /* 컬럼헤더처리 */
        ArrayList<ExcelDataDVO> arrayList = new ArrayList<ExcelDataDVO>();
        arrayList.add(new ExcelDataDVO(1, 0, VoWizardUtil.COLUMN_NAME, /* "컬럼명" */
        Color.GREEN));
        arrayList.add(new ExcelDataDVO(1, 1, VoWizardUtil.TYPE, /* "데이터타입" */
        Color.GREEN));
        arrayList.add(new ExcelDataDVO(1, 2, VoWizardUtil.DATA_LENGTH, /* "데이터사이즈" */
        Color.GREEN));
        arrayList.add(new ExcelDataDVO(1, 3, VoWizardUtil.COMMENTS, /* "설명" */
        Color.GREEN));
        return arrayList;
    }, (t, u) -> t.addAll(u), (t, u) -> t.addAll(u));
    ExcelSVO svo = new ExcelSVO();
    svo.addSheetExcelDVO(SHEET_NAME, collect);
    try {
        ExcelUtil.createExcel(saveFile.getAbsolutePath(), svo, false);
    } catch (Exception e1) {
        ValueUtil.toString(e1);
        saveFile = null;
    }
    return saveFile;
}
Also used : Color(java.awt.Color) TableMasterDVO(kyj.Fx.dao.wizard.core.model.vo.TableMasterDVO) ClassMeta(com.kyj.fx.voeditor.core.model.meta.ClassMeta) Logger(org.slf4j.Logger) GargoyleFileAlreadyExistException(com.kyj.fx.voeditor.visual.exceptions.GargoyleFileAlreadyExistException) LoggerFactory(org.slf4j.LoggerFactory) File(java.io.File) VoEditor(com.kyj.fx.voeditor.core.VoEditor) ArrayList(java.util.ArrayList) SQLException(java.sql.SQLException) List(java.util.List) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) TableModelDVO(kyj.Fx.dao.wizard.core.model.vo.TableModelDVO) ExcelDataDVO(com.kyj.fx.voeditor.visual.excels.base.ExcelDataDVO) ExcelSVO(com.kyj.fx.voeditor.visual.excels.base.ExcelSVO) DatabaseTypeMappingFunction(com.kyj.fx.voeditor.visual.functions.DatabaseTypeMappingFunction) ExcelDataDVO(com.kyj.fx.voeditor.visual.excels.base.ExcelDataDVO) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) GargoyleFileAlreadyExistException(com.kyj.fx.voeditor.visual.exceptions.GargoyleFileAlreadyExistException) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) ExcelSVO(com.kyj.fx.voeditor.visual.excels.base.ExcelSVO) File(java.io.File) GargoyleFileAlreadyExistException(com.kyj.fx.voeditor.visual.exceptions.GargoyleFileAlreadyExistException) SQLException(java.sql.SQLException)

Example 9 with TableModelDVO

use of kyj.Fx.dao.wizard.core.model.vo.TableModelDVO in project Gargoyle by callakrsos.

the class DatabaseTableView method initialize.

@FXML
void initialize() {
    contextMenuTbModelMst = new ContextMenu();
    txtTableName.setOnKeyReleased(event -> {
        if (KeyCode.ENTER == event.getCode()) {
            String tableName = txtTableName.getText();
            requestTables(tableName);
        }
    });
    btnSearch.setOnMouseClicked(event -> {
        String name = txtTableName.getText();
        String selectedItem = choType.getSelectionModel().getSelectedItem();
        switch(selectedItem) {
            case TYPE_TABLE:
                requestTables(name);
                break;
            case TYPE_VIEW:
                requestViews(name);
        }
    });
    tbMaster.setOnMouseClicked(event -> {
        if (event.getClickCount() == 2) {
            tbModelMst.getItems().clear();
            TableMasterDVO selectedItem = tbMaster.getSelectionModel().getSelectedItem();
            try {
                if (selectedItem == null)
                    return;
                List<TableModelDVO> list = listColumns(selectedItem);
                tbModelMst.getItems().addAll(list);
            } catch (Exception e) {
                DialogUtil.showExceptionDailog(e, "데이터베이스 처리 에러");
            }
        }
    });
    btnSelect.setOnMouseClicked(event -> {
        if (tbMaster.getItems().isEmpty() || tbModelMst.getItems().isEmpty()) {
            return;
        }
        TableMasterDVO selectedItem = tbMaster.getSelectionModel().getSelectedItem();
        ObservableList<TableModelDVO> items = tbModelMst.getItems();
        tableDVO = new TableDVO(selectedItem, items);
        close();
    });
    MenuItem menuDelete = new MenuItem("삭제");
    menuDelete.setOnAction(event -> {
        TableViewSelectionModel<TableModelDVO> selectionModel = tbModelMst.getSelectionModel();
        int selectedIndex = selectionModel.getSelectedIndex();
        if (selectedIndex >= 0) {
            tbModelMst.getItems().remove(selectedIndex);
            selectionModel.clearSelection();
        }
    });
    // MenuItem menuDistinct = new MenuItem("중복제거");
    // menuDistinct.setOnAction(event -> {
    // ObservableList<TableModelDVO> items = tbModelMst.getItems();
    // items.stream().filter(distinctByKey(new Function<TableModelDVO,
    // ObservableList<TableModelDVO>>(){
    //
    // @Override
    // public ObservableList<TableModelDVO> apply(TableModelDVO t) {
    // // TODO Auto-generated method stub
    // return null;
    // }));
    contextMenuTbModelMst.getItems().add(menuDelete);
    tbModelMst.setContextMenu(contextMenuTbModelMst);
}
Also used : TableMasterDVO(kyj.Fx.dao.wizard.core.model.vo.TableMasterDVO) TableDVO(kyj.Fx.dao.wizard.core.model.vo.TableDVO) ContextMenu(javafx.scene.control.ContextMenu) MenuItem(javafx.scene.control.MenuItem) TableModelDVO(kyj.Fx.dao.wizard.core.model.vo.TableModelDVO) SQLException(java.sql.SQLException) FXML(javafx.fxml.FXML)

Example 10 with TableModelDVO

use of kyj.Fx.dao.wizard.core.model.vo.TableModelDVO in project Gargoyle by callakrsos.

the class SimpleSQLResultView method executeSQL.

public void executeSQL(Node root) {
    LOGGER.debug("sql check....");
    if (this.sql == null || this.sql.isEmpty()) {
        return;
    }
    LOGGER.debug("param bind....");
    /* [시작] 바인드변수 맵핑시키는 테이블 */
    param.keySet().stream().forEach(key -> {
        KeyValue keyValue = new KeyValue();
        keyValue.setKey(key);
        keyValue.setValue(param.get(key));
        tbBind.getItems().add(keyValue);
    });
    /* [끝] 바인드변수 맵핑시키는 테이블 */
    String wrapperedSQL = ConfigResourceLoader.getInstance().get(ConfigResourceLoader.SQL_LIMIT_WRAPPER);
    LOGGER.debug(String.format("wrapperedSql : %s", wrapperedSQL));
    param.put(ConfigResourceLoader.USER_SQL, this.sql);
    String velocityToText = ValueUtil.getVelocityToText(wrapperedSQL, param);
    param.remove(ConfigResourceLoader.USER_SQL);
    LOGGER.debug(String.format("before velocityText %s", velocityToText));
    String sql = ValueUtil.getVelocityToText(velocityToText, param);
    LOGGER.debug(String.format("after velocityText %s", sql));
    columns = new ArrayList<>();
    try {
        // Iterator<Entry<String, Object>> iterator =
        // param.entrySet().iterator();
        MapSqlParameterSource mapSqlParameterSource = new MapSqlParameterSource(param);
        // while (iterator.hasNext()) {
        // Entry<String, Object> next = iterator.next();
        // Object value = null;
        // if (next.getValue() != null)
        // value = "'".concat(next.getValue().toString()).concat("'");
        // mapSqlParameterSource.addValue(next.getKey(), value);
        // }
        List<Map<String, Object>> select = DbUtil.select(sql, mapSqlParameterSource, (rs, row) -> {
            Map<String, Object> hashMap = new HashMap<String, Object>();
            final ResultSetMetaData metaData = rs.getMetaData();
            final int columnCount = metaData.getColumnCount();
            hashMap = new HashMap<String, Object>();
            for (int c = 1; c <= columnCount; c++) {
                String columnLabel = metaData.getColumnLabel(c);
                if (row == 0) {
                    TableModelDVO tableModelDVO = new TableModelDVO();
                    tableModelDVO.setDatabaseColumnName(columnLabel);
                    String columnTypeName = metaData.getColumnTypeName(c);
                    if ("unknown".equals(columnTypeName)) {
                        LOGGER.debug("unknown type detected....");
                        LOGGER.debug("convert varchar type...");
                        LOGGER.debug("type Number : " + metaData.getColumnType(c));
                        // TODO 잠재적인 버그가 있을 가능성이 있을지 ???? 확신이 안섬.
                        columnTypeName = "varchar";
                    }
                    tableModelDVO.setDabaseTypeName(columnTypeName);
                    columns.add(tableModelDVO);
                }
                hashMap.put(columnLabel, rs.getString(c));
            }
            return hashMap;
        });
        if (select != null && !select.isEmpty()) {
            clear();
            createColumns(columns);
            tbResult.getItems().addAll(select);
        }
    } catch (Exception e) {
        LOGGER.error(ValueUtil.toString(e));
        // DialogUtil.showConfirmDialog();
        // 에러 다이얼로그 수정.
        DialogUtil.showExceptionDailog(SharedMemory.getPrimaryStage(), e);
    }
    Iterator<String> iterator = param.keySet().iterator();
    while (iterator.hasNext()) {
        String key = iterator.next();
        Object value = param.get(key);
        if (value == null || value.toString().isEmpty())
            param.put(key, null);
        else if (value instanceof List) {
            List<Object> items = (List<Object>) value;
            // StringBuffer sb = new StringBuffer();
            // for (Object obj : items) {
            // sb.append(obj).append(",");
            // }
            // if (items != null && !items.isEmpty()) //bug fix. sb가 빈 경우
            // 에러발생.
            // sb.setLength(sb.length() - 1);
            param.put(key, items);
        } else
            param.put(key, value);
    }
    this.mappingedSqlKeywords.setContent(ValueUtil.getVelocityToText(this.sql, param, true));
    this.sqlKeywords.setContent(this.sql);
}
Also used : KeyValue(com.kyj.fx.voeditor.visual.framework.KeyValue) HashMap(java.util.HashMap) TableModelDVO(kyj.Fx.dao.wizard.core.model.vo.TableModelDVO) IOException(java.io.IOException) ResultSetMetaData(java.sql.ResultSetMetaData) MapSqlParameterSource(org.springframework.jdbc.core.namedparam.MapSqlParameterSource) ArrayList(java.util.ArrayList) List(java.util.List) ObservableList(javafx.collections.ObservableList) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

TableModelDVO (kyj.Fx.dao.wizard.core.model.vo.TableModelDVO)16 List (java.util.List)7 File (java.io.File)6 IOException (java.io.IOException)6 ArrayList (java.util.ArrayList)6 TableMasterDVO (kyj.Fx.dao.wizard.core.model.vo.TableMasterDVO)5 ClassMeta (com.kyj.fx.voeditor.core.model.meta.ClassMeta)4 GargoyleFileAlreadyExistException (com.kyj.fx.voeditor.visual.exceptions.GargoyleFileAlreadyExistException)4 DatabaseTypeMappingFunction (com.kyj.fx.voeditor.visual.functions.DatabaseTypeMappingFunction)4 ObservableList (javafx.collections.ObservableList)4 FXML (javafx.fxml.FXML)4 ParseException (com.github.javaparser.ParseException)3 FieldMeta (com.kyj.fx.voeditor.core.model.meta.FieldMeta)3 DatabaseTableView (com.kyj.fx.voeditor.visual.component.popup.DatabaseTableView)3 JavaTextView (com.kyj.fx.voeditor.visual.component.popup.JavaTextView)3 CommonContextMenuEvent (com.kyj.fx.voeditor.visual.events.CommonContextMenuEvent)3 SQLException (java.sql.SQLException)3 TableDVO (kyj.Fx.dao.wizard.core.model.vo.TableDVO)3 VoEditor (com.kyj.fx.voeditor.core.VoEditor)2 EditorUtil (com.kyj.fx.voeditor.util.EditorUtil)2