Skip to content

Commit 9e21c24

Browse files
committed
0.4.5 Update
fixed termination bug where trailing messages were not logged added field_access column to trend_mappings table
1 parent 3c822af commit 9e21c24

File tree

6 files changed

+23
-25
lines changed

6 files changed

+23
-25
lines changed

root/info.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<extension version="1">
22
<name>PostgreSQL_Connect</name>
33
<description>Periodically synchronizes data to an external PostgreSQL database.</description>
4-
<version>0.4.4</version>
4+
<version>0.4.5</version>
55
<vendor>Automatic Controls Equipment Systems, Inc.</vendor>
66
<system-menu-provider>aces.webctrl.postgresql.web.SystemMenuEditor</system-menu-provider>
77
</extension>

src/aces/webctrl/postgresql/core/Initializer.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -124,13 +124,13 @@ public void run(){
124124
@Override public void contextDestroyed(ServletContextEvent sce){
125125
stop = true;
126126
if (mainThread==null){
127-
handleDestruction();
127+
Config.save();
128128
}else{
129129
mainThread.interrupt();
130130
synchronized (syncNotifier){
131131
syncNotifier.notifyAll();
132132
}
133-
handleDestruction();
133+
Config.save();
134134
//Wait for the primary processing thread to terminate.
135135
while (true){
136136
try{
@@ -141,9 +141,6 @@ public void run(){
141141
}
142142
log("Execution terminated.");
143143
new Sync(Event.SHUTDOWN);
144-
}
145-
private static void handleDestruction(){
146-
Config.save();
147144
// We deregister the PostgreSQL driver so that Tomcat does not complain
148145
final ClassLoader cl = Thread.currentThread().getContextClassLoader();
149146
final Enumeration<Driver> drivers = DriverManager.getDrivers();

src/aces/webctrl/postgresql/core/Sync.java

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -514,36 +514,31 @@ public void execute(SystemAccess sys){
514514
"SELECT\n"+
515515
" \"x\".\"id\",\n"+
516516
" \"x\".\"persistent_identifier\",\n"+
517+
" \"x\".\"field_access\",\n"+
517518
" GREATEST(\"y\".\"time\", CURRENT_TIMESTAMP-make_interval(days=>\"retain_data\")) AS \"start\"\n"+
518519
"FROM (\n"+
519520
" SELECT * FROM webctrl.trend_mappings WHERE \"server_id\" = "+ID+"\n"+
520521
") \"x\" LEFT JOIN (\n"+
521-
" SELECT\n"+
522-
" \"x\".*\n"+
523-
" FROM (\n"+
524-
" SELECT DISTINCT ON (\"id\")\n"+
525-
" \"id\",\n"+
526-
" \"time\"\n"+
527-
" FROM webctrl.trend_data\n"+
528-
" ORDER BY \"id\" ASC, \"time\" DESC\n"+
529-
" ) \"x\" INNER JOIN (\n"+
530-
" SELECT \"id\" FROM webctrl.trend_mappings WHERE \"server_id\" = "+ID+"\n"+
531-
" ) \"y\"\n"+
532-
" ON \"x\".\"id\" = \"y\".\"id\"\n"+
522+
" SELECT DISTINCT ON (\"id\")\n"+
523+
" \"id\",\n"+
524+
" \"time\"\n"+
525+
" FROM webctrl.trend_data\n"+
526+
" ORDER BY \"id\" ASC, \"time\" DESC\n"+
533527
") \"y\"\n"+
534528
"ON \"x\".\"id\" = \"y\".\"id\";"
535529
);
536530
){
537531
TrendMapping tm;
538532
OffsetDateTime t;
539533
while (r.next()){
540-
t = r.getObject(3, OffsetDateTime.class);
534+
t = r.getObject(4, OffsetDateTime.class);
541535
if (t==null){
542536
continue;
543537
}
544538
tm = new TrendMapping();
545539
tm.ID = r.getInt(1);
546540
tm.persistentIdentifier = r.getString(2);
541+
tm.fieldAccess = r.getBoolean(3);
547542
tm.start = java.util.Date.from(t.toInstant());
548543
trends.add(tm);
549544
}
@@ -570,7 +565,7 @@ public void execute(SystemAccess sys){
570565
boolValues.x = null;
571566
boolNulls.x = null;
572567
try{
573-
sysCon.runReadAction(FieldAccessFactory.newFieldAccess(), new ReadAction(){
568+
sysCon.runReadAction(tm.fieldAccess?FieldAccessFactory.newFieldAccess():FieldAccessFactory.newDisabledFieldAccess(), new ReadAction(){
574569
@Override public void execute(SystemAccess sys){
575570
try{
576571
Location loc = sys.getTree(SystemTree.Geographic).resolve(tm.persistentIdentifier);

src/aces/webctrl/postgresql/core/TableCache.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ public class TableCache {
130130
//trend_mappings
131131
x = new TableTemplate("trend_mappings", "Trend Mappings");
132132
x.keyColumn = "id";
133-
x.otherColumns = "\"server_id\",\"name\",\"persistent_identifier\",\"retain_data\"";
133+
x.otherColumns = "\"server_id\",\"name\",\"persistent_identifier\",\"retain_data\",\"field_access\"";
134134
x.query =
135135
"SELECT\n"+
136136
" \"x\".\"id\",\n"+
@@ -139,6 +139,7 @@ public class TableCache {
139139
" \"x\".\"name\",\n"+
140140
" \"x\".\"persistent_identifier\",\n"+
141141
" \"x\".\"retain_data\",\n"+
142+
" \"x\".\"field_access\",\n"+
142143
" COALESCE(\"y\".\"sample_count\", 0) AS \"sample_count\",\n"+
143144
" COALESCE(DATE_TRUNC('seconds', \"y\".\"first_sample\" AT TIME ZONE '"+timezone+"')::TEXT, 'N/A') AS \"first_sample\",\n"+
144145
" COALESCE(DATE_TRUNC('seconds', \"y\".\"last_sample\" AT TIME ZONE '"+timezone+"')::TEXT, 'N/A') AS \"last_sample\"\n"+
@@ -158,14 +159,16 @@ public class TableCache {
158159
") \"z\"\n"+
159160
"ON \"x\".\"server_id\" = \"z\".\"id\"\n"+
160161
"ORDER BY \"x\".\"server_id\";";
161-
x.header = "[\"Trend ID\",\"Server ID\",\"Server Name\",\"Name\",\"Persistent Identifier\",\"Retain Data (Days)\",\"Sample Count\",\"First Sample\",\"Last Sample\"],"+
162-
"[\"<READONLY>N/A\",\"^\\\\d+$\",\"<READONLY>N/A\",\"^.+$\",\"^.+$\",\"^\\\\d+$\",\"<READONLY>0\",\"<READONLY>N/A\",\"<READONLY>N/A\"]";
162+
x.header = "[\"Trend ID\",\"Server ID\",\"Server Name\",\"Name\",\"Persistent Identifier\",\"Retain Data (Days)\",\"Field Access\",\"Sample Count\",\"First Sample\",\"Last Sample\"],"+
163+
"[\"<READONLY>N/A\",\"^\\\\d+$\",\"<READONLY>N/A\",\"^.+$\",\"^.+$\",\"^\\\\d+$\",\"^true$|^false$\",\"<READONLY>0\",\"<READONLY>N/A\",\"<READONLY>N/A\"]";
163164
x.conversion = new BiFunction<Integer,String,String>(){
164165
@Override public String apply(Integer i, String s){
165166
if (i==0){
166167
return s.equalsIgnoreCase("N/A")?"DEFAULT":String.valueOf(Integer.parseInt(s));
167168
}else if (i==1 || i==4){
168169
return String.valueOf(Integer.parseInt(s));
170+
}else if (i==5){
171+
return s.equals("1") || s.equalsIgnoreCase("true") ? "TRUE":"FALSE";
169172
}else{
170173
return Utility.escapePostgreSQL(s);
171174
}

src/aces/webctrl/postgresql/core/TrendMapping.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@
33
public class TrendMapping {
44
public volatile int ID;
55
public volatile String persistentIdentifier;
6+
public volatile boolean fieldAccess;
67
public volatile Date start;
78
}

src/aces/webctrl/postgresql/resources/Setup.sql

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,9 @@ CREATE TABLE webctrl.trend_mappings (
192192
-- com.controlj.green.addonsupport.access.Location.getPersistentLookupString(true)
193193
"persistent_identifier" TEXT,
194194
-- How many days of historical data should be kept in the database
195-
"retain_data" INTEGER
195+
"retain_data" INTEGER,
196+
-- Whether to collect field data from controllers
197+
"field_access" BOOLEAN
196198
);
197199

198200
-- Where collected trend source data lives
@@ -304,7 +306,7 @@ CREATE TABLE webctrl.settings (
304306
-- Populate default values for webctrl.settings
305307
INSERT INTO webctrl.settings VALUES
306308
-- Version of PostgreSQL connector addon
307-
('version','0.4.4'),
309+
('version','0.4.5'),
308310
-- Whether debug mode is enabled (e.g, verbose log messages when true)
309311
('debug','false'),
310312
-- Whether to auto-update the PostgreSQL connector addon

0 commit comments

Comments
 (0)