Search in sources :

Example 1 with GargoyleConnectionFailException

use of com.kyj.fx.voeditor.visual.exceptions.GargoyleConnectionFailException in project Gargoyle by callakrsos.

the class SchemaItemTree method read.

/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.kyj.fx.voeditor.visual.component.sql.dbtree.commons.DatabaseItemTree
	 * #read()
	 */
@Override
public void read() throws Exception {
    String childrenSQL = getChildrenSQL(getName());
    // Connection connection = getConnection();
    // try {
    // if (childrenSQL != null && !childrenSQL.isEmpty()) {
    // List<Map<String, Object>> select = DbUtil.select(connection,
    // childrenSQL);
    // childrens = applyChildren(select);
    //
    // if (childrens == null)
    // childrens = FXCollections.observableArrayList();
    // }
    // } finally {
    // connection.close();
    // }
    Connection connection = getConnection();
    if (connection == null)
        throw new GargoyleConnectionFailException("connect fail...");
    try {
        if (childrenSQL != null && !childrenSQL.isEmpty()) {
            List<Map<String, Object>> select = DbUtil.select(connection, childrenSQL);
            childrens.addAll(applyChildren(select));
        }
        //			if (childrens == null)
        //				childrens = FXCollections.observableArrayList();
        // SQL로 불가능한 처리는 Connection을 받아 처리하도록한다.
        ObservableList<TreeItem<DatabaseItemTree<T>>> second = applyChildren(connection, getName());
        if (second != null)
            childrens.addAll(second);
    } finally {
        if (connection != null)
            connection.close();
    }
}
Also used : TreeItem(javafx.scene.control.TreeItem) Connection(java.sql.Connection) Map(java.util.Map) GargoyleConnectionFailException(com.kyj.fx.voeditor.visual.exceptions.GargoyleConnectionFailException)

Example 2 with GargoyleConnectionFailException

use of com.kyj.fx.voeditor.visual.exceptions.GargoyleConnectionFailException in project Gargoyle by callakrsos.

the class ConnectionManager method getDataSource.

public static DataSource getDataSource(String driver, String url, String id, String pass) throws Exception {
    if (dataSource == null) {
        /*2016-08-10
			 * id도 입력안하는 경우가 있음 sqlite. by kyj
			 * */
        if (ValueUtil.isEmpty(driver, url)) {
            throw new GargoyleConnectionFailException("Check 'Datatabse Settings' on the 'Configuration tab' ");
        }
        dataSource = new DataSource();
        dataSource.setDriverClassName(driver);
        dataSource.setUrl(url);
        dataSource.setUsername(id);
        dataSource.setPassword(pass);
        dataSource.setDefaultAutoCommit(false);
        dataSource.setInitialSize(2);
        dataSource.setLoginTimeout(3);
    }
    return dataSource;
}
Also used : GargoyleConnectionFailException(com.kyj.fx.voeditor.visual.exceptions.GargoyleConnectionFailException) DataSource(org.apache.tomcat.jdbc.pool.DataSource)

Example 3 with GargoyleConnectionFailException

use of com.kyj.fx.voeditor.visual.exceptions.GargoyleConnectionFailException in project Gargoyle by callakrsos.

the class DatabaseTreeNode method createNode.

/**
	 * 파일 트리를 생성하기 위한 노드를 반환한다.
	 *
	 * @Date 2015. 10. 14.
	 * @param f
	 * @return
	 * @User KYJ
	 */
public TreeItem<DatabaseItemTree<String>> createNode(final DatabaseItemTree<String> f) {
    TreeItem<DatabaseItemTree<String>> treeItem = new TreeItem<DatabaseItemTree<String>>(f) {

        private boolean isLeaf;

        private boolean isFirstTimeChildren = true;

        private boolean isFirstTimeLeaf = true;

        @Override
        public ObservableList<TreeItem<DatabaseItemTree<String>>> getChildren() {
            if (isFirstTimeChildren) {
                isFirstTimeChildren = false;
                super.getChildren().setAll(buildChildren(this));
            }
            return super.getChildren();
        }

        @Override
        public boolean isLeaf() {
            if (isFirstTimeLeaf) {
                isFirstTimeLeaf = false;
                DatabaseItemTree<String> f = getValue();
                isLeaf = (f instanceof ColumnItemTree);
            }
            return isLeaf;
        }

        private ObservableList<TreeItem<DatabaseItemTree<String>>> buildChildren(TreeItem<DatabaseItemTree<String>> treeItem) {
            DatabaseItemTree<String> f = treeItem.getValue();
            // if (treeItem.getChildren().isEmpty()) {
            if (f == null) {
                return FXCollections.emptyObservableList();
            } else {
                try {
                    f.read();
                } catch (GargoyleConnectionFailException e) {
                    LOGGER.error(ValueUtil.toString(e));
                    DialogUtil.showExceptionDailog(e);
                } catch (Exception e) {
                    LOGGER.error(ValueUtil.toString(e));
                    return FXCollections.emptyObservableList();
                }
            }
            if (f == null) {
                return FXCollections.emptyObservableList();
            }
            if (f instanceof ColumnItemTree) {
                return FXCollections.emptyObservableList();
            }
            ObservableList<TreeItem<DatabaseItemTree<String>>> files = f.getChildrens();
            if (files != null) {
                ObservableList<TreeItem<DatabaseItemTree<String>>> children = FXCollections.observableArrayList();
                for (TreeItem<DatabaseItemTree<String>> childFile : files) {
                    DatabaseItemTree<String> value = childFile.getValue();
                    TreeItem<DatabaseItemTree<String>> createNode = createNode(value);
                    children.add(createNode);
                }
                return children;
            }
            return FXCollections.emptyObservableList();
        }
    };
    Node imageNode = getGraphics(f);
    treeItem.setGraphic(imageNode);
    return treeItem;
}
Also used : TreeItem(javafx.scene.control.TreeItem) Node(javafx.scene.Node) DatabaseItemTree(com.kyj.fx.voeditor.visual.component.sql.dbtree.commons.DatabaseItemTree) ColumnItemTree(com.kyj.fx.voeditor.visual.component.sql.dbtree.commons.ColumnItemTree) GargoyleConnectionFailException(com.kyj.fx.voeditor.visual.exceptions.GargoyleConnectionFailException) GargoyleConnectionFailException(com.kyj.fx.voeditor.visual.exceptions.GargoyleConnectionFailException)

