mirror of
https://github.com/querydsl/querydsl.git
synced 2026-06-13 21:01:01 +08:00
Fix intertable dml rendering
This commit is contained in:
parent
2c23b2eff9
commit
a4df2ea4c2
@ -13,6 +13,9 @@
|
||||
*/
|
||||
package com.mysema.query.sql;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.*;
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.Lists;
|
||||
@ -26,9 +29,6 @@ import com.mysema.query.support.SerializerBase;
|
||||
import com.mysema.query.types.*;
|
||||
import com.mysema.query.types.Template.Element;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* SqlSerializer serializes Querydsl queries into SQL
|
||||
*
|
||||
@ -746,7 +746,7 @@ public class SQLSerializer extends SerializerBase<SQLSerializer> {
|
||||
}
|
||||
}
|
||||
final PathMetadata<?> metadata = path.getMetadata();
|
||||
if (metadata.getParent() != null && !skipParent) {
|
||||
if (metadata.getParent() != null && (!skipParent || dml)) {
|
||||
visit(metadata.getParent(), context);
|
||||
append(".");
|
||||
}
|
||||
|
||||
@ -13,14 +13,12 @@
|
||||
*/
|
||||
package com.mysema.query.sql;
|
||||
|
||||
import static com.mysema.query.types.PathMetadataFactory.forVariable;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.mysema.query.types.path.NumberPath;
|
||||
import org.junit.Test;
|
||||
import static com.mysema.query.types.PathMetadataFactory.forVariable;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
public class KeyAccessorsTest {
|
||||
|
||||
@ -64,7 +62,7 @@ public class KeyAccessorsTest {
|
||||
|
||||
protected void addMetadata() {
|
||||
addMetadata(id, ColumnMetadata.named("ID"));
|
||||
addMetadata(id, ColumnMetadata.named("SUPERIOR_ID"));
|
||||
addMetadata(superiorId, ColumnMetadata.named("SUPERIOR_ID"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1,13 +1,11 @@
|
||||
package com.mysema.query.sql.dml;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.mysema.query.sql.KeyAccessorsTest.QEmployee;
|
||||
import com.mysema.query.sql.SQLBindings;
|
||||
import com.mysema.query.sql.SQLTemplates;
|
||||
import org.junit.Test;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class SQLDeleteClauseTest {
|
||||
|
||||
@ -26,7 +24,7 @@ public class SQLDeleteClauseTest {
|
||||
delete.where(emp1.id.eq(1));
|
||||
|
||||
SQLBindings sql = delete.getSQL().get(0);
|
||||
assertEquals("delete from EMPLOYEE\nwhere EMPLOYEE.SUPERIOR_ID = ?", sql.getSQL());
|
||||
assertEquals("delete from EMPLOYEE\nwhere EMPLOYEE.ID = ?", sql.getSQL());
|
||||
assertEquals(ImmutableList.of(1), sql.getBindings());
|
||||
}
|
||||
|
||||
|
||||
@ -1,13 +1,11 @@
|
||||
package com.mysema.query.sql.dml;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.mysema.query.sql.KeyAccessorsTest.QEmployee;
|
||||
import com.mysema.query.sql.SQLBindings;
|
||||
import com.mysema.query.sql.SQLTemplates;
|
||||
import org.junit.Test;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class SQLInsertClauseTest {
|
||||
|
||||
@ -18,7 +16,7 @@ public class SQLInsertClauseTest {
|
||||
insert.set(emp1.id, 1);
|
||||
|
||||
SQLBindings sql = insert.getSQL().get(0);
|
||||
assertEquals("insert into EMPLOYEE (SUPERIOR_ID)\nvalues (?)", sql.getSQL());
|
||||
assertEquals("insert into EMPLOYEE (ID)\nvalues (?)", sql.getSQL());
|
||||
assertEquals(ImmutableList.of(1), sql.getBindings());
|
||||
}
|
||||
|
||||
|
||||
@ -1,13 +1,12 @@
|
||||
package com.mysema.query.sql.dml;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.mysema.query.sql.KeyAccessorsTest.QEmployee;
|
||||
import com.mysema.query.sql.SQLBindings;
|
||||
import com.mysema.query.sql.SQLSubQuery;
|
||||
import com.mysema.query.sql.SQLTemplates;
|
||||
import org.junit.Test;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class SQLUpdateClauseTest {
|
||||
|
||||
@ -18,8 +17,42 @@ public class SQLUpdateClauseTest {
|
||||
update.set(emp1.id, 1);
|
||||
|
||||
SQLBindings sql = update.getSQL().get(0);
|
||||
assertEquals("update EMPLOYEE\nset SUPERIOR_ID = ?", sql.getSQL());
|
||||
assertEquals("update EMPLOYEE\nset ID = ?", sql.getSQL());
|
||||
assertEquals(ImmutableList.of(1), sql.getBindings());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void Intertable() {
|
||||
QEmployee emp1 = new QEmployee("emp1");
|
||||
QEmployee emp2 = new QEmployee("emp2");
|
||||
SQLUpdateClause update = new SQLUpdateClause(null, SQLTemplates.DEFAULT, emp1);
|
||||
update.set(emp1.id, 1)
|
||||
.where(emp1.id.eq(new SQLSubQuery().from(emp2)
|
||||
.where(emp2.superiorId.isNotNull())
|
||||
.unique(emp2.id)));
|
||||
|
||||
SQLBindings sql = update.getSQL().get(0);
|
||||
assertEquals("update EMPLOYEE\n" +
|
||||
"set ID = ?\n" +
|
||||
"where EMPLOYEE.ID = (select emp2.ID\n" +
|
||||
"from EMPLOYEE emp2\n" +
|
||||
"where emp2.SUPERIOR_ID is not null)", sql.getSQL());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void Intertable2() {
|
||||
QEmployee emp1 = new QEmployee("emp1");
|
||||
QEmployee emp2 = new QEmployee("emp2");
|
||||
SQLUpdateClause update = new SQLUpdateClause(null, SQLTemplates.DEFAULT, emp1);
|
||||
update.set(emp1.id, new SQLSubQuery().from(emp2)
|
||||
.where(emp2.superiorId.isNotNull())
|
||||
.unique(emp2.id));
|
||||
|
||||
SQLBindings sql = update.getSQL().get(0);
|
||||
assertEquals("update EMPLOYEE\n" +
|
||||
"set ID = (select emp2.ID\n" +
|
||||
"from EMPLOYEE emp2\n" +
|
||||
"where emp2.SUPERIOR_ID is not null)", sql.getSQL());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user