Merge remote-tracking branch 'remotes/origin/master' into zgl

zgl
曾国霖 6 years ago
commit 7e1f70ad66

@ -9,11 +9,12 @@ import java.util.Map;
public class Delete extends Operation {
@Override
public void execute(User subject) throws GExcptSQL {
public Map<String, Object> execute(User subject) throws GExcptSQL {
Map<String, String> map = new HashMap<>();
map.put("id",(String)options.get("id"));
map.put("id",(String)this.getOptions().get("id"));
for(String table:DBManagement.graduationDesignTables){
DBManagement.delete(table,map);
}
return options;
}
}

@ -1,3 +1,6 @@
{
"id": "java.lang.String"
"options":{
"id": "String"
},
"return":{}
}

@ -1,4 +1,12 @@
package core.operation;
public class DownloadFile {
import core.user.User;
import java.util.Map;
public class DownloadFile extends Operation{
@Override
public Map<String, Object> execute(User subject) throws Exception {
return this.getOptions();
}
}

@ -0,0 +1,6 @@
{
"options":{
},
"return":{}
}

@ -1,4 +1,18 @@
package core.operation;
public class FillInformation {
import core.user.User;
import dao.DBManagement;
import java.util.Map;
public class FillInformation extends Operation{
@Override
public Map<String, Object> execute(User subject) throws Exception {
String table = (String) this.getOptions().get("table");
Map<String,String> vMap = (Map<String, String>) this.getOptions().get("vMap");
Map<String,String> limits = (Map<String, String>) this.getOptions().get("limits");
DBManagement.update(table,vMap,limits);
return this.getOptions();
}
}

@ -0,0 +1,8 @@
{
"options":{
"table":"String",
"vMap":"Map<String,String>",
"limits":"Map<String,String>"
},
"return":{}
}

@ -2,7 +2,7 @@ package core.operation;
import core.user.User;
import error.GExcptSQL;
import error.GExcptFormat;
import gdms.Mode;
import java.util.Map;
@ -14,19 +14,21 @@ public abstract class Operation {
Operation(){
super();
}
public abstract Map<String, Object> execute(User subject) throws Exception;
public void setSubject(User subject) {
this.subject = subject;
}
public User getSubject() {
return subject;
}
public void setSubject(User subject) {
this.subject = subject;
public Map<String, Object> getOptions() {
return options;
}
public void setOptions(String options) {
public void setOptions(String options) throws GExcptFormat {
this.options = core.operation.utils.util.string2MapOptions(options);
}
public void setProcessOperations(String processOptions){
setOptions(processOptions);
}
public void addUserOperations(String key, Object value){
public void addOptions(String key, Object value){
if ( Mode.strict == 1){
if(!this.options.containsKey(key)) {
try {
@ -38,6 +40,7 @@ public abstract class Operation {
}
this.options.put(key,value);
}
public abstract void execute(User subject) throws Exception;
public void setOptions(Map<String, Object> options) {
this.options = options;
}
}

@ -4,18 +4,31 @@ import core.user.User;
import dao.DBManagement;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
public class Search extends Operation {
@Override
public void execute(User subject) throws Exception {
String table = (String)options.get("table");
List<String> fields = (List<String>)options.get("fields");
Map<String, String> limits = (Map<String, String>)options.get("limits");
int start = (int)options.get("start");
int end = (int)options.get("end");
public Map<String, Object> execute(User subject) throws Exception {
String table = (String)this.getOptions().get("table");
List<String> fields = (List<String>)this.getOptions().get("fields");
Map<String, String> limits = (Map<String, String>)this.getOptions().get("limits");
int start = (int)this.getOptions().get("start");
int end = (int)this.getOptions().get("end");
ResultSet rs = DBManagement.select(fields,table,limits,start,end);
//todo
ResultSetMetaData rsm = rs.getMetaData() ;
int columnCount = rsm.getColumnCount();
List<String[]> ls = new ArrayList<>();
while(rs.next()){
String[] s = new String[columnCount];
for(int i=0;i<columnCount;i++){
s[i] = rs.getString(i);
}
ls.add(s);
}
this.getOptions().put("result",ls);
return this.getOptions();
}
}

@ -1,8 +1,12 @@
{
"table": "java.lang.String",
"fields": "java.util.List",
"value": "java.lang.String",
"start": "int",
"end": "int",
"return": "java.lang.String[][]"
"options":{
"table": "String",
"fields": "List",
"value": "String",
"start": "int",
"end": "int"
},
"return": {
"result":"List<String[]>"
}
}

@ -10,10 +10,10 @@ import java.util.Map;
public class Select extends Operation {
@Override
public void execute(User subject) throws GExcptSQL {
public Map<String, Object> execute(User subject) throws GExcptSQL {
Map<String, String> vMap = new HashMap<>();
String id = (String)options.get("student_id");
String teacher_id = (String)options.get("teacher_id");
String id = (String)this.getOptions().get("student_id");
String teacher_id = (String)this.getOptions().get("teacher_id");
vMap.put("id",id);
vMap.put("student_id",id);
vMap.put("teacher_id",teacher_id);
@ -23,5 +23,6 @@ public class Select extends Operation {
for(int i=1;i<DBManagement.graduationDesignTables.length;i++){
DBManagement.insert(DBManagement.graduationDesignTables[i],vMap);
}
return this.getOptions();
}
}

@ -1,4 +1,7 @@
{
"student_id": "java.lang.String",
"teacher_id": "java.lang.String"
"options":{
"student_id": "String",
"teacher_id": "String"
},
"return":{}
}

@ -6,10 +6,8 @@ import error.GExcptSQL;
import java.util.Map;
public class UploadFileOperation extends Operation {
Map<String, Object> options;
@Override
public void execute(User subject) throws GExcptSQL {
public Map<String, Object> execute(User subject) throws GExcptSQL {
return this.getOptions();
}
}

@ -1,4 +1,6 @@
{
"java.lang.String": "activity",
"lava.io.File": "file"
"options":{
"file": "File"
},
"return":{}
}

@ -1,5 +1,8 @@
package core.operation.utils;
import error.GExcptFormat;
import gdms.Mode;
import java.util.HashMap;
import java.util.Map;
@ -7,12 +10,16 @@ public interface util {
static String stringOptionsFormat(String options){
return options.replaceAll(" {2,}", " ") ;
}
static Map<String, Object> string2MapOptions(String sOptions){
static Map<String, Object> string2MapOptions(String sOptions) throws GExcptFormat {
sOptions = stringOptionsFormat(sOptions);
Map<String, Object> options = new HashMap<>();
String[] sOpts = sOptions.split(" ");
for(int i=0;i<sOpts.length;i++){
options.put(sOpts[i],sOpts[++i]);
if(Mode.strict==1){
if(sOpts[i].indexOf(0)=='-')
throw new GExcptFormat("options format error");
}
options.put(sOpts[i].substring(1),sOpts[++i]);
}
return options;
}

@ -1,4 +1,10 @@
package core.user;
import java.util.Map;
public class Administrator extends User {
@Override
public void setAttr(Map<String, String> vMap){
super.setAttr(vMap);
}
}

@ -1,7 +1,31 @@
package core.user;
import java.io.File;
import java.util.Map;
public class Student extends User {
private String grade;
private String profession_code;
public void setAttr(Map<String, String> vMap){
super.setAttr(vMap);
this.setGrade(vMap.get("grade"));
this.setProfession_code(vMap.get("profession_code"));
}
public String getGrade() {
return grade;
}
public void setGrade(String grade) {
this.grade = grade;
}
public String getProfession_code() {
return profession_code;
}
public void setProfession_code(String profession_code) {
this.profession_code = profession_code;
}
}

@ -1,7 +1,41 @@
package core.user;
import java.io.File;
import java.util.Map;
public class Teacher extends User {
String job_title;
String education;
String profession_code;
@Override
public void setAttr(Map<String, String> vMap){
super.setAttr(vMap);
this.setEducation(vMap.get("education"));
this.setJob_title(vMap.get("job_title"));
this.setProfession_code(vMap.get("profession_code"));
}
public String getJob_title() {
return job_title;
}
public void setJob_title(String job_title) {
this.job_title = job_title;
}
public String getEducation() {
return education;
}
public void setEducation(String education) {
this.education = education;
}
public String getProfession_code() {
return profession_code;
}
public void setProfession_code(String profession_code) {
this.profession_code = profession_code;
}
}

@ -5,6 +5,7 @@ import core.user.userFun.AccountManageable;
import core.user.userFun.ProcessConfigurable;
import java.util.List;
import java.util.Map;
public abstract class User implements AccountManageable, ProcessConfigurable{
@ -109,4 +110,11 @@ public abstract class User implements AccountManageable, ProcessConfigurable{
public void syncFromDatabase() {
}
public void setAttr(Map<String, String> vMap){
this.setId(vMap.get("id"));
this.setName(vMap.get("name"));
this.setE_mail_location(vMap.get("e_mail_location"));
this.setPhone_number(vMap.get("phone_number"));
}
}

@ -8,23 +8,28 @@ import utils.Utils;
import java.lang.reflect.InvocationTargetException;
import java.sql.ResultSet;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import static dao.DBManagement.userTables;
public interface AccountManagement {
static User login(String id, String password) throws GExcptSQL, GExcptAccount, SQLException {
ResultSet rs = null;
String sql = null;
String userType = null;
for(String userTable:userTables){
sql = "SELECT * FROM "+userTable+" WHERE id=\'"+id+"\'";
List<String> columns = new ArrayList<>();
columns.add("*");
Map<String,String> limits = new HashMap<>();
limits.put("id",id);
try {
rs = DBManagement.query(sql);
rs = DBManagement.select(columns,userTable,limits,1,2);
} catch (Exception e) {
throw new GExcptSQL("QUERY\n\t"+sql+"\nfailure");
throw new GExcptSQL("QUERY\n\t"+id+"\nfailure");
}
if(rs!=null){
userType = userTable;
@ -38,25 +43,21 @@ public interface AccountManagement {
try {
if(!rs.getString(2).equals(password))
throw new GExcptAccount("password wrong");
List<String> necessaryInfo = new ArrayList<>();
for(int i=0;i<4;i++){
necessaryInfo.add(rs.getString(i));
Map<String, String> vMap = new HashMap<>();
ResultSetMetaData rsm = rs.getMetaData();
rs.next();
for(int i=0;i<rsm.getColumnCount();i++){
vMap.put(rsm.getCatalogName(i),rs.getString(i));
}
return createUser(userType,necessaryInfo);
return createUser(userType,vMap);
} catch (SQLException e) {
e.printStackTrace();
}
return null;
}
static User register(String userType, List<String> necessaryInfo) throws GExcptSQL {
necessaryInfo = Utils.formatUserInfo(userType,necessaryInfo);
String sql = "INSERT INTO "+userType+" VALUES(\'";
for(String info:necessaryInfo){
sql+=info+"\', \'";
}
sql =Utils.cutTail(sql,3)+")";
DBManagement.update(sql);
return createUser(userType, necessaryInfo);
static User register(String userType, Map<String, String> vMap) throws GExcptSQL {
DBManagement.insert(userType,vMap);
return createUser(userType, vMap);
}
static void logout(User user){
//todo
@ -67,25 +68,14 @@ public interface AccountManagement {
static User getUser(String userType){
try {
return (User) Class.forName("core.user."+ Utils.toUpperFirstChar(userType)).getDeclaredConstructor().newInstance();
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
} catch (NoSuchMethodException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
} catch (InstantiationException | IllegalAccessException | NoSuchMethodException | InvocationTargetException | ClassNotFoundException e) {
e.printStackTrace();
}
return null;
}
static User createUser(String userType, List<String> necessaryInfo) {
static User createUser(String userType, Map<String, String> vMap) {
User user = getUser(userType);
user.setId(necessaryInfo.get(0));
user.setName(necessaryInfo.get(1));
user.setE_mail_location(necessaryInfo.get(2));
user.setPhone_number(necessaryInfo.get(3));
user.setAttr(vMap);
return user;
}
}

@ -0,0 +1,7 @@
package error;
public class GExcptFormat extends GExcpt {
public GExcptFormat(String info) {
super(info);
}
}

@ -0,0 +1,21 @@
package gdms;
import dao.Select;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class test {
public static void main(String[] args){
List<String> list = new ArrayList<>();
list.add("q");
list.add("w");
Map<String,String> map=new HashMap<>();
map.put("a","b");
map.put("c","d");
Select sql = new Select(list,"zx",map,1,2);
System.out.println(sql.getSQL());
}
}
Loading…
Cancel
Save