Skip to content

Commit

Permalink
🐛 StackOverflowError endless loop #158
Browse files Browse the repository at this point in the history
  • Loading branch information
trydofor committed Dec 7, 2023
1 parent 7240b8e commit b889d34
Show file tree
Hide file tree
Showing 23 changed files with 504 additions and 150 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package pro.fessional.wings.faceless.jooqgen;

import lombok.val;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
import org.jooq.Converter;
Expand Down Expand Up @@ -66,11 +65,11 @@ public class WingsCodeGenerator {
}

try {
val src = conf.getGenerator().getTarget().getDirectory();
val pkg = conf.getGenerator().getTarget().getPackageName().replace('.', '/');
var src = conf.getGenerator().getTarget().getDirectory();
var pkg = conf.getGenerator().getTarget().getPackageName().replace('.', '/');
// tmp dir
val tmp = Files.createTempDirectory("jooq-safe-gen").toFile();
val tdr = tmp.getAbsolutePath();
var tmp = Files.createTempDirectory("jooq-safe-gen").toFile();
var tdr = tmp.getAbsolutePath();
conf.getGenerator().getTarget().setDirectory(tdr);
log.info("safely generate, tmp-dir={}", tdr);

Expand Down Expand Up @@ -137,8 +136,8 @@ private static Map<String, File> walkDir(String root, String child) throws IOExc

private static void safeCopy(String tmp, String src, String pkg, boolean inc) throws IOException {

val from = walkDir(tmp, pkg);
val dest = walkDir(src, pkg);
var from = walkDir(tmp, pkg);
var dest = walkDir(src, pkg);

if (!inc && !dest.isEmpty()) {
log.info("not incremental, Removing excess files in {}", new File(src, pkg).getCanonicalPath());
Expand All @@ -157,7 +156,7 @@ private static void safeCopy(String tmp, String src, String pkg, boolean inc) th
// date = "2019-09-09T01:33:51.762Z",
// schema version:2019090903
// serialVersionUID = 319604016;
val ignoreRegex = Pattern.compile(String.join("|",
var ignoreRegex = Pattern.compile(String.join("|",
"(import +[^\r\n]+;[\r\n ]+)+",
"The\\s+table\\s+<code>[^.]+",
"The\\s+schema\\s+<code>[^<]+",
Expand All @@ -166,19 +165,19 @@ private static void safeCopy(String tmp, String src, String pkg, boolean inc) th
"[\r\n]+"), Pattern.MULTILINE | Pattern.CASE_INSENSITIVE);

for (Map.Entry<String, File> entry : from.entrySet()) {
val k = entry.getKey();
val f = entry.getValue();
val d = dest.get(k);
var k = entry.getKey();
var f = entry.getValue();
var d = dest.get(k);
if (d == null) {
val t = new File(src, k);
var t = new File(src, k);
//noinspection ResultOfMethodCallIgnored
t.getParentFile().mkdirs();
Files.copy(f.toPath(), t.toPath(), StandardCopyOption.REPLACE_EXISTING);
log.info("create new file={}", k);
}
else {
val ft = ignoreRegex.matcher(InputStreams.readText(new FileInputStream(f))).replaceAll(Null.Str);
val dt = ignoreRegex.matcher(InputStreams.readText(new FileInputStream(d))).replaceAll(Null.Str);
var ft = ignoreRegex.matcher(InputStreams.readText(new FileInputStream(f))).replaceAll(Null.Str);
var dt = ignoreRegex.matcher(InputStreams.readText(new FileInputStream(d))).replaceAll(Null.Str);
if (ft.equals(dt)) {
log.info("skip main same file={}", k);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package pro.fessional.wings.faceless.jooqgen;

import lombok.val;
import org.jetbrains.annotations.NotNull;
import org.jooq.Condition;
import org.jooq.codegen.GeneratorStrategy;
Expand Down Expand Up @@ -92,8 +91,8 @@ public void printSingletonInstance(JavaWriter out, Definition definition) {
// table is TableDefinition : SysCommitJournalTable, SysCommitJournal
final String className = getStrategy().getJavaClassName(definition);
final String identifier = getStrategy().getJavaIdentifier(definition);
val aliasName = genAlias(identifier); // N6
val aliasLower = "pro.fessional.wings.faceless.database.jooq.WingsJooqEnv.uniqueAlias()"; // n6
var aliasName = genAlias(identifier); // N6
var aliasLower = "pro.fessional.wings.faceless.database.jooq.WingsJooqEnv.uniqueAlias()"; // n6
// public static final SysCommitJournalTable asN6 = SysCommitJournal.as(WingsJooqEnv.uniqueRuntimeAlias());
out.println("public static final %s %s = %s.as(%s);", className, aliasName, identifier, aliasLower);
// 🦁<<<
Expand All @@ -105,7 +104,7 @@ public void generateTableClassFooter(TableDefinition table, JavaWriter out) {
// table is TableDefinition : SysCommitJournalTable, SysCommitJournal
final String className = getStrategy().getJavaClassName(table);
final String identifier = getStrategy().getJavaIdentifier(table);
val aliasName = genAlias(identifier); // N6
var aliasName = genAlias(identifier); // N6

out.ref(NotNull.class);
final List<ColumnDefinition> columns = table.getColumns();
Expand All @@ -130,8 +129,8 @@ public void generateTableClassFooter(TableDefinition table, JavaWriter out) {
out.println("return %s;", aliasName);
out.println("}");

val logicCol = columns.stream().filter(it -> {
val col = it.getOutputName();
var logicCol = columns.stream().filter(it -> {
var col = it.getOutputName();
return col.equalsIgnoreCase(COL_DELETE_DT) || col.equalsIgnoreCase(COL_IS_DELETED);
}).findFirst();

Expand All @@ -142,14 +141,14 @@ public void generateTableClassFooter(TableDefinition table, JavaWriter out) {
out.ref(Map.class);
out.ref(HashMap.class);
out.ref(JournalService.class);
val fldDel = reflectMethodRef(out, getStrategy().getJavaIdentifier(colDel), colRefSegments(colDel));
var fldDel = reflectMethodRef(out, getStrategy().getJavaIdentifier(colDel), colRefSegments(colDel));

val namDel = colDel.getOutputName();
var namDel = colDel.getOutputName();
out.println("");
out.javadoc("The colDel <code>%s</code> condition", namDel);
final String markDelete;
if (namDel.equalsIgnoreCase(COL_DELETE_DT)) {
val colType = colDel.getDefinedType().getType().toLowerCase();
var colType = colDel.getDefinedType().getType().toLowerCase();
if (colType.contains("time")) {
markDelete = "commit.getCommitDt()";
if (WingsCodeGenConf.isLiveDataByMax()) {
Expand Down Expand Up @@ -202,11 +201,11 @@ else if (colType.contains("int")) {
out.println("Map<org.jooq.Field<?>, Object> map = new HashMap<>();");
out.println("map.put(%s, %s);", fldDel, markDelete);

val commitCol = columns.stream().filter(it ->
var commitCol = columns.stream().filter(it ->
it.getOutputName().equalsIgnoreCase(COL_COMMIT_ID)).findFirst();
if (commitCol.isPresent()) {
final ColumnDefinition colCid = commitCol.get();
val fldCid = reflectMethodRef(out, getStrategy().getJavaIdentifier(colCid), colRefSegments(colCid));
var fldCid = reflectMethodRef(out, getStrategy().getJavaIdentifier(colCid), colRefSegments(colCid));
out.println("map.put(%s, commit.getCommitId());", fldCid);
}
out.println("return map;");
Expand Down Expand Up @@ -269,9 +268,9 @@ public void generateDao(TableDefinition table, JavaWriter out) {

private String genAlias(String id) {
final String chr = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
val ix = id.hashCode() % chr.length();
val cd = ix < 0 ? chr.charAt(-ix) : chr.charAt(ix);
val sq = id.length() % 10;
var ix = id.hashCode() % chr.length();
var cd = ix < 0 ? chr.charAt(-ix) : chr.charAt(ix);
var sq = id.length() % 10;
return ("as" + cd) + sq;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package pro.fessional.wings.faceless.jooqgen;

import lombok.val;
import org.jooq.codegen.DefaultGeneratorStrategy;
import org.jooq.codegen.GeneratorStrategy;
import org.jooq.meta.ColumnDefinition;
Expand All @@ -22,7 +21,7 @@ public class WingsJavaStrategy extends DefaultGeneratorStrategy {
@Override
public List<String> getJavaClassImplements(Definition definition, Mode mode) {

val impls = super.getJavaClassImplements(definition, mode);
var impls = super.getJavaClassImplements(definition, mode);
if (!(definition instanceof TableDefinition)) return impls;

List<ColumnDefinition> columns = ((TableDefinition) definition).getColumns();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import io.qameta.allure.TmsLink;
import lombok.Setter;
import lombok.val;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down Expand Up @@ -30,7 +29,7 @@ public class TestWingsInitDatabaseSample {
@TmsLink("C12024")
public void init0601() {
// init
val sqls = scan(REVISION_PATH_MASTER, WingsRevision.V01_19_0521_01_EnumI18n.classpath());
var sqls = scan(REVISION_PATH_MASTER, WingsRevision.V01_19_0521_01_EnumI18n.classpath());
schemaRevisionManager.publishRevision(WingsRevision.V00_19_0512_01_Schema.revision(), 0);
schemaRevisionManager.checkAndInitSql(sqls, 0, false);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import io.qameta.allure.TmsLink;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import lombok.val;
import org.apache.shardingsphere.infra.hint.HintManager;
import org.jooq.Field;
import org.jooq.impl.DSL;
Expand All @@ -14,11 +13,11 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.sql.init.dependency.DependsOnDatabaseInitialization;
import org.springframework.boot.test.context.SpringBootTest;
import pro.fessional.wings.faceless.convention.EmptyValue;
import pro.fessional.wings.faceless.app.database.autogen.tables.TstShardingTable;
import pro.fessional.wings.faceless.app.database.autogen.tables.daos.TstShardingDao;
import pro.fessional.wings.faceless.app.database.autogen.tables.pojos.TstSharding;
import pro.fessional.wings.faceless.app.database.autogen.tables.records.TstShardingRecord;
import pro.fessional.wings.faceless.convention.EmptyValue;
import pro.fessional.wings.faceless.flywave.SchemaRevisionManager;
import pro.fessional.wings.faceless.flywave.SchemaShardingManager;
import pro.fessional.wings.faceless.helper.WingsTestHelper;
Expand Down Expand Up @@ -82,7 +81,7 @@ public void test3SplitTable5() {
@Test
@TmsLink("C12138")
public void test4InsertSeeLog() {
val rd = new TstSharding(id,
var rd = new TstSharding(id,
LocalDateTime.now(),
EmptyValue.DATE_TIME,
EmptyValue.DATE_TIME,
Expand All @@ -105,27 +104,27 @@ public void test4InsertSeeLog() {
@Test
@TmsLink("C12139")
public void test5UpdateSeeLog() {
val tp = TstShardingTable.TstSharding;
var tp = TstShardingTable.TstSharding;
// update `tst_sharding` set `modify_dt` = ?, `login_info` = ? where `id` <= ?
val rp = dao.ctx().update(tp)
var rp = dao.ctx().update(tp)
.set(tp.ModifyDt, LocalDateTime.now())
.set(tp.LoginInfo, "update 5")
.where(tp.Id.eq(id))
.execute();
testcaseNotice("plain updated= $rp");
testcaseNotice("update `tst_sharding_1` set `modify_dt` = ?, `login_info` = ? where `id` = ?");

val tw = dao.getTable();
val rw = dao.ctx().update(tw)
var tw = dao.getTable();
var rw = dao.ctx().update(tw)
.set(tw.ModifyDt, LocalDateTime.now())
.set(tw.LoginInfo, "update 5")
.where(tw.Id.eq(id))
.execute();
testcaseNotice("write updated= $rw");
testcaseNotice("update `tst_sharding_1` set `modify_dt` = ?, `login_info` = ? where `id` = ?");

val tr = dao.getAlias();
val rr = dao.ctx().update(tr)
var tr = dao.getAlias();
var rr = dao.ctx().update(tr)
.set(tr.ModifyDt, LocalDateTime.now())
.set(tr.LoginInfo, "update 5")
.where(tr.Id.eq(id))
Expand All @@ -147,8 +146,8 @@ public void test5UpdateSeeLog() {
public void test6SelectSeeLog() {
try (HintManager it = HintManager.getInstance()) {
it.setWriteRouteOnly();
val ta = TstShardingTable.asP1;
val ra = dao.ctx().select(ta.Id)
var ta = TstShardingTable.asP1;
var ra = dao.ctx().select(ta.Id)
.from(ta)
.where(ta.Id.le(id))
.limit(DSL.inline(1)) // RC3
Expand All @@ -157,8 +156,8 @@ public void test6SelectSeeLog() {
testcaseNotice("alias select", ra);
testcaseNotice("select `y8`.`id` from `tst_sharding` as `y8` where `y8`.`id` <= ?");

val tp = TstShardingTable.TstSharding;
val rp = dao.ctx().select(tp.Id)
var tp = TstShardingTable.TstSharding;
var rp = dao.ctx().select(tp.Id)
.from(tp)
.where(tp.Id.le(id))
// .limit(1) // https://github.com/apache/incubator-shardingsphere/issues/3330
Expand All @@ -167,8 +166,8 @@ public void test6SelectSeeLog() {
testcaseNotice("plain select", rp);
testcaseNotice("select `id` from `tst_sharding` where `id` <= ?");

val da = dao.getAlias();
val rd = dao.fetch(da, da.Id.eq(id));
var da = dao.getAlias();
var rd = dao.fetch(da, da.Id.eq(id));
testcaseNotice("dao select= $rd");
testcaseNotice("select `y8`.`id`, `y8`.`create_dt`, ... from `tst_sharding` as `y8` where `y8`.`id` = ?");

Expand All @@ -184,17 +183,17 @@ public void test6SelectSeeLog() {
@Test
@TmsLink("C12141")
public void test7DeleteSeeLog() {
val tp = TstShardingTable.TstSharding;
val rp = dao.ctx().delete(tp)
var tp = TstShardingTable.TstSharding;
var rp = dao.ctx().delete(tp)
.where(tp.Id.eq(id)) // Inline strategy cannot support range sharding.
.and(tp.CommitId.isNotNull())
.getSQL();
// .execute()
testcaseNotice("plain delete= $rp");
testcaseNotice("delete from `tst_sharding` where (`id` <= ? and `commit_id` is not null)");

val dw = dao.getTable();
val rw = dao.delete(dw, dw.Id.eq(id));
var dw = dao.getTable();
var rw = dao.delete(dw, dw.Id.eq(id));
testcaseNotice("dao delete= $rw");
testcaseNotice("delete from `tst_sharding_3` where `id` = ? ");

Expand All @@ -212,17 +211,17 @@ public void test7DeleteSeeLog() {
@Test
@TmsLink("C12142")
public void test8BatchSeeLog() {
val rds = Arrays.asList(
var rds = Arrays.asList(
new TstShardingRecord(119L, now, now, now, 9L, "Batch merge 119", "test8", ZH_CN.getId()),
new TstShardingRecord(308L, now, now, now, 9L, "Batch merge 308", "test8", ZH_CN.getId()),
new TstShardingRecord(309L, now, now, now, 9L, "Batch merge 309", "test8", ZH_CN.getId())
);
testcaseNotice("Batch Insert, check log, ignore in 2 batch, 119 ignore; 308, 309 insert");
val rs1 = dao.batchInsert(rds, 2, true);
var rs1 = dao.batchInsert(rds, 2, true);
Assertions.assertArrayEquals(new int[]{1, 1, 1}, rs1);

testcaseNotice("select first, then insert 310, or update 308, 309");
val rs3 = dao.batchMerge(tbl, new Field[]{tbl.Id}, Arrays.asList(
var rs3 = dao.batchMerge(tbl, new Field[]{tbl.Id}, Arrays.asList(
new TstShardingRecord(310L, now, now, now, 9L, "Batch merge 310", "Other 310", ZH_CN.getId()),
new TstShardingRecord(308L, now, now, now, 9L, "Batch merge 308", "Other 308", ZH_CN.getId()),
new TstShardingRecord(309L, now, now, now, 9L, "Batch merge 309", "Other 309", ZH_CN.getId())
Expand All @@ -233,14 +232,14 @@ public void test8BatchSeeLog() {
@Test
@TmsLink("C12143")
public void test9BatchSeeLog() {
val rds = Arrays.asList(
var rds = Arrays.asList(
new TstShardingRecord(119L, now, now, now, 9L, "Batch load 307", "test9", ZH_CN.getId()),
new TstShardingRecord(318L, now, now, now, 9L, "Batch load 318", "test9", ZH_CN.getId()),
new TstShardingRecord(319L, now, now, now, 9L, "Batch load 319", "test9", ZH_CN.getId())
);
testcaseNotice("Batch Insert, check log, replace 119, new318,319, in 2 batch, replace into");
try {
val rs2 = dao.batchInsert(rds, 2, false);
var rs2 = dao.batchInsert(rds, 2, false);
log.info(Arrays.toString(rs2));
Assertions.assertArrayEquals(new int[]{2, 1, 1}, rs2);
}
Expand All @@ -252,7 +251,7 @@ public void test9BatchSeeLog() {
testcaseNotice("Batch Merge, check log, new 320, on dupkey 318,319, in 2 batch, duplicate");
testcaseNotice("insert into `tst_sharding` (`id`, .., `other_info`) values (?,..., ?) on duplicate key update `login_info` = ?, `other_info` = ?");
try {
val rs3 = dao.batchMerge(tbl, Arrays.asList(
var rs3 = dao.batchMerge(tbl, Arrays.asList(
new TstShardingRecord(320L, now, now, now, 9L, "Batch merge 320", "Other 320", ZH_CN.getId()),
new TstShardingRecord(318L, now, now, now, 9L, "Batch merge 318", "Other 318", ZH_CN.getId()),
new TstShardingRecord(319L, now, now, now, 9L, "Batch merge 319", "Other 319", ZH_CN.getId())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,41 +19,23 @@
})
public class WingsEnabledTopFalseTest {

@Setter(onMethod_ = {@Autowired(required = false)})
protected WingsEnabledCatConfiguration.InnerCatConfigDefault innerCatConfigDefault;

@Setter(onMethod_ = {@Autowired(required = false)})
protected WingsEnabledCatConfiguration wingsEnabledCatConfiguration;
@Setter(onMethod_ = {@Autowired(required = false)})
protected WingsEnabledCatConfiguration.CatBean catBean;
@Setter(onMethod_ = {@Autowired(required = false)})
protected WingsEnabledCatConfiguration.InnerCatConfiguration innerCatConfiguration;
@Setter(onMethod_ = {@Autowired(required = false)})
protected WingsEnabledCatConfiguration.InnerCatBean innerCatBean;


@Setter(onMethod_ = {@Autowired(required = false)})
protected WingsEnabledDogConfiguration wingsEnabledDogConfiguration;
@Setter(onMethod_ = {@Autowired(required = false)})
protected WingsEnabledDogConfiguration.DogBean dogBean;
@Setter(onMethod_ = {@Autowired(required = false)})
protected WingsEnabledDogConfiguration.InnerDogConfiguration innerDogConfiguration;
@Setter(onMethod_ = {@Autowired(required = false)})
protected WingsEnabledDogConfiguration.InnerDogBean innerDogBean;

@Test
@TmsLink("C11029")
public void test() {
Assertions.assertNull(innerCatConfigDefault,"comment/unconment this to recompile");

Assertions.assertNull(wingsEnabledCatConfiguration);
Assertions.assertNull(catBean);
Assertions.assertNull(innerCatConfiguration);
Assertions.assertNull(innerCatBean);

Assertions.assertNull(wingsEnabledDogConfiguration);
Assertions.assertNull(dogBean);
Assertions.assertNull(innerDogConfiguration);
Assertions.assertNull(innerDogBean);
}
}
Loading

0 comments on commit b889d34

Please sign in to comment.