Skip to content

Commit e9494bd

Browse files
committed
2.0.2
various fixes
1 parent 5cc8b1b commit e9494bd

File tree

7 files changed

+66
-47
lines changed

7 files changed

+66
-47
lines changed

core/src/main/java/com/osiris/jsqlgen/Data.java

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
package com.osiris.jsqlgen;
22

33
import com.google.gson.*;
4+
import com.osiris.jlib.logger.AL;
5+
import com.osiris.jsqlgen.generator.GetTableChange;
46
import com.osiris.jsqlgen.generator.JavaCodeGenerator;
57
import com.osiris.jsqlgen.model.Column;
68
import com.osiris.jsqlgen.model.Database;
79
import com.osiris.jsqlgen.model.Table;
10+
import com.osiris.jsqlgen.model.TableChange;
811
import com.osiris.jsqlgen.utils.FileTypeAdapter;
912
import org.jetbrains.annotations.NotNull;
1013
import org.jetbrains.annotations.Nullable;
@@ -170,6 +173,41 @@ public static Map<Database, DBWrapper> getOldAndNewDBsMap(@NotNull CopyOnWriteAr
170173
if (isNewer) break;
171174
}
172175
if (isNewer) {
176+
177+
// If there are missing changes add them (which might happen when importing databases generated by older jSQL-Gen versions).
178+
// For example if the table contains a column, but there is no change referencing that column, then it will be added to the first
179+
// Note that this should only be execute here and not for all tables, since there are issues if the user closes the app without generating
180+
// which then saves the table with the change object missing.
181+
for (Table t : dbNew.tables) {
182+
if(t.changes.isEmpty()){
183+
TableChange currentTableChange = GetTableChange.get(t, Data.instance.databases);
184+
t.changes.add(currentTableChange);
185+
}
186+
for (Column col : t.columns) {
187+
boolean isAddedOnce = false;
188+
for (TableChange c : t.changes) {
189+
if(c.addedColumnNames.contains(col.name)) {
190+
isAddedOnce = true;
191+
break;
192+
}
193+
}
194+
boolean isRenamedOnce = false;
195+
for (TableChange c : t.changes) {
196+
if(c.newColumnNames.contains(col.name)) {
197+
isRenamedOnce = true;
198+
break;
199+
}
200+
}
201+
if(!isAddedOnce && !isRenamedOnce){
202+
TableChange firstChange = t.changes.get(0);
203+
firstChange.addedColumnNames.add(col.name);
204+
firstChange.addedColumnDefinitions.add(col.definition);
205+
AL.warn("Failed to find column '"+col.name+"' in a change, thus added to first change.");
206+
}
207+
}
208+
}
209+
210+
// Finally add the newer db to the list
173211
oldAndNew.put(db, new DBWrapper(dbNew, databaseStructureFile));
174212
}
175213
}

core/src/main/java/com/osiris/jsqlgen/Main.java

Lines changed: 7 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import com.osiris.jsqlgen.generator.GetTableChange;
1212

1313
import java.io.File;
14+
import java.util.Arrays;
1415
import java.util.concurrent.atomic.AtomicInteger;
1516

