📄 clsdatabase.java
字号:
clsTable temptbl;
clsField tempfld;
if (existsTable(tblname)) {
for (int i = 0; i < table.size(); i++) {
temptbl = (clsTable) table.get(i);
if (temptbl.getName().equals(tblname)
&& temptbl.field.size() > 0) {
for (int j = 0; j < temptbl.field.size(); j++) {
tempfld = (clsField) temptbl.field.get(i);
if (tempfld.value.size() == 0) {
out = false;
}
else {
out = true;
}
}
break;
}
else {
out = false;
}
}
}
else {
errorMessage = "(RowCountLargeThanOne)Can't find this table!";
}
}
catch (Exception e) {
errorMessage = "RowCount Error!\nMessage:" + e;
}
finally {
}
return out;
}
public boolean TableCountLargeThanOne() {
return (table.size() > 0);
}
public boolean FieldCountLargeThanOne(String tblname) {
boolean out = false;
try {
if (existsTable(tblname) == true) {
for (int i = 0; i < table.size(); i++) {
clsTable temptbl = (clsTable) table.get(i);
if (temptbl.field.size() > 0) {
out = true;
break;
}
}
}
else {
errorMessage = "(FieldCountLargeThanOne)Can't find this table!";
}
}
catch (Exception e) {
errorMessage = "FieldCount Error!\nMessage:" + e;
}
return out;
}
public int retTableIndex(String tblname) {
clsTable temptbl;
int out = -1;
try {
if (existsTable(tblname)) {
for (int i = 0; i < table.size(); i++) {
temptbl = (clsTable) table.get(i);
if (temptbl.getName().equals(tblname)) {
out = i;
break;
}
}
}
else {
errorMessage = "(retTableIndex)Can't find this table!";
}
}
catch (Exception e) {
errorMessage = "getTableIndex Error!\nMessage:" + e;
}
return out;
}
public int retFieldIndex(String tblname, String fldname) {
clsTable temptbl;
int out = -1;
try {
temptbl = retTableRef(tblname);
clsField tempfld;
if (existsTable(tblname) && existsField(tblname, fldname)) {
for (int i = 0; i < temptbl.field.size(); i++) {
tempfld = (clsField) temptbl.field.get(i);
if (tempfld.getName().equals(fldname)) {
out = i;
break;
}
}
}
else {
errorMessage = "(getFieldIndex)Can't find this table or field!";
}
}
catch (Exception e) {
errorMessage = "getFieldIndex Error!\nMessage:" + e;
}
return out;
}
public String getErrorMessage() {
return errorMessage;
}
public void setErrorMessageEmpty() {
errorMessage = null;
errorMessage = new String();
}
public boolean existsTable(String tblname) {
clsTable temptbl = null;
boolean out = false;
try {
for (int i = 0; i < table.size(); i++) {
temptbl = (clsTable) table.get(i);
if (temptbl.getName().equals(tblname)) {
out = true;
break;
}
}
}
catch (Exception e) {
errorMessage = "FindTableExists Error!!!";
}
return out;
}
public boolean existsField(String tblname, String fldname) {
clsTable temptbl = null;
clsField tempfld = null;
boolean out = false;
try {
for (int i = 0; i < table.size(); i++) {
temptbl = (clsTable) table.get(i);
if (temptbl.getName().equals(tblname)) {
for (int j = 0; j < temptbl.field.size(); j++) {
tempfld = (clsField) temptbl.field.get(j);
if (tempfld.getName().equals(fldname)) {
out = true;
break;
}
}
}
}
}
catch (Exception e) {
errorMessage = "FindFieldExists Error!!!";
}
return out;
}
public clsTable retTableRef(int tblIndex) {
clsTable ret = null;
try {
if (tblIndex < table.size()) {
ret = (clsTable) table.get(tblIndex);
}
else {
errorMessage = "(retTableRef)Error Index!";
}
}
catch (Exception e) {
errorMessage = "getTableRef Error!!!\nMessage:" + e;
}
return ret;
}
public clsTable retTableRef(String tblname) {
clsTable ret = null;
try {
if (existsTable(tblname)) {
for (int i = 0; i < table.size(); i++) {
ret = (clsTable) table.get(i);
if (ret.getName().equals(tblname)) {
break;
}
}
}
else {
errorMessage = "(retTableRef)Can't find this table!";
}
}
catch (Exception e) {
errorMessage = "getTableRef Error!!!\nMessage:" + e;
}
return ret;
}
public clsField retFieldRef(String tblname, String fldname) {
clsTable temptbl = null;
clsField ret = null;
try {
if (existsField(tblname, fldname)) {
temptbl = retTableRef(tblname);
for (int i = 0; i < temptbl.field.size(); i++) {
ret = (clsField) temptbl.field.get(i);
if (ret.getName().equals(fldname)) {
break;
}
}
}
else {
errorMessage = "(retFieldRef)Can't find this field!";
}
}
catch (Exception e) {
errorMessage = "getFieldRef Error!\nMessage:" + e;
}
return ret;
}
public clsField retFieldRef(String tblname, int fldIndex) {
clsTable temptbl = null;
clsField ret = null;
try {
if (existsTable(tblname)) {
temptbl = retTableRef(tblname);
if (fldIndex < temptbl.field.size()) {
ret = (clsField) temptbl.field.get(fldIndex);
}
else {
errorMessage = "(retFieldRef)Error Index!";
}
}
else {
errorMessage = "(retFieldRef)Can't find this table!";
}
}
catch (Exception e) {
errorMessage = "getFieldRef Error!\nMessage:" + e;
}
return ret;
}
public clsField retFieldRef(int tblIndex, int fldIndex) {
clsTable temptbl = null;
clsField ret = null;
try {
if (tblIndex < table.size()) {
temptbl = retTableRef(tblIndex);
if (fldIndex < temptbl.field.size()) {
ret = (clsField) temptbl.field.get(fldIndex);
}
}
else {
errorMessage = "(retFieldRef)Error Index!";
}
}
catch (Exception e) {
errorMessage = "getFieldRef Error!\nMessage:" + e;
}
return ret;
}
public Object[] query(String tblname, String fldname, String fldvalue) {
LinkedList out = new LinkedList();
clsField tempfld = retFieldRef(tblname, fldname);
try {
if (existsTable(tblname) == true
&& existsField(tblname, fldname) == true) {
for (int i = 0; i < tempfld.value.size(); i++) {
if ( ( (String) tempfld.value.get(i)).equals(fldvalue)) {
out.add( (String) tempfld.value.get(i));
}
}
}
else {
errorMessage = "(query)Can't find this table or field!";
}
}
catch (Exception e) {
errorMessage = "Query Error!\nMessage:" + e;
}
return out.toArray();
}
public class SaxParser
extends DefaultHandler {
private boolean fldstart = false;
private boolean dbstart = false;
private boolean tblstart = false;
private String temptblname = new String();
private LinkedList fldval = new LinkedList();
private String tempfldname = new String();
private boolean ParseValue = false;
public SaxParser(boolean isParseValue) {
ParseValue = isParseValue;
}
public void startElement(String nsuri, String localName, String qName,
Attributes attributes) {
if (ParseValue == false) {
if (qName.equals("Database")) {
dbstart = true;
setName(attributes.getValue(0));
System.out.println("Find a Database."
+ attributes.getValue(0));
}
else if (qName.equals("Table")) {
tblstart = true;
temptblname = attributes.getValue(0);
add_table(attributes.getValue(0));
System.out.println("Find a Table."
+ attributes.getValue(0));
}
else if (qName.equals("Field")) {
fldstart = true;
add_field(temptblname, attributes.getValue(0));
tempfldname = attributes.getValue(0);
System.out.println("Find a Field."
+ attributes.getValue(0));
}
}
else {
if (qName.equals("Table")) {
tblstart = true;
temptblname = attributes.getValue(0);
System.out.println("Find a Table."
+ attributes.getValue(0));
}
else if (qName.equals("Field")) {
fldstart = true;
tempfldname = attributes.getValue(0);
System.out.println("Find a Field."
+ attributes.getValue(0));
}
else if (qName.equals("Value")) {
if (tblstart == true && fldstart == true) {
clsTable temptbl = null;
clsField tempfld = null;
for (int i = 0; i < table.size(); i++) {
temptbl = (clsTable) table.get(i);
if (temptbl.getName().equals(temptblname)) {
for (int j = 0; j < temptbl.field.size(); j++) {
tempfld = (clsField) temptbl.field.get(j);
if (tempfld.getName().equals(tempfldname)) {
tempfld.value.add(attributes.getValue(0));
table.set(i, temptbl);
break;
}
}
break;
}
}
System.out.println("Find a Field Value.");
}
}
}
}
public void characters(char[] cha, int start, int length) {
}
public void endElement(String nsuri, String localName, String qName) {
if (qName.equals("Table")) {
tblstart = false;
temptblname = "";
tempfldname = "";
}
if (qName.equals("Field")) {
fldstart = false;
tempfldname = "";
}
}
}
public void finalize() {
name = null;
table.clear();
table = null;
errorMessage = null;
System.gc();
Runtime.getRuntime().gc();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -