-
Notifications
You must be signed in to change notification settings - Fork 397
Expand file tree
/
Copy pathMongoDBSchema.java
More file actions
97 lines (74 loc) · 3.03 KB
/
MongoDBSchema.java
File metadata and controls
97 lines (74 loc) · 3.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package sqlancer.mongodb;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.bson.BsonType;
import com.mongodb.client.MongoDatabase;
import sqlancer.Randomly;
import sqlancer.common.schema.AbstractSchema;
import sqlancer.common.schema.AbstractTable;
import sqlancer.common.schema.AbstractTableColumn;
import sqlancer.common.schema.AbstractTables;
import sqlancer.common.schema.TableIndex;
import sqlancer.mongodb.MongoDBProvider.MongoDBGlobalState;
public class MongoDBSchema extends AbstractSchema<MongoDBGlobalState, MongoDBSchema.MongoDBTable> {
public enum MongoDBDataType {
INTEGER(BsonType.INT32), STRING(BsonType.STRING), BOOLEAN(BsonType.BOOLEAN), DOUBLE(BsonType.DOUBLE),
DATE_TIME(BsonType.DATE_TIME), TIMESTAMP(BsonType.TIMESTAMP);
private final BsonType bsonType;
MongoDBDataType(BsonType type) {
this.bsonType = type;
}
public BsonType getBsonType() {
return bsonType;
}
public static MongoDBDataType getRandom(MongoDBGlobalState state) {
Set<MongoDBDataType> valueSet = new HashSet<>(Arrays.asList(values()));
if (state.getDmbsSpecificOptions().nullSafety) {
valueSet.remove(STRING);
}
MongoDBDataType[] configuredValues = new MongoDBDataType[valueSet.size()];
return Randomly.fromOptions(valueSet.toArray(configuredValues));
}
}
public static class MongoDBColumn extends AbstractTableColumn<MongoDBTable, MongoDBDataType> {
private final boolean isId;
private final boolean isNullable;
public MongoDBColumn(String name, MongoDBDataType type, boolean isId, boolean isNullable) {
super(name, null, type);
this.isId = isId;
this.isNullable = isNullable;
}
public boolean isId() {
return isId;
}
public boolean isNullable() {
return isNullable;
}
}
public static class MongoDBTables extends AbstractTables<MongoDBTable, MongoDBColumn> {
public MongoDBTables(List<MongoDBTable> tables) {
super(tables);
}
}
public MongoDBSchema(List<MongoDBTable> databaseTables) {
super(databaseTables);
}
public static class MongoDBTable extends AbstractTable<MongoDBColumn, TableIndex, MongoDBGlobalState> {
public MongoDBTable(String name, List<MongoDBColumn> columns, boolean isView) {
super(name, columns, Collections.emptyList(), isView);
}
@Override
public long getNrRows(MongoDBGlobalState globalState) {
throw new UnsupportedOperationException();
}
}
public static MongoDBSchema fromConnection(MongoDatabase connection, String databaseName) {
throw new UnsupportedOperationException();
}
public MongoDBTables getRandomTableNonEmptyTables() {
return new MongoDBTables(Randomly.nonEmptySubset(getDatabaseTables()));
}
}