📄 schema.java
字号:
/*
* Created on 2004-3-22
*
* To change the template for this generated file go to
* Window - Preferences - Java - Code Generation - Code and Comments
*/
package com.zosatapo.xls.core;
import java.io.File;
import java.io.FileInputStream;
import java.util.Properties;
import java.util.Vector;
import com.zosatapo.xls.util.IoUtils;
import com.zosatapo.xls.util.StoreConfig;
/**
* @author Administrator
*
* To change the template for this generated type comment go to
* Window - Preferences - Java - Code Generation - Code and Comments
*/
/**
* 行和列的计算基数都是 0
*/
public class Schema
{
private String tableName;
private String queryString;
private Type defaultType;
private int startRow;
private int endRow;
private Vector columns;
private StoreConfig storeConfig;
private boolean validating;
private String pathname;
public Schema()
{
}
public void open()
throws Exception
{
Properties props=new Properties();
FileInputStream fis=new FileInputStream(configFile());
props.load(fis);
fis.close();
//-------------global setting
this.tableName=props.getProperty("schema.table.name");
this.queryString=props.getProperty("schema.table.query");
String defType=props.getProperty("schema.column.default");
String colCount=props.getProperty("schema.column.count");
String check=props.getProperty("schema.column.validating");
String firstRow=props.getProperty("schema.row.start");
String endRow=props.getProperty("schema.row.end");
String connURL=props.getProperty(StoreConfig.STORE_URL);
String connDriver=props.getProperty(StoreConfig.STORE_DRIVER);
String connType=props.getProperty(StoreConfig.STORE_TYPE);
String connUSR=props.getProperty(StoreConfig.STORE_USERNAME);
String connPWD=props.getProperty(StoreConfig.STORE_PASSWORD);
this.storeConfig=new StoreConfig(connType,connURL,connUSR,connPWD,connDriver);
//System.err.println(storeConfig);
this.defaultType=Type.valueOf(defType);
int columnCount=0;
if(colCount!=null && colCount.length()>0)
{
columnCount=Integer.parseInt(colCount);
}
if(firstRow!=null && firstRow.length()>0)
{
this.startRow=Integer.parseInt(firstRow);
}
else
{
this.startRow=0;
}
if(endRow!=null && endRow.length()>0)
{
this.endRow=Integer.parseInt(endRow);
}
else
{
this.endRow=Integer.MAX_VALUE;
}
this.validating=Boolean.valueOf(check).booleanValue();
//-------------column setting
this.columns=new Vector();
String colName=null;
String colType=null;
String inType=null;
String outType=null;
String colDefault=null;
String colLength=null;
for(int i=0;i<columnCount;i++)
{
colName=props.getProperty("schema.column."+i+".name");
if(colName==null || colName.length()==0)
{
System.err.println("[skip column "+i+" ] name is invalid");
this.columns.addElement(Column.NULL_COLUMN);
}
else
{
colType=props.getProperty("schema.column."+i+".type");
inType=props.getProperty("schema.column."+i+".in");
outType=props.getProperty("schema.column."+i+".out");
colDefault=props.getProperty("schema.column."+i+".default");
colLength=props.getProperty("schema.column."+i+".length");
Column col=new Column(i,colName);
this.columns.addElement(col);
if(colType!=null && !"".equals(colType))
{
col.setType(Type.valueOf(colType).copy());
}
if(inType!=null && !"".equals(inType))
{
col.setInType(Type.valueOf(inType).copy());
}
if(outType!=null && !"".equals(outType))
{
col.setOutType(Type.valueOf(outType).copy());
}
/**
* 直接赋值保存的方式不是很合理,鉴于类型转换可能运行期被程序自动修改,
* 故采用这样的赋值设计
*
* @see com.zosatapo.xls.io.XlsReader,com.zosatapo.xls.io.SQLReader
*/
if(col.getType()==null)
{
col.setType(this.defaultType.copy());
}
if(col.getInType()==null)
{
col.setInType(col.getType().copy());
}
if(col.getOutType()==null)
{
col.setOutType(col.getType().copy());
}
if(colDefault!=null && !"".equals(colDefault))
{
col.setDefaultValue(IoUtils.formatDefaultValue(colDefault,col.getType()));
}
if(colLength!=null && !"".equals(colLength))
{
col.setLength(Integer.parseInt(colLength));
}
}//~end if(colName==null || colName.length()==0)
}//~end for
}
public int getStartRow()
{
return startRow;
}
public void setEndRow(int endRow_)
{
this.endRow=endRow_;
}
public int getEndtRow()
{
return endRow;
}
public void setStartRow(int startRow_)
{
this.startRow=startRow_;
}
public Column getColumn(int index)
{
Column column=(Column)columns.elementAt(index);
if(column.isNull() || column.getIndex()== index)
{
return column;
}
int sizeColumn=this.columns.size();
for(int i=0;i<sizeColumn;++i)
{
column=(Column)columns.elementAt(i);
if(column.getIndex()== index)
{
return column;
}
}
return null;
}
public void addColumn(Column column)
{
columns.addElement(column);
}
public StoreConfig getStoreConfig()
{
return this.storeConfig;
}
public void setStoreConfig(StoreConfig storeConfig_)
{
this.storeConfig=storeConfig_;
}
public int getColumnCount()
{
return columns.size();
}
public Type getDefaultType()
{
return defaultType;
}
public String getTableName()
{
return tableName;
}
public void setTableName(String tableName_)
{
tableName=tableName_;
}
public String getQuery()
{
return queryString;
}
public void setQuery(String query_)
{
queryString=query_;
}
public boolean isValidating()
{
return validating;
}
public void setValidating(boolean validating)
{
this.validating = validating;
}
public void setPathname(String pathname)
{
this.pathname=pathname;
}
public String getPathname()
{
return pathname;
}
private File configFile()
{
return new File(pathname);
}
public static void main(String args[])
throws Exception
{
Schema schema=new Schema();
schema.setPathname(".\\conf\\sql2xls.properties");
schema.open();
System.err.println(schema.getTableName());
int colCount=schema.getColumnCount();
for(int i=0;i<colCount;++i)
{
System.err.println(schema.getColumn(i));
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -