/*
* Copyright (C) 2011-2014 GeoForge Project
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
package org.geoforge.wrpbasprsdatecl;
import java.awt.geom.Point2D;
import java.util.ArrayList;
import org.geoforge.java.awt.geom.GfrUtilPoint2D;
import org.geoforge.basprjdat.table.object.GfrBasTblDatObjAbs;
import org.geoforge.basprjdat.table.object.GfrBasTblDatTloAbs;
import org.geoforge.basprjdat.table.object.GfrBasTblDatTloPointAbs;
import org.geoforge.basprjdat.table.object.GfrBasTblDatXloAbs;
import org.geoforge.basprjdatecl.table.objects.GfrBasTblDatChildNameImgPlc;
import org.geoforge.basprjdatecl.table.objects.GfrBasTblDatTloEclPlc;
import org.geoforge.java.lang.string.GfrUtlString;
import org.geoforge.sql.field.GfrFldAbs;
/**
*
* @author bantchao
*/
abstract public class GfrWrpBasTopDatEclPlcs extends GfrWrpBasTopDatEclAbs
{
protected String[] _getSortedNames(String strPathAbsDbDtaProject) throws Exception
{
return super._getSortedNames(
strPathAbsDbDtaProject,
GfrBasTblDatTloEclPlc.s_getInstance());
}
/*
* returns unique ID
*/
protected String _save(
String strPathAbsDbDtaThis,
String strName, String strDescShort, String strUrl,
Point2D.Double p2d)
throws Exception
{
GfrBasTblDatObjAbs tblObject = GfrBasTblDatTloEclPlc.s_getInstance();
String strIdObj = GfrUtlString.s_getUniqueId(tblObject.getName());
String strGeometry = GfrUtilPoint2D.s_toString(p2d);
GfrFldAbs[] flds =
{
GfrBasTblDatObjAbs.FLD_VAR_CHAR_ID_OBJ,
GfrBasTblDatTloAbs.FLD_VAR_CHAR_NAME,
GfrBasTblDatXloAbs.FLD_VAR_CHAR_DESCRIPTION,
GfrBasTblDatTloAbs.FLD_VAR_CHAR_URL,
GfrBasTblDatTloPointAbs.FLD_VAR_CHAR_GEOMETRY
};
String[] strs =
{
strIdObj,
strName,
strDescShort,
strUrl,
strGeometry
};
super._save(
strPathAbsDbDtaThis,
tblObject,
flds,
strs,
strIdObj);
return strIdObj;
}
protected String[] _save(
String strPathAbsDbDtaThis,
String[] strsName,
String[] strsDescShort,
String[] strsUrl,
Point2D.Double[] p2ds)
throws Exception
{
if (strsName == null || strsName.length < 1)
throw new Exception("Inserting corrupted data in db :\n strsName == null || strsName.length <1");
if (strsDescShort == null || strsDescShort.length < 1)
throw new Exception("Inserting corrupted data in db :\n strsDescShort == null || strsDescShort.length <1");
if (strsUrl == null || strsUrl.length < 1)
throw new Exception("Inserting corrupted data in db :\n strsUrl == null || strsUrl.length <1");
if (p2ds == null || p2ds.length < 1)
throw new Exception("Inserting corrupted data in db :\n p2ds == null || p2ds.length <1");
if (strsName.length != strsDescShort.length
|| strsDescShort.length != strsUrl.length
|| strsUrl.length != p2ds.length)
throw new Exception("Trying to insert corrupted dataset in db");
GfrBasTblDatObjAbs tblObject = GfrBasTblDatTloEclPlc.s_getInstance();
GfrFldAbs[] flds =
{
GfrBasTblDatObjAbs.FLD_VAR_CHAR_ID_OBJ,
GfrBasTblDatTloAbs.FLD_VAR_CHAR_NAME,
GfrBasTblDatXloAbs.FLD_VAR_CHAR_DESCRIPTION,
GfrBasTblDatTloAbs.FLD_VAR_CHAR_URL,
GfrBasTblDatTloPointAbs.FLD_VAR_CHAR_GEOMETRY
};
int intSize = strsUrl.length;
String[] strsIds = new String[intSize];
ArrayList<String[]> altStrs = new ArrayList<String[]>();
for (int i = 0; i < intSize; i++)
{
String strIdObj = GfrUtlString.s_getUniqueId(tblObject.getName());
strsIds[i] = strIdObj;
String strGeometry = GfrUtilPoint2D.s_toString(p2ds[i]);
String[] strsCur =
{
strIdObj,
strsName[i],
strsDescShort[i],
strsUrl[i],
strGeometry
};
altStrs.add(strsCur);
}
super._save(
strPathAbsDbDtaThis,
tblObject,
flds,
altStrs,
strsIds);
return strsIds;
}
@Override
public void deleteAllTlos() throws Exception
{
super._deleteAll(GfrBasTblDatChildNameImgPlc.s_getInstance()); // !!! TO BE CHECKED
GfrBasTblDatObjAbs tblObject = GfrBasTblDatTloEclPlc.s_getInstance();
if (!super.isNotEmpty())
return;
super._deleteAll(tblObject);
}
// avoid instantiation
protected GfrWrpBasTopDatEclPlcs()
{
super();
}
}