gvsig-projects-pool / org.gvsig.online / trunk / org.gvsig.online / org.gvsig.online.app / org.gvsig.online.app.mainplugin / src / main / java / org / gvsig / online / app / mainplugin / addlayer / OnlineTableInfo.java @ 9518
History | View | Annotate | Download (3.06 KB)
1 |
package org.gvsig.online.app.mainplugin.addlayer; |
---|---|
2 |
|
3 |
import org.gvsig.fmap.dal.DALLocator; |
4 |
import org.gvsig.fmap.dal.DataManager; |
5 |
import org.gvsig.fmap.dal.StoresRepository; |
6 |
import org.gvsig.fmap.dal.feature.FeatureAttributeDescriptor; |
7 |
import org.gvsig.fmap.dal.store.jdbc.JDBCStoreParameters; |
8 |
import org.gvsig.fmap.geom.Geometry; |
9 |
import org.gvsig.fmap.geom.type.GeometryType; |
10 |
import org.gvsig.geodb.TableInfo; |
11 |
import org.gvsig.online.lib.api.workingcopy.OnlineEntity; |
12 |
|
13 |
/**
|
14 |
*
|
15 |
* @author jjdelcerro
|
16 |
*/
|
17 |
public class OnlineTableInfo extends TableInfo { |
18 |
|
19 |
private OnlineEntity entity;
|
20 |
|
21 |
public OnlineTableInfo(OnlineEntity entity, JDBCStoreParameters parameters, boolean requireGeometry, boolean isView) { |
22 |
super(entity.getEntityName(), parameters, requireGeometry, isView);
|
23 |
this.entity = entity;
|
24 |
} |
25 |
|
26 |
public OnlineEntity getEntity() {
|
27 |
return this.entity; |
28 |
} |
29 |
|
30 |
@Override
|
31 |
protected void fetchFromStore() { |
32 |
if (this.featureType != null) { |
33 |
return;
|
34 |
} |
35 |
try {
|
36 |
this.featureType = entity.getFeatureType();
|
37 |
this.table = this.featureType.getTags().getString("Layer.name", this.table); |
38 |
FeatureAttributeDescriptor attr = this.featureType.getDefaultGeometryAttribute();
|
39 |
if (attr != null) { |
40 |
GeometryType geomType = attr.getGeomType(); |
41 |
if (geomType != null) { |
42 |
if (this.getGeometryType() == Geometry.TYPES.UNKNOWN) { |
43 |
this.setGeometryType(geomType.getType());
|
44 |
} |
45 |
if (this.getGeometrySubtype() == Geometry.SUBTYPES.UNKNOWN) { |
46 |
this.setGeometrySubtype(geomType.getSubType());
|
47 |
} |
48 |
} |
49 |
if (this.getProjection() == null) { |
50 |
this.setProjection(attr.getSRS());
|
51 |
} |
52 |
} |
53 |
if (this.readOnly == null) { |
54 |
this.readOnly = false; //!store.allowWrite(); |
55 |
} |
56 |
|
57 |
// this force calculate some required values of tableinfo
|
58 |
this.getGeomFieldComboModel();
|
59 |
this.getIdFieldComboModel();
|
60 |
|
61 |
} catch (Exception ex) { |
62 |
LOGGER.trace("Can't get feature type.", ex); // To allow set break points |
63 |
} finally {
|
64 |
|
65 |
} |
66 |
|
67 |
} |
68 |
|
69 |
public boolean existsDALInfo() { |
70 |
return true; |
71 |
} |
72 |
|
73 |
boolean needConnectToModel() {
|
74 |
OnlineEntity e = this.getEntity();
|
75 |
DataManager dataManager = DALLocator.getDataManager(); |
76 |
StoresRepository globalRepository = dataManager.getStoresRepository(); |
77 |
boolean connected = false; |
78 |
boolean hasModels = false; |
79 |
for (String dataModel : e.getDataModelsAsList()) { |
80 |
if( dataModel==null ) { |
81 |
continue;
|
82 |
} |
83 |
hasModels = true;
|
84 |
if( globalRepository.getSubrepository(dataModel)!=null ) { |
85 |
connected = true;
|
86 |
break;
|
87 |
} |
88 |
} |
89 |
if( !hasModels ) {
|
90 |
return false; |
91 |
} |
92 |
return !connected;
|
93 |
} |
94 |
} |