Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.bytebach.impl;
- import java.util.*;
- import com.bytebach.model.*;
- public class MyDatabase implements Database {
- Collection<? extends Table> tables;
- public MyDatabase(){
- }
- @Override
- public Collection<? extends Table> tables() {
- return tables;
- }
- @Override
- public Table table(String name) {
- for(Table t : tables){
- if(t.name().equals(name)){
- return t;
- }
- }
- // TODO Auto-generated method stub
- return null;
- }
- @Override
- public void createTable(String name, List<Field> fields) {
- if(table(name)!=null){
- throw new InvalidOperation("Table already exists");
- }
- Table newTable = new MyTable(name,fields);
- tables.add(newTable);
- }
- @Override
- public void deleteTable(String name) {
- for(Table t : tables){
- if(t.name().equals(name)){
- tables.remove(t);
- //references thingy
- }
- }
- throw new InvalidOperation("Fuck");
- }
- // This is where you'll probably want to start. You'll need to provide an
- // implementation of Table as well.
- //
- // One of the key challenges in this assignment is to provide you're
- // own implementations of the List interface which can intercept the various
- // operations (e.g. add, set, remove, etc) and check whether they violate
- // the constraints and/or update the database appropriately (e.g. for the
- // cascading delete).
- //
- // HINT: to get started, don't bother providing your own implementations of
- // List as discussed above! Instead, implement MyDatabase and MyTabe using
- // conventional Collections. When you have that working, and the web system
- // is doing something sensible, then consider how you're going to get those
- // unit test to past.
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement