Skip to content

Commit 71ec427

Browse files
committed
Fix dbgit messages and lil refactor
All messages are getting texts from Lang Added logback.xml and logback-test.xml, also logback.xml included in the classpath Fix messages levels so they are displayed in a tree manner based on action hierarchy Added .dblink in example folder of distribution package
1 parent a06f854 commit 71ec427

File tree

57 files changed

+955
-796
lines changed

Some content is hidden

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

57 files changed

+955
-796
lines changed

pom.xml

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,12 @@
8585
</plugins>
8686

8787
<resources>
88+
<resource>
89+
<directory>${project.basedir}/src/main/resources/</directory>
90+
<includes><!-- what -->
91+
<include>logback.xml</include>
92+
</includes>
93+
</resource>
8894
<resource>
8995
<directory>${project.basedir}/src/main/resources/scripts</directory><!-- from -->
9096
<targetPath>${project.build.directory}/dbgit</targetPath><!-- to -->
@@ -114,8 +120,15 @@
114120
</includes>
115121
</resource>
116122
<resource>
117-
<directory>${project.basedir}/src/main/resources</directory><!-- from -->
118-
<targetPath>${project.build.directory}/dbgit</targetPath><!-- to -->
123+
<directory>${project.basedir}/src/main/resources/example</directory><!-- from -->
124+
<targetPath>${project.build.directory}/dbgit/example</targetPath><!-- to -->
125+
<includes><!-- what -->
126+
<include>.dblink</include>
127+
</includes>
128+
</resource>
129+
<resource>
130+
<directory>${project.basedir}/src/main/resources/</directory><!-- from -->
131+
<targetPath>${project.build.directory}/dbgit/</targetPath><!-- to -->
119132
<includes><!-- what -->
120133
<include>dbgitconfig</include>
121134
</includes>

src/main/java/ru/fusionsoft/dbgit/adapters/DBAdapter.java

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package ru.fusionsoft.dbgit.adapters;
22

3+
import com.diogonunes.jcdp.color.api.Ansi;
34
import ru.fusionsoft.dbgit.core.*;
45
import ru.fusionsoft.dbgit.core.db.FieldType;
56
import ru.fusionsoft.dbgit.data_table.*;
@@ -101,8 +102,9 @@ public void restoreDataBase(IMapMetaObject updateObjs) throws Exception {
101102
Set<String> createdRoles = getRoles().values().stream().map(DBRole::getName).collect(Collectors.toSet());
102103

103104
// remove table indexes and constraints, which is step(-2) of restoreMetaObject(MetaTable)
104-
ConsoleWriter.println("Dropping constraints for all updating tables...");
105+
ConsoleWriter.println(lang.getValue("general", "restore", "droppingTablesConstraints"), 1);
105106
for (IMetaObject table : tablesExists.sortFromDependencies()) {
107+
ConsoleWriter.println(lang.getValue("general", "restore", "droppingTableConstraints").withParams(table.getName()), 2);
106108
getFactoryRestore().getAdapterRestore(DBGitMetaType.DBGitTable, this).restoreMetaObject(table, -2);
107109
}
108110

@@ -120,17 +122,23 @@ public void restoreDataBase(IMapMetaObject updateObjs) throws Exception {
120122
createSchemaIfNeed(obj, createdSchemas);
121123

122124
while (!res) {
125+
if(step==0) printRestoreMessage(obj);
126+
//if(step!=0) ConsoleWriter.print(" (step " + step + ")");
123127
res = restoreAdapter.restoreMetaObject(obj, step++);
124128

125129
if (step > 100) { throw new Exception(lang.getValue("errors", "restore", "restoreErrorDidNotReturnTrue").toString()); }
126130
}
127131

128132
Long timeDiff = new Timestamp(System.currentTimeMillis()).getTime() - timestampBefore.getTime();
129-
ConsoleWriter.detailsPrintlnGreen(MessageFormat.format("({1} {2})", obj.getName(), timeDiff, lang.getValue("general", "add", "ms")));
133+
// ConsoleWriter.detailsPrintColor(MessageFormat.format(" ({1} {2})"
134+
// , obj.getName()
135+
// , timeDiff
136+
// , lang.getValue("general", "add", "ms")), 0, Ansi.FColor.CYAN
137+
// );
130138
}
131139

132140
// restore table constraints, which is step(-1) of restoreMetaObject(MetaTable)
133-
ConsoleWriter.println("Restoring constraints for all updated tables...");
141+
ConsoleWriter.println(lang.getValue("general", "restore", "restoringTablesConstraints"), 2);
134142
for (IMetaObject table : tables.sortFromReferenced()) {
135143
getFactoryRestore().getAdapterRestore(DBGitMetaType.DBGitTable, this).restoreMetaObject(table, -1);
136144
}
@@ -145,6 +153,23 @@ public void restoreDataBase(IMapMetaObject updateObjs) throws Exception {
145153

146154
}
147155

156+
private void printRestoreMessage(IMetaObject obj) {
157+
String leafName = "";
158+
if(obj instanceof MetaSequence){ leafName = "restoreSeq"; }
159+
if(obj instanceof MetaView){ leafName = "restoreView"; }
160+
if(obj instanceof MetaTrigger){ leafName = "restoreTrigger"; }
161+
if(obj instanceof MetaSchema){ leafName = "restoreSchema"; }
162+
if(obj instanceof MetaRole){ leafName = "restoreRole"; }
163+
if(obj instanceof MetaProcedure){ leafName = "restorePrc"; }
164+
if(obj instanceof MetaPackage){ leafName = "restorePkg"; }
165+
if(obj instanceof MetaUser){ leafName = "restoreUser"; }
166+
if(obj instanceof MetaFunction){ leafName = "restoreFnc"; }
167+
if(obj instanceof MetaTable){ leafName = "restoreTable"; }
168+
if(obj instanceof MetaTableSpace){ leafName = "restoreTablespace"; }
169+
if(obj instanceof MetaTableData){ leafName = "restoreTableData"; }
170+
ConsoleWriter.println(lang.getValue("general", "restore", leafName).withParams(obj.getName()), 2);
171+
}
172+
148173
@Override
149174
public void deleteDataBase(IMapMetaObject deleteObjs) throws Exception {
150175
deleteDataBase(deleteObjs, false);

src/main/java/ru/fusionsoft/dbgit/adapters/DBBackupAdapter.java

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,13 @@ public void backupDatabase(IMapMetaObject updateObjs) throws Exception {
8484
.filter(this::isBackupObject)
8585
.collect(Collectors.toList()));
8686

87-
88-
89-
ConsoleWriter.printlnGreen(MessageFormat.format("Try to backup {0} present of {1} restoring objects ", dbToBackup.size(), updateObjs.size()));
87+
ConsoleWriter.println(DBGitLang.getInstance()
88+
.getValue("general", "backup", "tryToBackup")
89+
.withParams(
90+
String.valueOf(dbToBackup.size()),
91+
String.valueOf(updateObjs.size()))
92+
, 1
93+
);
9094

9195

9296
// collect restore objects dependencies to satisfy all backups create needs
@@ -104,8 +108,12 @@ public void backupDatabase(IMapMetaObject updateObjs) throws Exception {
104108
dbToBackup.putAll(addedObjs);
105109

106110
if(addedObjs.size() > 0) {
107-
ConsoleWriter.detailsPrintlnGreen(MessageFormat.format("Found {0} depending backups: {1}"
108-
, addedObjs.size(), String.join(" ,", addedObjs.keySet()))
111+
ConsoleWriter.println(DBGitLang.getInstance()
112+
.getValue("general", "backup", "dependingBackups")
113+
.withParams(
114+
String.valueOf(addedObjs.size()),
115+
String.join(" ,", addedObjs.keySet())
116+
), 2
109117
);
110118
}
111119
} while (addedObjs.size() > 0);
@@ -129,16 +137,23 @@ public void backupDatabase(IMapMetaObject updateObjs) throws Exception {
129137
dropList.addAll(dbDroppingBackupsDeps);
130138
List<IMetaObject> dropListSorted = new SortedListMetaObject(dropList).sortFromDependencies();
131139

132-
ConsoleWriter.printlnGreen(MessageFormat.format("Rewriting {0} backups with {1} dependencies", dbDroppingBackups.size(), dbDroppingBackupsDeps.size()));
133-
dropListSorted.forEach( x -> ConsoleWriter.detailsPrintlnGreen( x.getName()));
140+
ConsoleWriter.println(DBGitLang.getInstance()
141+
.getValue("general", "backup", "rewritingBackups")
142+
.withParams(
143+
String.valueOf(dbDroppingBackups.size()),
144+
String.valueOf(dbDroppingBackupsDeps.size())
145+
), 2
146+
);
147+
148+
//dropListSorted.forEach( x -> ConsoleWriter.detailsPrintLnColor( x.getName(), 3, Ansi.FColor.MAGENTA));
134149

135150
//drop backups in one place
136151
for(IMetaObject imo : dropListSorted){
137-
ConsoleWriter.detailsPrint(lang.getValue("general", "backup", "droppingBackup").withParams(imo.getName()), 1);
152+
ConsoleWriter.detailsPrintLn(lang.getValue("general", "backup", "droppingBackup").withParams(imo.getName()), 3);
138153

139154
dropIfExists(imo, stLog);
140155

141-
ConsoleWriter.detailsPrintlnGreen(lang.getValue("general", "ok"));
156+
ConsoleWriter.detailsPrintGreen(lang.getValue("general", "ok"));
142157
}
143158

144159
//create backups

src/main/java/ru/fusionsoft/dbgit/command/CmdAdd.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,15 +80,15 @@ public void execute(CommandLine cmdLine) throws Exception {
8080

8181
Timestamp timestampBefore = new Timestamp(System.currentTimeMillis());
8282
ConsoleWriter.detailsPrintLn(getLang().getValue("general", "add", "processingObject") + " " + obj.getName());
83-
ConsoleWriter.detailsPrint(getLang().getValue("general", "add", "savingToFile"), 2);
83+
ConsoleWriter.detailsPrintLn(getLang().getValue("general", "add", "savingToFile"), 2);
8484

8585
//TODO
8686
obj.saveToFile();
8787

88-
ConsoleWriter.detailsPrintlnGreen(getLang().getValue("general", "ok"));
88+
ConsoleWriter.detailsPrintGreen(getLang().getValue("general", "ok"));
8989
ConsoleWriter.detailsPrint(getLang().getValue("general", "addToGit"), 2);
9090
countSave += obj.addToGit();
91-
ConsoleWriter.detailsPrintlnGreen(getLang().getValue("general", "ok"));
91+
ConsoleWriter.detailsPrintGreen(getLang().getValue("general", "ok"));
9292

9393
Timestamp timestampAfter = new Timestamp(System.currentTimeMillis());
9494
Long diff = timestampAfter.getTime() - timestampBefore.getTime();

0 commit comments

Comments
 (0)