sde增加删除
来源:互联网 发布:广州多益网络员工收入 编辑:程序博客网 时间:2024/06/05 17:41
DataStoredataStore = DataStoreFinder.getDataStore(map);
package com.hdsx.query;
import java.beans.BeanInfo;
import java.beans.IntrospectionException;
import java.beans.Introspector;
import java.beans.PropertyDescriptor;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.NoSuchElementException;
import net.sf.jsqlparser.statement.truncate.Truncate;
import org.geotools.data.DataStore;
import org.geotools.data.DefaultTransaction;
import org.geotools.data.Transaction;
import org.geotools.data.collection.ListFeatureCollection;
import org.geotools.data.simple.SimpleFeatureCollection;
import org.geotools.data.simple.SimpleFeatureIterator;
import org.geotools.data.simple.SimpleFeatureStore;
import org.geotools.feature.FeatureFactory;
import org.geotools.feature.simple.SimpleFeatureBuilder;
import org.geotools.filter.text.cql2.CQL;
import org.geotools.filter.text.cql2.CQLException;
import org.opengis.feature.Property;
import org.opengis.feature.simple.SimpleFeature;
import org.opengis.feature.simple.SimpleFeatureType;
import org.opengis.feature.type.AttributeDescriptor;
import org.opengis.filter.Filter;
import org.opengis.util.InternationalString;
public class BaseQuery {
private SimpleFeatureStore simpleDataStore;
public BaseQuery(DataStore dataStore,String statement){
try {
simpleDataStore = (SimpleFeatureStore) dataStore.getFeatureSource(statement);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
/**
* 根据条件查询数据库的一条记录放入实体bean中
* @param where
* @param t
* @return
* @throws IntrospectionException
* @throws IllegalAccessException
* @throws IllegalArgumentException
* @throws InvocationTargetException
*/
public <T> T queryOne(String where,T t) throws IntrospectionException, IllegalAccessException, IllegalArgumentException, InvocationTargetException{
try {
Filter filter=CQL.toFilter(where);
SimpleFeatureCollection simpleCollection = simpleDataStore.getFeatures(filter);
SimpleFeatureIterator iterator = simpleCollection.features();
while( iterator.hasNext() ){
SimpleFeature feature = iterator.next();
/*查询所有字段名称*/
Collection<Property> colpro = feature.getProperties();
//属性
BeanInfo bean = Introspector.getBeanInfo(t.getClass());
PropertyDescriptor[] pd = bean.getPropertyDescriptors();
ss:for(PropertyDescriptor pda:pd){
String p = pda.getDisplayName().toUpperCase();
for(Property pro:colpro){
if(pro.getName().toString().equals(p)){
pda.getWriteMethod().invoke(t, pro.getValue());
break ss;
}
}
}
System.out.println("dddddddd");
}
} catch (CQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (NoSuchElementException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return t;
}
/**
* 为bean的String属性赋值
* @param t
* @return
* @throws IntrospectionException
* @throws IllegalAccessException
* @throws IllegalArgumentException
* @throws InvocationTargetException
*/
public <T> T get(T t) throws IntrospectionException, IllegalAccessException, IllegalArgumentException, InvocationTargetException{
BeanInfo bean = Introspector.getBeanInfo(t.getClass());
PropertyDescriptor[] pd = bean.getPropertyDescriptors();
for(PropertyDescriptor pda:pd){
Object ob= pda.getPropertyType();
System.out.println(ob);
if( ob==java.lang.String.class){
pda.getWriteMethod().invoke(t, "aas");
}
}
return t;
}
/**
* 根据条件查询多条记录放入list中
* SimpleFeature simpleFeature = iterator.next();
* Collection<Property> properties = simpleFeature.getProperties();
* 访问次数多导致程序不执行
* @throws IllegalAccessException
* @throws InstantiationException
* @throws IntrospectionException
* @throws InvocationTargetException
* @throws IllegalArgumentException
*/
public <T> List<T> queryList(String where,T t) throws InstantiationException, IllegalAccessException, IntrospectionException, IllegalArgumentException, InvocationTargetException {
List<T> list=new ArrayList<T>();
try {
Filter filter=CQL.toFilter(where);
SimpleFeatureCollection simpleCollection = simpleDataStore.getFeatures(filter);
SimpleFeatureIterator iterator = simpleCollection.features();
BeanInfo bean = Introspector.getBeanInfo(t.getClass());
PropertyDescriptor[] pd = bean.getPropertyDescriptors();
System.out.println(simpleCollection.size());
while(iterator.hasNext()){
SimpleFeature simpleFeature = iterator.next();
Collection<Property> properties = simpleFeature.getProperties();
int i=0;
//属性
T oa = (T) t.getClass().newInstance();
for(PropertyDescriptor pda:pd){
adad:for(Property propertie:properties){
if(propertie.getName().toString().equals(pda.getName().toUpperCase())){
if(propertie.getValue()!=null)
pda.getWriteMethod().invoke(oa, propertie.getValue());
break adad;
}
}
++i;
System.out.println("xxxxxxxxx");
}
System.out.println("tianjia");
list.add(oa);
}
} catch (CQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return list;
}
public <T> void insert(T t){
SimpleFeatureType sf = simpleDataStore.getSchema();
SimpleFeatureBuilder simpleBuilder = new SimpleFeatureBuilder(sf);
List<AttributeDescriptor> description = sf.getAttributeDescriptors();
System.out.println("bbbbbb");
Object[] param = null;
for(AttributeDescriptor attributeDescriptor:description){
//属性
BeanInfo bean;
try {
bean = Introspector.getBeanInfo(t.getClass());
PropertyDescriptor[] pd = bean.getPropertyDescriptors();
ss:for(PropertyDescriptor pda:pd){
String p = pda.getDisplayName().toUpperCase();
if(attributeDescriptor.getName().toString().equals(p)){
try {
System.out.println(p);
simpleBuilder.set(p,pda.getReadMethod().invoke(t, param));
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InvocationTargetException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
break ss;
}
}
} catch (IntrospectionException e) {
System.out.println("bean有错误");
}
}
SimpleFeature simpleFeature = simpleBuilder.buildFeature("in");
Transaction tr=new DefaultTransaction();
SimpleFeatureCollection simpleFeatureCollection=new ListFeatureCollection(sf);
simpleFeatureCollection.add(simpleFeature);
System.out.println("开始");
simpleDataStore.setTransaction(tr);
try {System.out.println("开始事务");
simpleDataStore.addFeatures(simpleFeatureCollection);
tr.commit();
tr.close();
System.out.println("结束");
} catch (IOException e) {
try {
tr.rollback();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
System.out.println("插入语句错误");
}
}
}
- sde增加删除
- 从SDE库文件手工删除SDE图层
- 增加删除
- sde
- sde
- sde
- SDE用户删除不了:ORAORA-21700
- 删除SDE用户报错 ORA-21700
- sde for Oracle10g 64bit 删除 SDE用户无法删除的问题
- 从SDE库文件手工删除SDE图层(转载)
- 向SDE中添加图层(删除图层)
- ArcGIS删除SDE存储所有对象但保留Schema
- 在oracle中删除sde导入的shp数据。
- 删除SDE.DBF所带来的影响oracle的…
- 动态增加删除行
- XML增加,修改,删除
- 动态增加、删除列
- 增加 修改 删除
- 非线程安全的函数
- VC转码方式
- 二排序数组中位数
- JS中使用JSTL标签
- 作业相关操作
- sde增加删除
- Linux下open与fopen的区别
- linux环境下 C++性能测试工具 gprof + kprof + gprof2dot
- hdu 2045 - 不容易系列之(3)—— LELE的RPG难题
- 使用Python进行验证码识别
- 50 Useful CSS Snippets Every Designer Should Have
- jdbc 事务的隔离级别
- CodeIgniter 核心代码阅读-Utf8转码文件Utf8.php
- iconv函数详解