Example 4 with GargoyleConnectionFailException

use of com.kyj.fx.voeditor.visual.exceptions.GargoyleConnectionFailException in project Gargoyle by callakrsos.

the class DatabaseItemTree method read.

public void read() throws Exception {
    String childrenSQL = getChildrenSQL("");
    Connection connection = getConnection();
    if (connection == null)
        throw new GargoyleConnectionFailException("connect fail...");
    try {
        if (childrenSQL != null && !childrenSQL.isEmpty()) {
            List<Map<String, Object>> select = DbUtil.select(connection, childrenSQL);
            childrens.addAll(applyChildren(select));
        }
        //			if (childrens == null)
        //				childrens = FXCollections.observableArrayList();
        // SQL로 불가능한 처리는 Connection을 받아 처리하도록한다.
        ObservableList<TreeItem<DatabaseItemTree<T>>> second = applyChildren(connection);
        if (second != null)
            childrens.addAll(second);
    } finally {
        if (connection != null)
            connection.close();
    }
}
Also used : TreeItem(javafx.scene.control.TreeItem) Connection(java.sql.Connection) Map(java.util.Map) GargoyleConnectionFailException(com.kyj.fx.voeditor.visual.exceptions.GargoyleConnectionFailException)

Example 5 with GargoyleConnectionFailException

use of com.kyj.fx.voeditor.visual.exceptions.GargoyleConnectionFailException in project Gargoyle by callakrsos.

the class TableItemTree method read.

/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.kyj.fx.voeditor.visual.component.sql.dbtree.commons.SchemaItemTree
	 * #read()
	 */
@Override
public void read() throws Exception {
    if (parent == null)
        return;
    String childrenSQL = getChildrenSQL(parent.getName(), getName());
    // Connection connection = getConnection();
    // try {
    // if (childrenSQL != null && !childrenSQL.isEmpty()) {
    // List<Map<String, Object>> select = DbUtil.select(connection,
    // childrenSQL);
    // childrens = applyChildren(select);
    //
    // if (childrens == null)
    // childrens = FXCollections.observableArrayList();
    // }
    // } finally {
    // if (connection != null)
    // connection.close();
    // }
    Connection connection = getConnection();
    if (connection == null)
        throw new GargoyleConnectionFailException("connect fail...");
    try {
        if (childrenSQL != null && !childrenSQL.isEmpty()) {
            List<Map<String, Object>> select = DbUtil.select(connection, childrenSQL);
            childrens.addAll(applyChildren(select));
        }
        //			if (childrens == null)
        //				childrens = FXCollections.observableArrayList();
        // SQL로 불가능한 처리는 Connection을 받아 처리하도록한다.
        ObservableList<TreeItem<DatabaseItemTree<T>>> second = applyChildren(connection, parent.getName(), getName());
        if (second != null)
            childrens.addAll(second);
    } finally {
        if (connection != null)
            connection.close();
    }
}
Also used : TreeItem(javafx.scene.control.TreeItem) Connection(java.sql.Connection) Map(java.util.Map) GargoyleConnectionFailException(com.kyj.fx.voeditor.visual.exceptions.GargoyleConnectionFailException)

Aggregations

GargoyleConnectionFailException (com.kyj.fx.voeditor.visual.exceptions.GargoyleConnectionFailException)5 TreeItem (javafx.scene.control.TreeItem)4 Connection (java.sql.Connection)3 Map (java.util.Map)3 ColumnItemTree (com.kyj.fx.voeditor.visual.component.sql.dbtree.commons.ColumnItemTree)1 DatabaseItemTree (com.kyj.fx.voeditor.visual.component.sql.dbtree.commons.DatabaseItemTree)1 Node (javafx.scene.Node)1 DataSource (org.apache.tomcat.jdbc.pool.DataSource)1