package app.database;
import java.sql.SQLException;
import org.ytreza.data.database.jdbc.JdbcConnectionManager;
import org.ytreza.data.table.jdbc.TableStrategyJdbc;
import app.database.model.ModelName;
import app.database.model.note.ModelNote;
import app.database.model.note.NoteStrategyJdbc;
import app.database.model.note.TableNote;
import app.database.model.tag.ModelTag;
import app.database.model.tag.TableTag;
import app.database.model.tag.TagStrategyJdbc;
import app.database.model.tagAndNote.ModelTagAndNote;
import app.database.model.tagAndNote.TableTagForNote;
import app.database.model.tagAndNote.TagAndNoteStrategyJdbc;
public class TableFactoryJdbc implements TableFactory {
private TableNote tableNote;
private TableTag tableTag;
private TableTagForNote tableTagForNote;
private JdbcConnectionManager connection;
public TableFactoryJdbc(JdbcConnectionManager connection) {
this.connection = connection;
tableNote = setUpTableNote();
tableTag = setUpTableTag();
tableTagForNote = setUpTableTagForNote();
}
private TableTagForNote setUpTableTagForNote() {
TagAndNoteStrategyJdbc strategy = new TagAndNoteStrategyJdbc();
strategy.setConnectionManager(connection);
return new TableTagForNote(ModelName.NOTE_TAG, ModelName.NOTE, strategy);
}
private TableTag setUpTableTag() {
TagStrategyJdbc strategy = new TagStrategyJdbc();
strategy.setConnectionManager(connection);
return new TableTag(ModelName.TAG, strategy);
}
private TableNote setUpTableNote() {
NoteStrategyJdbc strategy = new NoteStrategyJdbc();
strategy.setConnectionManager(connection);
return new TableNote(ModelName.NOTE, strategy);
}
@Override
public TableNote getTableNote() {
return tableNote;
}
@Override
public TableTag getTableTag() {
return tableTag;
}
@Override
public TableTagForNote getTableTagForNote() {
return tableTagForNote;
}
public void buildTable() {
try {
((TableStrategyJdbc<ModelNote>) tableNote.getStrategy()).createTable();
((TableStrategyJdbc<ModelTag>) tableTag.getStrategy()).createTable();
((TableStrategyJdbc<ModelTagAndNote>) tableTagForNote.getStrategy()).createTable();
} catch (SQLException e) {
// AUTO_TODO Auto-generated catch block
e.printStackTrace();
}
}
}