Definition at line 22 of file DBObjectManager.java.
Public Member Functions | |
DBObjectManager | passDBConnection (DBConnectionManager theDataBase) |
DBConnectionManager | getDBConnection () |
synchronized int | fillObject (Object obj, ResultSet dbrs) throws SQLException |
synchronized void | writeObject (Object obj, String tableName, String dbName) throws JetWebException |
Object | writeToDB (String tableName, String dbName) throws JetWebException |
Object | writeToDB (String dbName) throws JetWebException |
Private Member Functions | |
Vector< Method > | availableMethods (Object obj, String prefix) |
boolean | createTable (Object obj, String tableName, String dbName) throws JetWebException |
String | sqlType (Object obj, Method method) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException |
Static Private Member Functions | |
void | initAllowedTypes () |
void | initPrimitiveTypes () |
String | strip_ (String word) |
String | deCapitalise (String word) |
String | unCamelMe (String word) |
Private Attributes | |
HashMap< String, Vector< String > > | tableNames_ |
DBConnectionManager | db_ = null |
Static Private Attributes | |
HashMap< String, HashMap< String, Vector< Method > > > | availableMethodsMap_ |
HashMap< Class, String > | allowedTypes_ = new HashMap<Class String>() |
HashMap< Class, Method > | listTypes_ = new HashMap<Class Method>() |
boolean | allowedTypesInit_ = true |
HashMap< String, String > | primitiveTypes_ = new HashMap<String String>() |
boolean | primitiveTypesInit_ = true |
|
Definition at line 548 of file DBObjectManager.java. Referenced by DBParamManager.matchId(). 00548 { 00549 00550 if(obj==null) return new Vector<Method>(0); 00551 00552 Vector<Method> methods; 00553 HashMap<String, Vector<Method> > foundMethods = 00554 availableMethodsMap_.get(obj.getClass().toString()); 00555 00556 boolean findMethods = false; 00557 boolean foundObject = false; 00558 00559 if(foundMethods==null){ 00560 findMethods = true; 00561 }else if(!foundMethods.containsKey(prefix)){ 00562 findMethods = true; 00563 foundObject = true; 00564 }else{ 00565 00566 methods = foundMethods.get(prefix); 00567 return(methods); 00568 } 00569 00570 methods = new Vector<Method>(); 00571 00572 if(findMethods){ 00573 Class objClass = obj.getClass(); 00574 Method[] objMethods = objClass.getMethods(); 00575 for(int ii=0; ii!= objMethods.length; ++ii){ 00576 if(objMethods[ii]. 00577 getName(). 00578 substring(0,prefix.length()). 00579 equals(prefix)){ 00580 methods.add(objMethods[ii]); 00581 } 00582 } 00583 00584 if(!foundObject){ 00585 foundMethods = new HashMap<String, Vector<Method> >(); 00586 } 00587 00588 foundMethods.put(prefix, methods); 00589 } 00590 00591 availableMethodsMap_.put(obj.getClass().toString(), foundMethods); 00592 00593 return(methods); 00594 };
|
|
Definition at line 598 of file DBObjectManager.java. References DBConnectionManager.getConnectionAsAdmin(). 00599 { 00600 00601 String cmd1 = "DROP TABLE If EXISTS `" + tableName + "`"; 00602 00603 String columns = "("; 00604 Vector<Method> methods = availableMethods(obj, "get"); 00605 00606 int numberOfCommas = methods.size() - 1; 00607 00608 boolean addComma = false; 00609 00610 int numColumns = 0; 00611 00612 for(int ii=0; ii!= methods.size(); ++ii){ 00613 00614 String sqlCommand = null; 00615 00616 try{ 00617 00618 sqlCommand = sqlType(obj, methods.get(ii)); 00619 00620 //System.out.println("sqlCommand = "+sqlCommand); 00621 00622 }catch(Exception e){ 00623 System.out.println 00624 ("Unable to determine return type of method "+ 00625 methods.get(ii).getName()+ 00626 " in object "+obj.getClass().getName()); 00627 System.out.println("IllegalAccessException: "+e.getMessage()); 00628 throw new JetWebException(e); 00629 } 00630 00631 if(sqlCommand!="null"){ 00632 if(addComma){ 00633 columns = columns + ", "; 00634 } 00635 00636 ++numColumns; 00637 columns = columns + 00638 unCamelMe(methods.get(ii).getName().substring(3)) + 00639 " " + 00640 sqlCommand; 00641 00642 if(ii!=numberOfCommas){ 00643 addComma = true; 00644 } 00645 } 00646 } 00647 00648 columns = columns + ")"; 00649 00650 00651 if(numColumns >0){ 00652 String cmd2= 00653 "CREATE TABLE `" + 00654 tableName + 00655 "` " + 00656 columns + 00657 " ENGINE=MyISAM DEFAULT CHARSET=latin1"; 00658 00659 try{ 00660 Statement stmt = 00661 db_.getConnectionAsAdmin(dbName).createStatement(); 00662 stmt.execute(cmd1); 00663 stmt.execute(cmd2); 00664 stmt.close(); 00665 }catch(SQLException e){ 00666 System.out.println("Unable to create table " + 00667 tableName + 00668 " in database "+dbName); 00669 System.out.println("SQL command was: "+cmd2); 00670 System.out.println("SQLException: "+e.getMessage()); 00671 throw new JetWebException(e); 00672 } 00673 } 00674 return(numColumns>0); 00675 };
|
|
Definition at line 866 of file DBObjectManager.java. 00866 {
00867 return(word.substring(0,1).toLowerCase()+word.substring(1));
00868 }
|
|
Fills the object obj from the database resultset dbrs
Definition at line 72 of file DBObjectManager.java. Referenced by DBManager.getAllMCProcessTypes(), DBParamManager.selectById(), DBManager.selectFromDB(), and DBManager.selectId(). 00073 { 00074 00075 int numberFilled = 0; 00076 00077 //Examine the database metadata and put the available 00078 //columns in a vector 00079 00080 ResultSetMetaData metaData = dbrs.getMetaData(); 00081 HashMap<String, Vector<String> > availableColumns = 00082 new HashMap<String, Vector<String> >(); 00083 int numberOfColumns = metaData.getColumnCount(); 00084 ++numberOfColumns; 00085 00086 for(int ii=1; ii!=numberOfColumns; ++ii){ 00087 00088 String colName = metaData.getColumnName(ii); 00089 00090 Vector<String> colInf = new Vector<String>(); 00091 colInf.add(colName); 00092 colInf.add(metaData.getColumnClassName(ii)); 00093 00094 availableColumns.put 00095 (strip_(colName), colInf); 00096 } 00097 00098 --numberOfColumns; 00099 00100 Vector<Method> methods = availableMethods(obj, "set"); 00101 00102 initPrimitiveTypes(); 00103 00104 for(int ii=0; ii!= methods.size(); ++ii){ 00105 00106 Method method = methods.get(ii); 00107 00108 String columnName = method.getName().substring(3); 00109 00110 char toDeCapitalise = columnName.charAt(0); 00111 columnName = Character.toLowerCase(toDeCapitalise) + 00112 columnName.substring(1); 00113 00114 Vector<String> colInf = availableColumns.get 00115 (columnName); 00116 00117 if(colInf!=null){ 00118 00119 String columnType = colInf.get(1); 00120 00121 Class[] parameterTypes = method.getParameterTypes(); 00122 00123 if(parameterTypes.length == 1 && 00124 columnType!=null){ 00125 00126 String parameterType = parameterTypes[0].getName(); 00127 00128 if(parameterType == columnType || 00129 primitiveTypes_.get(parameterType)==columnType){ 00130 00131 Object[] param = {dbrs.getObject(colInf.get(0))}; 00132 try{ 00133 00134 method.invoke(obj, param); 00135 ++numberFilled; 00136 }catch (IllegalAccessException e){ 00137 System.out.println(e.getMessage()); 00138 }catch (InvocationTargetException e){ 00139 System.out.println(e.getMessage()); 00140 } 00141 }else if(columnType.equals("[B")){// can always attempt 00142 // to convert blob into 00143 // anything for filling. 00144 00145 Blob blob = dbrs.getBlob(colInf.get(0)); 00146 00147 Object param = 00148 DBBlob2Array.convert 00149 (blob, parameterTypes[0]); 00150 00151 if(param!=null){ 00152 try{ 00153 Object paramArray[] = {param}; 00154 method.invoke(obj, paramArray); 00155 ++numberFilled; 00156 }catch (IllegalAccessException e){ 00157 System.out.println(e.getMessage()); 00158 }catch (InvocationTargetException e){ 00159 System.out.println(e.getMessage()); 00160 } 00161 } 00162 } 00163 } 00164 } 00165 } 00166 00167 return(numberFilled); 00168 };
|
|
Return the DBConnectionManager that is being used Shouldn't write itself to the DB unless there is a column called DBConnection, in which case it might try! Definition at line 63 of file DBObjectManager.java. Referenced by DBManager.addToDB(), DBManager.selectFromDB(), and DBManager.selectId(). 00063 {
00064 return(db_);
00065 }
|
|
Definition at line 789 of file DBObjectManager.java. 00789 { 00790 00791 if(!allowedTypesInit_){ 00792 return; 00793 } 00794 00795 allowedTypesInit_ = false; 00796 00797 Class[] c = {Integer.class, Double.class, Float.class, int.class}; 00798 00799 for(int ii=0; ii!= c.length; ++ii){ 00800 String typeName = c[ii].getName(); 00801 typeName = typeName.substring 00802 (typeName.lastIndexOf(".")+1).toLowerCase(); 00803 allowedTypes_.put(c[ii], typeName+" default NULL"); 00804 } 00805 00806 allowedTypes_.put(String.class, "varchar(16) default ''"); 00807 allowedTypes_.put(Short.class, "smallint default NULL"); 00808 allowedTypes_.put(Byte.class, "blob default null"); 00809 allowedTypes_.put(Boolean.class, "tinyint default 0"); 00810 00811 Class[] arg = {int.class}; 00812 00813 try{ 00814 00815 listTypes_.put(Vector.class, Vector.class.getMethod("get", arg)); 00816 listTypes_.put(List.class, List.class.getMethod("get",arg)); 00817 listTypes_.put 00818 (Arrays.asList(new int[0]).getClass(), 00819 Arrays.asList(new int[0]).getClass().getMethod("get", arg)); 00820 00821 listTypes_.put 00822 (Collections.synchronizedList 00823 (Arrays.asList(new int[0])).getClass(), 00824 Collections.synchronizedList 00825 (Arrays.asList(new int[0])).getClass().getMethod("get", arg)); 00826 00827 }catch(NoSuchMethodException e){ 00828 00829 System.out.println("NoSuchMethodException: " + 00830 e.getMessage()); 00831 00832 } 00833 00834 return; 00835 };
|
|
Definition at line 837 of file DBObjectManager.java. 00837 { 00838 if (!primitiveTypesInit_) return; 00839 00840 primitiveTypes_.put(int.class.getName(), Integer.class.getName()); 00841 primitiveTypes_.put(double.class.getName(), Double.class.getName()); 00842 primitiveTypes_.put(float.class.getName(), Float.class.getName()); 00843 primitiveTypes_.put(char.class.getName(), String.class.getName()); 00844 primitiveTypes_.put(boolean.class.getName(), Boolean.class.getName()); 00845 00846 return; 00847 };
|
|
Pass the DBConnectionManager to be used for accessing the database(s)
Definition at line 51 of file DBObjectManager.java. Referenced by DBManager.addToDB(), FileUploader.doDefaultsXMLUpload(), GenDefaults.main(), BlobUpload.main(), DBManager.selectFromDB(), and DBManager.selectId(). 00051 { 00052 00053 db_ = theDataBase; 00054 00055 return(this); 00056 }
|
|
Definition at line 681 of file DBObjectManager.java. 00684 { 00685 00686 if(allowedTypesInit_) initAllowedTypes(); 00687 00688 //System.out.println("method name is "+method.getName()); 00689 00690 Object returnedObject = method.invoke(obj); 00691 //System.out.println("returnedObject = "+returnedObject); 00692 Class returnedClass = returnedObject.getClass(); 00693 00694 //Special case for arrays because they are neither proper 00695 //classes nor primitive types, so we turn it into a list... 00696 00697 if(returnedClass.getName().substring(0,2).equals("[B")){ 00698 return(allowedTypes_.get(Byte.class)); 00699 } 00700 00701 if(returnedClass.getName().substring(0,1).equals("[")){ 00702 00703 returnedObject = Arrays.asList(returnedObject); 00704 returnedClass = returnedObject.getClass(); 00705 } 00706 00707 if(allowedTypesInit_) initAllowedTypes(); 00708 00709 //System.out.println("returnedClass = "+returnedClass); 00710 00711 00712 String typeName = allowedTypes_.get(returnedClass); 00713 Method get = listTypes_.get(returnedClass); 00714 00715 00716 00717 boolean carryOn = true; 00718 int iii = 0; 00719 int counterMax = 10000; 00720 00721 while(carryOn){ 00722 00723 //System.out.println("typeName = "+typeName); 00724 //System.out.println("get = "+get); 00725 00726 iii++; 00727 if(typeName!=null){ 00728 carryOn = false; 00729 00730 }else if(get!=null&&typeName==null) { 00731 Method size = returnedClass.getMethod("size"); 00732 00733 //System.out.println("size = "+size); 00734 00735 int ii = 0; 00736 boolean notFound = true; 00737 00738 //System.out.println(returnedObject); 00739 00740 Integer listSize = (Integer)size.invoke(returnedObject); 00741 00742 //System.out.println("the listSize is "+listSize); 00743 while(notFound && ii != listSize){ 00744 Object tmpObject = get.invoke(returnedObject,ii); 00745 if(tmpObject!=null){ 00746 notFound = false; 00747 returnedObject = tmpObject; 00748 00749 returnedClass = returnedObject.getClass(); 00750 00751 typeName = allowedTypes_.get(returnedClass); 00752 get = listTypes_.get(returnedClass); 00753 }else{ 00754 ++ii; 00755 } 00756 } 00757 00758 if(ii==listSize){ 00759 System.out.println("List is full of nulls"); 00760 System.out.println 00761 ("- could not determine columns type. Using int"); 00762 00763 System.out.println("method name is "+method.getName()); 00764 00765 typeName = "integer default NULL"; 00766 carryOn = false; 00767 } 00768 00769 }else{ 00770 00771 typeName = "null"; 00772 carryOn = false; 00773 } 00774 00775 // protect against infinite loops. 00776 if (iii > counterMax) { 00777 System.out.println("Could not determine column type. Using int."); 00778 System.out.println("method name is "+method.getName()); 00779 00780 typeName = "integer default NULL"; 00781 carryOn = false; 00782 } 00783 00784 } 00785 00786 return(typeName); 00787 };
|
|
Definition at line 850 of file DBObjectManager.java. 00850 { 00851 int ii=word.indexOf("_"); 00852 while(ii>-1){ 00853 char toCapitalise = 0; 00854 if(ii!= word.length()-2){ 00855 toCapitalise = word.charAt(ii+1); 00856 } 00857 word = word.substring(0,ii) + 00858 Character.toUpperCase(toCapitalise) + 00859 word.substring(ii+2); 00860 ii = word.indexOf("_"); 00861 } 00862 return(word); 00863 }
|
|
Definition at line 870 of file DBObjectManager.java. Referenced by DBParamManager.matchId(), and DBParamManager.tableName(). 00870 { 00871 00872 for(int ii=0; ii< word.length()-1; ++ii){ 00873 char letter = word.charAt(ii); 00874 if(Character.isUpperCase(letter)){ 00875 String decapitalised = new String(); 00876 decapitalised += Character.toLowerCase(letter); 00877 if(ii!=0) decapitalised = "_"+decapitalised; 00878 word = word.substring(0,ii) + 00879 decapitalised+ 00880 word.substring(ii+1); 00881 00882 } 00883 } 00884 return(word); 00885 }
|
|
writes an Object obj to the database with the given name
Definition at line 179 of file DBObjectManager.java. References DBConnectionManager.getConnection(). Referenced by DBManager.addToDB(), FileUploader.doDefaultsXMLUpload(), GenDefaults.main(), BlobUpload.main(), and DBParamManager.toDB(). 00182 { 00183 00184 Vector<String> foundTables=null; 00185 boolean overWriteTableNames = false; 00186 00187 String connectedDBName = null; 00188 DatabaseMetaData metaData = null; 00189 00190 try{ 00191 00192 connectedDBName = db_.getConnection(dbName).getCatalog(); 00193 00194 metaData = db_.getConnection(dbName).getMetaData(); 00195 00196 //ResultSet existingTables = metaData.getCatalogs(); 00197 00198 if(!tableNames_.containsKey(dbName)){ 00199 00200 overWriteTableNames = true; 00201 00202 ResultSet existingTables = 00203 metaData.getTables 00204 (db_.getConnection(dbName).getCatalog(), null, "", null); 00205 00206 foundTables = new Vector<String>(); 00207 while(existingTables.next()){ 00208 00209 foundTables.add 00210 (existingTables.getString("TABLE_NAME")); 00211 } 00212 00213 }else{ 00214 foundTables = tableNames_.get(dbName); 00215 } 00216 00217 }catch(SQLException e){ 00218 System.out.println("Unable to get metadata for catalogue "+ 00219 tableName + 00220 " in database "+dbName); 00221 System.out.println(e.getMessage()); 00222 throw new JetWebException(e); 00223 } 00224 00225 //does the table we want exist. 00226 00227 boolean tableExists = foundTables.contains(tableName); 00228 00229 if(!tableExists){ 00230 00231 tableExists = createTable(obj, tableName, dbName); 00232 foundTables.add(tableName); 00233 overWriteTableNames = true; 00234 } 00235 00236 if(overWriteTableNames){ 00237 tableNames_.put(dbName, foundTables); 00238 } 00239 00240 Vector<Method> methods = availableMethods(obj, "get"); 00241 int numColumns = 0; 00242 00243 HashMap<String, Object> columnsToWrite = 00244 new HashMap<String, Object>(); 00245 00246 HashMap<String, Vector<String> > columnMap = 00247 new HashMap<String, Vector<String> >(); 00248 00249 try{ 00250 ResultSet existingColumns = 00251 metaData.getColumns 00252 (db_.getConnection(dbName).getCatalog(), null,tableName, ""); 00253 00254 while(existingColumns.next()){ 00255 00256 Vector<String> colInf = new Vector<String>(); 00257 colInf.add(existingColumns.getString("TYPE_NAME")); 00258 colInf.add(existingColumns.getString("COLUMN_SIZE")); 00259 colInf.add(existingColumns.getString("COLUMN_NAME")); 00260 00261 columnMap.put 00262 (strip_(existingColumns.getString("COLUMN_NAME")), colInf); 00263 00264 } 00265 00266 }catch(SQLException e){ 00267 System.out.println(e.getMessage()); 00268 } 00269 00270 Statement stmt = null; 00271 00272 try{ 00273 stmt = db_.getConnection(dbName).createStatement(); 00274 }catch (SQLException e){ 00275 System.out.println(e.getMessage()); 00276 throw new JetWebException(e); 00277 } 00278 00279 Vector<Vector<String> > stuffToWrite = new Vector<Vector<String> >(); 00280 Vector<ByteArrayInputStream> blobsToWrite = 00281 new Vector<ByteArrayInputStream>(); 00282 int numBlobs = 0; 00283 00284 int numRows = 0; 00285 00286 for( Method method: methods){ 00287 00288 String colName = method.getName().substring(3); 00289 00290 Vector<String> colInf = columnMap.get(deCapitalise(colName)); 00291 00292 if(colInf !=null){// Means a column with the same name as 00293 // the method exists. 00294 String methodType = null; 00295 String dbType = colInf.get(0); 00296 //colInf.add(colName); 00297 00298 try{ 00299 methodType = sqlType(obj, method); 00300 00301 }catch(Exception e){ 00302 System.out.println(e.getMessage()); 00303 throw new JetWebException(e); 00304 } 00305 00306 if(methodType.substring 00307 (0, dbType.length()).equalsIgnoreCase(dbType)|| 00308 dbType.equalsIgnoreCase("blob")||//can always write a blob! 00309 dbType.equalsIgnoreCase("enum")|| 00310 dbType.equalsIgnoreCase("set")){//can always attempt 00311 //to write an enum 00312 00313 //then we write it to the database. 00314 00315 Object result = null; 00316 try{ 00317 result = method.invoke(obj); 00318 }catch (IllegalAccessException e){ 00319 System.out.println(e.getMessage()); 00320 }catch (InvocationTargetException e){ 00321 System.out.println(e.getMessage()); 00322 } 00323 00324 boolean isAList = false; 00325 boolean isABlob = dbType.equalsIgnoreCase("blob"); 00326 boolean notNull = false; 00327 00328 if(result!=null){ 00329 notNull = true; 00330 Class[] interfaces = result.getClass().getInterfaces(); 00331 00332 //boolean carryOn = true; 00333 for(int kk=0; 00334 kk!= interfaces.length && 00335 !isAList; ++kk){ 00336 if(interfaces[kk].equals(List.class)){ 00337 //carryOn = false; 00338 isAList = true; 00339 } 00340 } 00341 } 00342 int maxEntryLength = 0; 00343 00344 if(isAList && !isABlob){ 00345 00346 try{ 00347 Class[] getParamType = {Integer.class}; 00348 Method size = result.getClass().getMethod("size"); 00349 00350 Method[] resultMethods = 00351 result.getClass().getMethods(); 00352 00353 Method get =null; 00354 for(int kk=0; kk!=resultMethods.length; ++kk){ 00355 if(resultMethods[kk].getName().equals 00356 ("get")){ 00357 get = resultMethods[kk]; 00358 } 00359 } 00360 00361 Integer resultSize = (Integer) size.invoke(result); 00362 for(Integer kk = 0; !resultSize.equals(kk); ++kk){ 00363 Object[] kkArray = {kk}; 00364 Object returnedObj = 00365 get.invoke(result, kkArray); 00366 if(returnedObj!=null){ 00367 String entry = "'"+ 00368 get.invoke(result, kkArray).toString() 00369 +"'"; 00370 if(entry.length()>maxEntryLength){ 00371 maxEntryLength = entry.length(); 00372 } 00373 00374 colInf.add(entry); 00375 }else{ 00376 colInf.add(null); 00377 } 00378 } 00379 }catch(Throwable e){ 00380 System.out.println(e.getClass().getName()+ 00381 ": "+ 00382 e.getMessage()); 00383 System.out.println("Caused by "+ 00384 e.getCause()); 00385 } 00386 00387 }else if(notNull&&isABlob){ 00388 String entry="?"; 00389 ++numBlobs; 00390 00391 ByteArrayInputStream blobInput = null; 00392 00393 blobInput = new ByteArrayInputStream 00394 (DBBlob2Array.byteMe(result)); 00395 00396 blobsToWrite.add(blobInput); 00397 colInf.add(entry); 00398 }else if(notNull&&!isAList){ 00399 00400 String entry = "'"+result.toString()+"'"; 00401 00402 colInf.add(entry); 00403 maxEntryLength = entry.length(); 00404 } 00405 00406 if(colInf.size()>numRows) numRows = colInf.size(); 00407 00408 stuffToWrite.add(colInf); 00409 00410 Integer colLength = new Integer(colInf.get(1)); 00411 00412 if(dbType.equals("varchar")&& 00413 colLength<maxEntryLength&& 00414 tableExists){ 00415 //then we need to increase the length of the column 00416 00417 String colIncr = "ALTER TABLE " + 00418 tableName + 00419 " MODIFY "+ 00420 unCamelMe(colName) + 00421 " VARCHAR("+ 00422 maxEntryLength+ 00423 ") DEFAULT ''"; 00424 00425 try{ 00426 stmt.execute(colIncr); 00427 }catch (SQLException e){ 00428 System.out.println(e.getMessage()); 00429 } 00430 } 00431 } 00432 } 00433 } 00434 00435 int numCols = stuffToWrite.size()-1; 00436 Vector<String> cmd1 = new Vector<String>(); 00437 Vector<String> cmd2 = new Vector<String>(); 00438 00439 int numEntries = numRows - 3; 00440 00441 for(int ii=0; ii!=numEntries; ++ii){ 00442 cmd1.add("INSERT INTO " + tableName +" ("); 00443 cmd2.add("VALUES("); 00444 } 00445 00446 for(int jj=0; jj!=numEntries; ++jj){ 00447 boolean thereIsAnEntry = false; 00448 for(int ii=0; ii!=stuffToWrite.size(); ++ii){ 00449 00450 if(stuffToWrite.get(ii).size()>jj+3){ 00451 if(stuffToWrite.get(ii).get(jj+3)!=null){ 00452 if(thereIsAnEntry){ 00453 cmd1.set(jj, cmd1.get(jj)+", "); 00454 cmd2.set(jj, cmd2.get(jj)+", "); 00455 } 00456 00457 thereIsAnEntry = true; 00458 cmd1.set(jj, cmd1.get(jj)+stuffToWrite.get(ii).get(2)); 00459 00460 String val = stuffToWrite.get(ii).get(jj+3); 00461 00462 if(val.equals("'true'")){ 00463 val="1"; 00464 }else if(val.equals("'false'")){ 00465 val = "0"; 00466 } 00467 cmd2.set(jj, cmd2.get(jj) + val); 00468 } 00469 } 00470 } 00471 } 00472 00473 for(int ii=0; ii!= cmd2.size()&&tableExists; ++ii){ 00474 cmd2.set(ii, cmd1.get(ii) + 00475 ") " + 00476 cmd2.get(ii) + 00477 ") "); 00478 try{ 00479 //System.out.println(cmd2.get(ii)); 00480 00481 if(numBlobs==0){ 00482 stmt.execute(cmd2.get(ii)); 00483 00484 }else{ 00485 00486 //System.out.println(cmd2.get(ii)); 00487 00488 PreparedStatement pstmt = 00489 db_.getConnection(dbName). 00490 prepareStatement(cmd2.get(ii)); 00491 if(ii==0){ 00492 for(int jj=0; jj<numBlobs; ++jj){ 00493 pstmt.setBinaryStream 00494 (jj+1,blobsToWrite.get(jj), 00495 blobsToWrite.get(jj).available()); 00496 } 00497 } 00498 pstmt.executeUpdate(); 00499 pstmt.close(); 00500 } 00501 }catch(SQLException e){ 00502 System.out.println("SQLException: "+e.getMessage()); 00503 } 00504 } 00505 00506 System.out.println("finished writing object"); 00507 try{ 00508 stmt.close(); 00509 }catch(Throwable err){ 00510 System.out.println(err.getMessage()); 00511 } 00512 return; 00513 };
|
|
Writes this object to a table of the same name as the object in the specified database
Definition at line 535 of file DBObjectManager.java. 00535 { 00536 00537 String fullName = this.getClass().getName(); 00538 00539 return(writeToDB 00540 (fullName.substring(fullName.lastIndexOf(".")+1), dbName)); 00541 };
|
|
Writes this object to the table with the given name in the database
Definition at line 522 of file DBObjectManager.java. 00523 { 00524 writeObject(this, tableName, dbName); 00525 return(this); 00526 };
|
|
Definition at line 33 of file DBObjectManager.java. |
|
Definition at line 36 of file DBObjectManager.java. |
|
Initial value:
new HashMap<String HashMap<String Vector<Method> > >()
Definition at line 29 of file DBObjectManager.java. |
|
Definition at line 42 of file DBObjectManager.java. |
|
Definition at line 35 of file DBObjectManager.java. |
|
Definition at line 39 of file DBObjectManager.java. |
|
Definition at line 40 of file DBObjectManager.java. |
|
Initial value:
new HashMap<String Vector<String> > ()
Definition at line 25 of file DBObjectManager.java. |
Generated Wed Jan 17 09:14:27 GMT 2007