forked from p81075629/datagear
Merge branch 'master' of https://gitee.com/datagear/datagear.git
This commit is contained in:
commit
1e0715d570
|
@ -19,5 +19,15 @@
|
|||
<artifactId>datagear-model</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.datagear</groupId>
|
||||
<artifactId>datagear-persistence</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.datagear</groupId>
|
||||
<artifactId>datagear-dbmodel</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
package org.datagear.dataexchange;
|
||||
|
||||
/**
|
||||
* 专职{@linkplain ModelDataReaderFactory}。
|
||||
* @author datagear@163.com
|
||||
*
|
||||
*/
|
||||
public interface DevotedModelDataReaderFactory extends ModelDataReaderFactory
|
||||
{
|
||||
/**
|
||||
* 是否支持指定{@linkplain Import}。
|
||||
* @param impt
|
||||
* @return
|
||||
*/
|
||||
boolean supports(Import impt);
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
package org.datagear.dataexchange;
|
||||
|
||||
/**
|
||||
* 专职{@linkplain ModelDataWriterFactory}。
|
||||
* @author datagear@163.com
|
||||
*
|
||||
*/
|
||||
public interface DevotedModelDataWriterFactory extends ModelDataWriterFactory
|
||||
{
|
||||
/**
|
||||
* 是否支持指定{@linkplain Export}。
|
||||
* @param expt
|
||||
* @return
|
||||
*/
|
||||
boolean supports(Export expt);
|
||||
}
|
|
@ -6,8 +6,6 @@ package org.datagear.dataexchange;
|
|||
|
||||
import java.sql.Connection;
|
||||
|
||||
import org.datagear.model.Model;
|
||||
|
||||
/**
|
||||
* 导出端。
|
||||
*
|
||||
|
@ -18,18 +16,15 @@ public abstract class Export
|
|||
{
|
||||
private Connection connection;
|
||||
|
||||
private Model model;
|
||||
|
||||
public Export()
|
||||
{
|
||||
super();
|
||||
}
|
||||
|
||||
public Export(Connection connection, Model model)
|
||||
public Export(Connection connection)
|
||||
{
|
||||
super();
|
||||
this.connection = connection;
|
||||
this.model = model;
|
||||
}
|
||||
|
||||
public Connection getConnection()
|
||||
|
@ -41,14 +36,4 @@ public abstract class Export
|
|||
{
|
||||
this.connection = connection;
|
||||
}
|
||||
|
||||
public Model getModel()
|
||||
{
|
||||
return model;
|
||||
}
|
||||
|
||||
public void setModel(Model model)
|
||||
{
|
||||
this.model = model;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,71 @@
|
|||
package org.datagear.dataexchange;
|
||||
|
||||
import org.springframework.core.GenericTypeResolver;
|
||||
|
||||
/**
|
||||
* 类型参数{@linkplain DevotedModelDataReaderFactory}。
|
||||
*
|
||||
* @author datagear@163.com
|
||||
*
|
||||
* @param <T>
|
||||
*/
|
||||
public abstract class TypedDevotedModelDataReaderFactory<T extends Import> implements DevotedModelDataReaderFactory
|
||||
{
|
||||
private Class<?> supportedImportType;
|
||||
|
||||
public TypedDevotedModelDataReaderFactory()
|
||||
{
|
||||
super();
|
||||
this.supportedImportType = resolveImportTypeParameter(getClass());
|
||||
}
|
||||
|
||||
public Class<?> getSupportedImportType()
|
||||
{
|
||||
return supportedImportType;
|
||||
}
|
||||
|
||||
protected void setSupportedImportType(Class<?> supportedImportType)
|
||||
{
|
||||
this.supportedImportType = supportedImportType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supports(Import impt)
|
||||
{
|
||||
if(impt == null)
|
||||
return false;
|
||||
|
||||
return this.supportedImportType.isAssignableFrom(impt.getClass());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModelDataReader get(Import impt)
|
||||
{
|
||||
@SuppressWarnings("unchecked")
|
||||
T timpt = (T) impt;
|
||||
|
||||
return getModelDataReader(timpt);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定{@linkplain Import}的{@linkplain ModelDataReader}。
|
||||
*
|
||||
* @param impt
|
||||
* @return
|
||||
*/
|
||||
protected abstract ModelDataReader getModelDataReader(T impt);
|
||||
|
||||
/**
|
||||
* 解析{@linkplain TypedDevotedModelDataReaderFactory}子类的类型参数。
|
||||
*
|
||||
* @param subClass
|
||||
* @return
|
||||
*/
|
||||
@SuppressWarnings("rawtypes")
|
||||
protected static Class<?> resolveImportTypeParameter(Class<? extends TypedDevotedModelDataReaderFactory> subClass)
|
||||
{
|
||||
Class<?> tp = GenericTypeResolver.resolveTypeArgument(subClass, TypedDevotedModelDataReaderFactory.class);
|
||||
|
||||
return tp;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,71 @@
|
|||
package org.datagear.dataexchange;
|
||||
|
||||
import org.springframework.core.GenericTypeResolver;
|
||||
|
||||
/**
|
||||
* 类型参数{@linkplain DevotedModelDataWriterFactory}。
|
||||
*
|
||||
* @author datagear@163.com
|
||||
*
|
||||
* @param <T>
|
||||
*/
|
||||
public abstract class TypedDevotedModelDataWriterFactory<T extends Export> implements DevotedModelDataWriterFactory
|
||||
{
|
||||
private Class<?> supportedExportType;
|
||||
|
||||
public TypedDevotedModelDataWriterFactory()
|
||||
{
|
||||
super();
|
||||
this.supportedExportType = resolveExportTypeParameter(getClass());
|
||||
}
|
||||
|
||||
public Class<?> getSupportedExportType()
|
||||
{
|
||||
return supportedExportType;
|
||||
}
|
||||
|
||||
protected void setSupportedExportType(Class<?> supportedExportType)
|
||||
{
|
||||
this.supportedExportType = supportedExportType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean supports(Export expt)
|
||||
{
|
||||
if(expt == null)
|
||||
return false;
|
||||
|
||||
return this.supportedExportType.isAssignableFrom(expt.getClass());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ModelDataWriter get(Export expt)
|
||||
{
|
||||
@SuppressWarnings("unchecked")
|
||||
T texpt = (T)expt;
|
||||
|
||||
return getModelDataWriter(texpt);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定{@linkplain Export}的{@linkplain ModelDataWriter}。
|
||||
*
|
||||
* @param expt
|
||||
* @return
|
||||
*/
|
||||
protected abstract ModelDataWriter getModelDataWriter(T expt);
|
||||
|
||||
/**
|
||||
* 解析{@linkplain TypedDevotedModelDataWriterFactory}子类的类型参数。
|
||||
*
|
||||
* @param subClass
|
||||
* @return
|
||||
*/
|
||||
@SuppressWarnings("rawtypes")
|
||||
protected static Class<?> resolveExportTypeParameter(Class<? extends TypedDevotedModelDataWriterFactory> subClass)
|
||||
{
|
||||
Class<?> tp = GenericTypeResolver.resolveTypeArgument(subClass, TypedDevotedModelDataWriterFactory.class);
|
||||
|
||||
return tp;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue