Skip to content

Commit 98e4fb3

Browse files
committed
DM-11814: Use embedded DB in table data support
1 parent 68cec09 commit 98e4fb3

File tree

69 files changed

+1517
-389
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+1517
-389
lines changed

buildScript/depends.gincl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ ext {
2929
':servlet-api',
3030
':websocket-api']
3131

32+
db_lib = [':h2-1.4.194', ':sqlite-jdbc-3.20.0', ':hsqldb']
3233
mysql_lib = ':mysql-connector-java-5.1.6-bin'
3334
starlink_lib = [':rayreg', ':regclient', ':stil']
3435
xbeanfinder_lib = [':xbean-finder-4.1', ':asm-5.0.3']
@@ -90,6 +91,7 @@ repositories {
9091
"$libPath/oidc",
9192
"$libPath/json",
9293
"$libPath/log4j",
94+
"$libPath/db",
9395
"$libPath/mysql",
9496
"$libPath/sdss",
9597
"$libPath/spring",

config/app.config

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ work.directory = "/hydra/workarea"
1212
stats.log.dir = '${catalina.base}/logs'
1313
alerts.dir = "/hydra/alerts"
1414

15-
debug.mode = false
15+
debug.mode = true
16+
17+
application.db.url = "jdbc:h2:/hydra/server/tomcat/temp/application;CACHE_SIZE=262144"
1618

1719
/* keep vis.shared.mem.size small if pct is used */
1820
pct.vis.shared.mem.size = 0.4

config/common.prop

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ BuildDate=@build_time@
1111
# app.prop env sensitive properties
1212
#==========================================================
1313

14+
DbAdapter.type = hsql
1415

1516
# a directory for storing intermediate files
1617
# default to System.getProperty("java.io.tmpdir") + "/workarea"

config/web.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,15 @@
9090
</servlet-mapping>
9191

9292

93+
<servlet>
94+
<servlet-name>H2Console</servlet-name>
95+
<servlet-class>org.h2.server.web.WebServlet</servlet-class>
96+
<load-on-startup>1</load-on-startup>
97+
</servlet>
98+
<servlet-mapping>
99+
<servlet-name>H2Console</servlet-name>
100+
<url-pattern>/admin/db/*</url-pattern>
101+
</servlet-mapping>
93102
<!-- Resources -->
94103

95104
<resource-ref>

jars/db/h2-1.4.194.jar

1.72 MB
Binary file not shown.

jars/db/hsqldb.jar

1.47 MB
Binary file not shown.

jars/db/sqlite-jdbc-3.20.0.jar

6.33 MB
Binary file not shown.

src/firefly/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ apply from: "$fireflyPath/buildScript/gwt_webapp.gincl"
55

66
dependencies {
77
compile project(':xstream'), project(':simbad'), project(':firefly_data')
8-
webappLib mysql_lib, FIREFLY_RUNTIME + ":$jar.baseName"
8+
webappLib db_lib, mysql_lib, FIREFLY_RUNTIME + ":$jar.baseName"
99
}
1010

1111
sourceSets {

src/firefly/html/demo/ffapi-highlevel-charttest.html

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,13 @@ <h2>
169169
{tbl_id: 'test-tbl'});
170170
firefly.showTable('table-1', tblReq);
171171

172+
// using column expressions
173+
var tblReqXpr = Object.assign({}, tblReq, {inclCols: 'ra + dec as "radec", ra, dec, ln(dec) as LnOfDec, power(ra, 2) as ra_sq'});
174+
tblReqXpr.META_INFO.tbl_id = 'tblwithXpr';
175+
tblReqXpr.META_INFO.title = 'table with expressions';
176+
tblReqXpr.tbl_id = 'tblwithXpr';
177+
firefly.showTable('table-1', tblReqXpr);
178+
172179
trace1 = {
173180
tbl_id: 'test-tbl',
174181
x: 'tables::ra',

src/firefly/html/firefly-dev.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
window.firefly = {
1414
app: {
1515
template: 'FireflyViewer',
16+
views: 'tables',
1617
options : {
1718
MenuItemKeys: {maskOverlay:true},
1819
}

src/firefly/java/edu/caltech/ipac/astro/IpacTableWriter.java

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public static void save(File file, DataGroup dataGroup)
7373
PrintWriter out = null;
7474
try {
7575
out = new PrintWriter(new BufferedWriter(new FileWriter(file)));
76-
save(out, dataGroup);
76+
save(out, dataGroup, false);
7777
} finally {
7878
if (out != null) out.close();
7979
}
@@ -88,15 +88,27 @@ public static void save(File file, DataGroup dataGroup)
8888
*/
8989
public static void save(OutputStream stream, DataGroup dataGroup)
9090
throws IOException {
91-
save(new PrintWriter(stream), dataGroup);
91+
save(new PrintWriter(stream), dataGroup, false);
9292
}
9393

94-
private static void save(PrintWriter out, DataGroup dataGroup)
95-
throws IOException {
94+
/**
95+
* save the catalogs to a stream, stream is not closed
96+
*
97+
* @param stream the output stream to write to
98+
* @param dataGroup data group
99+
* @param ignoreSysMeta ignore meta use by system.
100+
* @throws IOException on error
101+
*/
102+
public static void save(OutputStream stream, DataGroup dataGroup, boolean ignoreSysMeta)
103+
throws IOException {
104+
save(new PrintWriter(stream), dataGroup, ignoreSysMeta);
105+
}
106+
107+
private static void save(PrintWriter out, DataGroup dataGroup, boolean ignoreSysMeta) throws IOException {
96108
List<DataType> headers = Arrays.asList(dataGroup.getDataDefinitions());
97109
int totalRow = dataGroup.size();
98110

99-
IpacTableUtil.writeAttributes(out, dataGroup.getKeywords());
111+
IpacTableUtil.writeAttributes(out, dataGroup.getKeywords(), ignoreSysMeta);
100112
IpacTableUtil.writeHeader(out, headers);
101113

102114
for (int i = 0; i < totalRow; i++) {

src/firefly/java/edu/caltech/ipac/firefly/data/TableServerRequest.java

Lines changed: 59 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,25 @@
55

66
import edu.caltech.ipac.util.StringUtils;
77

8+
import javax.validation.constraints.NotNull;
89
import java.io.Serializable;
910
import java.util.ArrayList;
1011
import java.util.Arrays;
1112
import java.util.HashMap;
1213
import java.util.List;
1314
import java.util.Map;
15+
import java.util.SortedSet;
16+
import java.util.TreeSet;
1417

1518
public class TableServerRequest extends ServerRequest implements Serializable, DataEntry, Cloneable {
1619

20+
public static final String TBL_FILE_PATH = "tblFilePath"; // this meta if exists contains source of the data
21+
public static final String TBL_FILE_TYPE = "tblFileType"; // this meta if exists contains storage type, ipac, h2, sqlite, etc
22+
public static final String DATASET_ID = "datasetID"; // this meta if exists contains the ID of the dataset returned.
23+
1724
public static final String DECIMATE_INFO = "decimate";
18-
public static final String TBL_FILE_PATH = "tblFilePath";
25+
public static final String SQL_FROM = "sqlFrom";
26+
1927
public static final String TBL_ID = "tbl_id";
2028
public static final String TITLE = "title";
2129
public static final String FILTERS = "filters";
@@ -25,8 +33,7 @@ public class TableServerRequest extends ServerRequest implements Serializable, D
2533
public static final String INCL_COLUMNS = "inclCols";
2634
public static final String FIXED_LENGTH = "fixedLength";
2735
public static final String META_INFO = "META_INFO";
28-
public static final String SYS_PARAMS = "|" + StringUtils.toString(new String[]{FILTERS,SORT_INFO,PAGE_SIZE,START_IDX,INCL_COLUMNS,FIXED_LENGTH,META_INFO,TBL_ID,DECIMATE_INFO}, "|") + "|";
29-
36+
public static final List<String> SYS_PARAMS = Arrays.asList(new String[]{INCL_COLUMNS,FIXED_LENGTH,META_INFO,TBL_ID,DECIMATE_INFO,SQL_FROM});
3037
public static final String TBL_INDEX = "tbl_index"; // the table to show if it's a multi-table file.
3138

3239
private int pageSize;
@@ -51,6 +58,9 @@ public Map<String, String> getMeta() {
5158
}
5259

5360
public String getMeta(String key) {
61+
if (metaInfo == null) {
62+
63+
}
5464
return metaInfo == null ? null : metaInfo.get(key);
5565
}
5666

@@ -75,7 +85,7 @@ public String getTblTitle() {
7585

7686
@Override
7787
public boolean isInputParam(String paramName) {
78-
return !SYS_PARAMS.contains("|" + paramName + "|");
88+
return !SYS_PARAMS.contains(paramName);
7989
}
8090

8191
public int getStartIndex() {
@@ -145,12 +155,23 @@ public void setFilters(List<String> filters) {
145155
}
146156
}
147157

158+
/**
159+
* use this when you want to get full data in its
160+
* natural order.
161+
*/
162+
public void keepBaseParamOnly() {
163+
setFilters(null);
164+
setPageSize(Integer.MAX_VALUE);
165+
setSortInfo(null);
166+
removeParam(INCL_COLUMNS);
167+
}
168+
148169
@Override
149170
public ServerRequest newInstance() {
150171
return new TableServerRequest();
151172
}
152173

153-
//====================================================================
174+
//====================================================================
154175

155176
//====================================================================
156177

@@ -230,6 +251,39 @@ public static String toFilterStr(List<String> l) {
230251
return StringUtils.toString(l,";");
231252
}
232253

254+
/**
255+
* returns only the parameters used for searching. This excludes all system parameter, including
256+
* filtering, sorting, and paging.
257+
* @return
258+
*/
259+
@NotNull
260+
public SortedSet<Param> getSearchParams() {
261+
TreeSet<Param> params = new TreeSet<>();
262+
for (Param p : getParams()) {
263+
if (!SYS_PARAMS.contains(p.getName()) ||
264+
p.getName().equals(SORT_INFO)) {
265+
params.add(p);
266+
}
267+
}
268+
return params;
269+
}
270+
271+
/**
272+
* returns the parameters used to modified this dataset. This includes filtering and sorting.
273+
* @return
274+
*/
275+
@NotNull
276+
public SortedSet<Param> getDataSetParam() {
277+
TreeSet<Param> params = new TreeSet<>();
278+
if (filters != null && filters.size() > 0) {
279+
params.add(new Param(FILTERS, toFilterStr(filters)));
280+
}
281+
if (getSortInfo() != null) {
282+
params.add(new Param(SORT_INFO, getSortInfo().toString()));
283+
}
284+
return params;
285+
}
286+
233287
//====================================================================
234288
//
235289
//====================================================================
@@ -238,9 +292,6 @@ public static String toFilterStr(List<String> l) {
238292
protected boolean addPredefinedAttrib(Param param) {
239293
if (param == null || param.getName() == null || param.getValue() == null) return false;
240294

241-
// if (param.getName().equals(SORT_INFO)) {
242-
// sortInfo = SortInfo.parse(param.getValue());
243-
// }
244295
switch (param.getName()) {
245296
case PAGE_SIZE:
246297
pageSize = StringUtils.getInt(param.getValue());

src/firefly/java/edu/caltech/ipac/firefly/data/table/TableDataView.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public interface TableDataView extends HasAccessInfos, Serializable {
2626
public static final String ROW_DESELECT_ALL = "rowDeselectAll";
2727
public static final String MODEL_LOADED = "modelLoaded";
2828

29-
public static final String ROWID = "ROWID";
29+
public static final String ROWID = "ROW_IDX";
3030
public enum Align {LEFT, RIGHT, CENTER}
3131

3232
DatasetInfoConverter getDatasetInfoConverter();

src/firefly/java/edu/caltech/ipac/firefly/server/ServerContext.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
package edu.caltech.ipac.firefly.server;
55

66
import edu.caltech.ipac.firefly.server.cache.EhcacheProvider;
7-
import edu.caltech.ipac.firefly.server.filters.CommonFilter;
87
import edu.caltech.ipac.firefly.server.query.SearchProcessorFactory;
98
import edu.caltech.ipac.firefly.server.util.Logger;
109
import edu.caltech.ipac.firefly.server.visualize.VisContext;
@@ -88,7 +87,6 @@ public static void init(String contextPath, String contextName, String webappCon
8887
ServerContext.contextName = contextName;
8988

9089
configInit();
91-
9290
initVisSearchPath();
9391

9492
PERM_FILE_PATH_STR = getPermWorkDir().getPath();

src/firefly/java/edu/caltech/ipac/firefly/server/catquery/BaseGator.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -129,12 +129,6 @@ public ServerRequest inspectRequest(ServerRequest request) {
129129
return req;
130130
}
131131

132-
@Override
133-
protected String getWspaceSaveDirectory() {
134-
return "/" + WorkspaceManager.SEARCH_DIR + "/" + WspaceMeta.CATALOGS;
135-
136-
}
137-
138132
protected File loadDynDataFile(TableServerRequest request) throws IOException, DataAccessException {
139133
CatalogRequest req = QueryUtil.assureType(CatalogRequest.class, request);
140134
return searchGator(req);

src/firefly/java/edu/caltech/ipac/firefly/server/catquery/GatorDD.java

Lines changed: 75 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,29 @@
66
import edu.caltech.ipac.astro.DataGroupQueryStatement;
77
import edu.caltech.ipac.firefly.core.EndUserException;
88
import edu.caltech.ipac.firefly.data.CatalogRequest;
9+
import edu.caltech.ipac.firefly.data.FileInfo;
910
import edu.caltech.ipac.firefly.data.ServerRequest;
1011
import edu.caltech.ipac.firefly.data.TableServerRequest;
1112
import edu.caltech.ipac.firefly.data.table.TableMeta;
1213
import edu.caltech.ipac.firefly.server.ServerContext;
14+
import edu.caltech.ipac.firefly.server.db.DbAdapter;
15+
import edu.caltech.ipac.firefly.server.db.DbInstance;
16+
import edu.caltech.ipac.firefly.server.db.TableDbUtil;
17+
import edu.caltech.ipac.firefly.server.db.spring.JdbcFactory;
18+
import edu.caltech.ipac.firefly.server.db.spring.mapper.DataGroupUtil;
19+
import edu.caltech.ipac.firefly.server.query.DataAccessException;
20+
import edu.caltech.ipac.firefly.server.query.DbProcessor;
1321
import edu.caltech.ipac.firefly.server.query.ParamDoc;
22+
import edu.caltech.ipac.firefly.server.query.SearchManager;
1423
import edu.caltech.ipac.firefly.server.query.SearchProcessorImpl;
24+
import edu.caltech.ipac.firefly.server.util.StopWatch;
25+
import edu.caltech.ipac.firefly.server.util.ipactable.DataGroupPart;
26+
import edu.caltech.ipac.firefly.server.util.ipactable.TableDef;
1527
import edu.caltech.ipac.util.AppProperties;
28+
import edu.caltech.ipac.util.DataGroup;
1629
import edu.caltech.ipac.util.DataType;
30+
import edu.caltech.ipac.util.StringUtils;
31+
import org.apache.commons.codec.digest.DigestUtils;
1732

1833
import java.io.File;
1934
import java.io.IOException;
@@ -26,7 +41,9 @@
2641

2742

2843
/**
29-
* @author Trey Roby
44+
* This is a wrapper around GatorDDImpl. It uses the original code to retrieve Gator's DD
45+
* information, but stores it into a database. Unlike our single-results per database,
46+
* this database will contains all of the DD information retrieved by GatorDDImpl.
3047
*/
3148
@SearchProcessorImpl(id = "GatorDD", params =
3249
{@ParamDoc(name = CatalogRequest.CATALOG, desc = "the catalog name to search"),
@@ -39,7 +56,63 @@
3956
@ParamDoc(name = CatalogRequest.SERVICE_ROOT, desc = "the part of the URL string that specifies the service and first params. " +
4057
"optional: almost never used")
4158
})
42-
public class GatorDD extends BaseGator {
59+
public class GatorDD extends DbProcessor {
60+
61+
public FileInfo createDbFile(TableServerRequest treq) throws DataAccessException {
62+
DbAdapter dbAdapter = DbAdapter.getAdapter(treq);
63+
File dbFile = new File(ServerContext.getPermWorkDir(), "GatorDD." + dbAdapter.getName());
64+
DataGroup dd = new DataGroup("DD for GatorDD", new DataType[]{
65+
new DataType("name", String.class),
66+
new DataType("description", String.class),
67+
new DataType("units", String.class),
68+
new DataType("indx", String.class),
69+
new DataType("dbtype", String.class),
70+
new DataType("tableflg", Integer.class),
71+
new DataType("sel", String.class)
72+
});
73+
TableDbUtil.createDDTbl(dbFile, dd, dbAdapter);
74+
TableDbUtil.setDbMetaInfo(treq, DbAdapter.getAdapter(treq), dbFile);
75+
return new FileInfo(dbFile);
76+
}
77+
78+
@Override
79+
protected DataGroupPart getDataset(TableServerRequest treq, File dbFile) throws DataAccessException {
80+
DbAdapter dbAdapter = DbAdapter.getAdapter(treq);
81+
DbInstance dbInstance = dbAdapter.getDbInstance(dbFile);
82+
String tblName = "ds_" + DigestUtils.md5Hex(StringUtils.toString(treq.getSearchParams(), "|"));
83+
84+
String tblExists = String.format("select count(*) from %s", tblName);
85+
try {
86+
JdbcFactory.getSimpleTemplate(dbInstance).queryForInt(tblExists);
87+
} catch (Exception e) {
88+
// does not exists.. fetch data and populate
89+
fetchDataIntoTable(treq, tblName, dbFile, dbAdapter);
90+
}
91+
92+
treq.setParam(TableServerRequest.SQL_FROM, tblName);
93+
treq.setPageSize(Integer.MAX_VALUE);
94+
String sql = String.format("%s %s %s", dbAdapter.selectPart(treq), dbAdapter.fromPart(treq), dbAdapter.wherePart(treq));
95+
sql = dbAdapter.translateSql(sql);
96+
97+
DataGroup dg = TableDbUtil.runQuery(dbAdapter, dbFile, sql);
98+
TableDef tm = new TableDef();
99+
tm.setStatus(DataGroupPart.State.COMPLETED);
100+
return new DataGroupPart(tm, dg, treq.getStartIndex(), dg.size());
101+
}
102+
103+
private void fetchDataIntoTable(TableServerRequest treq, String tblName, File dbFile, DbAdapter dbAdapter) throws DataAccessException {
104+
TableServerRequest ntreq = (TableServerRequest) treq.cloneRequest();
105+
ntreq.keepBaseParamOnly();
106+
DataGroupPart dgp = new GatorDDImpl().getData(treq);
107+
TableDbUtil.createDataTbl(dbFile, dgp.getData(), dbAdapter, tblName);
108+
}
109+
}
110+
111+
112+
/**
113+
* @author Trey Roby
114+
*/
115+
class GatorDDImpl extends BaseGator {
43116

44117
private static final String DEF_DD_SERVICE = AppProperties.getProperty("irsa.gator.service.dd",
45118
"/cgi-bin/Gator/nph-dd");

0 commit comments

Comments
 (0)