Ray's patch to fix empty table insertion.
This commit is contained in:
@@ -493,46 +493,15 @@ public abstract class BuildVisitor implements FragmentVisitor<Void>
|
|||||||
|
|
||||||
public Void visit (InsertClause insertClause)
|
public Void visit (InsertClause insertClause)
|
||||||
{
|
{
|
||||||
Class<? extends PersistentRecord> pClass = insertClause.getPersistentClass();
|
|
||||||
Object pojo = insertClause.getPojo();
|
|
||||||
DepotMarshaller<?> marsh = _types.getMarshaller(pClass);
|
|
||||||
_innerClause = true;
|
_innerClause = true;
|
||||||
|
|
||||||
Set<String> idFields = insertClause.getIdentityFields();
|
|
||||||
ColumnExp[] fields = marsh.getColumnFieldNames();
|
|
||||||
|
|
||||||
_builder.append("insert into ");
|
_builder.append("insert into ");
|
||||||
appendTableName(insertClause.getPersistentClass());
|
appendTableName(insertClause.getPersistentClass());
|
||||||
_builder.append(" (");
|
_builder.append(" ");
|
||||||
|
appendInsertColumns(insertClause);
|
||||||
boolean comma = false;
|
|
||||||
for (ColumnExp field : fields) {
|
|
||||||
if (idFields.contains(field.name)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (comma) {
|
|
||||||
_builder.append(", ");
|
|
||||||
}
|
|
||||||
comma = true;
|
|
||||||
appendLhsColumn(pClass, field);
|
|
||||||
}
|
|
||||||
_builder.append(") values (");
|
|
||||||
|
|
||||||
comma = false;
|
|
||||||
for (ColumnExp field : fields) {
|
|
||||||
if (idFields.contains(field.name)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (comma) {
|
|
||||||
_builder.append(", ");
|
|
||||||
}
|
|
||||||
comma = true;
|
|
||||||
bindField(pClass, field, pojo);
|
|
||||||
}
|
|
||||||
_builder.append(")");
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public Void visit (CreateIndexClause createIndexClause)
|
public Void visit (CreateIndexClause createIndexClause)
|
||||||
{
|
{
|
||||||
_builder.append("create ");
|
_builder.append("create ");
|
||||||
@@ -912,6 +881,43 @@ public abstract class BuildVisitor implements FragmentVisitor<Void>
|
|||||||
_builder.append(")");
|
_builder.append(")");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// output the column names and values for an insert
|
||||||
|
protected void appendInsertColumns (InsertClause insertClause)
|
||||||
|
{
|
||||||
|
Class<? extends PersistentRecord> pClass = insertClause.getPersistentClass();
|
||||||
|
Object pojo = insertClause.getPojo();
|
||||||
|
DepotMarshaller<?> marsh = _types.getMarshaller(pClass);
|
||||||
|
Set<String> idFields = insertClause.getIdentityFields();
|
||||||
|
ColumnExp[] fields = marsh.getColumnFieldNames();
|
||||||
|
|
||||||
|
_builder.append("(");
|
||||||
|
boolean comma = false;
|
||||||
|
for (ColumnExp field : fields) {
|
||||||
|
if (idFields.contains(field.name)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (comma) {
|
||||||
|
_builder.append(", ");
|
||||||
|
}
|
||||||
|
comma = true;
|
||||||
|
appendLhsColumn(pClass, field);
|
||||||
|
}
|
||||||
|
_builder.append(") values (");
|
||||||
|
|
||||||
|
comma = false;
|
||||||
|
for (ColumnExp field : fields) {
|
||||||
|
if (idFields.contains(field.name)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (comma) {
|
||||||
|
_builder.append(", ");
|
||||||
|
}
|
||||||
|
comma = true;
|
||||||
|
bindField(pClass, field, pojo);
|
||||||
|
}
|
||||||
|
_builder.append(")");
|
||||||
|
}
|
||||||
|
|
||||||
protected BuildVisitor (DepotTypes types)
|
protected BuildVisitor (DepotTypes types)
|
||||||
{
|
{
|
||||||
_types = types;
|
_types = types;
|
||||||
|
|||||||
@@ -39,6 +39,8 @@ import com.samskivert.depot.Exps;
|
|||||||
import com.samskivert.depot.PersistentRecord;
|
import com.samskivert.depot.PersistentRecord;
|
||||||
import com.samskivert.depot.annotation.FullTextIndex.Configuration;
|
import com.samskivert.depot.annotation.FullTextIndex.Configuration;
|
||||||
import com.samskivert.depot.annotation.FullTextIndex;
|
import com.samskivert.depot.annotation.FullTextIndex;
|
||||||
|
import com.samskivert.depot.clause.InsertClause;
|
||||||
|
import com.samskivert.depot.expression.ColumnExp;
|
||||||
import com.samskivert.depot.impl.expression.IntervalExp;
|
import com.samskivert.depot.impl.expression.IntervalExp;
|
||||||
import com.samskivert.depot.impl.expression.DateFun.DatePart;
|
import com.samskivert.depot.impl.expression.DateFun.DatePart;
|
||||||
import com.samskivert.depot.impl.expression.DateFun.DateTruncate;
|
import com.samskivert.depot.impl.expression.DateFun.DateTruncate;
|
||||||
@@ -136,6 +138,22 @@ public class PostgreSQLBuilder
|
|||||||
_builder.append("\"").append(field).append("\"");
|
_builder.append("\"").append(field).append("\"");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override protected void appendInsertColumns (InsertClause insertClause)
|
||||||
|
{
|
||||||
|
// see if we will be inserting any columns whatsoever
|
||||||
|
Class<? extends PersistentRecord> pClass = insertClause.getPersistentClass();
|
||||||
|
Set<String> idFields = insertClause.getIdentityFields();
|
||||||
|
for (ColumnExp field : _types.getMarshaller(pClass).getColumnFieldNames()) {
|
||||||
|
if (!idFields.contains(field.name)) {
|
||||||
|
// we found a field we're inserting, so call super and finish
|
||||||
|
super.appendInsertColumns(insertClause);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// we never found anything we'll actually be inserting
|
||||||
|
_builder.append("default values");
|
||||||
|
}
|
||||||
|
|
||||||
protected PGBuildVisitor (DepotTypes types)
|
protected PGBuildVisitor (DepotTypes types)
|
||||||
{
|
{
|
||||||
super(types);
|
super(types);
|
||||||
|
|||||||
Reference in New Issue
Block a user