Im trying to make a small DSL in Java that I can use to populate testdata in a database. The language I would like to use is as follows.
createRowInTableA().
   createRowInTableB().
createRowInTableA().
   createRowInTableB().
      createRowInTableC().
end();
The order the tables are created is important, for example tableB depends on tableA and tableC depends on tableA and tableB. Therefore I want to make it so that the option to create tableB only is available directly after tableA is created etc. I have started to create the interfaces describing the DSL but I don't know how I should actually implement the interfaces inorder to make the type of nested behavior I'm looking for. This is what the interfaces looks like.
public interface End {
    public void sendTestData(); 
}
public interface TableA extends End {
   public Builder createRowInTableA();
}
public interface TableB extends TableA {
   public Builder createRowInTableB();
}
public interface TableC extends TableB {
   public Builder createRowInTableC();
}
However when I start implementing this language using builder pattern to create a fluent API the hierarchy I want goes away.
public class DBBuilder implements TableC {
   static class Builder {
      public Builder createRowInTableA(){...}
      public Builder createRowInTableB(){...}
      public Builder createRowInTableC(){...}
   }
}
				
                        
You can use a set of interfaces and class adapters: