· 6 years ago · May 18, 2019, 11:26 AM
1public class DoctorType extends IData{
2
3 private AliasedString name = null;
4
5 public DoctorType() {
6 super();
7 }
8
9 public DoctorType(MedicineCenter mc) {
10 super(mc);
11 }
12
13 public void setName(AliasedString i) {
14 this.name = i;
15 }
16
17 public AliasedString getName() {
18 return this.name;
19 }
20
21 @Override
22 public void cleanUp() {
23
24 this.name = null;
25 }
26
27 @Override
28 public int getDriverId() {
29 return 1230921981;
30 }
31
32 public static class Driver extends DataDriver<DoctorType>{
33
34 @Override
35 public void writeToStream(IData data, DataOutputStream out, List<IData> dependencies) throws IOException {
36
37 DoctorType type = (DoctorType) data;
38
39 DataDriversUtils.writeObject(type.getName(), out);
40 }
41
42 @Override
43 public void readFromStream(IData data, DataInputStream in, Queue<IData> dependencies) throws IOException {
44
45 DoctorType type = (DoctorType)data;
46
47 try {
48 type.setName((AliasedString) DataDriversUtils.readObject(in));
49 } catch (ClassNotFoundException e) {
50
51 e.printStackTrace();
52 }
53 }
54
55 @Override
56 public Map<String, Object> saveToDataBase(IData data, List<IData> dependencies) {
57
58 InsertSql is = new InsertSql();
59
60 DoctorType type = (DoctorType) data;
61
62 is.set("name", type.getName().toString());
63
64 return is.getData();
65 }
66
67 @Override
68 public void loadFromDataBase(IData data, Map<String, Object> rawData, Queue<IData> dependencies) {
69
70 DoctorType type = (DoctorType) data;
71
72 type.setName(AliasedString.fromString((String) rawData.get("name"), "_"));
73 }
74
75 @Override
76 public String getDefaultTableName() {
77
78 return "doctor_types";
79 }
80
81 @Override
82 public String getSqlCreateTableRequest() {
83 return "CREATE TABLE IF NOT EXISTS `doctor_types` ("
84 + "id BIGINT(20), PRIMARY KEY(id), "
85 + "name TEXT, "
86 + "system_dependencies TEXT)";
87 }
88
89 @Override
90 public String getDefaultSectorName() {
91
92 return "/humans/staff/doctor_types";
93 }
94
95 @Override
96 public String getNewFileName(IData data, MedicineCenter mc) {
97
98 return "doctor_type_"+data.getId()+".dat";
99 }
100
101 @Override
102 public IData getInstance() {
103
104 return new DoctorType();
105 }
106 }
107}