use of com.kyj.fx.voeditor.visual.exceptions.GargoyleException in project Gargoyle by callakrsos.
the class SAXPasrerUtil method saveXml.
// private static final Logger LOGGER =
// LoggerFactory.getLogger(SAXPasrerUtil.class);
/**
* 특정객체를 파일로 저장
*
* 단.. 클래스에 XmlRootElement 어노테이션이 붙어 있을것
*
* @작성자 : KYJ
* @작성일 : 2016. 3. 16.
* @param file
* @param job
* @throws JAXBException
* @throws GargoyleException
*/
public static <T> void saveXml(File file, T job) throws JAXBException, GargoyleException {
if (job.getClass().getAnnotation(XmlRootElement.class) == null)
throw new GargoyleException("this object is not contains XmlRootElement annotation");
JAXBContext context = JAXBContext.newInstance(job.getClass());
Marshaller m = context.createMarshaller();
m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
m.marshal(job, file);
}
use of com.kyj.fx.voeditor.visual.exceptions.GargoyleException in project Gargoyle by callakrsos.
the class DbUtil method tables.
/********************************
* 작성일 : 2016. 8. 11. 작성자 : KYJ
*
* 2016-11-10
* 모든 테이블탐색후 대소문자무시 검색으로 수정
*</br>
*</br>
1.TABLE_CAT String => table catalog (may be null) </br>
2.TABLE_SCHEM String => table schema (may be null) </br>
3.TABLE_NAME String => table name </br>
4.TABLE_TYPE String => table type. Typical types are "TABLE", "VIEW", "SYSTEM TABLE", "GLOBAL TEMPORARY", "LOCAL TEMPORARY", "ALIAS", "SYNONYM". </br>
5.REMARKS String => explanatory comment on the table </br>
6.TYPE_CAT String => the types catalog (may be null) </br>
7.TYPE_SCHEM String => the types schema (may be null) </br>
8.TYPE_NAME String => type name (may be null) </br>
9.SELF_REFERENCING_COL_NAME String => name of the designated "identifier" column of a typed table (may be null) </br>
10.REF_GENERATION String => specifies how values in SELF_REFERENCING_COL_NAME are created. Values are "SYSTEM", "USER", "DERIVED". (may be null) </br>
* @param converter
* @return
* @throws Exception
********************************/
public static <T> List<T> tables(String tableNamePattern, Function<ResultSet, T> converter) throws Exception {
if (converter == null)
throw new GargoyleException(GargoyleException.ERROR_CODE.PARAMETER_EMPTY, "converter is null ");
List<T> tables = new ArrayList<>();
try (Connection connection = getConnection()) {
DatabaseMetaData metaData = connection.getMetaData();
ResultSet rs = metaData.getTables(null, null, "%", /* + tableNamePattern + "%"*/
new String[] { "TABLE" });
String tableNamePatternUpperCase = tableNamePattern.toUpperCase();
while (rs.next()) {
// 2016-08-18 특정데이터베이스(sqlite)에서는 인덱스 트리거정보도 동시에 출력된다.
String tableType = rs.getString(4);
if ("TABLE".equals(tableType)) {
String tableName = rs.getString(3);
if (tableName.toUpperCase().indexOf(tableNamePatternUpperCase) != -1) {
T apply = converter.apply(rs);
if (apply != null)
tables.add(apply);
}
}
}
}
return tables;
}
use of com.kyj.fx.voeditor.visual.exceptions.GargoyleException in project Gargoyle by callakrsos.
the class DbUtil method columns.
/**
1. TABLE_CAT String => table catalog (may be null) </br>
2.TABLE_SCHEM String => table schema (may be null) </br>
3.TABLE_NAME String => table name </br>
4.COLUMN_NAME String => column name </br>
5.DATA_TYPE int => SQL type from java.sql.Types </br>
6.TYPE_NAME String => Data source dependent type name, for a UDT the type name is fully qualified </br>
7.COLUMN_SIZE int => column size. </br>
8.BUFFER_LENGTH is not used. </br>
9.DECIMAL_DIGITS int => the number of fractional digits. Null is returned for data types where DECIMAL_DIGITS is not applicable. </br>
10.NUM_PREC_RADIX int => Radix (typically either 10 or 2) </br>
11.NULLABLE int => is NULL allowed. ◦ columnNoNulls - might not allow NULL values </br>
◦ columnNullable - definitely allows NULL values </br>
◦ columnNullableUnknown - nullability unknown </br>
</br>
12.REMARKS String => comment describing column (may be null) </br>
13.COLUMN_DEF String => default value for the column, which should be interpreted as a string when the value is enclosed in single quotes (may be null) </br>
14.SQL_DATA_TYPE int => unused </br>
15.SQL_DATETIME_SUB int => unused </br>
16.CHAR_OCTET_LENGTH int => for char types the maximum number of bytes in the column </br>
17.ORDINAL_POSITION int => index of column in table (starting at 1) </br>
18.IS_NULLABLE String => ISO rules are used to determine the nullability for a column. ◦ YES --- if the column can include NULLs </br>
◦ NO --- if the column cannot include NULLs </br>
◦ empty string --- if the nullability for the column is unknown </br>
</br>
19.SCOPE_CATALOG String => catalog of table that is the scope of a reference attribute (null if DATA_TYPE isn't REF) </br>
20.SCOPE_SCHEMA String => schema of table that is the scope of a reference attribute (null if the DATA_TYPE isn't REF) </br>
21.SCOPE_TABLE String => table name that this the scope of a reference attribute (null if the DATA_TYPE isn't REF) </br>
22.SOURCE_DATA_TYPE short => source type of a distinct type or user-generated Ref type, SQL type from java.sql.Types (null if DATA_TYPE isn't DISTINCT or user-generated REF) </br>
23.IS_AUTOINCREMENT String => Indicates whether this column is auto incremented ◦ YES --- if the column is auto incremented </br>
◦ NO --- if the column is not auto incremented </br>
◦ empty string --- if it cannot be determined whether the column is auto incremented </br>
</br>
24.IS_GENERATEDCOLUMN String => Indicates whether this is a generated column ◦ YES --- if this a generated column </br>
◦ NO --- if this not a generated column </br>
◦ empty string --- if it cannot be determined whether this is a generated column </br>
* @작성자 : KYJ
* @작성일 : 2016. 11. 10.
* @param connection
* @param tableNamePattern
* @param converter
* @return
* @throws Exception
*/
public static <T> List<T> columns(Connection connection, String tableNamePattern, Function<ResultSet, T> converter) throws Exception {
if (converter == null)
throw new GargoyleException(GargoyleException.ERROR_CODE.PARAMETER_EMPTY, "converter is null ");
List<T> tables = new ArrayList<>();
// try (Connection connection = getConnection()) {
DatabaseMetaData metaData = connection.getMetaData();
// metaData.getColumns(null,
ResultSet rs = COLUMN_CONVERTER.apply(tableNamePattern, metaData);
while (rs.next()) {
tables.add(converter.apply(rs));
}
return tables;
}
use of com.kyj.fx.voeditor.visual.exceptions.GargoyleException in project Gargoyle by callakrsos.
the class FxExcelUtil method createExcel.
/**
* 엑셀파일을 생성한다.
* @작성자 : KYJ
* @작성일 : 2016. 9. 6.
*
* @param exportExcelFile
* export하려는 파일 확장자는 .xlsx 사용 권고
*
* @param dataSource
* 데이터셋. 개발자 혼동(순서)을 피하기 위해 LinkedMap(순서유지)을 강제적으로 사용
* 값은 Map<Sheet명, Map<컬럼메타,List<값>> 순 매핑이되어있다.
*
* @param handler
* 데이터 컨버터, 데이터내에 특화가 필요한 처리가 필요한경우 구현하여 사용하도록한다.
*
* @throws Exception
*/
public static void createExcel(File exportExcelFile, LinkedHashMap<String, LinkedHashMap<ExcelColumnExpression, List<Object>>> dataSource, IExcelDataSetHandler<Sheet, LinkedHashMap<ExcelColumnExpression, List<Object>>> handler, Map<String, Map<String, String>> metadata, boolean overwrite) throws Exception {
//파일이 이미 존재하는 상황에서 overrite하려는 경우 에러.
if (exportExcelFile.exists() && !overwrite) {
throw new GargoyleException(String.format("output File : {%s} already exists.!", exportExcelFile.getName()));
}
Workbook createNewWorkBookXlsx = createNewWorkBookXlsx();
//시트를 의미하는 iterator.
Iterator<String> iterator = dataSource.keySet().iterator();
int sheetIndex = 0;
while (iterator.hasNext()) {
String sheetName = iterator.next();
Sheet createSheet = createNewWorkBookXlsx.createSheet(sheetName);
Map<String, String> meta = metadata.get(sheetName);
if (meta == null || meta.isEmpty())
continue;
//각 헤더컬럼의 개수(높이)
String columnMaxHeight = meta.get($$META_COLUMN_MAX_HEIGHT$$);
int maxColumnRowSize = ValueUtil.decode(columnMaxHeight, val -> Integer.parseInt(val), () -> 0);
LinkedHashMap<ExcelColumnExpression, List<Object>> linkedHashMap = dataSource.get(sheetName);
createHeaders(handler, createSheet, linkedHashMap, maxColumnRowSize);
//컬럼 + 데이터리스트로 이루어진 데이터셋
LinkedHashMap<ExcelColumnExpression, List<Object>> dataSet = dataSource.get(sheetName);
drawBody(handler, createSheet, maxColumnRowSize, dataSet);
//(short) (createSheet.getRow(maxColumnRowSize + 1).getLastCellNum() - 1);
short lastColumnNum = (short) dataSet.size();
IExcelScreenHandler screenHandler = handler.getExcelScreenHandler();
if (handler.isApplyAutoFit()) {
for (int i = 0; i < lastColumnNum; i++) {
createSheet.autoSizeColumn(i);
}
}
if (screenHandler != null) {
//사용자 정의 sheet 처리를 지원한다.
screenHandler.customSheetHandle(sheetIndex, createSheet);
sheetIndex++;
}
//로고 이미지 처리.
Utils.createDefaultLogo(createSheet);
createSheet.setAutoFilter(new CellRangeAddress((maxColumnRowSize), (maxColumnRowSize), START_COLUMN_INDEX, lastColumnNum));
createSheet.createFreezePane(0, (maxColumnRowSize + 1));
}
//사용자 정의 workbook 처리를 지원함.
IExcelScreenHandler excelScreenHandler = handler.getExcelScreenHandler();
if (excelScreenHandler != null)
excelScreenHandler.customWorkbookHandle(createNewWorkBookXlsx);
//파일 write처리.
try (FileOutputStream fileOutputStream = new FileOutputStream(exportExcelFile)) {
createNewWorkBookXlsx.write(fileOutputStream);
}
}
use of com.kyj.fx.voeditor.visual.exceptions.GargoyleException in project Gargoyle by callakrsos.
the class FxUtil method newInstance.
private static <T, C> T newInstance(Class<?> controllerClass, Object rootInstance, boolean isSelfController, String _fxml, Consumer<T> option, Consumer<C> controllerAction) throws Exception {
String fxml = _fxml;
if (fxml == null) {
FXMLController controller = getFxmlController(controllerClass);
if (controller == null) {
throw new GargoyleException("this is not FXMLController. check @FXMLController");
}
//controller.value();
fxml = getFxml(controller);
}
URL resource = controllerClass.getResource(fxml);
FXMLLoader loader = createNewFxmlLoader();
loader.setLocation(resource);
if (isSelfController && rootInstance != null) {
try {
loader.setRoot(rootInstance);
loader.setController(rootInstance);
} catch (Exception e) {
throw new GargoyleException(e);
}
}
T load = loader.load();
C instanceController = loader.getController();
// show warning...
if (load == null) {
LOGGER.warn("load result is empty.. controller class : {} ", controllerClass);
}
Method[] declaredMethods = controllerClass.getDeclaredMethods();
// 2017-02-07 findfirst에서 어노테이션으로 선언된 다건의 함수를 호출하게 다시 유도.
// findfirst로 수정. @FxPostInitialize가 여러건있는경우를 잘못된 로직 유도를 방지.
Stream.of(declaredMethods).filter(m -> m.getParameterCount() == 0 && m.getAnnotation(FxPostInitialize.class) != null).forEach(m -> {
if (m.getModifiers() == Modifier.PUBLIC) {
try {
if (instanceController != null) {
Platform.runLater(() -> {
try {
m.setAccessible(true);
m.invoke(instanceController);
} catch (Exception e) {
LOGGER.error(ValueUtil.toString(e));
}
});
}
} catch (Exception e) {
LOGGER.error(ValueUtil.toString(e));
}
}
});
if (option != null) {
option.accept(load);
}
if (controllerAction != null)
controllerAction.accept(instanceController);
Platform.runLater(() -> {
Parent parent = (Parent) load;
List<Node> findAllByNodes = FxUtil.findAllByNodes(parent, v -> v instanceof Button);
findAllByNodes.forEach(v -> {
GargoyleButtonBuilder.applyStyleClass((Button) v, SkinManager.BUTTON_STYLE_CLASS_NAME);
});
});
return load;
}
Aggregations