forked from p81075629/datagear
[dataexchange]添加IndexFormatDataExchangeContext类
This commit is contained in:
parent
bc2872d479
commit
2082d73685
|
@ -48,10 +48,21 @@ public abstract class AbstractDevotedTextDataExportService<T extends TextDataExp
|
|||
@Override
|
||||
protected DataExchangeContext createDataExchangeContext(T dataExchange)
|
||||
{
|
||||
return new TextDataExportContext(dataExchange.getConnectionFactory(),
|
||||
return new IndexFormatDataExchangeContext(dataExchange.getConnectionFactory(),
|
||||
new DataFormatContext(dataExchange.getDataFormat()));
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换{@linkplain DataExchangeContext}类型。
|
||||
*
|
||||
* @param context
|
||||
* @return
|
||||
*/
|
||||
protected IndexFormatDataExchangeContext castDataExchangeContext(DataExchangeContext context)
|
||||
{
|
||||
return (IndexFormatDataExchangeContext) context;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取{@linkplain ResultSet}列信息。
|
||||
*
|
||||
|
@ -64,48 +75,4 @@ public abstract class AbstractDevotedTextDataExportService<T extends TextDataExp
|
|||
{
|
||||
return super.getColumnInfos(cn, rs, this.databaseInfoResolver);
|
||||
}
|
||||
|
||||
/**
|
||||
* 文本导出上下文。
|
||||
*
|
||||
* @author datagear@163.com
|
||||
*
|
||||
*/
|
||||
protected static class TextDataExportContext extends DataExchangeContext
|
||||
{
|
||||
private DataFormatContext dataFormatContext;
|
||||
|
||||
private DataIndex dataIndex;
|
||||
|
||||
public TextDataExportContext()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public TextDataExportContext(ConnectionFactory connectionFactory, DataFormatContext dataFormatContext)
|
||||
{
|
||||
super(connectionFactory);
|
||||
this.dataFormatContext = dataFormatContext;
|
||||
}
|
||||
|
||||
public DataFormatContext getDataFormatContext()
|
||||
{
|
||||
return dataFormatContext;
|
||||
}
|
||||
|
||||
public void setDataFormatContext(DataFormatContext dataFormatContext)
|
||||
{
|
||||
this.dataFormatContext = dataFormatContext;
|
||||
}
|
||||
|
||||
public DataIndex getDataIndex()
|
||||
{
|
||||
return dataIndex;
|
||||
}
|
||||
|
||||
public void setDataIndex(DataIndex dataIndex)
|
||||
{
|
||||
this.dataIndex = dataIndex;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -50,10 +50,21 @@ public abstract class AbstractDevotedTextValueDataImportService<T extends TextVa
|
|||
@Override
|
||||
protected DataExchangeContext createDataExchangeContext(T dataExchange)
|
||||
{
|
||||
return new TextValueDataImportContext(dataExchange.getConnectionFactory(),
|
||||
return new IndexFormatDataExchangeContext(dataExchange.getConnectionFactory(),
|
||||
new DataFormatContext(dataExchange.getDataFormat()));
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换{@linkplain DataExchangeContext}类型。
|
||||
*
|
||||
* @param context
|
||||
* @return
|
||||
*/
|
||||
protected IndexFormatDataExchangeContext castDataExchangeContext(DataExchangeContext context)
|
||||
{
|
||||
return (IndexFormatDataExchangeContext) context;
|
||||
}
|
||||
|
||||
/**
|
||||
* 导入一条数据。
|
||||
*
|
||||
|
@ -67,7 +78,7 @@ public abstract class AbstractDevotedTextValueDataImportService<T extends TextVa
|
|||
* @throws DataExchangeException
|
||||
*/
|
||||
protected boolean importData(T impt, Connection cn, PreparedStatement st, List<ColumnInfo> columnInfos,
|
||||
List<String> columnValues, TextValueDataImportContext context) throws DataExchangeException
|
||||
List<String> columnValues, IndexFormatDataExchangeContext context) throws DataExchangeException
|
||||
{
|
||||
TextValueDataImportListener listener = impt.getListener();
|
||||
|
||||
|
@ -117,7 +128,7 @@ public abstract class AbstractDevotedTextValueDataImportService<T extends TextVa
|
|||
* @param context
|
||||
* @throws ExecuteDataImportSqlException
|
||||
*/
|
||||
protected void executeImportPreparedStatement(T impt, PreparedStatement st, TextValueDataImportContext context)
|
||||
protected void executeImportPreparedStatement(T impt, PreparedStatement st, IndexFormatDataExchangeContext context)
|
||||
throws ExecuteDataImportSqlException
|
||||
{
|
||||
try
|
||||
|
@ -142,7 +153,7 @@ public abstract class AbstractDevotedTextValueDataImportService<T extends TextVa
|
|||
* @throws SetImportColumnValueException
|
||||
*/
|
||||
protected void setImportColumnValues(T impt, Connection cn, PreparedStatement st, List<ColumnInfo> columnInfos,
|
||||
List<String> columnValues, TextValueDataImportContext context) throws SetImportColumnValueException
|
||||
List<String> columnValues, IndexFormatDataExchangeContext context) throws SetImportColumnValueException
|
||||
{
|
||||
DataIndex dataIndex = context.getDataIndex();
|
||||
int columnCount = columnInfos.size();
|
||||
|
@ -227,48 +238,4 @@ public abstract class AbstractDevotedTextValueDataImportService<T extends TextVa
|
|||
{
|
||||
return getColumnInfos(cn, table, columnNames, nullIfColumnNotFound, this.databaseInfoResolver);
|
||||
}
|
||||
|
||||
/**
|
||||
* 文本值数据导入上下文。
|
||||
*
|
||||
* @author datagear@163.com
|
||||
*
|
||||
*/
|
||||
protected static class TextValueDataImportContext extends DataExchangeContext
|
||||
{
|
||||
private DataFormatContext dataFormatContext;
|
||||
|
||||
private DataIndex dataIndex;
|
||||
|
||||
public TextValueDataImportContext()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public TextValueDataImportContext(ConnectionFactory connectionFactory, DataFormatContext dataFormatContext)
|
||||
{
|
||||
super(connectionFactory);
|
||||
this.dataFormatContext = dataFormatContext;
|
||||
}
|
||||
|
||||
public DataFormatContext getDataFormatContext()
|
||||
{
|
||||
return dataFormatContext;
|
||||
}
|
||||
|
||||
public void setDataFormatContext(DataFormatContext dataFormatContext)
|
||||
{
|
||||
this.dataFormatContext = dataFormatContext;
|
||||
}
|
||||
|
||||
public DataIndex getDataIndex()
|
||||
{
|
||||
return dataIndex;
|
||||
}
|
||||
|
||||
public void setDataIndex(DataIndex dataIndex)
|
||||
{
|
||||
this.dataIndex = dataIndex;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,49 @@
|
|||
/*
|
||||
* Copyright (c) 2018 datagear.tech. All Rights Reserved.
|
||||
*/
|
||||
|
||||
package org.datagear.dataexchange;
|
||||
|
||||
/**
|
||||
* 带当前数据索引信息和格式化上下文的{@linkplain DataExchangeContext}。
|
||||
*
|
||||
* @author datagear@163.com
|
||||
*
|
||||
*/
|
||||
public class IndexFormatDataExchangeContext extends DataExchangeContext
|
||||
{
|
||||
private DataFormatContext dataFormatContext;
|
||||
|
||||
private DataIndex dataIndex;
|
||||
|
||||
public IndexFormatDataExchangeContext()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public IndexFormatDataExchangeContext(ConnectionFactory connectionFactory, DataFormatContext dataFormatContext)
|
||||
{
|
||||
super(connectionFactory);
|
||||
this.dataFormatContext = dataFormatContext;
|
||||
}
|
||||
|
||||
public DataFormatContext getDataFormatContext()
|
||||
{
|
||||
return dataFormatContext;
|
||||
}
|
||||
|
||||
public void setDataFormatContext(DataFormatContext dataFormatContext)
|
||||
{
|
||||
this.dataFormatContext = dataFormatContext;
|
||||
}
|
||||
|
||||
public DataIndex getDataIndex()
|
||||
{
|
||||
return dataIndex;
|
||||
}
|
||||
|
||||
public void setDataIndex(DataIndex dataIndex)
|
||||
{
|
||||
this.dataIndex = dataIndex;
|
||||
}
|
||||
}
|
|
@ -15,6 +15,7 @@ import org.apache.commons.csv.CSVPrinter;
|
|||
import org.datagear.dataexchange.AbstractDevotedTextDataExportService;
|
||||
import org.datagear.dataexchange.DataExchangeContext;
|
||||
import org.datagear.dataexchange.DataExchangeException;
|
||||
import org.datagear.dataexchange.IndexFormatDataExchangeContext;
|
||||
import org.datagear.dataexchange.RowDataIndex;
|
||||
import org.datagear.dataexchange.TextDataExportListener;
|
||||
import org.datagear.dataexchange.TextDataExportOption;
|
||||
|
@ -42,7 +43,7 @@ public class CsvDataExportService extends AbstractDevotedTextDataExportService<C
|
|||
@Override
|
||||
protected void exchange(CsvDataExport dataExchange, DataExchangeContext context) throws Throwable
|
||||
{
|
||||
TextDataExportContext exportContext = (TextDataExportContext) context;
|
||||
IndexFormatDataExchangeContext exportContext = castDataExchangeContext(context);
|
||||
|
||||
TextDataExportListener listener = dataExchange.getListener();
|
||||
TextDataExportOption exportOption = dataExchange.getExportOption();
|
||||
|
|
|
@ -17,6 +17,7 @@ import org.datagear.dataexchange.AbstractDevotedTextValueDataImportService;
|
|||
import org.datagear.dataexchange.ColumnNotFoundException;
|
||||
import org.datagear.dataexchange.DataExchangeContext;
|
||||
import org.datagear.dataexchange.DataExchangeException;
|
||||
import org.datagear.dataexchange.IndexFormatDataExchangeContext;
|
||||
import org.datagear.dataexchange.RowDataIndex;
|
||||
import org.datagear.dbinfo.ColumnInfo;
|
||||
import org.datagear.dbinfo.DatabaseInfoResolver;
|
||||
|
@ -42,7 +43,7 @@ public class CsvDataImportService extends AbstractDevotedTextValueDataImportServ
|
|||
@Override
|
||||
protected void exchange(CsvDataImport dataExchange, DataExchangeContext context) throws Throwable
|
||||
{
|
||||
TextValueDataImportContext importContext = (TextValueDataImportContext) context;
|
||||
IndexFormatDataExchangeContext importContext = castDataExchangeContext(context);
|
||||
|
||||
Reader csvReader = getResource(dataExchange.getReaderFactory(), importContext);
|
||||
|
||||
|
|
|
@ -21,6 +21,7 @@ import org.apache.poi.xssf.streaming.SXSSFWorkbook;
|
|||
import org.datagear.dataexchange.AbstractDevotedTextDataExportService;
|
||||
import org.datagear.dataexchange.DataExchangeContext;
|
||||
import org.datagear.dataexchange.DataFormatContext;
|
||||
import org.datagear.dataexchange.IndexFormatDataExchangeContext;
|
||||
import org.datagear.dataexchange.TextDataExportListener;
|
||||
import org.datagear.dataexchange.TextDataExportOption;
|
||||
import org.datagear.dbinfo.ColumnInfo;
|
||||
|
@ -47,7 +48,7 @@ public class ExcelDataExportService extends AbstractDevotedTextDataExportService
|
|||
@Override
|
||||
protected void exchange(ExcelDataExport dataExchange, DataExchangeContext context) throws Throwable
|
||||
{
|
||||
TextDataExportContext exportContext = (TextDataExportContext) context;
|
||||
IndexFormatDataExchangeContext exportContext = castDataExchangeContext(context);
|
||||
|
||||
OutputStream out = getResource(dataExchange.getOutputFactory(), exportContext);
|
||||
|
||||
|
@ -72,7 +73,7 @@ public class ExcelDataExportService extends AbstractDevotedTextDataExportService
|
|||
* @throws Throwable
|
||||
*/
|
||||
protected void writeRecords(ExcelDataExport dataExchange, Connection cn, List<ColumnInfo> columnInfos, ResultSet rs,
|
||||
OutputStream out, TextDataExportContext exportContext) throws Throwable
|
||||
OutputStream out, IndexFormatDataExchangeContext exportContext) throws Throwable
|
||||
{
|
||||
TextDataExportListener listener = dataExchange.getListener();
|
||||
TextDataExportOption exportOption = dataExchange.getExportOption();
|
||||
|
@ -153,8 +154,8 @@ public class ExcelDataExportService extends AbstractDevotedTextDataExportService
|
|||
* @throws Throwable
|
||||
*/
|
||||
protected void setCellValue(ExcelDataExport dataExchange, Connection cn, ResultSet rs, int columnIndex,
|
||||
ColumnInfo columnInfo, TextDataExportOption exportOption, TextDataExportContext exportContext, Cell cell)
|
||||
throws Throwable
|
||||
ColumnInfo columnInfo, TextDataExportOption exportOption, IndexFormatDataExchangeContext exportContext,
|
||||
Cell cell) throws Throwable
|
||||
{
|
||||
TextDataExportListener listener = dataExchange.getListener();
|
||||
DataFormatContext dataFormatContext = exportContext.getDataFormatContext();
|
||||
|
|
|
@ -13,6 +13,7 @@ import java.util.List;
|
|||
|
||||
import org.datagear.dataexchange.AbstractDevotedTextDataExportService;
|
||||
import org.datagear.dataexchange.DataExchangeContext;
|
||||
import org.datagear.dataexchange.IndexFormatDataExchangeContext;
|
||||
import org.datagear.dataexchange.RowDataIndex;
|
||||
import org.datagear.dataexchange.TextDataExportListener;
|
||||
import org.datagear.dataexchange.TextDataExportOption;
|
||||
|
@ -42,7 +43,7 @@ public class SqlDataExportService extends AbstractDevotedTextDataExportService<S
|
|||
@Override
|
||||
protected void exchange(SqlDataExport dataExchange, DataExchangeContext context) throws Throwable
|
||||
{
|
||||
TextDataExportContext exportContext = (TextDataExportContext) context;
|
||||
IndexFormatDataExchangeContext exportContext = castDataExchangeContext(context);
|
||||
|
||||
Writer sqlWriter = getResource(dataExchange.getWriterFactory(), exportContext);
|
||||
|
||||
|
@ -66,7 +67,7 @@ public class SqlDataExportService extends AbstractDevotedTextDataExportService<S
|
|||
* @param exportContext
|
||||
*/
|
||||
protected void writeRecords(SqlDataExport dataExchange, Connection cn, List<ColumnInfo> columnInfos, ResultSet rs,
|
||||
Writer out, TextDataExportContext exportContext) throws Throwable
|
||||
Writer out, IndexFormatDataExchangeContext exportContext) throws Throwable
|
||||
{
|
||||
TextDataExportListener listener = dataExchange.getListener();
|
||||
TextDataExportOption exportOption = dataExchange.getExportOption();
|
||||
|
|
Loading…
Reference in New Issue