1617
public class Main {
@@ -20,14 +21,16 @@ public class Main {
2021

2122
public static MainRoute mainRoute = new MainRoute();
2223

23-
public static void main(String[] args) {
24+
public static void main(String[] _args) {
2425
App.name = "jSQL-Gen";
2526
App.theme = new MyTheme();
2627
App.LoggerParams loggerParams = new App.LoggerParams();
27-
loggerParams.debug = true;
28-
App.isInDepthDebugging = true;
28+
if(Arrays.asList(_args).contains("debug")){
29+
loggerParams.debug = true;
30+
App.isInDepthDebugging = true;
31+
}
2932
App.init(null, loggerParams);
30-
AL.info("DB initialized at: "+com.osiris.jsqlgen.jsqlgen.Database.url);
33+
AL.info("DB initialized at: "+com.osiris.jsqlgen.jsqlgen.Database.url); // Init DB by static constructor
3134

3235
for (Database db : Data.instance.databases) {
3336
// If there are missing ids set them
@@ -38,42 +41,11 @@ public static void main(String[] args) {
3841
}
3942
}
4043

41-
// If there are missing changes add them (which might happen when importing databases generated by older jSQL-Gen versions).
42-
// For example if the table contains a column, but there is no change referencing that column
43-
for (Table t : db.tables) {
44-
if(t.changes.isEmpty()){
45-
TableChange currentTableChange = GetTableChange.get(t, Data.instance.databases);
46-
t.changes.add(currentTableChange);
47-
}
48-
for (Column col : t.columns) {
49-
boolean isAddedOnce = false;
50-
for (TableChange c : t.changes) {
51-
if(c.addedColumnNames.contains(col.name)) {
52-
isAddedOnce = true;
53-
break;
54-
}
55-
}
56-
boolean isRenamedOnce = false;
57-
for (TableChange c : t.changes) {
58-
if(c.newColumnNames.contains(col.name)) {
59-
isRenamedOnce = true;
60-
break;
61-
}
62-
}
63-
if(!isAddedOnce && !isRenamedOnce){
64-
TableChange firstChange = t.changes.get(0);
65-
firstChange.addedColumnNames.add(col.name);
66-
firstChange.addedColumnDefinitions.add(col.definition);
67-
}
68-
}
69-
}
70-
7144
// Cache current data
7245
JavaCodeGenerator.oldDatabases.add(db.duplicate());
7346
}
7447

7548

76-
7749
// Create and show windows
7850
try{
7951
App.uis.create(mainRoute);

core/src/main/java/com/osiris/jsqlgen/generator/JavaCodeGenerator.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package com.osiris.jsqlgen.generator;
22

3+
import com.osiris.jlib.logger.AL;
34
import com.osiris.jsqlgen.Data;
45
import com.osiris.jsqlgen.model.*;
56
import net.sf.jsqlparser.parser.CCJSqlParser;
@@ -206,7 +207,10 @@ public static String generateTableFile(File oldGeneratedClass, Table t, Database
206207

207208
// STATIC TABLE INIT METHOD
208209
TableChange currentTableChange = GetTableChange.get(t, oldDatabases);
209-
if(t.changes.isEmpty() || currentTableChange.hasChanges()) t.changes.add(currentTableChange);
210+
if(t.changes.isEmpty() || currentTableChange.hasChanges()) {
211+
t.changes.add(currentTableChange);
212+
AL.info("Detected change in table '"+t.name+"' and added it.");
213+
}
210214
classContentBuilder.append(GenStaticTableConstructor.s(t, tNameQuoted));
211215

212216
if (t.isCache)

core/src/main/java/com/osiris/jsqlgen/ui/timer/LayoutSliders.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public LayoutSliders setValue(@Nullable Timer timer) {
5555
return super.setValue(timer);
5656
}
5757

58-
private Component<?, ?> getTimerTaskUI(TimerTask timerTask) {
58+
private TimerTaskUI getTimerTaskUI(TimerTask timerTask) {
5959
TimerTaskUI comp = new TimerTaskUI(timerTask);
6060
var slider = comp.slider;
6161
AtomicReference<Double> refValueBefore = new AtomicReference<>(slider.getValue());
@@ -79,13 +79,16 @@ public LayoutSliders setValue(@Nullable Timer timer) {
7979
double remainingPercentage = 100.0 - currentValue;
8080
double scaleFactor = remainingPercentage / (100.0 - currentValue);
8181

82-
if(this.children.size() != timerTasks.size())
83-
throw new RuntimeException(this.children.size() +" != "+ timerTasks.size());
82+
if(this.children.size() != timerTasks.size()) {
83+
AL.warn(this.children.size() +" != "+ timerTasks.size());
84+
return;
85+
};
86+
AL.info("Sliders: "+children.size());
8487
for (Object obj : this.children) {
8588
TimerTaskUI otherComp = (TimerTaskUI) obj;
86-
AL.info("EXPECTING GETVALUE() FROM "+otherComp.toPrintString());
89+
//AL.info("EXPECTING GETVALUE() FROM "+otherComp.toPrintString());
8790
TimerTask otherTask = debugGetValue(otherComp);
88-
AL.info("SUCCESS "+otherComp.toPrintString());
91+
//AL.info("SUCCESS "+otherComp.toPrintString());
8992

9093
if (otherComp.slider == slider) {
9194
otherTask.percentageOfTimer = currentValue;

core/src/main/java/com/osiris/jsqlgen/ui/timer/LayoutTimer.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ public LayoutTimer() {
6464
}
6565
Timer timer = Timer.whereId().biggestFirst().limit(1).getFirstOrNull();
6666
Objects.requireNonNull(timer);
67-
if(timer.end != Timer.NULL){
67+
if(msLastActivity <= 0) throw new RuntimeException("msLastActivity="+msLastActivity+" for timer="+timer.toPrintString());
68+
if(timer.end == Timer.NULL){
6869
timer.end = new Timestamp(msLastActivity);
6970
timer.update();
7071
}

core/src/main/java/com/osiris/jsqlgen/ui/timer/SlidersPopup.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,6 @@ public SlidersPopup(boolean isBackFromAFK, Timer timer) {
2929
Task.createAndAdd(v);
3030
}));
3131

32-
var lySliders = new LayoutSliders(timer).padding(false).grow(1);
33-
var lyBtnsTasks = new LayoutButtonsTasks(timer, lySliders);
34-
3532
// Get recently used task
3633
Task task = null;
3734
for (TimerTask timerTask : TimerTask.whereId().biggestFirst().limit(50).get()) {
@@ -48,14 +45,18 @@ public SlidersPopup(boolean isBackFromAFK, Timer timer) {
4845
TimerTask.createAndAdd(timer.id, Task.PAUSE.id, isBackFromAFK ? 90 : 10);
4946
} else{
5047
TimerTask.createAndAdd(timer.id, task.id, isBackFromAFK ? 10 : 90);
51-
TimerTask.createAndAdd(timer.id, Task.PAUSE.id, isBackFromAFK ? 90 : 10);
48+
if(task.id != Task.PAUSE.id)
49+
TimerTask.createAndAdd(timer.id, Task.PAUSE.id, isBackFromAFK ? 90 : 10);
5250
}
5351
}
5452

5553

5654
this.body.scrollable(true, "100%", "100%");
5755
this.add(text(isBackFromAFK ? "Please select the amount of work and tasks done while you were away." :
5856
"Please select the amount of work and tasks done."));
57+
58+
var lySliders = new LayoutSliders(timer).padding(false).grow(1);
59+
var lyBtnsTasks = new LayoutButtonsTasks(timer, lySliders);
5960
this.add(hlNewTask, lyBtnsTasks, lySliders);
6061
}
6162
}

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ org.gradle.jvmargs=-Xms512M -Xmx4096m -XX:MaxMetaspaceSize=1G
33
org.gradle.configureondemand=false
44
robovmVersion=2.3.16
55
androidPluginVersion=7.3.0
6-
deskuVersion=bbeafc38d4
6+
deskuVersion=b3346e2b3c

0 commit comments

Comments
 (0)