Source Code Cross Referenced for DataStoreBuffer.java in  » J2EE » Sofia » com » salmonllc » sql » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » J2EE » Sofia » com.salmonllc.sql 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        package com.salmonllc.sql;
0002:
0003:        import com.salmonllc.xml.*; /////////////////////////
0004:        //$Archive: /SOFIA/SourceCode/com/salmonllc/sql/DataStoreBuffer.java $
0005:        //$Author: Dan $
0006:        //$Revision: 87 $
0007:        //$Modtime: 11/08/04 10:08a $
0008:        /////////////////////////
0009:
0010:        import java.sql.*;
0011:        import java.util.*;
0012:        import java.io.*;
0013:        import java.text.*;
0014:
0015:        import com.salmonllc.localizer.LanguagePreferences;
0016:        import com.salmonllc.util.*;
0017:
0018:        /**
0019:         * This class provides a storage buffer for data in the form of rows and column.
0020:         */
0021:        public class DataStoreBuffer implements  Serializable {
0022:
0023:            public static final int DATATYPE_STRING = 0;
0024:            public static final int DATATYPE_INT = 1;
0025:            public static final int DATATYPE_DATETIME = 2;
0026:            public static final int DATATYPE_DOUBLE = 3;
0027:            public static final int DATATYPE_BYTEARRAY = 4;
0028:            public static final int DATATYPE_SHORT = 5;
0029:            public static final int DATATYPE_LONG = 6;
0030:            public static final int DATATYPE_FLOAT = 7;
0031:            public static final int DATATYPE_DATE = 8;
0032:            public static final int DATATYPE_TIME = 9;
0033:            protected static final int DATATYPE_ANY = 99;
0034:
0035:            public static final int SORT_ASC = 0;
0036:            public static final int SORT_DES = 1;
0037:
0038:            public static final int EXPORT_XML = 0;
0039:            public static final int EXPORT_HTML = 1;
0040:            public static final int EXPORT_TAB_DELIMITED = 2;
0041:
0042:            public static final int STATUS_NOT_MODIFIED = 0;
0043:            public static final int STATUS_MODIFIED = 1;
0044:            public static final int STATUS_NEW = 2;
0045:            public static final int STATUS_NEW_MODIFIED = 3;
0046:
0047:            public static final int BUFFER_STANDARD = 0;
0048:            public static final int BUFFER_DELETED = 1;
0049:            public static final int BUFFER_FILTERED = 2;
0050:
0051:            public static final int BIND_DEFAULT = 0;
0052:            public static final int BIND_TRUE = 1;
0053:            public static final int BIND_FALSE = 2;
0054:
0055:            //fc 06/11/04: Added these Constants to be used in the One to Many Relationship Models (Master/Detail)
0056:            public static final int RELATION_ONE_TO_ONE = 1;
0057:            public static final int RELATION_MANY_TO_ONE = 2;
0058:            public static final int RELATION_ONE_TO_MANY = 3;
0059:
0060:            protected DSDataStoreDescriptor _desc = new DSDataStoreDescriptor();
0061:            protected Vector _rows = new Vector();
0062:            protected Vector _deletedRows = new Vector();
0063:            protected Vector _filteredRows = new Vector();
0064:            protected boolean _retrieveInProgress, _cancelInProgress;
0065:            protected Vector _waitingRetrieveThreads = new Vector();
0066:            protected Vector _waitingCancelThreads = new Vector();
0067:
0068:            private int _currentRow = -1;
0069:            private DataStoreEvaluator _find;
0070:
0071:            SimpleDateFormat _dateTimeFormatVSE = new SimpleDateFormat(
0072:                    "yyyy-MM-dd-HH.mm.ss");
0073:            SimpleDateFormat _dateTimeFormatSTD = new SimpleDateFormat(
0074:                    "yyyy-MM-dd HH:mm:ss");
0075:
0076:            public static final int AUTORETRIEVE_NEVER = 0;
0077:            public static final int AUTORETRIEVE_ALWAYS = 1;
0078:            public static final int AUTORETRIEVE_ONCHANGE = 2;
0079:
0080:            private boolean _autoBind = false;
0081:            private int _autoRetrieve = AUTORETRIEVE_NEVER;
0082:            private AutoRetrieveCriteria _crit;
0083:
0084:            protected static final boolean debug = false;
0085:            private String _remoteID;
0086:            private String _remoteUpdateRetVal;
0087:            private Vector _modelListeners;
0088:            private LanguagePreferences _lang;
0089:            //fc 06/14/04: indicates whether master row should be deleted on update for a one to many relationship. Default is true.
0090:            private boolean _allowMasterRowDelete = true;
0091:            //fc 06/11/04: indicates whether model is a one to many relationship model.
0092:            protected boolean _manytoonerelationship = false;
0093:
0094:            /**
0095:             * Creates a new empty DataStore object. Any method requiring a database connection (retrieve,update and union) will have to be explicitly passed a DBConnection created outside the datastore.
0096:             */
0097:            public DataStoreBuffer() {
0098:                super ();
0099:            }
0100:
0101:            /**
0102:             * This method adds a bucket to the DataStoreBuffer. The bucket will be filled in with nulls when the datastore is retrieved.
0103:             * @param internalname The name of the bucket to add to the datastore.
0104:             * @param type The type of the column to add to the datastore. This must be one of the "TYPE" constants in the class.
0105:             */
0106:            public void addBucket(String internalname, int type) {
0107:                _desc.addColumn(null, null, type, false, false, internalname);
0108:            }
0109:
0110:            /**
0111:             * This method adds a bucket to the DataStoreBuffer. The bucket will be filled in with nulls when the datastore is retrieved.
0112:             * @param internalname The name of the bucket to add to the datastore.
0113:             * @param type The type of the column to add to the datastore. This must be one of the "TYPE" constants in the class.
0114:             */
0115:            public void addBucket(String internalname, int type, String format) {
0116:                try {
0117:
0118:                    addBucket(internalname, type);
0119:                    setFormat(internalname, format);
0120:                } catch (DataStoreException de) {
0121:                    MessageLog
0122:                            .writeErrorMessage(
0123:                                    "addBucket(String internalname, int type, String format)",
0124:                                    de, this );
0125:                }
0126:            }
0127:
0128:            /**
0129:             * This method will append the rows in the DataStore. The vector to append should be created via the getRows method of this datastore.
0130:             */
0131:            public void appendRows(Vector rows) {
0132:                Vector rowTemp = (Vector) rows.elementAt(0);
0133:                int rowSize = rowTemp.size();
0134:                // transfer rows
0135:                for (int i = 0; i < rowSize; i++) {
0136:                    _rows.addElement(rowTemp.elementAt(i));
0137:                }
0138:                rowTemp = (Vector) rows.elementAt(1);
0139:                rowSize = rowTemp.size();
0140:                // transfer filter rows
0141:                for (int i = 0; i < rowSize; i++) {
0142:                    _filteredRows.addElement(rowTemp.elementAt(i));
0143:                }
0144:                rowTemp = (Vector) rows.elementAt(2);
0145:                rowSize = rowTemp.size();
0146:                // transfer deleted rows
0147:                for (int i = 0; i < rowSize; i++) {
0148:                    _deletedRows.addElement(rowTemp.elementAt(i));
0149:                }
0150:            }
0151:
0152:            /**
0153:             * This method is invoked when the datastore buffer needs to be automatically retrieved by a JspController
0154:             */
0155:            public void autoRetrieve() throws Exception {
0156:
0157:            }
0158:
0159:            /**
0160:             * This method will compare the contents of two rows using the specified column list. It will return < 0 if row1 is less then row2, 0 if they are equal and > 0 if row1 is greater than row2
0161:             * @param row1 the first row to check
0162:             * @param row2 the next row to check
0163:             * @param cols An array of column numbers to use for the comparison
0164:             */
0165:            public int compareRows(int row1, int row2, int[] cols) {
0166:
0167:                if (row1 < 0 || row1 >= getRowCount())
0168:                    return -1;
0169:
0170:                if (row2 < 0 || row2 >= getRowCount())
0171:                    return 1;
0172:
0173:                DSDataRow d1 = (DSDataRow) _rows.elementAt(row1);
0174:                DSDataRow d2 = (DSDataRow) _rows.elementAt(row2);
0175:
0176:                return d1.compareRows(d2, cols);
0177:
0178:            }
0179:
0180:            /**
0181:             * This method will compare the contents of two rows using the specified column list. It will return < 0 if row1 is less then row2, 0 if they are equal and > 0 if row1 is greater than row2
0182:             * @param row1 the first row to check
0183:             * @param row2 the next row to check
0184:             * @param cols An array of column names to use for the comparison
0185:             */
0186:            public int compareRows(int row1, int row2, String[] cols) {
0187:
0188:                int colsn[] = new int[cols.length];
0189:
0190:                for (int i = 0; i < cols.length; i++) {
0191:                    int ndx = getColumnIndex(cols[i]);
0192:                    if (ndx < 0)
0193:                        return 0;
0194:                    colsn[i] = ndx;
0195:                }
0196:
0197:                return compareRows(row1, row2, colsn);
0198:
0199:            }
0200:
0201:            /**
0202:             * This deletes the current row in the DataStoreBuffer. This will generate a delete statment that will remove the row from the database when the update method is called.
0203:             * @return true if the row is deleted and false if not.
0204:             */
0205:            public boolean deleteRow() {
0206:                return deleteRow(getRow());
0207:            }
0208:
0209:            /**
0210:             * This deletes the row in the DataStoreBuffer. This will generate a delete statment that will remove the row from the database when the update method is called.
0211:             * @param row The number of the row to delete.
0212:             * @return True if the row is deleted and false if not.
0213:             */
0214:            public boolean deleteRow(int row) {
0215:                if (row < 0)
0216:                    return false;
0217:                waitForRow(row);
0218:                if (row >= getRowCount())
0219:                    return false;
0220:                DSDataRow d = (DSDataRow) _rows.elementAt(row);
0221:                d.copyDataToOrig();
0222:                //fc 06/11/04: Code to handle the deletion of the first row in a One to Many Relationship Model.
0223:                if (d.getRowStatus() != STATUS_NEW
0224:                        && d.getRowStatus() != STATUS_NEW_MODIFIED) {
0225:                    if (_manytoonerelationship && row == 0) {
0226:                        if (getRowCount() > 1) {
0227:                            if (this  instanceof  DataStoreInterface) {
0228:                                DSDataRow dsTo = (DSDataRow) _rows.elementAt(1);
0229:                                DataStoreRow dsrFrom = new DataStoreRow(this ,
0230:                                        d, getDescriptor());
0231:                                DataStoreRow dsrTo = new DataStoreRow(this ,
0232:                                        dsTo, getDescriptor());
0233:                                try {
0234:                                    copyMasterDataValuesToRow(
0235:                                            getTablesRelationshipDescription((DataStoreInterface) this ),
0236:                                            dsrFrom, dsrTo);
0237:                                } catch (DataStoreException dse) {
0238:                                    MessageLog.writeErrorMessage(dse, this );
0239:                                }
0240:                            }
0241:                        }
0242:                    }
0243:                }
0244:                _rows.removeElementAt(row);
0245:                if (d.getRowStatus() != STATUS_NEW
0246:                        && d.getRowStatus() != STATUS_NEW_MODIFIED)
0247:                    _deletedRows.addElement(d);
0248:
0249:                if (areThereModelListeners()) {
0250:                    ModelChangedEvent evt = new ModelChangedEvent(this ,
0251:                            getRow());
0252:                    notifyListeners(evt);
0253:                }
0254:
0255:                if (row == getRow() && row >= getRowCount())
0256:                    setCurrentRow(getRow() - 1);
0257:                //fc 06/11/04: Ensures the current row cannot be greater than the row count after a delete.
0258:                if (getRow() >= getRowCount())
0259:                    setCurrentRow(getRowCount() - 1);
0260:
0261:                return true;
0262:            }
0263:
0264:            public String export() throws com.salmonllc.sql.DataStoreException {
0265:                ByteArrayOutputStream out = new ByteArrayOutputStream();
0266:                PrintWriter p = new PrintWriter(out);
0267:                p.println();
0268:                export(p);
0269:                p.close();
0270:                return out.toString();
0271:            }
0272:
0273:            /**
0274:             * Exports the rows of the data store in the format specified.
0275:             * @param format: Can be EXPORT_XML, EXPORT_HTML or EXPORT_TAB_DELIMITED;
0276:             * @param includeHeaders: True if the output should contain column headings.
0277:             * @param p: The PrintWriter to send the output to.
0278:             *
0279:             */
0280:            public void export(int format, boolean includeHeaders, PrintWriter p) {
0281:                waitForRetrieve();
0282:                DSColumnDescriptor col = null;
0283:                DSDataRow row = null;
0284:                StringBuffer work = new StringBuffer();
0285:                Object o;
0286:                if (format == EXPORT_XML) {
0287:                    exportXML(p);
0288:                } else if (format == EXPORT_HTML) {
0289:                    //do html
0290:                    p.write("<TABLE BORDER = \"1\">");
0291:                    if (includeHeaders) {
0292:                        work.append("<TR>");
0293:                        for (int i = 0; i < _desc.getColumnCount(); i++) {
0294:                            col = _desc.getColumn(i);
0295:                            String name = col.getColumn();
0296:                            if (name == null) {
0297:                                name = col.getInternalName();
0298:                            }
0299:                            String table = col.getTable();
0300:                            if (table == null)
0301:                                table = _desc.getDefaultTable();
0302:                            work.append("<TH>");
0303:                            work.append(table);
0304:                            work.append(".");
0305:                            work.append(name);
0306:                            work.append("</TH>");
0307:                        }
0308:                        work.append("</TR>");
0309:                        p.println(work.toString());
0310:                    }
0311:                    for (int i = 0; i < getRowCount(); i++) {
0312:                        work.setLength(0);
0313:                        work.append("<TR>");
0314:                        row = (DSDataRow) _rows.elementAt(i);
0315:                        for (int j = 0; j < _desc.getColumnCount(); j++) {
0316:                            o = row.getData(j);
0317:                            work.append("<TD>");
0318:                            if (o == null)
0319:                                work.append("&nbsp;");
0320:                            else {
0321:                                try {
0322:                                    work
0323:                                            .append(fixSpecialHTMLCharacters(getFormattedString(
0324:                                                    i, j)));
0325:                                } catch (Exception e) {
0326:                                }
0327:                            }
0328:                            work.append("</TD>");
0329:                        }
0330:                        work.append("</TR>");
0331:                        p.println(work.toString());
0332:                    }
0333:                    p.write("</TABLE>");
0334:                } else {
0335:                    //tab delimited
0336:                    if (includeHeaders) {
0337:                        for (int i = 0; i < _desc.getColumnCount(); i++) {
0338:                            col = _desc.getColumn(i);
0339:                            String name = col.getColumn();
0340:                            if (name == null) {
0341:                                name = col.getInternalName();
0342:                            }
0343:                            String table = col.getTable();
0344:                            if (table == null)
0345:                                table = _desc.getDefaultTable();
0346:                            work.append(table);
0347:                            work.append(".");
0348:                            work.append(name);
0349:                            work.append('\t');
0350:                        }
0351:                        p.println(work.toString());
0352:                    }
0353:                    for (int i = 0; i < getRowCount(); i++) {
0354:                        work.setLength(0);
0355:                        row = (DSDataRow) _rows.elementAt(i);
0356:                        for (int j = 0; j < _desc.getColumnCount(); j++) {
0357:
0358:                            o = row.getData(j);
0359:                            if (o != null) {
0360:                                try {
0361:                                    work
0362:                                            .append(removeSpecialCharacters(getFormattedString(
0363:                                                    i, j)));
0364:                                } catch (Exception e) {
0365:                                }
0366:                            }
0367:                            work.append('\t');
0368:                        }
0369:                        p.println(work.toString());
0370:                    }
0371:                }
0372:            }
0373:
0374:            public void export(PrintWriter p)
0375:                    throws com.salmonllc.sql.DataStoreException {
0376:                String TAB = "      ";
0377:                p.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
0378:                p.println("");
0379:                p.println("<!DOCTYPE ResultSet SYSTEM \"datastore.dtd\">");
0380:
0381:                p.println("<ResultSet>");
0382:
0383:                // Printing the Meta Data
0384:                // ------------------------
0385:                p.println("<ResultSetMetaData>");
0386:                String columnMetaData = "";
0387:                for (int i = 0; i < _desc.getColumnCount(); i++) {
0388:                    columnMetaData = "";
0389:                    DSColumnDescriptor col = _desc.getColumn(i);
0390:                    columnMetaData += TAB + "<ColumnMetaData ";
0391:                    String cName = col.getColumn();
0392:                    if (cName == null)
0393:                        cName = "Column" + i;
0394:
0395:                    columnMetaData += " component=\"" + cName + "\"";
0396:                    columnMetaData += " columnName=\"" + cName + "\"";
0397:                    columnMetaData += " caption=\"" + cName + "\"";
0398:
0399:                    String table = col.getTable();
0400:                    if (table == null)
0401:                        table = "defaultTable";
0402:
0403:                    columnMetaData += " table=\"" + table + "\"";
0404:                    columnMetaData += " columnType=\"";
0405:                    int colType = col.getType();
0406:                    switch (colType) {
0407:                    case DATATYPE_STRING:
0408:                        columnMetaData += "String";
0409:                        break;
0410:                    case DATATYPE_DATE:
0411:                        columnMetaData += "Date";
0412:                        break;
0413:                    case DATATYPE_DATETIME:
0414:                        columnMetaData += "DateTime";
0415:                        break;
0416:                    case DATATYPE_TIME:
0417:                        columnMetaData += "Time";
0418:                        break;
0419:                    case DATATYPE_SHORT:
0420:                        columnMetaData += "Short";
0421:                        break;
0422:                    case DATATYPE_INT:
0423:                        columnMetaData += "Integer";
0424:                        break;
0425:                    case DATATYPE_LONG:
0426:                        columnMetaData += "Long";
0427:                        break;
0428:                    case DATATYPE_FLOAT:
0429:                        columnMetaData += "Float";
0430:                        break;
0431:                    case DATATYPE_DOUBLE:
0432:                        columnMetaData += "Double";
0433:                        break;
0434:                    case DATATYPE_BYTEARRAY:
0435:                        columnMetaData += "ByteArray";
0436:                        break;
0437:                    }
0438:                    columnMetaData += "\"";
0439:                    columnMetaData += " primaryKey=\"" + col.isPrimaryKey()
0440:                            + "\"";
0441:
0442:                    if (col.getFormat() != null)
0443:                        columnMetaData += " format=\"" + col.getFormat() + "\"";
0444:
0445:                    if (col.getInternalName() != null)
0446:                        columnMetaData += " internalName=\""
0447:                                + col.getInternalName() + "\"";
0448:
0449:                    columnMetaData += "> </ColumnMetaData>";
0450:
0451:                    p.println(columnMetaData);
0452:                }
0453:                p.println("</ResultSetMetaData>");
0454:
0455:                // Printing the Data
0456:                // -----------------------
0457:                p.println("<ResultSetData>");
0458:                String row = "";
0459:                for (int r = 0; r < getRowCount(); r++) {
0460:                    row = "";
0461:                    DSDataRow dRow = getDataRow(r);
0462:                    row += TAB + "<Row>";
0463:                    for (int c = 0; c < getColumnCount(); c++) {
0464:                        if (dRow.getData(c) != null) {
0465:                            row += "\n"
0466:                                    + TAB
0467:                                    + "<Column "
0468:                                    + " table=\""
0469:                                    + (_desc.getColumn(c).getTable() == null ? "defaultTable"
0470:                                            : _desc.getColumn(c).getTable())
0471:                                    + "\""
0472:                                    + " name=\""
0473:                                    + (_desc.getColumn(c).getColumn() == null ? ("Column" + c)
0474:                                            : _desc.getColumn(c).getColumn())
0475:                                    + "\"" + " value=\""
0476:                                    + getFormattedString(r, c) + "\" />";
0477:                        }
0478:                    }
0479:                    row += "</Row>";
0480:                    p.println(row);
0481:                }
0482:                p.println("</ResultSetData>");
0483:
0484:                p.println("</ResultSet>");
0485:            }
0486:
0487:            private void exportXML(PrintWriter p) {
0488:                p.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
0489:                p.println("");
0490:                p.println("<!DOCTYPE resultSet [");
0491:                p.println("<!ELEMENT resultSet (dataDef, dataRows)>");
0492:                p.println("<!ATTLIST resultSet rows CDATA #REQUIRED>");
0493:                p.println("<!ELEMENT dataDef (columnDef)+>");
0494:                p.println("<!ELEMENT columnDef EMPTY>");
0495:                p.println("<!ATTLIST columnDef name CDATA #REQUIRED");
0496:                p
0497:                        .println("  type (String|Date|DateTime|Time|Short|Integer|Long|Float|Double|ByteArray) #REQUIRED");
0498:                p.println("  number CDATA #REQUIRED");
0499:                p.println("  pkey (true|false) #REQUIRED");
0500:                p.println("  updateable (true|false) #REQUIRED >");
0501:                p.println("<!ELEMENT dataRows (row*)>");
0502:                String rowElement = "<!ELEMENT row (";
0503:                for (int i = 0; i < _desc.getColumnCount(); i++) {
0504:                    if (i != 0)
0505:                        rowElement += ",";
0506:                    rowElement += "c" + i;
0507:                }
0508:                rowElement += ")+>";
0509:                p.println(rowElement);
0510:                p.println("<!ATTLIST row number CDATA #REQUIRED>");
0511:                for (int i = 0; i < _desc.getColumnCount(); i++)
0512:                    p.println("<!ELEMENT c" + i + " (#PCDATA)>");
0513:                p.println("]>");
0514:                p.println("");
0515:                p.println("<resultSet rows=\"" + getRowCount() + "\">");
0516:                p.println("");
0517:                p.println(" <dataDef>");
0518:                DSColumnDescriptor col;
0519:                String colDef = "";
0520:                for (int i = 0; i < _desc.getColumnCount(); i++) {
0521:                    col = _desc.getColumn(i);
0522:                    String name = col.getColumn();
0523:                    if (name == null) {
0524:                        name = col.getInternalName();
0525:                    }
0526:                    String table = col.getTable();
0527:                    if (table == null)
0528:                        table = "defaultTable";
0529:
0530:                    colDef = "  <columnDef name=\"" + table + "." + name
0531:                            + "\" type=\"";
0532:                    int colType = col.getType();
0533:                    switch (colType) {
0534:                    case DATATYPE_STRING:
0535:                        colDef += "String";
0536:                        break;
0537:                    case DATATYPE_DATE:
0538:                        colDef += "Date";
0539:                        break;
0540:                    case DATATYPE_DATETIME:
0541:                        colDef += "DateTime";
0542:                        break;
0543:                    case DATATYPE_TIME:
0544:                        colDef += "Time";
0545:                        break;
0546:                    case DATATYPE_SHORT:
0547:                        colDef += "Short";
0548:                        break;
0549:                    case DATATYPE_INT:
0550:                        colDef += "Integer";
0551:                        break;
0552:                    case DATATYPE_LONG:
0553:                        colDef += "Long";
0554:                        break;
0555:                    case DATATYPE_FLOAT:
0556:                        colDef += "Float";
0557:                        break;
0558:                    case DATATYPE_DOUBLE:
0559:                        colDef += "Double";
0560:                        break;
0561:                    case DATATYPE_BYTEARRAY:
0562:                        colDef += "ByteArray";
0563:                        break;
0564:                    }
0565:                    colDef += "\" number=\"" + i + "\" pkey=\""
0566:                            + col.isPrimaryKey() + "\" updateable=\""
0567:                            + col.isUpdateable() + "\"/>";
0568:                    p.println(colDef);
0569:                }
0570:                p.println(" </dataDef>");
0571:                p.println("");
0572:                p.println(" <dataRows>");
0573:                StringBuffer sb = new StringBuffer();
0574:                DSDataRow row;
0575:                for (int i = 0; i < getRowCount(); i++) {
0576:                    sb.setLength(0);
0577:                    sb.append("   <row number=\"" + i + "\">");
0578:                    row = (DSDataRow) _rows.elementAt(i);
0579:                    for (int j = 0; j < _desc.getColumnCount(); j++) {
0580:                        sb.append("<c" + j + ">");
0581:                        Object o = row.getData(j);
0582:                        if (o != null) {
0583:                            try {
0584:                                sb
0585:                                        .append(fixSpecialHTMLCharacters(getFormattedString(
0586:                                                i, j)));
0587:                            } catch (Exception e) {
0588:                            }
0589:                        }
0590:                        sb.append("</c" + j + ">");
0591:                    }
0592:                    sb.append("</row>");
0593:                    p.println(sb.toString());
0594:                }
0595:                p.println(" </dataRows>");
0596:                p.println("");
0597:                p.println("</resultSet>");
0598:            }
0599:
0600:            /**
0601:             * This method will remove all rows from the buffer that don't match the criteria and place them in the datastore's filter buffer.
0602:             * @param filter A QBEBuilder that will build the filter
0603:             */
0604:            public void filterQBE(QBEBuilder filter) throws DataStoreException {
0605:                filter(filter.generateDataStoreFilter(this ));
0606:
0607:            }
0608:
0609:            /**
0610:             * This method will remove all rows from the buffer that don't match the criteria and place them in the datastore's filter buffer.
0611:             * The method is passed a String containing the filter expression that will be used.
0612:             * Examples:<BR>
0613:             *		  <pre>
0614:             *        ds.filter("table1.column1 == 'xxxx'); <BR>
0615:             * 		  ds.filter("table1.column1.substring(2,3) == table1.column2");<BR>
0616:             * 		  ds.filter("table1.column1.substring(2,3) == table1.column2 || table1.column3.startsWith('xxx')");<BR><BR>
0617:             *		  </pre>
0618:             * @param filter The criteria to filter on. Enter a value of null to clear the filter.
0619:             * @see DataStoreEvaluator
0620:             */
0621:
0622:            public void filter(String filter) throws DataStoreException {
0623:                waitForRetrieve();
0624:
0625:                for (int i = getFilteredCount() - 1; i >= 0; i--)
0626:                    _rows.addElement(_filteredRows.elementAt(i));
0627:
0628:                _filteredRows.removeAllElements();
0629:
0630:                if (filter != null) {
0631:                    DataStoreEvaluator eval = new DataStoreEvaluator(this ,
0632:                            filter);
0633:                    int rowCount = getRowCount();
0634:                    for (int i = rowCount - 1; i > -1; i--) {
0635:                        DSDataRow row = (DSDataRow) _rows.elementAt(i);
0636:                        try {
0637:                            Boolean result = (Boolean) eval.evaluateRow(i);
0638:                            if (!result.booleanValue()) {
0639:                                _rows.removeElementAt(i);
0640:                                _filteredRows.addElement(row);
0641:                            }
0642:                        } catch (DataStoreException e) {
0643:                            throw (e);
0644:                        } catch (Exception e) {
0645:                            throw (new DataStoreException(
0646:                                    "Results of expression must be boolean"));
0647:                        }
0648:                    }
0649:                    notifyListeners(ModelChangedEvent.TYPE_DATA_FILTERED);
0650:                }
0651:
0652:            }
0653:
0654:            /**
0655:             * This method finds the next row in the result set that matches the criteria entered and is within the start and end range.
0656:             * @param start The first row in the DataStoreBuffer to search.
0657:             * @param end The last row in the DataStoreBuffer to search (Make start > end to search backwards).
0658:             * @return Returns the first row matching the criteria within the range or -1 if none are found.
0659:             * @see DataStore#setFindExpression
0660:             */
0661:            public synchronized int find(int start, int end)
0662:                    throws DataStoreException {
0663:                if (_find == null)
0664:                    throw new DataStoreException(
0665:                            "Find Expression not initialized. Use the setFindExpression before calling this method");
0666:
0667:                if (start < end) {
0668:                    if (start < 0)
0669:                        start = 0;
0670:                    if (end >= getRowCount())
0671:                        end = getRowCount() - 1;
0672:
0673:                    for (int i = start; i <= end; i++) {
0674:                        try {
0675:                            Boolean res = (Boolean) _find.evaluateRow(i);
0676:                            if (res.booleanValue())
0677:                                return i;
0678:                        } catch (DataStoreException e) {
0679:                            throw (e);
0680:                        } catch (Exception e) {
0681:                            throw new DataStoreException(
0682:                                    "Find Expression must return a boolean value.");
0683:                        }
0684:                    }
0685:                } else {
0686:                    if (end < 0)
0687:                        end = 0;
0688:                    if (start >= getRowCount())
0689:                        start = getRowCount() - 1;
0690:
0691:                    for (int i = start; i >= end; i--) {
0692:                        try {
0693:                            Boolean res = (Boolean) _find.evaluateRow(i);
0694:                            if (res.booleanValue())
0695:                                return i;
0696:                        } catch (DataStoreException e) {
0697:                            throw (e);
0698:                        } catch (Exception e) {
0699:                            throw new DataStoreException(
0700:                                    "Find Expression must return a boolean value.");
0701:                        }
0702:                    }
0703:                }
0704:
0705:                return -1;
0706:            }
0707:
0708:            /**
0709:             * This method finds the firs row in the result set that matches the criteria entered and makes it the current row.
0710:             * @return Returns false if no rows are found that match the criteria.
0711:             * @see DataStoreBuffer#setFindExpression
0712:             */
0713:            public synchronized boolean findFirst() throws DataStoreException {
0714:                int row = find(0, getRowCount());
0715:                if (row != -1)
0716:                    return gotoRow(row);
0717:                else
0718:                    return false;
0719:            }
0720:
0721:            /**
0722:             * This method finds the last row in the result set that matches the criteria entered and makes it the current row.
0723:             * @return Returns false if no rows are found that match the criteria.
0724:             * @see DataStoreBuffer#setFindExpression
0725:             */
0726:            public synchronized boolean findLast() throws DataStoreException {
0727:                int row = find(getRowCount() - 1, 0);
0728:                if (row != -1)
0729:                    return gotoRow(row);
0730:                else
0731:                    return false;
0732:            }
0733:
0734:            /**
0735:             * This method finds the next row in the result set that matches the criteria entered and makes it the current row.
0736:             * @return Returns false if no rows are found that match the criteria.
0737:             * @see DataStoreBuffer#setFindExpression
0738:             */
0739:            public synchronized boolean findNext() throws DataStoreException {
0740:                int st = getRow() + 1;
0741:                if (st == getRowCount())
0742:                    return false;
0743:
0744:                int row = find(st, getRowCount());
0745:                if (row != -1)
0746:                    return gotoRow(row);
0747:                else
0748:                    return false;
0749:            }
0750:
0751:            /**
0752:             * This method finds the next row in the result set that matches the criteria entered and makes it the current row.
0753:             * @return Returns false if no rows are found that match the criteria.
0754:             * @see DataStoreBuffer#setFindExpression
0755:             */
0756:            public synchronized boolean findPrior() throws DataStoreException {
0757:                int en = getRow() - 1;
0758:                if (en < 0)
0759:                    return false;
0760:
0761:                int row = find(en, 0);
0762:                if (row != -1)
0763:                    return gotoRow(row);
0764:                else
0765:                    return false;
0766:            }
0767:
0768:            protected String fixSpecialHTMLCharacters(String input) {
0769:                if (input == null)
0770:                    return null;
0771:
0772:                StringBuffer sb = new StringBuffer(input.length());
0773:
0774:                for (int i = 0; i < input.length(); i++) {
0775:                    char c = input.charAt(i);
0776:                    if (c == '<')
0777:                        sb.append("&lt;");
0778:
0779:                    else if (c == '&')
0780:                        sb.append("&amp;");
0781:
0782:                    else if (c == '>')
0783:                        sb.append("&gt;");
0784:
0785:                    else if (c == '>')
0786:                        sb.append("&gt;");
0787:
0788:                    else if (c == '"')
0789:                        sb.append("&quot;");
0790:                    else
0791:                        sb.append(c);
0792:                }
0793:
0794:                return sb.toString();
0795:            }
0796:
0797:            /**
0798:             * This method return a Object value from the current row of the data store buffer.
0799:             * @return The Object value
0800:             * @param column The column number in the data store buffer.
0801:             */
0802:            public Object getAny(int column) throws DataStoreException {
0803:                return getObject(getRow(), column, DATATYPE_ANY);
0804:            }
0805:
0806:            /**
0807:             * This method return a Object value from the data store buffer.
0808:             * @return The Object value
0809:             * @param row The row number in the data store buffer.
0810:             * @param column The column number in the data store buffer.
0811:             */
0812:            public Object getAny(int row, int column) throws DataStoreException {
0813:                return getObject(row, column, DATATYPE_ANY);
0814:            }
0815:
0816:            /**
0817:             * This method return a Object value from the data store buffer.
0818:             * @return The Object value
0819:             * @param row The row number in the data store buffer.
0820:             * @param column The column name (in the form table.column) in the data store buffer.
0821:             */
0822:            public Object getAny(int row, String column)
0823:                    throws DataStoreException {
0824:                return getObject(row, column, DATATYPE_ANY);
0825:            }
0826:
0827:            /**
0828:             * This method return a Object value from the current row of the data store buffer.
0829:             * @return The Object value
0830:             * @param column The column name in the data store buffer.
0831:             */
0832:            public Object getAny(String column) throws DataStoreException {
0833:                return getObject(getRow(), column, DATATYPE_ANY);
0834:            }
0835:
0836:            /**
0837:             * This method will get the whether or not columns in the DatastoreBuffer should be automatically bound to components in the page (Only used for DataStoreBuffers created via the DataSource jsp tag)
0838:             */
0839:            public boolean getAutoBind() {
0840:                return _autoBind;
0841:            }
0842:
0843:            /**
0844:             * This method will get whether or not the DatastoreBuffer should be automatically retrieved when a page is requested (Only used for DataStoreBuffers created via the DataSource jsp tag)
0845:             * Valid values are AUTORETRIEVE_NEVER (Don't Autoretrieve),AUTORETRIEVE_ALWAYS (Retrieve on each page request), AUTORETRIEVE_ONCHANGE (Autoretrieve if the selection criteria changes);
0846:             */
0847:            public int getAutoRetrieve() {
0848:                return _autoRetrieve;
0849:            }
0850:
0851:            /**
0852:             * This method will return the autoretrieve criteria used for the datastore.
0853:             */
0854:            public AutoRetrieveCriteria getAutoRetrieveCriteria() {
0855:                return _crit;
0856:            }
0857:
0858:            static String getBoolProperty(boolean p) {
0859:                return (p ? "true" : "false");
0860:            }
0861:
0862:            /**
0863:             * This method returns the true if any bucket columns (columns not representing database columns) have been modified on the current row. Bucket column modfications aren't reflected in the row status for each row.
0864:             */
0865:            public boolean getBucketsModified() {
0866:                return getBucketsModified(getRow());
0867:            }
0868:
0869:            /**
0870:             * This method returns the true if any bucket columns (columns not representing database columns) have been modified on the specified row. Bucket column modfications aren't reflected in the row status for each row.
0871:             * @param row The row in the datastore buffer.
0872:             */
0873:            public boolean getBucketsModified(int row) {
0874:                if (row < 0)
0875:                    return false;
0876:                waitForRow(row);
0877:                if (row >= getRowCount())
0878:                    return false;
0879:                DSDataRow d = (DSDataRow) _rows.elementAt(row);
0880:                return d.getBucketsModified();
0881:            }
0882:
0883:            /**
0884:             * This method return a byte array value from the current row in the data store buffer.
0885:             * @return The byte array
0886:             * @param column The column number in the data store buffer.
0887:             */
0888:            public byte[] getByteArray(int column) throws DataStoreException {
0889:                return (byte[]) getObject(getRow(), column, DATATYPE_BYTEARRAY);
0890:            }
0891:
0892:            /**
0893:             * This method return a byte array value from the data store buffer.
0894:             * @return The byte array
0895:             * @param row The row number in the data store buffer.
0896:             * @param column The column number in the data store buffer.
0897:             */
0898:            public byte[] getByteArray(int row, int column)
0899:                    throws DataStoreException {
0900:                return (byte[]) getObject(row, column, DATATYPE_BYTEARRAY);
0901:            }
0902:
0903:            /**
0904:             * This method return a byte array value from the data store buffer.
0905:             * @return The byte array
0906:             * @param row The row number in the data store buffer.
0907:             * @param column The column name (in the form table.column) in the data store buffer.
0908:             */
0909:            public byte[] getByteArray(int row, String column)
0910:                    throws DataStoreException {
0911:                return (byte[]) getObject(row, column, DATATYPE_BYTEARRAY);
0912:            }
0913:
0914:            /**
0915:             * This method return a byte array value from the current row in the data store buffer.
0916:             * @return The byte array
0917:             * @param column The column name (in the form table.column) in the data store buffer.
0918:             */
0919:            public byte[] getByteArray(String column) throws DataStoreException {
0920:                return (byte[]) getObject(getRow(), column, DATATYPE_BYTEARRAY);
0921:            }
0922:
0923:            /**
0924:             * This method returns the number of columns in the datastore.
0925:             */
0926:            public int getColumnCount() {
0927:                return _desc.getColumnCount();
0928:            }
0929:
0930:            /**
0931:             * This method returns the Data Type for a particular column.
0932:             * @param column The column number in the data store buffer.
0933:             */
0934:
0935:            public int getColumnDataType(int column) throws DataStoreException {
0936:                if (column < 0 || column >= _desc.getColumnCount())
0937:                    throw new DataStoreException("Specified column (" + column
0938:                            + ") is out of range.");
0939:
0940:                DSColumnDescriptor des = _desc.getColumn(column);
0941:                return des.getType();
0942:            }
0943:
0944:            /**
0945:             * This method returns the Data Type for a particular column.
0946:             * @param column The column name in the data store buffer.
0947:             */
0948:
0949:            public int getColumnDataType(String column)
0950:                    throws DataStoreException {
0951:                int col = getColumnIndex(column);
0952:                return getColumnDataType(col);
0953:            }
0954:
0955:            /**
0956:             * This method returns the index of the column in the data store given its name.
0957:             * @return The column number or -1 if the column name is not found.
0958:             * @param column The name of the column to search for.
0959:             */
0960:            public int getColumnIndex(String column) {
0961:                return _desc.getColumnIndex(column);
0962:            }
0963:
0964:            /**
0965:             * This method returns a list with the names of all the columns in the data store.
0966:             */
0967:            public String[] getColumnList() {
0968:                String[] colList = new String[_desc.getColumnCount()];
0969:
0970:                try {
0971:                    for (int i = 0; i < _desc.getColumnCount(); i++)
0972:                        colList[i] = getColumnName(i);
0973:                } catch (Exception e) {
0974:                }
0975:
0976:                return colList;
0977:            }
0978:
0979:            /**
0980:             * This method returns the name of the column in the data store given its index.
0981:             */
0982:            public String getColumnName(int col) throws DataStoreException {
0983:                if (col < 0 || _desc.getColumnCount() == 0)
0984:                    throw new DataStoreException("Specified column (" + col
0985:                            + ") does not exist.");
0986:                DSColumnDescriptor d = _desc.getColumn(col);
0987:                String inName = d.getInternalName();
0988:                if (inName != null && inName.trim().length() > 0)
0989:                    return inName;
0990:                String table = d.getTable();
0991:                if (table == null)
0992:                    table = _desc.getDefaultTable();
0993:
0994:                if (table == null)
0995:                    return d.getColumn();
0996:                else
0997:                    return table + "." + d.getColumn();
0998:            }
0999:
1000:            DSDataRow getDataRow(int rowNo) {
1001:                if (_rows == null)
1002:                    return null;
1003:
1004:                if (rowNo < 0 || rowNo >= _rows.size())
1005:                    return null;
1006:
1007:                return (DSDataRow) _rows.elementAt(rowNo);
1008:            }
1009:
1010:            /**
1011:             * If the datastore is connected to a client side proxy datastore, the row in the proxy that matches the specified one in the server side datastore
1012:             */
1013:            public int getProxyRow(int rowNo) {
1014:                if (_rows == null)
1015:                    return -1;
1016:
1017:                if (rowNo < 0 || rowNo >= _rows.size())
1018:                    return -1;
1019:
1020:                return ((DSDataRow) _rows.elementAt(rowNo)).getProxyRow();
1021:            }
1022:
1023:            /**
1024:             * This method gets the specified row from the DataStore.
1025:             * @param rowNo The number of the row to get.
1026:             * @param buffer The datastore buffer to look in. Valid values are BUFFER_STANDARD, BUFFER_DELETED, BUFFER_FILTERED.
1027:             */
1028:            public DataStoreRow getDataStoreRow(int rowNo, int buffer)
1029:                    throws DataStoreException {
1030:                Vector rows = null;
1031:                if (buffer == BUFFER_STANDARD)
1032:                    rows = _rows;
1033:                else if (buffer == BUFFER_DELETED)
1034:                    rows = _deletedRows;
1035:                else if (buffer == BUFFER_FILTERED)
1036:                    rows = _filteredRows;
1037:                else
1038:                    throw new DataStoreException("Buffer is invalid");
1039:                ;
1040:
1041:                if (rows == null)
1042:                    throw new DataStoreException("Row number:" + rowNo
1043:                            + " is out of range.");
1044:                ;
1045:
1046:                if (rowNo < 0 || rowNo >= rows.size())
1047:                    throw new DataStoreException("Row number:" + rowNo
1048:                            + " is out of range.");
1049:                ;
1050:
1051:                return new DataStoreRow(this ,
1052:                        (DSDataRow) rows.elementAt(rowNo), _desc);
1053:            }
1054:
1055:            /**
1056:             * This method return a date value from current row of the data store buffer.
1057:             * @return The DateTime Value
1058:             * @param column The column number in the data store buffer.
1059:             */
1060:            public java.sql.Date getDate(int column) throws DataStoreException {
1061:                return getDate(getRow(), column);
1062:            }
1063:
1064:            /**
1065:             * This method return a date value from the data store buffer.
1066:             * @return The DateTime Value
1067:             * @param row The row number in the data store buffer.
1068:             * @param column The column number in the data store buffer.
1069:             */
1070:            public java.sql.Date getDate(int row, int column)
1071:                    throws DataStoreException {
1072:                Object o = getObject(row, column, DATATYPE_DATE);
1073:                if (o == null)
1074:                    return null;
1075:                else {
1076:                    try {
1077:                        return (java.sql.Date) o;
1078:                    } catch (ClassCastException e) {
1079:                        return new java.sql.Date(((java.sql.Timestamp) o)
1080:                                .getTime());
1081:                    }
1082:                }
1083:            }
1084:
1085:            /**
1086:             * This method return a date value from the data store buffer.
1087:             * @return The DateTime Value
1088:             * @param row The row number in the data store buffer.
1089:             * @param column The column name in the data store buffer.
1090:             */
1091:            public java.sql.Date getDate(int row, String column)
1092:                    throws DataStoreException {
1093:                return getDate(row, getColumnIndex(column));
1094:            }
1095:
1096:            /**
1097:             * This method return a date value from current row of the data store buffer.
1098:             * @return The DateTime Value
1099:             * @param column The column name in the data store buffer.
1100:             */
1101:            public java.sql.Date getDate(String column)
1102:                    throws DataStoreException {
1103:                return getDate(getRow(), column);
1104:            }
1105:
1106:            /**
1107:             * This method return a date value from current row of the data store buffer.
1108:             * @return The DateTime Value
1109:             * @param column The column number in the data store buffer.
1110:             */
1111:            public Timestamp getDateTime(int column) throws DataStoreException {
1112:                return getDateTime(getRow(), column);
1113:            }
1114:
1115:            /**
1116:             * This method return a date value from the data store buffer.
1117:             * @return The DateTime Value
1118:             * @param row The row number in the data store buffer.
1119:             * @param column The column number in the data store buffer.
1120:             */
1121:            public Timestamp getDateTime(int row, int column)
1122:                    throws DataStoreException {
1123:                Object o = getObject(row, column, DATATYPE_DATETIME);
1124:                if (o == null)
1125:                    return null;
1126:                else
1127:                    return (Timestamp) o;
1128:            }
1129:
1130:            /**
1131:             * This method return a date value from the data store buffer.
1132:             * @return The DateTime Value
1133:             * @param row The row number in the data store buffer.
1134:             * @param column The column name in the data store buffer.
1135:             */
1136:            public Timestamp getDateTime(int row, String column)
1137:                    throws DataStoreException {
1138:                Object o = getObject(row, column, DATATYPE_DATETIME);
1139:                if (o == null)
1140:                    return null;
1141:                else
1142:                    return (Timestamp) o;
1143:            }
1144:
1145:            /**
1146:             * This method return a datetime value from current row of the data store buffer.
1147:             * @return The DateTime Value
1148:             * @param column The column name in the data store buffer.
1149:             */
1150:            public java.sql.Timestamp getDateTime(String column)
1151:                    throws DataStoreException {
1152:                return getDateTime(getRow(), column);
1153:            }
1154:
1155:            /**
1156:             * This method returns the current number of rows that will be deleted when the datastores update method is called.
1157:             * @return int
1158:             */
1159:            public int getDeletedCount() {
1160:                return _deletedRows.size();
1161:            }
1162:
1163:            DSDataStoreDescriptor getDescriptor() {
1164:                return _desc;
1165:            }
1166:
1167:            /**
1168:             * This method return a double value from the current row in data store buffer.
1169:             * @return The double value.
1170:             * @param column The column number in the in the data store buffer.
1171:             */
1172:            public double getDouble(int column) throws DataStoreException {
1173:                return getNumber(getRow(), column, DATATYPE_DOUBLE)
1174:                        .doubleValue();
1175:            }
1176:
1177:            /**
1178:             * This method return a double value from the data store buffer.
1179:             * @return The double value.
1180:             * @param row The row number in the data store buffer.
1181:             * @param column The column number in the in the data store buffer.
1182:             */
1183:            public double getDouble(int row, int column)
1184:                    throws DataStoreException {
1185:                return getNumber(row, column, DATATYPE_DOUBLE).doubleValue();
1186:            }
1187:
1188:            /**
1189:             * This method return a double value from the data store buffer.
1190:             * @return The double value.
1191:             * @param row The row number in the data store buffer.
1192:             * @param column The column name in the form table.column in the data store buffer
1193:             */
1194:            public double getDouble(int row, String column)
1195:                    throws DataStoreException {
1196:                return getNumber(row, column, DATATYPE_DOUBLE).doubleValue();
1197:            }
1198:
1199:            /**
1200:             * This method return a double value from the current row in data store buffer.
1201:             * @return The double value.
1202:             * @param column The column name in the form table.column in the data store buffer
1203:             */
1204:            public double getDouble(String column) throws DataStoreException {
1205:                return getNumber(getRow(), column, DATATYPE_DOUBLE)
1206:                        .doubleValue();
1207:            }
1208:
1209:            /**
1210:             * This method returns the current number of rows in the DataStores filter buffer.
1211:             * @return the number of rows in the filter buffer.
1212:             */
1213:            public int getFilteredCount() {
1214:                return _filteredRows.size();
1215:            }
1216:
1217:            /**
1218:             * This method return a float value from the current row in the data store buffer.
1219:             * @return The long value.
1220:             * @param column The column number in the data store buffer.
1221:             */
1222:            public float getFloat(int column) throws DataStoreException {
1223:                return getNumber(getRow(), column, DATATYPE_FLOAT).floatValue();
1224:            }
1225:
1226:            /**
1227:             * This method return a float value from the data store buffer.
1228:             * @return The long value.
1229:             * @param row The row number in the data store buffer.
1230:             * @param column The column number in the data store buffer.
1231:             */
1232:            public float getFloat(int row, int column)
1233:                    throws DataStoreException {
1234:                return getNumber(row, column, DATATYPE_FLOAT).floatValue();
1235:            }
1236:
1237:            /**
1238:             * This method return a float value from the data store buffer.
1239:             * @return The long value.
1240:             * @param row The row number in the data store buffer.
1241:             * @param column The column name in the data store buffer.
1242:             */
1243:            public float getFloat(int row, String column)
1244:                    throws DataStoreException {
1245:                return getNumber(row, column, DATATYPE_FLOAT).floatValue();
1246:            }
1247:
1248:            /**
1249:             * This method return a float value from the current row in the data store buffer.
1250:             * @return The long value.
1251:             * @param column The column name in the data store buffer.
1252:             */
1253:            public float getFloat(String column) throws DataStoreException {
1254:                return getNumber(getRow(), column, DATATYPE_FLOAT).floatValue();
1255:            }
1256:
1257:            /**
1258:             * This method returns a the format string for a date, time, datetime or numeric type column.
1259:             * @param col The column number to get the format for.
1260:             * @see DataStore#getFormattedString
1261:             * @see DataStore#setFormattedString
1262:             */
1263:            public String getFormat(int col) throws DataStoreException {
1264:                if (col < 0 || col >= _desc.getColumnCount())
1265:                    throw new DataStoreException("Specified column (" + col
1266:                            + ") does not exist.");
1267:
1268:                DSColumnDescriptor d = _desc.getColumn(col);
1269:
1270:                java.text.Format f = d.getFormat();
1271:
1272:                if (f == null)
1273:                    return null;
1274:                else if (f instanceof  java.text.DecimalFormat)
1275:                    return ((java.text.DecimalFormat) f).toPattern();
1276:                else
1277:                    return ((java.text.SimpleDateFormat) f).toPattern();
1278:
1279:            }
1280:
1281:            /**
1282:             * This method returns a the format string for a date, time, datetime or numeric type column.
1283:             * @param col The column name to get the format for.
1284:             * @see DataStore#getFormattedString
1285:             * @see DataStore#setFormattedString
1286:             */
1287:            public String getFormat(String col) throws DataStoreException {
1288:                int coln = getColumnIndex(col);
1289:                return getFormat(coln);
1290:            }
1291:
1292:            /**
1293:             * This method return a string value from the data store buffer. If the column is numeric, date, time or datetime it will first be formatted into a String based on the pattern specified in the setFormat method.<BR><BR>
1294:             * @see DataStore#setFormat
1295:             */
1296:            public String getFormattedString(int column)
1297:                    throws DataStoreException {
1298:                if (getRow() == -1)
1299:                    return null;
1300:                else
1301:                    return getFormattedString(getRow(), column);
1302:            }
1303:
1304:            /**
1305:             * This method return a string value from the data store buffer. If the column is numeric, date, time or datetime it will first be formatted into a String based on the pattern specified in the setFormat method.<BR><BR>If there is a temporary value specified for the column, that will be returned instead.
1306:             * @see DataStore#setFormat
1307:             * @see DataStoreBuffer#setTempValue
1308:             */
1309:            public String getFormattedString(int row, int column)
1310:                    throws DataStoreException {
1311:                if (column < 0 || column >= _desc.getColumnCount())
1312:                    throw new DataStoreException("Specified column (" + column
1313:                            + ") is out of range.");
1314:
1315:                if (row < 0 || row >= _rows.size())
1316:                    throw new DataStoreException("Specified row (" + row
1317:                            + ") is out of range.");
1318:
1319:                DSColumnDescriptor d = _desc.getColumn(column);
1320:
1321:                DSDataRow dsRow = (DSDataRow) _rows.elementAt(row);
1322:                String tempVal = dsRow.getTempValue(column);
1323:                if (tempVal != null)
1324:                    return tempVal;
1325:
1326:                java.text.Format f = d.getFormat();
1327:                Object value = getObject(row, column, DATATYPE_ANY);
1328:                String retVal = null;
1329:
1330:                if (value == null)
1331:                    retVal = null;
1332:                else if (value instanceof  String)
1333:                    retVal = (String) value;
1334:                else if (value instanceof  byte[])
1335:                    retVal = new String((byte[]) value);
1336:                else if (f == null)
1337:                    retVal = value.toString();
1338:                else {
1339:                    if (f instanceof  java.text.DecimalFormat)
1340:                        retVal = f.format(value);
1341:                    else
1342:                        retVal = ((SalmonDateFormat) f)
1343:                                .format((java.util.Date) value);
1344:                }
1345:
1346:                return retVal;
1347:            }
1348:
1349:            /**
1350:             * This method return a string value from the data store buffer. If the column is numeric, date, time or datetime it will first be formatted into a String based on the pattern specified in the setFormat method.<BR><BR>
1351:             * @see DataStore#setFormat
1352:             */
1353:            public String getFormattedString(int row, String column)
1354:                    throws DataStoreException {
1355:                int coln = getColumnIndex(column);
1356:                return getFormattedString(row, coln);
1357:            }
1358:
1359:            /**
1360:             * This method return a string value from the data store buffer. If the column is numeric, date, time or datetime it will first be formatted into a String based on the pattern specified in the setFormat method.<BR><BR>
1361:             * @see DataStore#setFormat
1362:             */
1363:            public String getFormattedString(String column)
1364:                    throws DataStoreException {
1365:                return getFormattedString(getRow(), column);
1366:            }
1367:
1368:            /**
1369:             * This method return a integer value from the current row in the data store buffer.
1370:             * @return The integer value.
1371:             * @param column The column number in the data store buffer
1372:             */
1373:            public int getInt(int column) throws DataStoreException {
1374:                return getNumber(getRow(), column, DATATYPE_INT).intValue();
1375:            }
1376:
1377:            /**
1378:             * This method return a integer value from the data store buffer.
1379:             * @return The integer value.
1380:             * @param row The row number in the data store buffer.
1381:             * @param column The column number in the data store buffer
1382:             */
1383:            public int getInt(int row, int column) throws DataStoreException {
1384:                return getNumber(row, column, DATATYPE_INT).intValue();
1385:            }
1386:
1387:            /**
1388:             * This method return a integer value from the data store buffer.
1389:             * @return The integer value.
1390:             * @param row The row number in the data store buffer.
1391:             * @param column The column name in the form table.column in the data store buffer
1392:             */
1393:            public int getInt(int row, String column) throws DataStoreException {
1394:                return getNumber(row, column, DATATYPE_INT).intValue();
1395:            }
1396:
1397:            /**
1398:             * This method return a integer value from the current row in data store buffer.
1399:             * @return The integer value.
1400:             * @param column The column name in the form table.column in the data store buffer
1401:             */
1402:            public int getInt(String column) throws DataStoreException {
1403:                return getNumber(getRow(), column, DATATYPE_INT).intValue();
1404:            }
1405:
1406:            static String getIntProperty(int p) {
1407:                return new Integer(p).toString();
1408:            }
1409:
1410:            /**
1411:             * This method return a long value from the current row in the data store buffer.
1412:             * @return The long value.
1413:             * @param column The column number in the data store buffer.
1414:             */
1415:            public long getLong(int column) throws DataStoreException {
1416:                return getNumber(getRow(), column, DATATYPE_LONG).longValue();
1417:            }
1418:
1419:            /**
1420:             * This method return a long value from the data store buffer.
1421:             * @return The long value.
1422:             * @param row The row number in the data store buffer.
1423:             * @param column The column number in the data store buffer.
1424:             */
1425:            public long getLong(int row, int column) throws DataStoreException {
1426:                return getNumber(row, column, DATATYPE_LONG).longValue();
1427:            }
1428:
1429:            /**
1430:             * This method return a long value from the data store buffer.
1431:             * @return The long value.
1432:             * @param row The row number in the data store buffer.
1433:             * @param column The column name in the data store buffer.
1434:             */
1435:            public long getLong(int row, String column)
1436:                    throws DataStoreException {
1437:                return getNumber(row, column, DATATYPE_LONG).longValue();
1438:            }
1439:
1440:            /**
1441:             * This method return a long value from the data store buffer.
1442:             * @return The long value.
1443:             * @param column The column name in the data store buffer.
1444:             */
1445:            public long getLong(String column) throws DataStoreException {
1446:                return getNumber(getRow(), column, DATATYPE_LONG).longValue();
1447:            }
1448:
1449:            private Number getNumber(int row, int column, int type)
1450:                    throws DataStoreException {
1451:                Object o = getObject(row, column, type);
1452:                if (o == null)
1453:                    return new Integer(0);
1454:                else
1455:                    return (Number) o;
1456:            }
1457:
1458:            private Number getNumber(int row, String column, int type)
1459:                    throws DataStoreException {
1460:                Object o = getObject(row, column, type);
1461:                if (o == null)
1462:                    return new Integer(0);
1463:                else
1464:                    return (Number) o;
1465:            }
1466:
1467:            private Object getObject(int row, int column, int type)
1468:                    throws DataStoreException {
1469:                waitForRow(row);
1470:                if (row < 0 || row >= _rows.size())
1471:                    throw new DataStoreException("Specified row (" + row
1472:                            + ") is out of range.");
1473:                if (column < 0 || column >= _desc.getColumnCount())
1474:                    throw new DataStoreException("Specified column (" + column
1475:                            + ") is out of range.");
1476:
1477:                if (type != DATATYPE_ANY) {
1478:                    DSColumnDescriptor des = _desc.getColumn(column);
1479:                    if (des.getType() != type)
1480:                        throw new DataStoreException("Column type mismatch.");
1481:                }
1482:
1483:                DSDataRow d = (DSDataRow) _rows.elementAt(row);
1484:                Object oData = d.getData(column);
1485:                //fc 06/11/04: If this model is a One To Many Model and column is in master then get value from first row.
1486:                if (_manytoonerelationship
1487:                        && row > 0
1488:                        && isColumnInOneToManyRelationship(getColumnName(column))) {
1489:                    //fc 10/11/04: If this model is a One To Many Model and column is new or new modified get value from first row.
1490:                    if (row != 0
1491:                            && (getRowStatus(row) == STATUS_NEW || getRowStatus(row) == STATUS_NEW_MODIFIED)) {
1492:                        DSDataRow dsFrom = (DSDataRow) _rows.elementAt(0);
1493:                        DSDataRow dsTo = (DSDataRow) _rows.elementAt(row);
1494:                        DataStoreRow dsrFrom = new DataStoreRow(this , dsFrom,
1495:                                getDescriptor());
1496:                        DataStoreRow dsrTo = new DataStoreRow(this , dsTo,
1497:                                getDescriptor());
1498:                        try {
1499:                            copyMasterDataValuesToRow(
1500:                                    getTablesRelationshipDescription((DataStoreInterface) this ),
1501:                                    dsrFrom, dsrTo);
1502:                        } catch (DataStoreException dse) {
1503:                            MessageLog.writeErrorMessage(dse, this );
1504:                        }
1505:                        oData = d.getData(column);
1506:                        //oData=((DSDataRow)_rows.elementAt(0)).getData(column);
1507:                    }
1508:                }
1509:                return oData;
1510:            }
1511:
1512:            private Object getObject(int row, String column, int type)
1513:                    throws DataStoreException {
1514:                int col = getColumnIndex(column);
1515:                if (col == -1) {
1516:                    MessageLog.writeInfoMessage("column : " + column
1517:                            + " -> NOT FOUND", this );
1518:                }
1519:                return getObject(row, col, type);
1520:            }
1521:
1522:            protected int getObjectType(Object obj) {
1523:
1524:                if (obj instanceof  String)
1525:                    return DATATYPE_STRING;
1526:
1527:                if (obj instanceof  Integer)
1528:                    return DATATYPE_INT;
1529:
1530:                if (obj instanceof  java.sql.Timestamp)
1531:                    return DATATYPE_DATETIME;
1532:
1533:                if (obj instanceof  java.sql.Time)
1534:                    return DATATYPE_TIME;
1535:
1536:                if (obj instanceof  java.sql.Date)
1537:                    return DATATYPE_DATE;
1538:
1539:                if (obj instanceof  Double)
1540:                    return DATATYPE_DOUBLE;
1541:
1542:                if (obj instanceof  byte[])
1543:                    return DATATYPE_BYTEARRAY;
1544:
1545:                if (obj instanceof  Short)
1546:                    return DATATYPE_SHORT;
1547:
1548:                if (obj instanceof  Long)
1549:                    return DATATYPE_LONG;
1550:
1551:                if (obj instanceof  Float)
1552:                    return DATATYPE_FLOAT;
1553:
1554:                return DATATYPE_ANY;
1555:            }
1556:
1557:            /**
1558:             * This method creates a properties object containing the definition of the data store.
1559:             */
1560:            public Properties getProperties() {
1561:
1562:                Properties p = new Properties();
1563:                java.text.DecimalFormat fmt = new java.text.DecimalFormat(
1564:                        "0000");
1565:
1566:                String desc = "base.";
1567:                p.put(desc + "defaultTable", getStringProperty(_desc
1568:                        .getDefaultTable()));
1569:                p.put(desc + "whereClause", getStringProperty(_desc
1570:                        .getWhereClause()));
1571:                p.put(desc + "groupByClause", getStringProperty(_desc
1572:                        .getGroupByClause()));
1573:                p.put(desc + "havingClause", getStringProperty(_desc
1574:                        .getHavingClause()));
1575:                p.put(desc + "orderByClause", getStringProperty(_desc
1576:                        .getOrderByClause()));
1577:                p.put(desc + "distinct", getBoolProperty(_desc.getDistinct()));
1578:                p.put(desc + "trimStrings", getBoolProperty(_desc
1579:                        .getTrimStrings()));
1580:
1581:                for (int i = 0; i < _desc.getColumnCount(); i++) {
1582:                    DSColumnDescriptor d = _desc.getColumn(i);
1583:                    String name = "col." + fmt.format(i) + ".";
1584:                    p.put(name + "table", getStringProperty(d.getTable()));
1585:                    p.put(name + "column", getStringProperty(d.getColumn()));
1586:                    p.put(name + "type", getIntProperty(d.getType()));
1587:                    p.put(name + "pkey", getBoolProperty(d.isPrimaryKey()));
1588:                    p.put(name + "update", getBoolProperty(d.isUpdateable()));
1589:                    p
1590:                            .put(name + "name", getStringProperty(d
1591:                                    .getInternalName()));
1592:                    p.put(name + "concurrency", getBoolProperty(d
1593:                            .getConcurrency()));
1594:                    p.put(name + "useBind", getIntProperty(d.getUseBind()));
1595:
1596:                    java.text.Format f = d.getFormat();
1597:                    if (f instanceof  java.text.SimpleDateFormat)
1598:                        p
1599:                                .put(
1600:                                        name + "format",
1601:                                        getStringProperty(((java.text.SimpleDateFormat) f)
1602:                                                .toPattern()));
1603:                    else if (f instanceof  java.text.DecimalFormat)
1604:                        p.put(name + "format",
1605:                                getStringProperty(((java.text.DecimalFormat) f)
1606:                                        .toPattern()));
1607:                    else
1608:                        p.put(name + "format", "null");
1609:                }
1610:
1611:                StringBuffer s = new StringBuffer();
1612:                for (int i = 0; i < _desc.getJoinCount(); i++) {
1613:                    DSJoinDescriptor d = _desc.getJoin(i);
1614:                    String name = "join." + fmt.format(i) + ".";
1615:
1616:                    s.setLength(0);
1617:                    for (int j = 0; j < d.getLeftCount(); j++) {
1618:                        s.append(d.getLeftColumn(j));
1619:                        s.append(',');
1620:                    }
1621:                    if (s.length() > 0)
1622:                        s.setLength(s.length() - 1);
1623:                    p.put(name + "left", s.toString());
1624:
1625:                    s.setLength(0);
1626:                    for (int j = 0; j < d.getRightCount(); j++) {
1627:                        s.append(d.getRightColumn(j));
1628:                        s.append(',');
1629:                    }
1630:                    if (s.length() > 0)
1631:                        s.setLength(s.length() - 1);
1632:                    p.put(name + "right", s.toString());
1633:
1634:                    p.put(name + "outer", getBoolProperty(d.isOuter()));
1635:                }
1636:
1637:                for (int i = 0; i < _desc.getAliasCount(); i++) {
1638:                    DSTableAliasDescriptor d = _desc.getAlias(i);
1639:                    String name = "tableAlias." + fmt.format(i) + ".";
1640:                    p.put(name + "table", getStringProperty(d.getTable()));
1641:                    p.put(name + "alias", getStringProperty(d.getAlias()));
1642:                }
1643:
1644:                return p;
1645:            }
1646:
1647:            /**
1648:             * This method returns the current row in the result set.
1649:             * @return The current row in the result set or -1 if the result set is empty.
1650:             */
1651:            public int getRow() {
1652:                return _currentRow;
1653:            }
1654:
1655:            /**
1656:             * This method returns the current number of rows in the DataStores data buffer. If a retrieve is in progress this value will change as the rows are retrieved.
1657:             * @return the number of rows in the buffer.
1658:             */
1659:            public int getRowCount() {
1660:                return _rows.size();
1661:            }
1662:
1663:            /**
1664:             * This method will return a copy of all the rows in the DataStore. The rows can then be restored with the setRows method. The intention of this method is to allow for the caching of data in the datastore so it doesn't have to be retrieved.
1665:             */
1666:            public Vector getRows() {
1667:                Vector v = new Vector(3);
1668:                v.addElement(_rows.clone());
1669:                v.addElement(_filteredRows.clone());
1670:                v.addElement(_deletedRows.clone());
1671:                return v;
1672:            }
1673:
1674:            /**
1675:             * This method returns the status flag of the current row.
1676:             * @return -1 if the row is not in the buffer or the status if it is (Valid values: STATUS_NOT_MODIFIED, STATUS_MODIFIED, STATUS_NEW, STATUS_NEW_MODIFIED).
1677:             */
1678:            public int getRowStatus() {
1679:                return getRowStatus(getRow());
1680:            }
1681:
1682:            /**
1683:             * This method returns the status flag of the specified row.
1684:             * @param row The row in the datastore buffer.
1685:             * @return -1 if the row is not in the buffer or the status if it is. (Valid values: STATUS_NOT_MODIFIED, STATUS_MODIFIED, STATUS_NEW, STATUS_NEW_MODIFIED).
1686:             */
1687:            public int getRowStatus(int row) {
1688:                if (row < 0)
1689:                    return -1;
1690:                waitForRow(row);
1691:                if (row >= getRowCount())
1692:                    return -1;
1693:                DSDataRow d = (DSDataRow) _rows.elementAt(row);
1694:                return d.getRowStatus();
1695:            }
1696:
1697:            /**
1698:             * This method return a short value from the current row in the data store buffer.
1699:             * @return The short value.
1700:             * @param column The column number in the data store buffer.
1701:             */
1702:            public short getShort(int column) throws DataStoreException {
1703:                return getNumber(getRow(), column, DATATYPE_SHORT).shortValue();
1704:            }
1705:
1706:            /**
1707:             * This method return a short value from the data store buffer.
1708:             * @return The short value.
1709:             * @param row The row number in the data store buffer.
1710:             * @param column The column number in the data store buffer.
1711:             */
1712:            public short getShort(int row, int column)
1713:                    throws DataStoreException {
1714:                return getNumber(row, column, DATATYPE_SHORT).shortValue();
1715:            }
1716:
1717:            /**
1718:             * This method return a short value from the data store buffer.
1719:             * @return The short value.
1720:             * @param row The row number in the data store buffer.
1721:             * @param column The column name in the form table.column in the data store buffer
1722:             */
1723:            public short getShort(int row, String column)
1724:                    throws DataStoreException {
1725:                return getNumber(row, column, DATATYPE_SHORT).shortValue();
1726:            }
1727:
1728:            /**
1729:             * This method return a short value from the current row in the data store buffer.
1730:             * @return The short value.
1731:             * @param column The column name in the form table.column in the data store buffer
1732:             */
1733:            public short getShort(String column) throws DataStoreException {
1734:                return getNumber(getRow(), column, DATATYPE_SHORT).shortValue();
1735:            }
1736:
1737:            /**
1738:             * This method return a string value from the data store buffer.
1739:             * @return The String Value
1740:             * @param column The column number in the data store buffer
1741:             */
1742:            public String getString(int column) throws DataStoreException {
1743:                return (String) getObject(getRow(), column, DATATYPE_STRING);
1744:            }
1745:
1746:            /**
1747:             * This method return a string value from the data store buffer.
1748:             * @return The String Value
1749:             * @param row The row number in the data store buffer.
1750:             * @param column The column number in the data store buffer.
1751:             */
1752:            public String getString(int row, int column)
1753:                    throws DataStoreException {
1754:                return (String) getObject(row, column, DATATYPE_STRING);
1755:            }
1756:
1757:            /**
1758:             * This method return a String value from the data store buffer.
1759:             * @return The String value
1760:             * @param row The row number in the data store buffer.
1761:             * @param column The column name (in the form table.column) in the data store buffer.
1762:             */
1763:            public String getString(int row, String column)
1764:                    throws DataStoreException {
1765:                return (String) getObject(row, column, DATATYPE_STRING);
1766:            }
1767:
1768:            /**
1769:             * This method return a string value from the data store buffer.
1770:             * @return The String Value
1771:             * @param column The column name (in the form table.column) in the data store buffer.
1772:             */
1773:            public String getString(String column) throws DataStoreException {
1774:                return (String) getObject(getRow(), column, DATATYPE_STRING);
1775:            }
1776:
1777:            static String getStringProperty(String p) {
1778:                if (p == null)
1779:                    return "null";
1780:                else
1781:                    return p;
1782:            }
1783:
1784:            /**
1785:             * This method returns an array of all the tables referenced in the datastore.
1786:             * @param updateable True if the table list should only include updateable tables and false if it should include all.
1787:             */
1788:            public String[] getTableList(boolean updateable) {
1789:
1790:                DSColumnDescriptor col = null;
1791:
1792:                Vector tables = new Vector();
1793:                Vector pkey = new Vector();
1794:
1795:                for (int i = 0; i < _desc.getColumnCount(); i++) {
1796:                    col = _desc.getColumn(i);
1797:                    String tableName = col.getTable();
1798:                    if (tableName == null)
1799:                        tableName = _desc.getDefaultTable();
1800:
1801:                    if ((!updateable) || col.isUpdateable()) {
1802:                        boolean found = false;
1803:                        for (int j = 0; j < tables.size(); j++) {
1804:                            if ((tables.elementAt(j)).equals(tableName)) {
1805:                                if (col.isPrimaryKey())
1806:                                    pkey.setElementAt(new Boolean(true), j);
1807:                                found = true;
1808:                                break;
1809:                            }
1810:                        }
1811:                        if (!found) {
1812:                            tables.addElement(tableName);
1813:                            pkey.addElement(new Boolean(col.isPrimaryKey()));
1814:                        }
1815:                    }
1816:
1817:                }
1818:
1819:                if (updateable) {
1820:                    for (int i = pkey.size() - 1; i > -1; i--) {
1821:                        if (!((Boolean) pkey.elementAt(i)).booleanValue())
1822:                            tables.removeElementAt(i);
1823:                    }
1824:                }
1825:
1826:                String retVal[] = new String[tables.size()];
1827:                tables.copyInto(retVal);
1828:
1829:                return retVal;
1830:            }
1831:
1832:            /**
1833:             * This method return a time value from current row of the data store buffer.
1834:             * @return The time Value
1835:             * @param column The column number in the data store buffer.
1836:             */
1837:            public java.sql.Time getTime(int column) throws DataStoreException {
1838:                return getTime(getRow(), column);
1839:            }
1840:
1841:            /**
1842:             * This method return a time value from the data store buffer.
1843:             * @return The time Value
1844:             * @param row The row number in the data store buffer.
1845:             * @param column The column number in the data store buffer.
1846:             */
1847:            public java.sql.Time getTime(int row, int column)
1848:                    throws DataStoreException {
1849:                Object o = getObject(row, column, DATATYPE_TIME);
1850:                if (o == null)
1851:                    return null;
1852:                else
1853:                    return (java.sql.Time) o;
1854:            }
1855:
1856:            /**
1857:             * This method return a time value from the data store buffer.
1858:             * @return The Time Value
1859:             * @param row The row number in the data store buffer.
1860:             * @param column The column name in the data store buffer.
1861:             */
1862:            public java.sql.Time getTime(int row, String column)
1863:                    throws DataStoreException {
1864:                Object o = getObject(row, column, DATATYPE_TIME);
1865:                if (o == null)
1866:                    return null;
1867:                else
1868:                    return (java.sql.Time) o;
1869:            }
1870:
1871:            /**
1872:             * This method return a time value from current row of the data store buffer.
1873:             * @return The Time Value
1874:             * @param column The column name in the data store buffer.
1875:             */
1876:            public java.sql.Time getTime(String column)
1877:                    throws DataStoreException {
1878:                return getTime(getRow(), column);
1879:            }
1880:
1881:            public static String getTypeDescription(int type) {
1882:                String ret = "";
1883:                switch (type) {
1884:                case DATATYPE_STRING:
1885:                    ret = "DATATYPE_STRING";
1886:                    break;
1887:                case DATATYPE_INT:
1888:                    ret = "DATATYPE_INT";
1889:                    break;
1890:                case DATATYPE_DATETIME:
1891:                    ret = "DATATYPE_DATETIME";
1892:                    break;
1893:                case DATATYPE_DOUBLE:
1894:                    ret = "DATATYPE_DOUBLE";
1895:                    break;
1896:                case DATATYPE_BYTEARRAY:
1897:                    ret = "DATATYPE_BYTEARRAY";
1898:                    break;
1899:                case DATATYPE_SHORT:
1900:                    ret = "DATATYPE_SHORT";
1901:                    break;
1902:                case DATATYPE_LONG:
1903:                    ret = "DATATYPE_LONG";
1904:                    break;
1905:                case DATATYPE_FLOAT:
1906:                    ret = "DATATYPE_FLOAT";
1907:                    break;
1908:                case DATATYPE_DATE:
1909:                    ret = "DATATYPE_DATE";
1910:                    break;
1911:                case DATATYPE_TIME:
1912:                    ret = "DATATYPE_TIME";
1913:                    break;
1914:                default:
1915:                    ret = "UNDEFINED";
1916:                    break;
1917:                }
1918:                return ret;
1919:            }
1920:
1921:            /**
1922:             * This method makes the current row the first one in the result set.
1923:             * @return Returns fals if the result set is empty.
1924:             */
1925:            public synchronized boolean gotoFirst() {
1926:                return gotoRow(0);
1927:            }
1928:
1929:            /**
1930:             * This method makes the current row the last one in the result set.
1931:             * @return Returns fals if the result set is empty.
1932:             */
1933:            public synchronized boolean gotoLast() {
1934:                waitForRetrieve();
1935:                return gotoRow(getRowCount() - 1);
1936:            }
1937:
1938:            /**
1939:             * This method increments the current row in the result set.
1940:             * @return Returns false if the result set is empty or the current row is the last.
1941:             */
1942:            public synchronized boolean gotoNext() {
1943:                return gotoRow(getRow() + 1);
1944:            }
1945:
1946:            /**
1947:             * This method decrements the current row in the result set.
1948:             * @return Returns false if the result set is empty or the current row is the first.
1949:             */
1950:            public synchronized boolean gotoPrior() {
1951:                return gotoRow(getRow() - 1);
1952:            }
1953:
1954:            /**
1955:             * This method makes a specific row the current one in the result set.
1956:             * @return Returns false if the result set is empty or the row passed is beyond the bounds of the result set.
1957:             * @param row The row in the result set to make current.
1958:             */
1959:            public synchronized boolean gotoRow(int row) {
1960:                if (row < 0)
1961:                    return false;
1962:                waitForRow(row);
1963:                if (row >= getRowCount())
1964:                    return false;
1965:                setCurrentRow(row);
1966:                return true;
1967:
1968:            }
1969:
1970:            /**
1971:             * Imports an XML row into the Buffer
1972:             */
1973:            public void importRow(com.salmonllc.xml.Row row)
1974:                    throws DataStoreException {
1975:                // Insert a row
1976:                // Then set row data
1977:                int i = insertRow();
1978:
1979:                DataStoreRow dataStoreRow = new DataStoreRow(this ,
1980:                        new DSDataRow(_desc), _desc);
1981:                DSDataRow dsRow = dataStoreRow.getDSDataRow();
1982:
1983:                for (int c = 0; c < _desc.getColumnCount(); c++) {
1984:                    DSColumnDescriptor col = _desc.getColumn(c);
1985:                    String tableName = col.getTable();
1986:                    if (tableName == null)
1987:                        tableName = "";
1988:
1989:                    String colName = col.getColumn();
1990:                    if (colName == null)
1991:                        colName = "Column" + c;
1992:
1993:                    Column columnData = (Column) row
1994:                            .get(tableName == "" ? colName : tableName + "."
1995:                                    + colName);
1996:
1997:                    int colType = col.getType();
1998:                    if (columnData != null) {
1999:                        Object oVal = null;
2000:                        switch (colType) {
2001:                        case DATATYPE_STRING:
2002:                            oVal = columnData.getValue();
2003:                            break;
2004:                        case DATATYPE_DATE:
2005:                            try {
2006:                                oVal = new SalmonDateFormat().parse(columnData
2007:                                        .getValue());
2008:                            } catch (ParseException ex) {
2009:                                MessageLog.writeErrorMessage(ex, this );
2010:                            }
2011:                            break;
2012:                        case DATATYPE_DATETIME:
2013:                            try {
2014:                                oVal = new Timestamp(new SalmonDateFormat()
2015:                                        .parse(columnData.getValue()).getTime());
2016:                            } catch (ParseException ex) {
2017:                                MessageLog.writeErrorMessage(ex, this );
2018:                            }
2019:                            break;
2020:                        case DATATYPE_TIME:
2021:                            try {
2022:                                oVal = new Time(new SalmonDateFormat().parse(
2023:                                        columnData.getValue()).getTime());
2024:                            } catch (ParseException ex) {
2025:                                MessageLog.writeErrorMessage(ex, this );
2026:                            }
2027:                            break;
2028:                        case DATATYPE_SHORT:
2029:                            try {
2030:                                oVal = new Short(columnData.getValue());
2031:                            } catch (NumberFormatException ex) {
2032:                                MessageLog.writeErrorMessage(ex, this );
2033:                            }
2034:                            break;
2035:                        case DATATYPE_INT:
2036:                            try {
2037:                                oVal = new Integer(columnData.getValue());
2038:                            } catch (NumberFormatException ex) {
2039:                                MessageLog.writeErrorMessage(ex, this );
2040:                            }
2041:                            break;
2042:                        case DATATYPE_LONG:
2043:                            try {
2044:                                oVal = new Long(columnData.getValue());
2045:                            } catch (NumberFormatException ex) {
2046:                                MessageLog.writeErrorMessage(ex, this );
2047:                            }
2048:                            break;
2049:                        case DATATYPE_FLOAT:
2050:                            try {
2051:                                oVal = new Float(columnData.getValue());
2052:                            } catch (NumberFormatException ex) {
2053:                                MessageLog.writeErrorMessage(ex, this );
2054:                            }
2055:                            break;
2056:                        case DATATYPE_DOUBLE:
2057:                            try {
2058:                                oVal = new Double(columnData.getValue());
2059:                            } catch (NumberFormatException ex) {
2060:                                MessageLog.writeErrorMessage(ex, this );
2061:                            }
2062:                            break;
2063:                        case DATATYPE_BYTEARRAY:
2064:                            oVal = columnData.getValue().getBytes();
2065:                            break;
2066:                        }
2067:                        dsRow.setValue(c, oVal, _desc);
2068:                    }
2069:                }
2070:
2071:                setDataStoreRow(i, BUFFER_STANDARD, dataStoreRow);
2072:
2073:            }
2074:
2075:            /**
2076:             * Inserts a blank row at the end of the DataStoreBuffer. Returns the number of the row added.
2077:             */
2078:            public int insertRow() {
2079:                DSDataRow d = new DSDataRow(_desc);
2080:                _rows.addElement(d);
2081:                if (areThereModelListeners()) {
2082:                    ModelChangedEvent evt = new ModelChangedEvent(this , _rows
2083:                            .size() - 1);
2084:                    notifyListeners(evt);
2085:                }
2086:                setCurrentRow(_rows.size() - 1);
2087:                return getRow();
2088:            }
2089:
2090:            /**
2091:             * Inserts a blank row at the specified position of the DataStore's result set buffer. Returns the number of the row added.
2092:             */
2093:            public int insertRow(int atPosition) {
2094:                int rows = _rows.size();
2095:
2096:                DSDataRow d = new DSDataRow(_desc);
2097:                if (atPosition < 0)
2098:                    atPosition = 0;
2099:
2100:                if (atPosition >= rows) {
2101:                    _rows.addElement(d);
2102:                    atPosition = rows;
2103:                } else
2104:                    _rows.insertElementAt(d, atPosition);
2105:                if (areThereModelListeners()) {
2106:                    ModelChangedEvent evt = new ModelChangedEvent(this ,
2107:                            atPosition);
2108:                    notifyListeners(evt);
2109:                }
2110:                setCurrentRow(atPosition);
2111:
2112:                return _currentRow;
2113:            }
2114:
2115:            /**
2116:             * This method returns true if a particular column is modified
2117:             */
2118:            public boolean isColumnModified(int row, int column)
2119:                    throws DataStoreException {
2120:                if (row < 0)
2121:                    throw new DataStoreException("Invalid Row Number: " + row);
2122:                waitForRow(row);
2123:                if (row >= getRowCount())
2124:                    throw new DataStoreException("Invalid Row Number: " + row);
2125:                DSDataRow d = (DSDataRow) _rows.elementAt(row);
2126:                return d.getColumnStatus(column) == STATUS_MODIFIED
2127:                        || d.getColumnStatus(column) == STATUS_NEW_MODIFIED;
2128:            }
2129:
2130:            /**
2131:             * This method returns true if a particular column is modified
2132:             */
2133:            public boolean isColumnModified(int row, String column)
2134:                    throws DataStoreException {
2135:                int ndx = getColumnIndex(column);
2136:                if (ndx == -1)
2137:                    throw new DataStoreException("Invalid Column Name:"
2138:                            + column);
2139:                return isColumnModified(row, ndx);
2140:            }
2141:
2142:            /**
2143:             * This method will return true if the passed string value if a valid entry for the column based on the String format specified for the column via the setFormat method.
2144:             * @see DataStoreBuffer#setFormat
2145:             */
2146:            public boolean isFormattedStringValid(int column, String value)
2147:                    throws DataStoreException {
2148:                if (column < 0 || column >= _desc.getColumnCount())
2149:                    throw new DataStoreException("Specified column (" + column
2150:                            + ") is out of range.");
2151:
2152:                DSColumnDescriptor d = _desc.getColumn(column);
2153:                int type = d.getType();
2154:                java.text.Format f = d.getFormat();
2155:
2156:                try {
2157:                    if (value == null)
2158:                        return true;
2159:                    else if (f == null) {
2160:                        if (type == DATATYPE_INT)
2161:                            Integer.valueOf(value);
2162:                        else if (type == DATATYPE_DOUBLE)
2163:                            Double.valueOf(value);
2164:                        else if (type == DATATYPE_FLOAT)
2165:                            Float.valueOf(value);
2166:                        else if (type == DATATYPE_SHORT)
2167:                            Short.valueOf(value);
2168:                        else if (type == DATATYPE_LONG)
2169:                            Long.valueOf(value);
2170:                        else if (type == DATATYPE_DATETIME)
2171:                            Timestamp.valueOf(value);
2172:                        else if (type == DATATYPE_TIME)
2173:                            java.sql.Time.valueOf(value);
2174:                        else if (type == DATATYPE_DATE)
2175:                            java.sql.Date.valueOf(value);
2176:                    } else {
2177:                        if (f instanceof  java.text.DecimalFormat)
2178:                            ((java.text.DecimalFormat) f).parse(value);
2179:                        else
2180:                            ((SalmonDateFormat) f).parse(value);
2181:                    }
2182:                } catch (Exception e) {
2183:                    return false;
2184:                }
2185:
2186:                return true;
2187:            }
2188:
2189:            /**
2190:             * This method will return true if the passed string value if a valid entry for the column based on the String format specified for the column via the setFormat method.
2191:             * @see DataStoreBuffer#setFormat
2192:             */
2193:            public boolean isFormattedStringValid(String column, String value)
2194:                    throws DataStoreException {
2195:                int coln = getColumnIndex(column);
2196:                return isFormattedStringValid(coln, value);
2197:            }
2198:
2199:            /**
2200:             * This removes the current row from the DataStore buffer. This will not generate a delete statment that will remove the row from the database when the update method is called.
2201:             * @return True if the row is remove and false if not.
2202:             */
2203:            public boolean removeRow() {
2204:                return removeRow(getRow());
2205:            }
2206:
2207:            /**
2208:             * This removes the row from the DataStore buffer. This will not generate a delete statment that will remove the row from the database when the update method is called.
2209:             * @param row The number of the row to remove.
2210:             * @return True if the row is remove and false if not.
2211:             */
2212:            public boolean removeRow(int row) {
2213:                if (row < 0)
2214:                    return false;
2215:                waitForRow(row);
2216:                if (row >= getRowCount())
2217:                    return false;
2218:
2219:                if (areThereModelListeners()) {
2220:                    ModelChangedEvent evt = new ModelChangedEvent(this ,
2221:                            getRow());
2222:                    notifyListeners(evt);
2223:                }
2224:                _rows.removeElementAt(row);
2225:
2226:                if (row == getRow() && row >= getRowCount())
2227:                    _currentRow--;
2228:
2229:                return true;
2230:            }
2231:
2232:            private String removeSpecialCharacters(String input) {
2233:                if (input == null)
2234:                    return null;
2235:
2236:                StringBuffer sb = new StringBuffer(input.length());
2237:
2238:                for (int i = 0; i < input.length(); i++) {
2239:                    char c = input.charAt(i);
2240:                    if (c < 32 || c == '\t')
2241:                        sb.append(' ');
2242:                    else
2243:                        sb.append(c);
2244:                }
2245:
2246:                return sb.toString();
2247:            }
2248:
2249:            /**
2250:             * This method will clear all rows in the dataStore.
2251:             */
2252:            public synchronized void reset() {
2253:                _rows.removeAllElements();
2254:                _rows.trimToSize();
2255:                //
2256:                _deletedRows.removeAllElements();
2257:                _deletedRows.trimToSize();
2258:                //
2259:                _filteredRows.removeAllElements();
2260:                _deletedRows.trimToSize();
2261:                //
2262:                notifyListeners(ModelChangedEvent.TYPE_RESET);
2263:                setCurrentRow(-1);
2264:            }
2265:
2266:            /**
2267:             * This method will clear the row status flags and clear the deleted buffer in the DataStoreBuffer.
2268:             */
2269:            public void resetStatus() {
2270:                DSDataRow row;
2271:
2272:                for (int i = 0; i < _rows.size(); i++) {
2273:                    row = (DSDataRow) _rows.elementAt(i);
2274:                    //fc 06/11/04: Only reset status of modified rows not new rows.
2275:                    if (row.getRowStatus() != STATUS_NEW)
2276:                        row.setRowStatus(STATUS_NOT_MODIFIED);
2277:                    row.setBucketsModified(false);
2278:                    row.copyDataToOrig();
2279:                }
2280:                _deletedRows.removeAllElements();
2281:            }
2282:
2283:            /**
2284:             * This method sets a value in the data store's internal buffer.
2285:             * @param row The row number for the value to set.
2286:             * @param column The column for the value to set.
2287:             * @param value The data to place in the column
2288:             */
2289:            public void setAny(int row, int column, Object value)
2290:                    throws DataStoreException {
2291:                setObject(row, column, value, DATATYPE_ANY);
2292:            }
2293:
2294:            /**
2295:             * This method sets a value in the data store's internal buffer at the current row.
2296:             * @param column The column for the value to set.
2297:             * @param value The data to place in the column.
2298:             */
2299:            public void setAny(int column, Object value)
2300:                    throws DataStoreException {
2301:                setObject(getRow(), column, value, DATATYPE_ANY);
2302:            }
2303:
2304:            /**
2305:             * This method sets a value in the data store's internal buffer.
2306:             * @param row The row number for the value to set.
2307:             * @param column The column for the value to set.
2308:             * @param value The data to place in the column.
2309:             */
2310:            public void setAny(int row, String column, Object value)
2311:                    throws DataStoreException {
2312:                setObject(row, column, value, DATATYPE_ANY);
2313:            }
2314:
2315:            /**
2316:             * This method sets a value in the data store's internal buffer at the current row.
2317:             * @param column The column for the value to set.
2318:             * @param value The data to place in the column
2319:             */
2320:            public void setAny(String column, Object value)
2321:                    throws DataStoreException {
2322:                setObject(getRow(), column, value, DATATYPE_ANY);
2323:            }
2324:
2325:            /**
2326:             * This method will set the whether or not columns in the DatastoreBuffer should be automatically bound to components in the page (Only used for DataStoreBuffers created via the DataSource jsp tag)
2327:             */
2328:            public void setAutoBind(boolean value) {
2329:                _autoBind = value;
2330:            }
2331:
2332:            /**
2333:             * This method will set the whether or not the DatastoreBuffer should be automatically retrieved when a page is requested (Only used for DataStoreBuffers created via the DataSource jsp tag)
2334:             * Valid values are AUTORETRIEVE_NEVER (Don't Autoretrieve),AUTORETRIEVE_ALWAYS (Retrieve on each page request), AUTORETRIEVE_ONCHANGE (Autoretrieve if the selection criteria changes);
2335:             */
2336:            public void setAutoRetrieve(int value) {
2337:                _autoRetrieve = value;
2338:            }
2339:
2340:            /**
2341:             * This method will set the autoretrieve criteria used for the datastore.
2342:             */
2343:            public void setAutoRetrieveCriteria(AutoRetrieveCriteria crit) {
2344:                _crit = crit;
2345:            }
2346:
2347:            static boolean setBoolProperty(String p) {
2348:                if (p == null)
2349:                    return false;
2350:                else if (p.equals("true"))
2351:                    return true;
2352:                else
2353:                    return false;
2354:            }
2355:
2356:            /**
2357:             * This method sets a flag indicating if any bucket columns (columns not representing database columns) have been modified on the specified row. Bucket column modfications aren't reflected in the row status for each row.
2358:             * @param row The row in the datastore buffer.
2359:             */
2360:            public void setBucketsModified(int row, boolean modified) {
2361:                if (row < 0)
2362:                    return;
2363:                waitForRow(row);
2364:                if (row >= getRowCount())
2365:                    return;
2366:                DSDataRow d = (DSDataRow) _rows.elementAt(row);
2367:                d.setBucketsModified(modified);
2368:            }
2369:
2370:            /**
2371:             * This method sets a flag indicating if any bucket columns (columns not representing database columns) have been modified on the current row. Bucket column modfications aren't reflected in the row status for each row.
2372:             */
2373:            public void setBucketsModified(boolean modified) {
2374:                setBucketsModified(getRow(), modified);
2375:            }
2376:
2377:            /**
2378:             * This method sets a value in the data store's internal buffer at the current row.
2379:             * @param column The column for the value to set.
2380:             * @param value The data to place in the column.
2381:             */
2382:            public void setByteArray(int column, byte[] value)
2383:                    throws DataStoreException {
2384:                setObject(getRow(), column, value, DATATYPE_BYTEARRAY);
2385:            }
2386:
2387:            /**
2388:             * This method sets a value in the data store's internal buffer.
2389:             * @param row The row number for the value to set.
2390:             * @param column The column for the value to set.
2391:             * @param value The data to place in the column.
2392:             */
2393:            public void setByteArray(int row, int column, byte[] value)
2394:                    throws DataStoreException {
2395:                setObject(row, column, value, DATATYPE_BYTEARRAY);
2396:            }
2397:
2398:            /**
2399:             * This method sets a value in the data store's internal buffer.
2400:             * @param row The row number for the value to set.
2401:             * @param column The column for the value to set.
2402:             * @param value The data to place in the column.
2403:             */
2404:            public void setByteArray(int row, String column, byte[] value)
2405:                    throws DataStoreException {
2406:                setObject(row, column, value, DATATYPE_BYTEARRAY);
2407:            }
2408:
2409:            /**
2410:             * This method sets a value in the data store's internal buffer at the current row.
2411:             * @param column The column for the value to set.
2412:             * @param value The data to place in the column
2413:             */
2414:            public void setByteArray(String column, byte[] value)
2415:                    throws DataStoreException {
2416:                setObject(getRow(), column, value, DATATYPE_BYTEARRAY);
2417:            }
2418:
2419:            /**
2420:             * This method sets the specified row in the DataStore. The DataStoreRow must be compatible with the internal structure of the datastore (eg created with the getDataStoreRow method from the same datastore). To create a blank row in the datastore call the insertRow method and then getDataStoreRow.
2421:             * @param rowNo The number of the row to get.
2422:             * @param buffer The datastore buffer to look in. Valid values are BUFFER_STANDARD, BUFFER_DELETED, BUFFER_FILTERED.
2423:             * @param row The row to set
2424:             */
2425:            public void setDataStoreRow(int rowNo, int buffer, DataStoreRow row)
2426:                    throws DataStoreException {
2427:                Vector rows = null;
2428:                if (buffer == BUFFER_STANDARD)
2429:                    rows = _rows;
2430:                else if (buffer == BUFFER_DELETED)
2431:                    rows = _deletedRows;
2432:                else if (buffer == BUFFER_FILTERED)
2433:                    rows = _filteredRows;
2434:                else
2435:                    throw new DataStoreException("Buffer is invalid.");
2436:                ;
2437:
2438:                if (rows == null)
2439:                    throw new DataStoreException("Row number:" + rowNo
2440:                            + " is out of range.");
2441:                ;
2442:
2443:                if (rowNo < 0 || rowNo >= rows.size())
2444:                    throw new DataStoreException("Row number:" + rowNo
2445:                            + " is out of range.");
2446:                ;
2447:
2448:                rows.setElementAt(row.getDSDataRow(), rowNo);
2449:            }
2450:
2451:            /**
2452:             * This method sets a value in the data store's internal buffer.
2453:             * @param row The row number for the value to set.
2454:             * @param column The column for the value to set.
2455:             * @param value The data to place in the column.
2456:             */
2457:            public void setDate(int row, int column, java.sql.Date value)
2458:                    throws DataStoreException {
2459:                setObject(row, column, value, DATATYPE_DATE);
2460:            }
2461:
2462:            /**
2463:             * This method sets a value in the data store's internal buffer.
2464:             * @param row The row number for the value to set.
2465:             * @param column The column for the value to set.
2466:             * @param value The data to place in the column.
2467:             */
2468:            public void setDate(int row, String column, java.sql.Date value)
2469:                    throws DataStoreException {
2470:                setObject(row, column, value, DATATYPE_DATE);
2471:            }
2472:
2473:            /**
2474:             * This method sets a value in the data store's internal buffer at the current row.
2475:             * @param column The column for the value to set.
2476:             * @param value The data to place in the column.
2477:             */
2478:            public void setDate(int column, java.sql.Date value)
2479:                    throws DataStoreException {
2480:                setObject(getRow(), column, value, DATATYPE_DATE);
2481:            }
2482:
2483:            /**
2484:             * This method sets a value in the data store's internal buffer at the current row.
2485:             * @param column The column for the value to set.
2486:             * @param value The data to place in the column
2487:             */
2488:            public void setDate(String column, java.sql.Date value)
2489:                    throws DataStoreException {
2490:                setObject(getRow(), column, value, DATATYPE_DATE);
2491:            }
2492:
2493:            /**
2494:             * This method sets a value in the data store's internal buffer.
2495:             * @param row The row number for the value to set.
2496:             * @param column The column for the value to set.
2497:             * @param value The data to place in the column.
2498:             */
2499:            public void setDateTime(int row, int column,
2500:                    java.sql.Timestamp value) throws DataStoreException {
2501:                setObject(row, column, value, DATATYPE_DATETIME);
2502:            }
2503:
2504:            /**
2505:             * This method sets a value in the data store's internal buffer.
2506:             * @param row The row number for the value to set.
2507:             * @param column The column for the value to set.
2508:             * @param value The data to place in the column.
2509:             */
2510:            public void setDateTime(int row, String column,
2511:                    java.sql.Timestamp value) throws DataStoreException {
2512:                setObject(row, column, value, DATATYPE_DATETIME);
2513:            }
2514:
2515:            /**
2516:             * This method sets a value in the data store's internal buffer at the current row.
2517:             * @param column The column for the value to set.
2518:             * @param value The data to place in the column.
2519:             */
2520:            public void setDateTime(int column, java.sql.Timestamp value)
2521:                    throws DataStoreException {
2522:                setObject(getRow(), column, value, DATATYPE_DATETIME);
2523:            }
2524:
2525:            /**
2526:             * This method sets a value in the data store's internal buffer at the current row.
2527:             * @param column The column for the value to set.
2528:             * @param value The data to place in the column
2529:             */
2530:            public void setDateTime(String column, java.sql.Timestamp value)
2531:                    throws DataStoreException {
2532:                setObject(getRow(), column, value, DATATYPE_DATETIME);
2533:            }
2534:
2535:            /**
2536:             * This method will set the distinct flag in the data store.
2537:             * @param distinct if the flag is set to true the generated select statement will begin with a select distinct.
2538:             */
2539:            public void setDistinct(boolean distinct) {
2540:                _desc.setDistinct(distinct);
2541:            }
2542:
2543:            /**
2544:             * This method sets a value in the data store's internal buffer at the current row.
2545:             * @param column The column for the value to set.
2546:             * @param value The data to place in the column.
2547:             */
2548:            public void setDouble(int column, double value)
2549:                    throws DataStoreException {
2550:                setObject(getRow(), column, new Double(value), DATATYPE_DOUBLE);
2551:            }
2552:
2553:            /**
2554:             * This method sets a value in the data store's internal buffer.
2555:             * @param row The row number for the value to set.
2556:             * @param column The column for the value to set.
2557:             * @param value The data to place in the column.
2558:             */
2559:            public void setDouble(int row, int column, double value)
2560:                    throws DataStoreException {
2561:                setObject(row, column, new Double(value), DATATYPE_DOUBLE);
2562:            }
2563:
2564:            /**
2565:             * This method sets a value in the data store's internal buffer.
2566:             * @param row The row number for the value to set.
2567:             * @param column The column for the value to set.
2568:             * @param value The data to place in the column.
2569:             */
2570:            public void setDouble(int row, String column, double value)
2571:                    throws DataStoreException {
2572:                setObject(row, column, new Double(value), DATATYPE_DOUBLE);
2573:            }
2574:
2575:            /**
2576:             * This method sets a value in the data store's internal buffer at the current row.
2577:             * @param column The column for the value to set.
2578:             * @param value The data to place in the column.
2579:             */
2580:            public void setDouble(String column, double value)
2581:                    throws DataStoreException {
2582:                setObject(getRow(), column, new Double(value), DATATYPE_DOUBLE);
2583:            }
2584:
2585:            /**
2586:             * This method will set the expression used to find rows in the datastore. It is used in conjunction with the findNext, findPrior, findFirst, findLast and find methods.
2587:             * @param exp The expression to use in the find.
2588:             * @see DataStore#findNext
2589:             * @see DataStore#findPrior
2590:             * @see DataStore#findFirst
2591:             * @see DataStore#findLast
2592:             * @see DataStore#find
2593:             * @see DataStore#filter
2594:             * @see DataStoreEvaluator
2595:             */
2596:            public void setFindExpression(String exp) throws DataStoreException {
2597:                _find = new DataStoreEvaluator(this , exp);
2598:            }
2599:
2600:            /**
2601:             * This method sets a value in the data store's internal buffer at the current row.
2602:             * @param column The column for the value to set.
2603:             * @param value The data to place in the column.
2604:             */
2605:            public void setFloat(int column, float value)
2606:                    throws DataStoreException {
2607:                setObject(getRow(), column, new Float(value), DATATYPE_FLOAT);
2608:            }
2609:
2610:            /**
2611:             * This method sets a value in the data store's internal buffer.
2612:             * @param row The row number for the value to set.
2613:             * @param column The column for the value to set.
2614:             * @param value The data to place in the column.
2615:             */
2616:            public void setFloat(int row, int column, float value)
2617:                    throws DataStoreException {
2618:                setObject(row, column, new Float(value), DATATYPE_FLOAT);
2619:            }
2620:
2621:            /**
2622:             * This method sets a value in the data store's internal buffer.
2623:             * @param row The row number for the value to set.
2624:             * @param column The column for the value to set.
2625:             * @param value The data to place in the column.
2626:             */
2627:            public void setFloat(int row, String column, float value)
2628:                    throws DataStoreException {
2629:                setObject(row, column, new Float(value), DATATYPE_FLOAT);
2630:            }
2631:
2632:            /**
2633:             * This method sets a value in the data store's internal buffer at the current row.
2634:             * @param column The column for the value to set.
2635:             * @param value The data to place in the column.
2636:             */
2637:            public void setFloat(String column, float value)
2638:                    throws DataStoreException {
2639:                setObject(getRow(), column, new Float(value), DATATYPE_FLOAT);
2640:            }
2641:
2642:            /**
2643:             * This method sets a the format string for a date, time, datetime or numeric type column.
2644:             * @param col The column number to set the format for.
2645:             * @param format The format to use in parsing or formatting the value
2646:             * @see DataStore#getFormattedString
2647:             * @see DataStore#setFormattedString
2648:             */
2649:            public void setFormat(int col, String format)
2650:                    throws DataStoreException {
2651:                if (col < 0 || col >= _desc.getColumnCount())
2652:                    throw new DataStoreException("Specified column (" + col
2653:                            + ") does not exist.");
2654:
2655:                DSColumnDescriptor d = _desc.getColumn(col);
2656:
2657:                if (d.getType() == DATATYPE_INT || d.getType() == DATATYPE_LONG
2658:                        || d.getType() == DATATYPE_DOUBLE
2659:                        || d.getType() == DATATYPE_SHORT
2660:                        || d.getType() == DATATYPE_FLOAT)
2661:                    d.setFormat(new java.text.DecimalFormat(format));
2662:                else if (d.getType() == DATATYPE_DATE
2663:                        || d.getType() == DATATYPE_TIME
2664:                        || d.getType() == DATATYPE_DATETIME) {
2665:                    java.text.SimpleDateFormat df = new SalmonDateFormat(format);
2666:                    df.setLenient(false);
2667:                    d.setFormat(df);
2668:                } else
2669:                    throw new DataStoreException(
2670:                            "Formats may only be specified on numeric or date columns");
2671:
2672:            }
2673:
2674:            /**
2675:             * This method sets a the format string for a date, time, datetime or numeric type column.<BR><BR>
2676:             * Date Formats<BR><BR>
2677:             *  Symbol   Meaning                 Presentation        Example<BR>
2678:             *  ------   -------                 ------------        -------<BR>
2679:             *  G        era designator          (Text)              AD<BR>
2680:             *  y        year                    (Number)            1996<BR>
2681:             *  M        month in year           (Text & Number)     July & 07<BR>
2682:             *  d        day in month            (Number)            10<BR>
2683:             *  h        hour in am/pm (1~12)    (Number)            12<BR>
2684:             *  H        hour in day (0~23)      (Number)            0<BR>
2685:             *  m        minute in hour          (Number)            30<BR>
2686:             *  s        second in minute        (Number)            55<BR>
2687:             *  S        millisecond             (Number)            978<BR>
2688:             *  E        day in week             (Text)              Tuesday<BR>
2689:             *  D        day in year             (Number)            189<BR>
2690:             *  F        day of week in month    (Number)            2 (2nd Wed in July)<BR>
2691:             *  w        week in year            (Number)            27<BR>
2692:             *  W        week in month           (Number)            2<BR>
2693:             *  a        am/pm marker            (Text)              PM<BR>
2694:             *  k        hour in day (1~24)      (Number)            24<BR>
2695:             *  K        hour in am/pm (0~11)    (Number)            0<BR>
2696:             *  z        time zone               (Text)              Pacific Standard Time<BR>
2697:             *  '        escape for text         (Delimiter)<BR>
2698:             *  ''       single quote            (Literal)           '<BR><BR>
2699:             * Numeric Formats<BR><BR>
2700:             *  Symbol Meaning<BR>
2701:             *  ------ -------<BR>
2702:             *  0      a digit<BR>
2703:             *  #      a digit, zero shows as absent<BR>
2704:             *  .      placeholder for decimal separator<BR>
2705:             *  ,      placeholder for grouping separator.<BR>
2706:             *  ;      separates formats.<BR>
2707:             *  -      default negative prefix.<BR>
2708:             *  %      multiply by 100 and show as percentage<BR>
2709:             *  ?      multiply by 1000 and show as per mille<BR>
2710:             *  ¤      currency sign; replaced by currency symbol; if<BR>
2711:             *         doubled, replaced by international currency symbol.<BR>
2712:             *         If present in a pattern, the monetary decimal separator<BR>
2713:             *         is used instead of the decimal separator.<BR>
2714:             *  X      any other characters can be used in the prefix or suffix<BR>
2715:             *  '      used to quote special characters in a prefix or suffix.<BR>
2716:             * @param col The column name to set the format for.
2717:             * @param format The format to use in parsing or formatting the value
2718:             * @see DataStore#getFormattedString
2719:             * @see DataStore#setFormattedString
2720:             */
2721:            public void setFormat(String col, String format)
2722:                    throws DataStoreException {
2723:                int coln = getColumnIndex(col);
2724:                setFormat(coln, format);
2725:            }
2726:
2727:            /**
2728:             * This method will set a parse a string value using the format specified in setFormat for this column and place it in the datastore if it is valid.<BR>
2729:             * @see DataStore#setFormat
2730:             */
2731:            public void setFormattedString(int row, int column, String value)
2732:                    throws DataStoreException {
2733:                if (column < 0 || column >= _desc.getColumnCount())
2734:                    throw new DataStoreException("Specified column (" + column
2735:                            + ") is out of range.");
2736:
2737:                if (row < 0 || row >= _rows.size())
2738:                    throw new DataStoreException("Specified row (" + row
2739:                            + ") is out of range.");
2740:
2741:                DSColumnDescriptor d = _desc.getColumn(column);
2742:                int colType = d.getType();
2743:                java.text.Format f = d.getFormat();
2744:
2745:                try {
2746:                    if (value == null)
2747:                        setObject(row, column, null, DATATYPE_ANY);
2748:                    else if (f == null)
2749:                        setAny(row, column, value);
2750:                    else {
2751:                        if (f instanceof  java.text.DecimalFormat) {
2752:                            Number parsed = ((java.text.DecimalFormat) f)
2753:                                    .parse(value);
2754:                            if (colType == DATATYPE_INT)
2755:                                setInt(row, column, parsed.intValue());
2756:                            else if (colType == DATATYPE_DOUBLE)
2757:                                setDouble(row, column, parsed.doubleValue());
2758:                            else if (colType == DATATYPE_SHORT)
2759:                                setShort(row, column, parsed.shortValue());
2760:                            else if (colType == DATATYPE_LONG)
2761:                                setLong(row, column, parsed.longValue());
2762:                            else if (colType == DATATYPE_FLOAT)
2763:                                setFloat(row, column, parsed.floatValue());
2764:                        } else {
2765:                            java.util.Date dt = ((SalmonDateFormat) f)
2766:                                    .parse(value);
2767:                            GregorianCalendar cal = (GregorianCalendar) GregorianCalendar
2768:                                    .getInstance();
2769:                            cal.setTime(dt);
2770:                            int year = cal.get(Calendar.YEAR);
2771:                            int century = year / 100;
2772:                            if (century == 0) {
2773:                                GregorianCalendar c1 = (GregorianCalendar) GregorianCalendar
2774:                                        .getInstance();
2775:                                century = c1.get(Calendar.YEAR) / 100;
2776:                                century *= 100;
2777:                                cal.set(Calendar.YEAR, century + year);
2778:                            }
2779:
2780:                            long parsed = cal.getTime().getTime();
2781:                            if (colType == DATATYPE_DATE)
2782:                                setDate(row, column, new java.sql.Date(parsed));
2783:                            else if (colType == DATATYPE_TIME)
2784:                                setTime(row, column, new java.sql.Time(parsed));
2785:                            else if (colType == DATATYPE_DATETIME)
2786:                                setDateTime(row, column,
2787:                                        new java.sql.Timestamp(parsed));
2788:
2789:                        }
2790:                    }
2791:                } catch (Exception e) {
2792:                    setObject(row, column, null, DATATYPE_ANY);
2793:                }
2794:
2795:            }
2796:
2797:            /**
2798:             * This method will set a parse a string value using the format specified in setFormat for this column and place it in the datastore if it is valid.<BR>
2799:             * @see DataStore#setFormat
2800:             */
2801:            public void setFormattedString(int column, String value)
2802:                    throws DataStoreException {
2803:                setFormattedString(getRow(), column, value);
2804:
2805:            }
2806:
2807:            /**
2808:             * This method will set a parse a string value using the format specified in setFormat for this column and place it in the datastore if it is valid.<BR>
2809:             * @see DataStore#setFormat
2810:             */
2811:            public void setFormattedString(int row, String column, String value)
2812:                    throws DataStoreException {
2813:                int coln = getColumnIndex(column);
2814:                setFormattedString(row, coln, value);
2815:            }
2816:
2817:            /**
2818:             * This method will set a parse a string value using the format specified in setFormat for this column and place it in the datastore if it is valid.<BR>
2819:             * @see DataStore#setFormat
2820:             */
2821:            public void setFormattedString(String column, String value)
2822:                    throws DataStoreException {
2823:                setFormattedString(getRow(), column, value);
2824:            }
2825:
2826:            /**
2827:             * This method sets a value in the data store's internal buffer.
2828:             * @param row The row number for the value to set.
2829:             * @param column The column for the value to set.
2830:             * @param value The data to place in the column.
2831:             */
2832:            public void setInt(int row, int column, int value)
2833:                    throws DataStoreException {
2834:                setObject(row, column, new Integer(value), DATATYPE_INT);
2835:            }
2836:
2837:            /**
2838:             * This method sets a value in the data store's internal buffer.
2839:             * @param row The row number for the value to set.
2840:             * @param column The column for the value to set.
2841:             * @param value The data to place in the column.
2842:             */
2843:            public void setInt(int row, String column, int value)
2844:                    throws DataStoreException {
2845:                setObject(row, column, new Integer(value), DATATYPE_INT);
2846:            }
2847:
2848:            /**
2849:             * This method sets a value in the data store's internal buffer at the current row.
2850:             * @param column The column for the value to set.
2851:             * @param value The data to place in the column.
2852:             */
2853:            public void setInt(String column, int value)
2854:                    throws DataStoreException {
2855:                setObject(getRow(), column, new Integer(value), DATATYPE_INT);
2856:            }
2857:
2858:            static int setIntProperty(String p) {
2859:                if (p == null)
2860:                    return -1;
2861:                else {
2862:                    try {
2863:                        return (new Integer(p).intValue());
2864:                    } catch (Exception e) {
2865:                        return -1;
2866:                    }
2867:                }
2868:            }
2869:
2870:            /**
2871:             * This method sets a value in the data store's internal buffer.
2872:             * @param row The row number for the value to set.
2873:             * @param column The column for the value to set.
2874:             * @param value The data to place in the column.
2875:             */
2876:            public void setLong(int row, int column, long value)
2877:                    throws DataStoreException {
2878:                setObject(row, column, new Long(value), DATATYPE_LONG);
2879:            }
2880:
2881:            /**
2882:             * This method sets a value in the data store's internal buffer at the current row.
2883:             * @param column The column for the value to set.
2884:             * @param value The data to place in the column.
2885:             */
2886:            public void setLong(int column, long value)
2887:                    throws DataStoreException {
2888:                setObject(getRow(), column, new Long(value), DATATYPE_LONG);
2889:            }
2890:
2891:            /**
2892:             * This method sets a value in the data store's internal buffer.
2893:             * @param row The row number for the value to set.
2894:             * @param column The column for the value to set.
2895:             * @param value The data to place in the column.
2896:             */
2897:            public void setLong(int row, String column, long value)
2898:                    throws DataStoreException {
2899:                setObject(row, column, new Long(value), DATATYPE_LONG);
2900:            }
2901:
2902:            /**
2903:             * This method sets a value in the data store's internal buffer at the current row.
2904:             * @param column The column for the value to set.
2905:             * @param value The data to place in the column.
2906:             */
2907:            public void setLong(String column, long value)
2908:                    throws DataStoreException {
2909:                setObject(getRow(), column, new Long(value), DATATYPE_LONG);
2910:            }
2911:
2912:            private void setObject(int row, int col, Object data, int type)
2913:                    throws DataStoreException {
2914:                waitForRow(row);
2915:                if (row < 0 || row >= _rows.size())
2916:                    throw new DataStoreException("Specified row (" + row
2917:                            + ") is out of range.");
2918:
2919:                if (col < 0 || _desc.getColumnCount() == 0)
2920:                    throw new DataStoreException("Specified column (" + col
2921:                            + ") does not exist.");
2922:
2923:                DSColumnDescriptor des = _desc.getColumn(col);
2924:
2925:                if (type == DATATYPE_ANY) {
2926:                    type = getObjectType(data);
2927:                    if (type == DATATYPE_STRING
2928:                            && des.getType() != DATATYPE_STRING) {
2929:                        try {
2930:                            type = des.getType();
2931:                            if (type == DATATYPE_INT)
2932:                                data = Integer.valueOf((String) data);
2933:                            else if (type == DATATYPE_DOUBLE)
2934:                                data = Double.valueOf((String) data);
2935:                            else if (type == DATATYPE_FLOAT)
2936:                                data = Float.valueOf((String) data);
2937:                            else if (type == DATATYPE_SHORT)
2938:                                data = Short.valueOf((String) data);
2939:                            else if (type == DATATYPE_LONG)
2940:                                data = Long.valueOf((String) data);
2941:                            else if (type == DATATYPE_DATETIME) {
2942:                                //Correction added by Fred Cahill on 4/26/01
2943:                                //try/catch for the test to check if data passed
2944:                                //is either a date or timestamp.
2945:                                //if not timestamp then must be a date
2946:                                //therefore try to convert to timestamp.
2947:                                try {
2948:                                    data = Timestamp.valueOf((String) data);
2949:                                } catch (Exception e) {
2950:                                    SalmonDateFormat sdf = new SalmonDateFormat();
2951:                                    data = new Timestamp(sdf.parse(
2952:                                            (String) data).getTime());
2953:                                    //data = new Timestamp(Timestamp.parse((String) data));
2954:                                    com.salmonllc.util.MessageLog
2955:                                            .writeDebugMessage(
2956:                                                    "setObject() - received date expecting timestamp performed conversion",
2957:                                                    this );
2958:                                }
2959:                            } else if (type == DATATYPE_TIME)
2960:                                data = java.sql.Time.valueOf((String) data);
2961:                            else if (type == DATATYPE_DATE) {
2962:                                //Correction added by Fred Cahill on 4/26/01
2963:                                //try/catch for the test to check if data passed
2964:                                //is either a date or timestamp.
2965:                                //if not date then must be a timestamp
2966:                                //therefore try to convert to date.
2967:                                try {
2968:                                    data = java.sql.Date.valueOf((String) data);
2969:                                } catch (Exception e) {
2970:                                    SalmonDateFormat sdf = new SalmonDateFormat();
2971:                                    data = new java.sql.Date(sdf.parse(
2972:                                            (String) data).getTime());
2973:                                    //data = new java.sql.Date(java.sql.Date.parse((String) data));
2974:                                    com.salmonllc.util.MessageLog
2975:                                            .writeDebugMessage(
2976:                                                    "setObject() - received timestamp expecting date performed conversion",
2977:                                                    this );
2978:                                }
2979:                            }
2980:                            //					data = java.sql.Date.valueOf((String) data);
2981:                            else
2982:                                data = ((String) data).getBytes();
2983:                        } catch (Exception e) {
2984:                            data = null;
2985:                            com.salmonllc.util.MessageLog.writeErrorMessage(
2986:                                    "setObject()", e, this );
2987:                        }
2988:                    }
2989:                }
2990:
2991:                if (des.getType() != type && data != null)
2992:                    throw new DataStoreException(
2993:                            "Column type mismatch.\n\tExpecting: "
2994:                                    + getTypeDescription(des.getType())
2995:                                    + "\n\tPassed: " + getTypeDescription(type),
2996:                            row, getColumnName(col));
2997:
2998:                DSDataRow d = (DSDataRow) _rows.elementAt(row);
2999:
3000:                Object oldData = d.getData(col);
3001:                d.setValue(col, data, _desc);
3002:                if (_manytoonerelationship && row > 0
3003:                        && isColumnInOneToManyRelationship(getColumnName(col)))
3004:                    setObject(0, col, data, type);
3005:
3006:                if (areThereModelListeners()) {
3007:                    if (oldData == null && data == null)
3008:                        return;
3009:                    if (oldData != null && data != null)
3010:                        if (oldData.equals(data))
3011:                            return;
3012:                    notifyListeners(new ModelChangedEvent(this , col, oldData,
3013:                            data));
3014:                }
3015:            }
3016:
3017:            private void setObject(int row, String column, Object data, int type)
3018:                    throws DataStoreException {
3019:                int col = getColumnIndex(column);
3020:                if (col == -1) {
3021:                    MessageLog.writeInfoMessage("column : " + column
3022:                            + " -> NOT FOUND", this );
3023:                }
3024:                setObject(row, col, data, type);
3025:            }
3026:
3027:            /**
3028:             * Sets the order by clause of the DataStore's SQL Statement
3029:             * @param orderBy The columns to use to sort the result set.
3030:             */
3031:            public void setOrderBy(String orderBy) {
3032:                _desc.setOrderByClause(orderBy);
3033:            }
3034:
3035:            /**
3036:             * This method is used to indicate whether a column is part of the primary key
3037:             */
3038:            public void setPrimaryKey(int col, boolean pkey)
3039:                    throws DataStoreException {
3040:                if (col < 0 || _desc.getColumnCount() == 0)
3041:                    throw new DataStoreException("Specified column (" + col
3042:                            + ") does not exist.");
3043:
3044:                DSColumnDescriptor c = _desc.getColumn(col);
3045:                c.setPrimaryKey(pkey);
3046:            }
3047:
3048:            /**
3049:             * This method is used to indicate whether a column is part of the primary key
3050:             */
3051:            public void setPrimaryKey(String col, boolean pkey)
3052:                    throws DataStoreException {
3053:                int c = getColumnIndex(col);
3054:                setPrimaryKey(c, pkey);
3055:            }
3056:
3057:            /**
3058:             * This method reads a properties object containing the definition of the data store and builds the datastore from it.
3059:             */
3060:            public void setProperties(Properties p) {
3061:
3062:                reset();
3063:                java.text.DecimalFormat fmt = new java.text.DecimalFormat(
3064:                        "0000");
3065:                _desc = new DSDataStoreDescriptor();
3066:
3067:                String desc = "base.";
3068:
3069:                _desc.setDefaultTable(setStringProperty(p.getProperty(desc
3070:                        + "defaultTable")));
3071:                _desc.setWhereClause(setStringProperty(p.getProperty(desc
3072:                        + "whereClause")));
3073:                _desc.setGroupByClause(setStringProperty(p.getProperty(desc
3074:                        + "groupByClause")));
3075:                _desc.setHavingClause(setStringProperty(p.getProperty(desc
3076:                        + "havingClause")));
3077:                _desc.setOrderByClause(setStringProperty(p.getProperty(desc
3078:                        + "orderByClause")));
3079:                _desc.setDistinct(setBoolProperty(p.getProperty(desc
3080:                        + "distinct")));
3081:                _desc.setTrimStrings(setBoolProperty(p.getProperty(desc
3082:                        + "trimStrings")));
3083:
3084:                //columns
3085:                int i = 0;
3086:                String name = "col." + fmt.format(i) + ".";
3087:                while (p.getProperty(name + "column") != null) {
3088:                    DSColumnDescriptor d = new DSColumnDescriptor();
3089:                    d
3090:                            .setTable(setStringProperty(p.getProperty(name
3091:                                    + "table")));
3092:                    d.setColumn(setStringProperty(p
3093:                            .getProperty(name + "column")));
3094:                    d.setType(setIntProperty(p.getProperty(name + "type")));
3095:                    d.setPrimaryKey(setBoolProperty(p
3096:                            .getProperty(name + "pkey")));
3097:                    d.setUpdateable(setBoolProperty(p.getProperty(name
3098:                            + "update")));
3099:                    d.setConcurrency(setBoolProperty(p.getProperty(name
3100:                            + "concurrency")));
3101:                    d
3102:                            .setUseBind(setIntProperty(p.getProperty(name
3103:                                    + "useBind")));
3104:                    d.setInternalName(setStringProperty(p.getProperty(name
3105:                            + "name")));
3106:                    String format = setStringProperty(p.getProperty(name
3107:                            + "format"));
3108:                    if (format != null) {
3109:                        if (d.getType() == DATATYPE_INT
3110:                                || d.getType() == DATATYPE_LONG
3111:                                || d.getType() == DATATYPE_DOUBLE
3112:                                || d.getType() == DATATYPE_SHORT
3113:                                || d.getType() == DATATYPE_FLOAT)
3114:                            d.setFormat(new java.text.DecimalFormat(format));
3115:                        else if (d.getType() == DATATYPE_DATE
3116:                                || d.getType() == DATATYPE_TIME
3117:                                || d.getType() == DATATYPE_DATETIME) {
3118:                            java.text.SimpleDateFormat df = new SalmonDateFormat(
3119:                                    format);
3120:                            df.setLenient(false);
3121:                            d.setFormat(df);
3122:                        }
3123:                    }
3124:
3125:                    _desc.addColumn(d);
3126:                    i++;
3127:                    name = "col." + fmt.format(i) + ".";
3128:                }
3129:
3130:                //joins
3131:                i = 0;
3132:                name = "join." + fmt.format(i) + ".";
3133:                while (p.getProperty(name + "outer") != null) {
3134:                    _desc.addJoin(setStringProperty(p
3135:                            .getProperty(name + "left")), setStringProperty(p
3136:                            .getProperty(name + "right")), setBoolProperty(p
3137:                            .getProperty(name + "outer")));
3138:                    i++;
3139:                    name = "join." + fmt.format(i) + ".";
3140:                }
3141:
3142:                //table aliases
3143:                i = 0;
3144:                name = "tableAlias." + fmt.format(i) + ".";
3145:                while (p.getProperty(name + "table") != null) {
3146:                    _desc.addAlias(setStringProperty(p.getProperty(name
3147:                            + "table")), setStringProperty(p.getProperty(name
3148:                            + "alias")));
3149:                    i++;
3150:                    name = "tableAlias." + fmt.format(i) + ".";
3151:                }
3152:
3153:            }
3154:
3155:            /**
3156:             * This method will set the rows in the DataStore. The vector set should be created via the getRows method of this datastore.
3157:             */
3158:            public void setRows(Vector rows) {
3159:                _rows = (Vector) rows.elementAt(0);
3160:                _filteredRows = (Vector) rows.elementAt(1);
3161:                _deletedRows = (Vector) rows.elementAt(2);
3162:            }
3163:
3164:            /**
3165:             * This method sets the status flag of the current row.
3166:             * @param status (STATUS_NOT_MODIFIED,STATUS_MODIFIED,STATUS_NEW,STATUS_NEW_MODIFIED)
3167:             * @return True if the row is in the buffer and false if not
3168:             */
3169:            public boolean setRowStatus(int status) {
3170:                return setRowStatus(getRow(), status);
3171:            }
3172:
3173:            /**
3174:             * This method sets the status flag of the specified row.
3175:             * @param row The row in the datastore buffer.
3176:             * @param status (STATUS_NOT_MODIFIED,STATUS_MODIFIED,STATUS_NEW,STATUS_NEW_MODIFIED)
3177:             * @return True if the row is in the buffer and false if not
3178:             */
3179:            public boolean setRowStatus(int row, int status) {
3180:                if (row < 0)
3181:                    return false;
3182:                waitForRow(row);
3183:                if (row >= getRowCount())
3184:                    return false;
3185:                DSDataRow d = (DSDataRow) _rows.elementAt(row);
3186:                d.setRowStatus(status);
3187:                return true;
3188:            }
3189:
3190:            /**
3191:             * This method sets a value in the data store's internal buffer.
3192:             * @param row The row number for the value to set.
3193:             * @param column The column for the value to set.
3194:             * @param value The data to place in the column.
3195:             */
3196:            public void setShort(int row, int column, short value)
3197:                    throws DataStoreException {
3198:                setObject(row, column, new Short(value), DATATYPE_SHORT);
3199:            }
3200:
3201:            /**
3202:             * This method sets a value in the data store's internal buffer.
3203:             * @param row The row number for the value to set.
3204:             * @param column The column for the value to set.
3205:             * @param value The data to place in the column.
3206:             */
3207:            public void setShort(int row, String column, short value)
3208:                    throws DataStoreException {
3209:                setObject(row, column, new Short(value), DATATYPE_SHORT);
3210:            }
3211:
3212:            /**
3213:             * This method sets a value in the data store's internal buffer at the current row.
3214:             * @param column The column for the value to set.
3215:             * @param value The data to place in the column.
3216:             */
3217:            public void setShort(int column, short value)
3218:                    throws DataStoreException {
3219:                setObject(getRow(), column, new Short(value), DATATYPE_SHORT);
3220:            }
3221:
3222:            /**
3223:             * This method sets a value in the data store's internal buffer at the current row.
3224:             * @param column The column for the value to set.
3225:             * @param value The data to place in the column.
3226:             */
3227:            public void setShort(String column, short value)
3228:                    throws DataStoreException {
3229:                setObject(getRow(), column, new Short(value), DATATYPE_SHORT);
3230:            }
3231:
3232:            /**
3233:             * This method sets a value in the data store's internal buffer.
3234:             * @param row The row number for the value to set.
3235:             * @param column The column for the value to set.
3236:             * @param value The data to place in the column.
3237:             */
3238:            public void setString(int row, int column, String value)
3239:                    throws DataStoreException {
3240:                setObject(row, column, value, DATATYPE_STRING);
3241:            }
3242:
3243:            /**
3244:             * This method sets a value in the data store's internal buffer at the current row.
3245:             * @param column The column for the value to set.
3246:             * @param value The data to place in the column.
3247:             */
3248:            public void setString(int column, String value)
3249:                    throws DataStoreException {
3250:                setObject(getRow(), column, value, DATATYPE_STRING);
3251:            }
3252:
3253:            /**
3254:             * This method sets a value in the data store's internal buffer.
3255:             * @param row The row number for the value to set.
3256:             * @param column The column for the value to set.
3257:             * @param value The data to place in the column.
3258:             */
3259:            public void setString(int row, String column, String value)
3260:                    throws DataStoreException {
3261:                setObject(row, column, value, DATATYPE_STRING);
3262:            }
3263:
3264:            /**
3265:             * This method sets a value in the data store's internal buffer at the current row.
3266:             * @param column The column for the value to set.
3267:             * @param value The data to place in the column
3268:             */
3269:            public void setString(String column, String value)
3270:                    throws DataStoreException {
3271:                setObject(getRow(), column, value, DATATYPE_STRING);
3272:            }
3273:
3274:            static String setStringProperty(String p) {
3275:                if (p == null)
3276:                    return null;
3277:                else if (p.equals("null"))
3278:                    return null;
3279:                else
3280:                    return p;
3281:            }
3282:
3283:            /**
3284:             * This method sets a value in the data store's internal buffer.
3285:             * @param row The row number for the value to set.
3286:             * @param column The column for the value to set.
3287:             * @param value The data to place in the column.
3288:             */
3289:            public void setTime(int row, int column, java.sql.Time value)
3290:                    throws DataStoreException {
3291:                setObject(row, column, value, DATATYPE_TIME);
3292:            }
3293:
3294:            /**
3295:             * This method sets a value in the data store's internal buffer.
3296:             * @param row The row number for the value to set.
3297:             * @param column The column for the value to set.
3298:             * @param value The data to place in the column.
3299:             */
3300:            public void setTime(int row, String column, java.sql.Time value)
3301:                    throws DataStoreException {
3302:                setObject(row, column, value, DATATYPE_TIME);
3303:            }
3304:
3305:            /**
3306:             * This method sets a value in the data store's internal buffer at the current row.
3307:             * @param column The column for the value to set.
3308:             * @param value The data to place in the column.
3309:             */
3310:            public void setTime(int column, java.sql.Time value)
3311:                    throws DataStoreException {
3312:                setObject(getRow(), column, value, DATATYPE_TIME);
3313:            }
3314:
3315:            /**
3316:             * This method sets a value in the data store's internal buffer at the current row.
3317:             * @param column The column for the value to set.
3318:             * @param value The data to place in the column
3319:             */
3320:            public void setTime(String column, java.sql.Time value)
3321:                    throws DataStoreException {
3322:                setObject(getRow(), column, value, DATATYPE_TIME);
3323:            }
3324:
3325:            /**
3326:             * This method will sort the rows in the data store on an array of columns.
3327:             * @param col A array of column numbers to sort on.
3328:             * @param dir An integer array of the direction to sort on. Each element can contain either SORT_ASC or SORT_DESC.
3329:             */
3330:            public void sort(int[] col, int dir[]) throws DataStoreException {
3331:                notifyListeners(ModelChangedEvent.TYPE_DATA_SORTING);
3332:                for (int i = 0; i < col.length; i++) {
3333:                    if (col[i] < 0 || col[i] >= _desc.getColumnCount())
3334:                        throw new DataStoreException(
3335:                                "Sort error:column not found");
3336:                }
3337:
3338:                waitForRetrieve();
3339:                new DSQuickSort(_rows, col, dir);
3340:                notifyListeners(ModelChangedEvent.TYPE_DATA_SORTED);
3341:            }
3342:
3343:            /**
3344:             * This method will sort the rows in the data store on an array of columns.
3345:             * @param col A array of column numbers to sort on.
3346:             * @param dir An integer array of the direction to sort on. Each element can contain either SORT_ASC or SORT_DESC.
3347:             * @param bUseQSAlgoritm A boolean to indicate to use only the Quick Sort Algoritm. No use of Hash Maps.
3348:             */
3349:            public void sort(int[] col, int dir[], boolean bUseQSAlgoritm)
3350:                    throws DataStoreException {
3351:                notifyListeners(ModelChangedEvent.TYPE_DATA_SORTING);
3352:                for (int i = 0; i < col.length; i++) {
3353:                    if (col[i] < 0 || col[i] >= _desc.getColumnCount())
3354:                        throw new DataStoreException(
3355:                                "Sort error:column not found");
3356:                }
3357:
3358:                waitForRetrieve();
3359:                new DSQuickSort(_rows, col, dir, bUseQSAlgoritm);
3360:                notifyListeners(ModelChangedEvent.TYPE_DATA_SORTED);
3361:            }
3362:
3363:            /**
3364:             * This method will sort the rows in the data store on an array of columns.
3365:             * @param obj A array of objects to sort on. The array can contain Strings (column name), Integers (column numbers) or DataStoreEvaluators (expressions)
3366:             * @param dir An integer array of the direction to sort on. Each element can contain either SORT_ASC or SORT_DESC.
3367:             */
3368:            public void sort(Object[] obj, int dir[]) throws DataStoreException {
3369:                notifyListeners(ModelChangedEvent.TYPE_DATA_SORTING);
3370:                Object sort[] = new Object[obj.length];
3371:
3372:                for (int i = 0; i < obj.length; i++) {
3373:                    if (obj[i] instanceof  DataStoreEvaluator)
3374:                        sort[i] = obj[i];
3375:                    else if (obj[i] instanceof  String) {
3376:                        int index = getColumnIndex((String) obj[i]);
3377:                        if (index < 0)
3378:                            throw new DataStoreException(
3379:                                    "Sort error:column not found");
3380:                        sort[i] = new Integer(index);
3381:                    } else if (obj[i] instanceof  Integer) {
3382:                        int colNo = ((Integer) obj[i]).intValue();
3383:                        if (colNo < 0 || colNo >= _desc.getColumnCount())
3384:                            throw new DataStoreException(
3385:                                    "Sort error:column not found");
3386:                        sort[i] = obj[i];
3387:                    } else
3388:                        throw new DataStoreException(
3389:                                "Sort error:column not found");
3390:                }
3391:                waitForRetrieve();
3392:                new DSQuickSort(_rows, sort, dir);
3393:                notifyListeners(ModelChangedEvent.TYPE_DATA_SORTED);
3394:            }
3395:
3396:            /**
3397:             * This method will sort the rows in the data store on an array of columns.
3398:             * @param col A String array of column names to sort on.
3399:             * @param dir An integer array of the direction to sort on. Each element can contain either SORT_ASC or SORT_DESC.
3400:             */
3401:            public void sort(String col[], int dir[]) throws DataStoreException {
3402:                int[] c = new int[col.length];
3403:
3404:                for (int i = 0; i < c.length; i++) {
3405:                    c[i] = getColumnIndex(col[i]);
3406:                }
3407:                sort(c, dir);
3408:
3409:            }
3410:
3411:            /**
3412:             * This method will sort the rows in the data store on a particular column.
3413:             * @param col The column number of the column to sort on.
3414:             * @param dir The direction to sort on. Either SORT_ASC or SORT_DESC.
3415:             */
3416:            public void sort(int col, int dir) throws DataStoreException {
3417:                int cols[] = new int[1];
3418:                int dirs[] = new int[1];
3419:                cols[0] = col;
3420:                dirs[0] = dir;
3421:                sort(cols, dirs);
3422:            }
3423:
3424:            /**
3425:             * This method will sort the rows in the data store using an expression.
3426:             * @param eval A datastore evaluator containing the expression.
3427:             * @param dir An integer indicating the sort direction valid values are SORT_ASC or SORT_DESC.
3428:             */
3429:            public void sort(DataStoreEvaluator eval, int dir)
3430:                    throws DataStoreException {
3431:                notifyListeners(ModelChangedEvent.TYPE_DATA_SORTING);
3432:                waitForRetrieve();
3433:                new DSQuickSort(_rows, eval, dir);
3434:                notifyListeners(ModelChangedEvent.TYPE_DATA_SORTED);
3435:            }
3436:
3437:            /**
3438:             * This method will sort the rows in the data store on a particular column.
3439:             * @param col The name of the column to sort on.
3440:             * @param dir The direction to sort on. Either SORT_ASC or SORT_DESC.
3441:             */
3442:            public void sort(String col, int dir) throws DataStoreException {
3443:                String cols[] = new String[1];
3444:                int dirs[] = new int[1];
3445:                cols[0] = col;
3446:                dirs[0] = dir;
3447:                sort(cols, dirs);
3448:            }
3449:
3450:            /**
3451:             * This method will take a row from the datastores deleted buffer and move it back to the standard buffer.
3452:             * @param row The number of the row to undelete. Note: this is the row number of the row in the deleted buffer not the standard buffer.
3453:             * @return The number that the deleted row was moved to in the standard buffer or -1 if an error occurs.
3454:             */
3455:            public int unDeleteRow(int row) {
3456:                if (row < 0)
3457:                    return -1;
3458:                if (row >= getDeletedCount())
3459:                    return -1;
3460:                DSDataRow d = (DSDataRow) _deletedRows.elementAt(row);
3461:                _deletedRows.removeElementAt(row);
3462:                _rows.addElement(d);
3463:
3464:                if (areThereModelListeners()) {
3465:                    ModelChangedEvent evt = new ModelChangedEvent(this ,
3466:                            getRow());
3467:                    notifyListeners(evt);
3468:                }
3469:
3470:                return _rows.size() - 1;
3471:            }
3472:
3473:            /**
3474:             * This method will block until a datastore cancel command is finished
3475:             */
3476:            public void waitForCancel() {
3477:                Thread waitForCancelThread = null;
3478:                try {
3479:                    while (_cancelInProgress) {
3480:                        waitForCancelThread = Thread.currentThread();
3481:                        _waitingCancelThreads.addElement(waitForCancelThread);
3482:                        try {
3483:                            Thread.sleep(1000 * 60 * 60);
3484:                        } catch (InterruptedException ie) {
3485:                            ;
3486:                        }
3487:                    }
3488:                } catch (Exception e) {
3489:                }
3490:                if (waitForCancelThread != null)
3491:                    _waitingCancelThreads.remove(waitForCancelThread);
3492:            }
3493:
3494:            /**
3495:             * This method will block until all the data from the last retrieve method call has been loaded into the DataStore's internal buffer.
3496:             */
3497:            public void waitForRetrieve() {
3498:                Thread waitForRetrieveThread = null;
3499:                try {
3500:                    while (_retrieveInProgress) {
3501:                        waitForRetrieveThread = Thread.currentThread();
3502:                        _waitingRetrieveThreads
3503:                                .addElement(waitForRetrieveThread);
3504:                        try {
3505:                            Thread.sleep(1000 * 60 * 60);
3506:                        } catch (InterruptedException ie) {
3507:                            ;
3508:                        }
3509:                    }
3510:                } catch (Exception e) {
3511:                }
3512:                if (waitForRetrieveThread != null)
3513:                    _waitingRetrieveThreads.remove(waitForRetrieveThread);
3514:            }
3515:
3516:            /**
3517:             * Waits for the retrieve process to finish for the period specified in seconds.
3518:             */
3519:            public void waitForRetrieve(int iSeconds) {
3520:                Thread waitForRetrieveThread = null;
3521:                try {
3522:                    while (_retrieveInProgress) {
3523:                        waitForRetrieveThread = Thread.currentThread();
3524:                        _waitingRetrieveThreads
3525:                                .addElement(waitForRetrieveThread);
3526:                        try {
3527:                            Thread.sleep(1000 * iSeconds);
3528:                        } catch (InterruptedException ie) {
3529:                            ;
3530:                        }
3531:                    }
3532:                } catch (Exception e) {
3533:                }
3534:                if (waitForRetrieveThread != null)
3535:                    _waitingRetrieveThreads.remove(waitForRetrieveThread);
3536:            }
3537:
3538:            /**
3539:             * This method was created in VisualAge.
3540:             * @param row int
3541:             */
3542:            protected void waitForRow(int row) {
3543:                try {
3544:                    while (_retrieveInProgress && (row >= _rows.size())) {
3545:                        Thread.yield();
3546:                    }
3547:                } catch (Exception e) {
3548:                }
3549:            }
3550:
3551:            /**
3552:             * This method was created in VisualAge.
3553:             * @param out java.io.ObjectOutputStream
3554:             */
3555:            private void writeObject(java.io.ObjectOutputStream out)
3556:                    throws java.io.IOException {
3557:                waitForRetrieve();
3558:                out.defaultWriteObject();
3559:            }
3560:
3561:            /**
3562:             * Used to set the remote id for the datastore
3563:             */
3564:            public void setRemoteID(String remoteID) {
3565:                _remoteID = remoteID;
3566:            }
3567:
3568:            /**
3569:             * Used to get the remote id for the datastore
3570:             */
3571:            public String getRemoteID() {
3572:                return _remoteID;
3573:            }
3574:
3575:            /**
3576:             * This method will return the value that will be returned to the proxy datastore after an remote update.
3577:             */
3578:            public String getRemoteUpdateReturnValue() {
3579:                return _remoteUpdateRetVal;
3580:            }
3581:
3582:            /**
3583:             * This method will return the value that will be returned to the a proxy datastore after a remote update.
3584:             */
3585:            public void setRemoteUpdateReturnValue(String update) {
3586:                _remoteUpdateRetVal = update;
3587:            }
3588:
3589:            /**
3590:             * Sets the _currentRow.
3591:             * @param currentRow The _currentRow to set
3592:             */
3593:            protected void setCurrentRow(int currentRow) {
3594:                int oldRow = _currentRow;
3595:                _currentRow = currentRow;
3596:                if (areThereModelListeners() && oldRow != currentRow) {
3597:                    ModelChangedEvent evt = new ModelChangedEvent(this , oldRow,
3598:                            _currentRow);
3599:                    notifyListeners(evt);
3600:                }
3601:
3602:            }
3603:
3604:            /**
3605:             * Adds a new listerner to this datastore to be notified when the model changes in some way
3606:             */
3607:            public void addModelChangedListener(ModelChangedListener l) {
3608:                if (_modelListeners == null)
3609:                    _modelListeners = new Vector();
3610:
3611:                for (int i = 0; i < _modelListeners.size(); i++) {
3612:                    if (((ModelChangedListener) _modelListeners.elementAt(i)) == l)
3613:                        return;
3614:                }
3615:
3616:                _modelListeners.addElement(l);
3617:            }
3618:
3619:            /**
3620:             * This method removes a listener from the list of listeners that will be notified when a model changed event is fired.
3621:             */
3622:            public void removeModelChangedListener(ModelChangedListener l) {
3623:                if (_modelListeners == null)
3624:                    return;
3625:
3626:                for (int i = 0; i < _modelListeners.size(); i++) {
3627:                    if (((ModelChangedListener) _modelListeners.elementAt(i)) == l) {
3628:                        _modelListeners.removeElementAt(i);
3629:                        return;
3630:                    }
3631:                }
3632:            }
3633:
3634:            /**
3635:             * Notifies all listeners that a model changed event occurred
3636:             */
3637:            public void notifyListeners(ModelChangedEvent e) {
3638:                if (_modelListeners == null)
3639:                    return;
3640:
3641:                for (int i = 0; i < _modelListeners.size(); i++) {
3642:                    ((ModelChangedListener) _modelListeners.elementAt(i))
3643:                            .modelChanged(e);
3644:                }
3645:            }
3646:
3647:            protected void notifyListeners(int type) {
3648:                if (_modelListeners == null)
3649:                    return;
3650:
3651:                ModelChangedEvent e = new ModelChangedEvent(type, this );
3652:
3653:                notifyListeners(e);
3654:            }
3655:
3656:            protected boolean areThereModelListeners() {
3657:                return (_modelListeners != null);
3658:            }
3659:
3660:            protected Vector getModelListeners() {
3661:                return _modelListeners;
3662:            }
3663:
3664:            /**
3665:             * Sets a temporary value in the buffer. A temporary value in one that doesn't effect the interaction with the datasource and will get cleared whenever a actual value is set on the column. It's intended purpose is to provide an area where invalid values entered by users can be safely stored for later processing without effecting the clean data in the buffer.
3666:             * @param row The row number for the value to set.
3667:             * @param column The column for the value to set.
3668:             * @param data The data to place in the temporary column.
3669:             */
3670:            private void setTempValue(int row, String column, String data)
3671:                    throws DataStoreException {
3672:                int col = getColumnIndex(column);
3673:                if (col == -1) {
3674:                    MessageLog.writeInfoMessage("column : " + column
3675:                            + " -> NOT FOUND", this );
3676:                }
3677:                setTempValue(row, col, data);
3678:            }
3679:
3680:            /**
3681:             * Sets a temporary value in the buffer. A temporary value in one that doesn't effect the interaction with the datasource and will get cleared whenever a actual value is set on the column. It's intended purpose is to provide an area where invalid values entered by users can be safely stored for later processing without effecting the clean data in the buffer.
3682:             * @param row The row number for the value to set.
3683:             * @param col The column for the value to set.
3684:             * @param value The data to place in the temporary column.
3685:             */
3686:            public void setTempValue(int row, int col, String value)
3687:                    throws DataStoreException {
3688:                waitForRow(row);
3689:                if (row < 0 || row >= _rows.size())
3690:                    throw new DataStoreException("Specified row (" + row
3691:                            + ") is out of range.");
3692:
3693:                if (col < 0 || _desc.getColumnCount() == 0)
3694:                    throw new DataStoreException("Specified column (" + col
3695:                            + ") does not exist.");
3696:
3697:                DSDataRow d = (DSDataRow) _rows.elementAt(row);
3698:                d.setTempValue(col, value, _desc);
3699:                if (areThereModelListeners())
3700:                    notifyListeners(new ModelChangedEvent(this , col, getAny(
3701:                            row, col), value));
3702:
3703:            }
3704:
3705:            /**
3706:             * Sets a temporary value in the buffer for the current row. A temporary value in one that doesn't effect the interaction with the datasource and will get cleared whenever a actual value is set on the column. It's intended purpose is to provide an area where invalid values entered by users can be safely stored for later processing without effecting the clean data in the buffer.
3707:             * @param col The column for the value to set.
3708:             * @param value The data to place in the temporary column.
3709:             */
3710:            public void setTempValue(int col, String value)
3711:                    throws DataStoreException {
3712:                setTempValue(getRow(), col, value);
3713:            }
3714:
3715:            /**
3716:             * Sets a temporary value in the buffer for the current row. A temporary value in one that doesn't effect the interaction with the datasource and will get cleared whenever a actual value is set on the column. It's intended purpose is to provide an area where invalid values entered by users can be safely stored for later processing without effecting the clean data in the buffer.
3717:             * @param col The column for the value to set.
3718:             * @param value The data to place in the temporary column.
3719:             */
3720:            public void setTempValue(String col, String value)
3721:                    throws DataStoreException {
3722:                setTempValue(getRow(), col, value);
3723:            }
3724:
3725:            /**
3726:             * Gets a temporary value in the buffer. A temporary value in one that doesn't effect the interaction with the datasource and will get cleared whenever a actual value is set on the column. It's intended purpose is to provide an area where invalid values entered by users can be safely stored for later processing without effecting the clean data in the buffer.
3727:             * @param row The row number for the value to set.
3728:             * @param column The column for the value to set.
3729:             */
3730:            public String getTempValue(int row, int column)
3731:                    throws DataStoreException {
3732:                waitForRow(row);
3733:                if (row < 0 || row >= _rows.size())
3734:                    throw new DataStoreException("Specified row (" + row
3735:                            + ") is out of range.");
3736:                if (column < 0 || column >= _desc.getColumnCount())
3737:                    throw new DataStoreException("Specified column (" + column
3738:                            + ") is out of range.");
3739:
3740:                DSDataRow d = (DSDataRow) _rows.elementAt(row);
3741:                return d.getTempValue(column);
3742:            }
3743:
3744:            /**
3745:             * Gets a temporary value in the buffer. A temporary value in one that doesn't effect the interaction with the datasource and will get cleared whenever a actual value is set on the column. It's intended purpose is to provide an area where invalid values entered by users can be safely stored for later processing without effecting the clean data in the buffer.
3746:             * @param row The row number for the value to set.
3747:             * @param column The column for the value to set.
3748:             */
3749:            public String getTempValue(int row, String column)
3750:                    throws DataStoreException {
3751:                int col = getColumnIndex(column);
3752:                if (col == -1) {
3753:                    MessageLog.writeInfoMessage("column : " + column
3754:                            + " -> NOT FOUND", this );
3755:                }
3756:                return getTempValue(row, col);
3757:            }
3758:
3759:            /**
3760:             * Gets a temporary value in the buffer. A temporary value in one that doesn't effect the interaction with the datasource and will get cleared whenever a actual value is set on the column. It's intended purpose is to provide an area where invalid values entered by users can be safely stored for later processing without effecting the clean data in the buffer.
3761:             * @param column The column to get the value for
3762:             */
3763:            public String getTempValue(String column) throws DataStoreException {
3764:                return getTempValue(getRow(), column);
3765:            }
3766:
3767:            /**
3768:             * Gets a temporary value in the buffer. A temporary value in one that doesn't effect the interaction with the datasource and will get cleared whenever a actual value is set on the column. It's intended purpose is to provide an area where invalid values entered by users can be safely stored for later processing without effecting the clean data in the buffer.
3769:             * @param column The column to get the value for
3770:             */
3771:            public String getTempValue(int column) throws DataStoreException {
3772:                return getTempValue(getRow(), column);
3773:            }
3774:
3775:            /**
3776:             * Clears all temporary values from the specified row
3777:             * @param row The row number to clear.
3778:             */
3779:            public void clearTempValues(int row) throws DataStoreException {
3780:                waitForRow(row);
3781:                if (row < 0 || row >= _rows.size())
3782:                    throw new DataStoreException("Specified row (" + row
3783:                            + ") is out of range.");
3784:
3785:                DSDataRow d = (DSDataRow) _rows.elementAt(row);
3786:                d.clearTempValues();
3787:            }
3788:
3789:            /**
3790:             * Clears all temporary values from the whole datastore
3791:             */
3792:            public void clearTempValues() throws DataStoreException {
3793:                for (int i = 0; i < getRowCount(); i++) {
3794:                    DSDataRow d = (DSDataRow) _rows.elementAt(i);
3795:                    d.clearTempValues();
3796:                }
3797:            }
3798:
3799:            /**
3800:             * Returns true if the specified row has temporary values
3801:             * @param row The row number to check
3802:             */
3803:            public boolean hasTempValues(int row) throws DataStoreException {
3804:                waitForRow(row);
3805:                if (row < 0 || row >= _rows.size())
3806:                    throw new DataStoreException("Specified row (" + row
3807:                            + ") is out of range.");
3808:
3809:                DSDataRow d = (DSDataRow) _rows.elementAt(row);
3810:                return d.hasTempValues();
3811:            }
3812:
3813:            /**
3814:             * Adds a validation rule to the datastore for the specified column
3815:             */
3816:            int addValidationRule(int column, ValidationRule rule)
3817:                    throws DataStoreException {
3818:                if (column < 0 || column >= _desc.getColumnCount())
3819:                    throw new DataStoreException("Specified column (" + column
3820:                            + ") is out of range.");
3821:                return _desc.getColumn(column).addRule(rule);
3822:            }
3823:
3824:            /**
3825:             * Adds a validation rule to the datastore for the specified column
3826:             */
3827:            int addValidationRule(String column, ValidationRule rule)
3828:                    throws DataStoreException {
3829:                return addValidationRule(_desc.getColumnIndex(column), rule);
3830:            }
3831:
3832:            /**
3833:             * Use this method to add validation rules that will be checked by the validator.
3834:             * @param column The name of the column to validate.
3835:             * @param expression A DataStoreExpression class that returns a boolean value. It will trigger an error if the value returns false.
3836:             * @param errorMessage The error message to display if the validation fails.
3837:             * @param executeOnServer Whether or not this rule should evaluate on the server for proxy datastores. Otherwise the expression object will be serialized and copied to the client to execute there.
3838:             */
3839:            public void addExpressionRule(String column,
3840:                    DataStoreExpression expression, String errorMessage,
3841:                    boolean executeOnServer) throws DataStoreException {
3842:                addValidationRule(column, new ValidationRule(expression,
3843:                        errorMessage, executeOnServer));
3844:            }
3845:
3846:            /**
3847:             * Use this method to add validation rules that will be checked by the validator.
3848:             * @param column The name of the column to validate.
3849:             * @param expression A DataStore expression  that returns a boolean value. It will trigger an error if the value returns false.
3850:             * @param errorMessage The error message to display if the validation fails.
3851:             */
3852:            public void addExpressionRule(String column, String expression,
3853:                    String errorMessage) throws DataStoreException {
3854:                addValidationRule(column, new ValidationRule(expression,
3855:                        errorMessage));
3856:            }
3857:
3858:            /**
3859:             * Use this method to add validation rules that will be checked by the validator.
3860:             * @param column The name of the column to validate.
3861:             * @param expression A DataStoreExpression class that returns a boolean value. It will trigger an error if the value returns false.
3862:             * @param errorMessage The error message to display if the validation fails.
3863:             * @param executeOnServer Whether or not this rule should evaluate on the server for proxy datastores. Otherwise the expression object will be serialized and copied to the client to execute there.
3864:             */
3865:            public void addExpressionRule(int column,
3866:                    DataStoreExpression expression, String errorMessage,
3867:                    boolean executeOnServer) throws DataStoreException {
3868:                addValidationRule(column, new ValidationRule(expression,
3869:                        errorMessage, executeOnServer));
3870:            }
3871:
3872:            /**
3873:             * Use this method to add validation rules that will be checked by the validator.
3874:             * @param column The name of the column to validate.
3875:             * @param expression A DataStore expression  that returns a boolean value. It will trigger an error if the value returns false.
3876:             * @param errorMessage The error message to display if the validation fails.
3877:             */
3878:            public void addExpressionRule(int column, String expression,
3879:                    String errorMessage) throws DataStoreException {
3880:                addValidationRule(column, new ValidationRule(expression,
3881:                        errorMessage));
3882:            }
3883:
3884:            /**
3885:             * Adds a range rule to the DataStore buffer
3886:             * @param column The name of the column to validate.
3887:             * @param minValue The minimum value to allow in the column. Null to allow any minimum value.
3888:             * @param maxValue The maximum value to allow in the column. Null to allow any maximum value.
3889:             * @param errorMessage The error message to display if the validation fails.
3890:             */
3891:            public void addRangeRule(int column, Object minValue,
3892:                    Object maxValue, String errorMessage)
3893:                    throws DataStoreException {
3894:                addValidationRule(column, new ValidationRule(minValue,
3895:                        maxValue, errorMessage));
3896:            }
3897:
3898:            /**
3899:             * Adds a range rule to the DataStore buffer
3900:             * @param column The name of the column to validate.
3901:             * @param minValue The minimum value to allow in the column. Null to allow any minimum value.
3902:             * @param maxValue The maximum value to allow in the column. Null to allow any maximum value.
3903:             * @param errorMessage The error message to display if the validation fails.
3904:             */
3905:            public void addRangeRule(String column, Object minValue,
3906:                    Object maxValue, String errorMessage)
3907:                    throws DataStoreException {
3908:                addValidationRule(column, new ValidationRule(minValue,
3909:                        maxValue, errorMessage));
3910:            }
3911:
3912:            /**
3913:             * Adds a type check rule to the validator. This makes sure that the value in temp area for the column is of the correct datatype.
3914:             * @param column The column to validate
3915:             * @param errorMessage The error message to display if the validation fails
3916:             */
3917:            public void addTypeCheckRule(String column, String errorMessage)
3918:                    throws DataStoreException {
3919:                addValidationRule(column, new ValidationRule(errorMessage));
3920:            }
3921:
3922:            /**
3923:             * Adds a type check rule to the validator. This makes sure that the value in temp area for the column is of the correct datatype.
3924:             * @param column The column to validate
3925:             * @param errorMessage The error message to display if the validation fails
3926:             */
3927:            public void addTypeCheckRule(int column, String errorMessage)
3928:                    throws DataStoreException {
3929:                addValidationRule(column, new ValidationRule(errorMessage));
3930:            }
3931:
3932:            /**
3933:             * Adds a validation rule to indicate a value is required
3934:             * @param column The column to validate
3935:             * @param errorMessage The error message to display if the validation fails
3936:             */
3937:            public void addRequiredRule(String column, String errorMessage)
3938:                    throws DataStoreException {
3939:                addValidationRule(column, new ValidationRule(errorMessage,
3940:                        ValidationRule.TYPE_REQUIRED));
3941:            }
3942:
3943:            /**
3944:             * Adds a validation rule to indicate a value is required
3945:             * @param column The column to validate
3946:             * @param errorMessage The error message to display if the validation fails
3947:             */
3948:            public void addRequiredRule(int column, String errorMessage)
3949:                    throws DataStoreException {
3950:                addValidationRule(column, new ValidationRule(errorMessage,
3951:                        ValidationRule.TYPE_REQUIRED));
3952:            }
3953:
3954:            /**
3955:             * Adds a regular expression rule. The specified column must match the regular expression to be valid
3956:             * @param column The column to validate
3957:             * @param regExp The regular expression to match
3958:             * @param errorMessage The error message to display if the validation fails
3959:             */
3960:            public void addReqularExpressionRule(String column, String regExp,
3961:                    String errorMessage) throws DataStoreException {
3962:                addValidationRule(column, new ValidationRule(regExp,
3963:                        errorMessage, ValidationRule.TYPE_REGULAR_EXPRESSION));
3964:            }
3965:
3966:            /**
3967:             * Adds a regular expression rule. The specified column must match the regular expression to be valid
3968:             * @param column The column to validate
3969:             * @param regExp The regular expression to match
3970:             * @param errorMessage The error message to display if the validation fails
3971:             */
3972:            public void addReqularExpressionRule(int column, String regExp,
3973:                    String errorMessage) throws DataStoreException {
3974:                addValidationRule(column, new ValidationRule(regExp,
3975:                        errorMessage, ValidationRule.TYPE_REGULAR_EXPRESSION));
3976:            }
3977:
3978:            /**
3979:             * Adds a javascript rule. Since javascript must be executed on a browser, and a this is a server side component, the rule won't be executed in this component. This method allows the rule to be placed here in case the datastore's rules are imported into an HtmlValidatorText component which can execute javascript rules.
3980:             * @param column The column to validate
3981:             * @param javaScript The javascript to execute. The javascript may contain replaceable parameters beginning with a % sign that are translated into the proper component names in the javascript. For example %comp1 would represent a form component on the page called comp1.
3982:             * @param errorMessage The error message to display if the validation fails
3983:             */
3984:            public void addJavaScriptRule(String column, String javaScript,
3985:                    String errorMessage) throws DataStoreException {
3986:                addValidationRule(column, new ValidationRule(javaScript,
3987:                        errorMessage, ValidationRule.TYPE_JAVASCRIPT));
3988:            }
3989:
3990:            /**
3991:             * Adds a javascript rule. Since javascript must be executed on a browser, and a this is a server side component, the rule won't be executed in this component. This method allows the rule to be placed here in case the datastore's rules are imported into an HtmlValidatorText component which can execute javascript rules.
3992:             * @param column The column to validate
3993:             * @param javaScript The javascript to execute. The javascript may contain replaceable parameters beginning with a % sign that are translated into the proper component names in the javascript. For example %comp1 would represent a form component on the page called comp1.
3994:             * @param errorMessage The error message to display if the validation fails
3995:             */
3996:            public void addJavaScriptRule(int column, String javaScript,
3997:                    String errorMessage) throws DataStoreException {
3998:                addValidationRule(column, new ValidationRule(javaScript,
3999:                        errorMessage, ValidationRule.TYPE_JAVASCRIPT));
4000:            }
4001:
4002:            /**
4003:             * Creates a lookup rule
4004:             * @param lookupTable The name of the table to lookup the value against.
4005:             * @param searchExpression A DataStore Expression that returns a String and will be used as the where clause for the SQL that will validate the data.
4006:             * @param errorMessage The error message to display if the error expression returns false.
4007:             * @param descriptionColumn The name of the column in the lookup table used to fill in the description.
4008:             * @param descriptionBucket The name of a bucket column in the datastore to place the description.
4009:             * @param errorMessage The message to return if the rule is violated
4010:             */
4011:            public void addLookupRule(String column, String lookupTable,
4012:                    String searchExpression, String descriptionColumn,
4013:                    String descriptionBucket, String errorMessage)
4014:                    throws DataStoreException {
4015:                addValidationRule(column, new ValidationRule(lookupTable,
4016:                        searchExpression, descriptionColumn, descriptionBucket,
4017:                        errorMessage));
4018:            }
4019:
4020:            /**
4021:             * Creates a lookup rule
4022:             * @param lookupTable The name of the table to lookup the value against.
4023:             * @param searchExpression A DataStore Expression that returns a String and will be used as the where clause for the SQL that will validate the data.
4024:             * @param errorMessage The error message to display if the error expression returns false.
4025:             * @param descriptionColumn The name of the column in the lookup table used to fill in the description.
4026:             * @param descriptionBucket The name of a bucket column in the datastore to place the description.
4027:             * @param errorMessage The message to return if the rule is violated
4028:             */
4029:            public void addLookupRule(int column, String lookupTable,
4030:                    String searchExpression, String descriptionColumn,
4031:                    String descriptionBucket, String errorMessage)
4032:                    throws DataStoreException {
4033:                addValidationRule(column, new ValidationRule(lookupTable,
4034:                        searchExpression, descriptionColumn, descriptionBucket,
4035:                        errorMessage));
4036:            }
4037:
4038:            /**
4039:             * Clears all validation rules for the specified column
4040:             */
4041:            public void clearValidationRules(int column)
4042:                    throws DataStoreException {
4043:                if (column < 0 || column >= _desc.getColumnCount())
4044:                    throw new DataStoreException("Specified column (" + column
4045:                            + ") is out of range.");
4046:                _desc.getColumn(column).clearValidationRules();
4047:            }
4048:
4049:            /**
4050:             * Clears all validation rules for the specified column
4051:             */
4052:            public void clearValidationRules(String column)
4053:                    throws DataStoreException {
4054:                clearValidationRules(_desc.getColumnIndex(column));
4055:            }
4056:
4057:            /**
4058:             * Clears all validations rules from all columns in the DataStore
4059:             */
4060:            public void clearAllValidationRules() {
4061:                try {
4062:                    for (int i = 0; i < getColumnCount(); i++)
4063:                        clearValidationRules(i);
4064:                } catch (Exception e) {
4065:                }
4066:            }
4067:
4068:            /**
4069:             * Validates all rows in the datastore that are candidates for insert or update. stopAtFIrstError is an indication to stop the validation after the first error is found.
4070:             */
4071:            public DataStoreException[] validateRowsToUpdate(DBConnection conn,
4072:                    boolean stopAtFirstError) {
4073:                Vector v = new Vector();
4074:                for (int i = 0; i < getRowCount(); i++) {
4075:                    if (getRowStatus(i) == STATUS_MODIFIED
4076:                            || getRowStatus() == STATUS_NEW_MODIFIED) {
4077:                        for (int j = 0; j < getColumnCount(); j++) {
4078:                            validateColumn(i, j, v, conn);
4079:                            if (v.size() > 0 && stopAtFirstError) {
4080:                                DataStoreException ret[] = new DataStoreException[1];
4081:                                ret[0] = (DataStoreException) v.elementAt(0);
4082:                                return ret;
4083:                            }
4084:                        }
4085:                    }
4086:                }
4087:                DataStoreException ret[] = new DataStoreException[v.size()];
4088:                v.copyInto(ret);
4089:                return ret;
4090:            }
4091:
4092:            /**
4093:             * Validates an entire row in the DataStore. Returns an array of exceptions that will be empty if there are no errors.
4094:             */
4095:            public DataStoreException[] validateRow(int rowNo, DBConnection conn) {
4096:                Vector v = new Vector();
4097:                for (int i = 0; i < getColumnCount(); i++)
4098:                    validateColumn(rowNo, i, v, conn);
4099:                DataStoreException ret[] = new DataStoreException[v.size()];
4100:                v.copyInto(ret);
4101:                return ret;
4102:            }
4103:
4104:            /**
4105:             * Executes all the validation rules for the specified column and row. Returns an array of exceptions that will be empty if there are no errors.
4106:             */
4107:            public DataStoreException[] validateColumn(int rowNo,
4108:                    String colName, DBConnection conn) {
4109:                return validateColumn(rowNo, getColumnIndex(colName), conn);
4110:            }
4111:
4112:            /**
4113:             * Executes all the validation rules for the specified column and row. Returns an array of exceptions that will be empty if there are no errors.
4114:             */
4115:            public DataStoreException[] validateColumn(int rowNo, int colNo,
4116:                    DBConnection conn) {
4117:                Vector v = new Vector();
4118:                validateColumn(rowNo, colNo, v, conn);
4119:                DataStoreException ret[] = new DataStoreException[v.size()];
4120:                v.copyInto(ret);
4121:                return ret;
4122:            }
4123:
4124:            /**
4125:             * Returns a list of all validation rules for each column or null if there aren't any
4126:             */
4127:            public ValidationRule[] getValidationRulesForColumn(int colNo) {
4128:                if (colNo < 0 || colNo >= getColumnCount())
4129:                    return null;
4130:                DSColumnDescriptor col = _desc.getColumn(colNo);
4131:                if (col.getRuleCount() == 0)
4132:                    return null;
4133:                ValidationRule[] ret = new ValidationRule[col.getRuleCount()];
4134:                for (int i = 0; i < col.getRuleCount(); i++) {
4135:                    ret[i] = col.getRule(i);
4136:                }
4137:                return ret;
4138:            }
4139:
4140:            protected void validateColumn(int rowNo, int colNo, Vector v,
4141:                    DBConnection conn) {
4142:                if (rowNo < 0 || rowNo >= getRowCount() || colNo < 0
4143:                        || colNo >= getColumnCount())
4144:                    return;
4145:                //fc 06/11/04: Dont validate the column if its a master column not from the first row.
4146:                try {
4147:                    if (_manytoonerelationship
4148:                            && rowNo > 0
4149:                            && isColumnInOneToManyRelationship(getColumnName(colNo)))
4150:                        return;
4151:                } catch (DataStoreException ex) {
4152:                    ;
4153:                }
4154:                DSColumnDescriptor col = _desc.getColumn(colNo);
4155:                for (int i = 0; i < col.getRuleCount(); i++) {
4156:                    try {
4157:                        col.getRule(i).evaluateRule(this , rowNo, colNo, conn);
4158:                    } catch (DataStoreException ex) {
4159:                        ex.setRowNo(rowNo);
4160:                        try {
4161:                            ex.setColumn(getColumnName(colNo));
4162:                        } catch (DataStoreException e) {
4163:                        }
4164:                        ;
4165:                        v.add(ex);
4166:                    }
4167:                }
4168:            }
4169:
4170:            protected synchronized void interruptWaitingRetrieveThreads() {
4171:                for (int i = 0; i < _waitingRetrieveThreads.size(); i++) {
4172:                    ((Thread) _waitingRetrieveThreads.elementAt(i)).interrupt();
4173:                }
4174:                _waitingRetrieveThreads.removeAllElements();
4175:            }
4176:
4177:            protected synchronized void interruptWaitingCancelThreads() {
4178:                for (int i = 0; i < _waitingCancelThreads.size(); i++) {
4179:                    ((Thread) _waitingCancelThreads.elementAt(i)).interrupt();
4180:                }
4181:                _waitingCancelThreads.removeAllElements();
4182:            }
4183:
4184:            /**
4185:             * For Systems that don't allow null values in columns, specify the value to use in place of null for each datastore datatype. Whenever the datastore encounters a null value for a column it will replace it with real value for the appropriate type
4186:             * @param dataType One of the datatype constants, ex: DATATYPE_STRING, DATATYPE_INT, etc..
4187:             * @param defaultValue The value to use to replace null values set in the datastore
4188:             */
4189:            public void setNullDefault(int dataType, Object defaultValue) {
4190:                _desc.setNullDefault(dataType, defaultValue);
4191:            }
4192:
4193:            /**
4194:             * Returns the value to use in place of null for a particular datatype
4195:             * @param dataType One of the datatype constants, ex: DATATYPE_STRING, DATATYPE_INT, etc..
4196:             */
4197:            public Object getNullDefault(int dataType) {
4198:                return _desc.getNullDefault(dataType);
4199:            }
4200:
4201:            /**
4202:             * @return the language preferences object for the datastore
4203:             */
4204:            public LanguagePreferences getLang() {
4205:                return _lang;
4206:            }
4207:
4208:            /**
4209:             * @param sets a language preference for this datastore. The datastore implementation doesn't use it, but classes extending the datastore may find it useful
4210:             */
4211:            public void setLang(LanguagePreferences preferences) {
4212:                _lang = preferences;
4213:            }
4214:
4215:            private boolean compare(Object com1, Object com2) {
4216:                if ((com1 == null) && (com2 == null)) {
4217:                    return false;
4218:                } else if ((com1 == null) && (com2 != null)) {
4219:                    return false;
4220:                } else if ((com1 != null) && (com2 == null)) {
4221:                    return true;
4222:                } else if (com1 instanceof  String) {
4223:                    if (!(com2 instanceof  String))
4224:                        return false;
4225:                    int comp = ((String) com1).toUpperCase().compareTo(
4226:                            ((String) com2).toUpperCase());
4227:                    if (comp == 0)
4228:                        return false;
4229:                    else if (comp < 0)
4230:                        return false;
4231:                    else
4232:                        return true;
4233:                } else if (com1 instanceof  Number) {
4234:                    if (!(com2 instanceof  Number))
4235:                        return false;
4236:                    double v1 = ((Number) com1).doubleValue();
4237:                    double v2 = ((Number) com2).doubleValue();
4238:                    if (v1 == v2)
4239:                        return false;
4240:                    else if (v1 < v2)
4241:                        return false;
4242:                    else
4243:                        return true;
4244:                } else if (com1 instanceof  Timestamp) {
4245:                    if (!(com2 instanceof  Timestamp))
4246:                        return false;
4247:
4248:                    if (((Timestamp) com1).equals((Timestamp) com2))
4249:                        return false;
4250:                    else if (((Timestamp) com1).before((Timestamp) com2))
4251:                        return false;
4252:                    else
4253:                        return true;
4254:                } else if (com1 instanceof  java.sql.Date) {
4255:                    if (!(com2 instanceof  java.sql.Date))
4256:                        return false;
4257:                    if (com1.equals(com2))
4258:                        return false;
4259:                    else if (((java.sql.Date) com1)
4260:                            .before((java.sql.Date) com2))
4261:                        return false;
4262:                    else
4263:                        return true;
4264:                } else if (com1 instanceof  java.sql.Time) {
4265:                    if (!(com2 instanceof  java.sql.Time))
4266:                        return false;
4267:
4268:                    if (com1.equals(com2))
4269:                        return false;
4270:                    else if (((java.sql.Time) com1)
4271:                            .before((java.sql.Time) com2))
4272:                        return false;
4273:                    else
4274:                        return true;
4275:                } else
4276:                    return false;
4277:            }
4278:
4279:            /**
4280:             * Returns true if the value passed is greater then the value in the specified datastore column
4281:             */
4282:            public boolean valueGreater(int row, int col, Object value)
4283:                    throws DataStoreException {
4284:                Object com1 = value;
4285:                Object com2 = getAny(row, col);
4286:                return compare(com2, com1);
4287:            }
4288:
4289:            /**
4290:             * Returns true if the value passed is less then the value in the specified datastore column
4291:             */
4292:            public boolean valueLess(int row, int col, Object value)
4293:                    throws DataStoreException {
4294:                Object com1 = value;
4295:                Object com2 = getAny(row, col);
4296:                return compare(com1, com2);
4297:            }
4298:
4299:            /**
4300:             * Returns true if the value passed is less then the value in the specified datastore column
4301:             */
4302:            public boolean valueEqual(int row, int col, Object value)
4303:                    throws DataStoreException {
4304:                Object com1 = value;
4305:                Object com2 = getAny(row, col);
4306:                if (compare(com2, com1))
4307:                    return false;
4308:                else if (compare(com1, com2))
4309:                    return false;
4310:                else
4311:                    return true;
4312:            }
4313:
4314:            /**
4315:             * This method will fix quotes in a string constant so it can be used in a SQL Statement
4316:             */
4317:            public static String fixQuote(String data, int dataType) {
4318:                if (dataType != DATATYPE_STRING || data == null)
4319:                    return data;
4320:
4321:                StringBuffer buf = null;
4322:                for (int i = 0; i < data.length(); i++) {
4323:                    char c = data.charAt(i);
4324:                    if (c == '\'' || c == '\"') {
4325:                        if (buf == null) {
4326:                            buf = new StringBuffer(data.length());
4327:                            buf.append(data.substring(0, i));
4328:                        }
4329:                        int ic = c;
4330:                        buf.append("' + char(");
4331:                        buf.append(ic);
4332:                        buf.append(") + '");
4333:                    } else if (buf != null) {
4334:                        buf.append(c);
4335:                    }
4336:                }
4337:
4338:                if (buf == null)
4339:                    return data;
4340:                else
4341:                    return buf.toString();
4342:
4343:            }
4344:
4345:            /**
4346:             * This method will fix quotes in a string constant so it can be used in a SQL Statement
4347:             */
4348:            public static String fixQuote(String data, int dataType,
4349:                    String connectionType) {
4350:                if (dataType != DATATYPE_STRING || data == null)
4351:                    return data;
4352:
4353:                boolean mySQLConn = connectionType
4354:                        .equals(DBConnection.MYSQL_CONNECTION);
4355:                //if (!connectionType.startsWith(DBConnection.DB2_CONNECTION) && !connectionType.equals(DBConnection.ORACLE_CONNECTION) && !mySQLConn)
4356:                //    return fixQuote(data, dataType);
4357:                if (!connectionType.startsWith(DBConnection.DB2_CONNECTION)
4358:                        && !connectionType
4359:                                .equals(DBConnection.ORACLE_CONNECTION)
4360:                        && !connectionType
4361:                                .equals(DBConnection.POSTGRES_CONNECTION)
4362:                        && !mySQLConn)
4363:                    return fixQuote(data, dataType);
4364:
4365:                String append = "''";
4366:                if (mySQLConn)
4367:                    append = "\\'";
4368:
4369:                StringBuffer buf = null;
4370:                for (int i = 0; i < data.length(); i++) {
4371:                    char c = data.charAt(i);
4372:                    if (c == '\'') {
4373:                        if (buf == null) {
4374:                            buf = new StringBuffer(data.length());
4375:                            buf.append(data.substring(0, i));
4376:                        }
4377:                        buf.append(append);
4378:                    } else if (buf != null) {
4379:                        buf.append(c);
4380:                    }
4381:                }
4382:
4383:                if (buf == null)
4384:                    return data;
4385:                else
4386:                    return buf.toString();
4387:
4388:            }
4389:
4390:            /**
4391:             * Resets the current row pointer to an undefined row
4392:             */
4393:            public void clearSelectedRow() {
4394:                _currentRow = -1;
4395:            }
4396:
4397:            /**
4398:             * Restores a row to the state it was when it was first loaded from the database
4399:             */
4400:            public void undoChanges(int row) {
4401:                if (row < 0 || row >= getRowCount())
4402:                    return;
4403:                getDataRow(row).undoChanges();
4404:            }
4405:
4406:            /**
4407:             * Converts a string to a DataStoreBuffer object type using the type of the specified column
4408:             * @throws ParseException
4409:             */
4410:
4411:            public Object convertValue(String val, String columnName)
4412:                    throws DataStoreException {
4413:                int type = getColumnDataType(columnName);
4414:                try {
4415:                    return convertValue(val, type);
4416:                } catch (ParseException e) {
4417:                    throw new DataStoreException(
4418:                            "Parse Error converting value " + val
4419:                                    + " for column " + columnName, e);
4420:                }
4421:            }
4422:
4423:            /**
4424:             * Converts a string to a DataStoreBuffer object type
4425:             * @throws ParseException
4426:             */
4427:            public static Object convertValue(String val, int dataType)
4428:                    throws ParseException {
4429:                if (val == null)
4430:                    return val;
4431:                if (dataType == DataStoreBuffer.DATATYPE_STRING)
4432:                    return val;
4433:                if (dataType == DataStoreBuffer.DATATYPE_LONG)
4434:                    return new Long(Long.parseLong(val));
4435:                if (dataType == DataStoreBuffer.DATATYPE_SHORT)
4436:                    return new Short(Short.parseShort(val));
4437:                if (dataType == DataStoreBuffer.DATATYPE_INT)
4438:                    return new Integer(Integer.parseInt(val));
4439:                if (dataType == DataStoreBuffer.DATATYPE_DOUBLE)
4440:                    return new Double(Double.parseDouble(val));
4441:                if (dataType == DataStoreBuffer.DATATYPE_FLOAT)
4442:                    return new Double(Float.parseFloat(val));
4443:                if (dataType == DataStoreBuffer.DATATYPE_DATE)
4444:                    return new java.sql.Date(new SimpleDateFormat("yyyy-MM-dd")
4445:                            .parse(val).getTime());
4446:                if (dataType == DataStoreBuffer.DATATYPE_TIME)
4447:                    return new java.sql.Time(new SimpleDateFormat("hh:mm")
4448:                            .parse(val).getTime());
4449:                if (dataType == DataStoreBuffer.DATATYPE_DATETIME)
4450:                    return new Timestamp(new SimpleDateFormat(
4451:                            "yyyy-MM-dd hh:mm").parse(val).getTime());
4452:
4453:                return null;
4454:            }
4455:
4456:            //fc 06/11/04: Method to return whether model is a One to Many Relationship model (Master/Detail)
4457:            /**
4458:             * Returns whether the Datastore has a Many to One Relationship in its joins.
4459:             * @return boolean
4460:             */
4461:            public boolean hasManyToOneRelationship() {
4462:                return _manytoonerelationship;
4463:            }
4464:
4465:            //fc 06/14/04: Method to set whether Master Row can be deleted on update for a One to Many Relationship model (Master/Detail)
4466:            /**
4467:             * Sets whether Master Row can be deleted on update for a One to Many Relationship model (Master/Detail)
4468:             * @param bAllow - Indicates whether to allow Master Row Delete on update.
4469:             */
4470:            public void setAllowMasterRowDelete(boolean bAllow) {
4471:                _allowMasterRowDelete = bAllow;
4472:            }
4473:
4474:            //fc 06/14/04: Method returns whether Master Row can be deleted on update for a One to Many Relationship model (Master/Detail)
4475:            /**
4476:             * Returns whether Master Row can be deleted on update for a One to Many Relationship model (Master/Detail)
4477:             * @return boolean - Indicates whether to allow Master Row Delete on update.
4478:             */
4479:            public boolean getAllowMasterRowDelete() {
4480:                return _allowMasterRowDelete;
4481:            }
4482:
4483:            //fc 06/11/04: Inner class to store One to Many relationship metadata
4484:            // Used to code the correct logic for updates/inserts and deletes
4485:            class TablesRelationshipDescription extends DataStoreBuffer {
4486:                public static final String TABLE = "TABLE";
4487:                public static final String RELATIONSHIPTYPE = "RELATIONSHIPTYPE";
4488:                public static final String MASTERKEYCOLUMNS = "MASTERKEYCOLUMNS";
4489:                public static final String DETAILKEYCOLUMNS = "DETAILKEYCOLUMNS";
4490:
4491:                public TablesRelationshipDescription() {
4492:                    addBucket(TABLE, DataStoreBuffer.DATATYPE_STRING);
4493:                    addBucket(RELATIONSHIPTYPE, DataStoreBuffer.DATATYPE_INT);
4494:                    addBucket(MASTERKEYCOLUMNS, DataStoreBuffer.DATATYPE_STRING);
4495:                    addBucket(DETAILKEYCOLUMNS, DataStoreBuffer.DATATYPE_STRING);
4496:                }
4497:            }
4498:
4499:            //fc 06/11/04: Returns an Instance of the inner class TablesRelationshipDescription
4500:            TablesRelationshipDescription getTablesRelationshipDescription(
4501:                    DataStoreInterface ds) {
4502:                return getTablesRelationshipDescription(ds, true);
4503:            }
4504:
4505:            //fc 06/11/04: Returns an Instance of the inner class TablesRelationshipDescription
4506:            TablesRelationshipDescription getTablesRelationshipDescription(
4507:                    DataStoreInterface ds, boolean bUpdateable) {
4508:                TablesRelationshipDescription dsb = new TablesRelationshipDescription();
4509:
4510:                String sTable;
4511:                int iJoinCount;
4512:                int iJoinColumnCount;
4513:                String sLeftJoin;
4514:                String sRightJoin;
4515:                int iJoinRelType;
4516:                String[] tables = getTableList(bUpdateable);
4517:                try {
4518:                    nextTable: for (int i = 0; i < tables.length; i++) {
4519:                        sTable = tables[i] + ".";
4520:                        iJoinCount = ds.getJoinCount();
4521:                        for (int j = 0; j < iJoinCount; j++) {
4522:                            iJoinRelType = ds.getJoinRelationType(j);
4523:                            if (iJoinRelType != DataStoreBuffer.RELATION_ONE_TO_ONE) {
4524:                                iJoinColumnCount = ds.getJoinColumnCount(j);
4525:                                for (int k = 0; k < iJoinColumnCount; k++) {
4526:                                    sLeftJoin = ds.getJoinLeftColumn(j, k);
4527:                                    sRightJoin = ds.getJoinRightColumn(j, k);
4528:                                    if (sLeftJoin.startsWith(sTable)
4529:                                            || sRightJoin.startsWith(sTable)) {
4530:                                        StringBuffer sbLeftKeyColumns = new StringBuffer(
4531:                                                sLeftJoin);
4532:                                        StringBuffer sbRightKeyColumns = new StringBuffer(
4533:                                                sRightJoin);
4534:                                        for (int m = 1; m < iJoinColumnCount; m++) {
4535:                                            sbLeftKeyColumns.append(',');
4536:                                            sbRightKeyColumns.append(',');
4537:                                            sbLeftKeyColumns.append(ds
4538:                                                    .getJoinLeftColumn(j, m));
4539:                                            sbRightKeyColumns.append(ds
4540:                                                    .getJoinRightColumn(j, m));
4541:                                        }
4542:                                        dsb.insertRow();
4543:                                        dsb
4544:                                                .setString(
4545:                                                        TablesRelationshipDescription.TABLE,
4546:                                                        tables[i]);
4547:                                        if (sLeftJoin.startsWith(sTable)) {
4548:                                            dsb
4549:                                                    .setInt(
4550:                                                            TablesRelationshipDescription.RELATIONSHIPTYPE,
4551:                                                            iJoinRelType == DataStoreBuffer.RELATION_ONE_TO_MANY ? DataStoreBuffer.RELATION_ONE_TO_MANY
4552:                                                                    : DataStoreBuffer.RELATION_MANY_TO_ONE);
4553:                                        }
4554:                                        if (sRightJoin.startsWith(sTable)) {
4555:                                            dsb
4556:                                                    .setInt(
4557:                                                            TablesRelationshipDescription.RELATIONSHIPTYPE,
4558:                                                            iJoinRelType == DataStoreBuffer.RELATION_ONE_TO_MANY ? DataStoreBuffer.RELATION_MANY_TO_ONE
4559:                                                                    : DataStoreBuffer.RELATION_ONE_TO_MANY);
4560:                                        }
4561:                                        dsb
4562:                                                .setString(
4563:                                                        TablesRelationshipDescription.MASTERKEYCOLUMNS,
4564:                                                        iJoinRelType == DataStoreBuffer.RELATION_ONE_TO_MANY ? sbLeftKeyColumns
4565:                                                                .toString()
4566:                                                                : sbRightKeyColumns
4567:                                                                        .toString());
4568:                                        dsb
4569:                                                .setString(
4570:                                                        TablesRelationshipDescription.DETAILKEYCOLUMNS,
4571:                                                        iJoinRelType == DataStoreBuffer.RELATION_ONE_TO_MANY ? sbRightKeyColumns
4572:                                                                .toString()
4573:                                                                : sbLeftKeyColumns
4574:                                                                        .toString());
4575:                                        continue nextTable;
4576:                                    }
4577:                                }
4578:                            }
4579:                        }
4580:                        dsb.insertRow();
4581:                        dsb.setString(TablesRelationshipDescription.TABLE,
4582:                                tables[i]);
4583:                        dsb.setInt(
4584:                                TablesRelationshipDescription.RELATIONSHIPTYPE,
4585:                                DataStoreBuffer.RELATION_ONE_TO_ONE);
4586:                    }
4587:                } catch (DataStoreException e) {
4588:                    MessageLog.writeErrorMessage(
4589:                            "getTablesRelationshipDescription", e, this );
4590:                }
4591:                return dsb;
4592:            }
4593:
4594:            //fc 06/11/04: Indicates whether column is part of the master of a One To Many Relationship Model.
4595:            /**
4596:             * Indicates whether column is part of the master of a One To Many Relationship Model.
4597:             * @return booelan
4598:             */
4599:            public boolean isColumnInOneToManyRelationship(String sColumn) {
4600:                if (!(this  instanceof  DataStoreInterface))
4601:                    return false;
4602:                TablesRelationshipDescription trd = getTablesRelationshipDescription((DataStoreInterface) this );
4603:                String[] saTableColumn = Util.split(sColumn, ".");
4604:                if (saTableColumn.length < 2)
4605:                    return false;
4606:                String sTable = saTableColumn[0];
4607:                try {
4608:                    for (int i = 0; i < trd.getRowCount(); i++) {
4609:                        if (sTable.equals(trd.getString(i,
4610:                                TablesRelationshipDescription.TABLE))) {
4611:                            if (trd
4612:                                    .getInt(
4613:                                            i,
4614:                                            TablesRelationshipDescription.RELATIONSHIPTYPE) == RELATION_ONE_TO_MANY)
4615:                                return true;
4616:                            else
4617:                                return false;
4618:                        }
4619:                    }
4620:                } catch (DataStoreException dse) {
4621:                    MessageLog.writeErrorMessage(dse, this );
4622:                }
4623:                return false;
4624:            }
4625:
4626:            //fc 06/11/04: Copies the master data values from one row to another. Used for one to many relationship models.
4627:            void copyMasterDataValuesToRow(
4628:                    DataStoreBuffer.TablesRelationshipDescription dsTables,
4629:                    DataStoreRow fromrow, DataStoreRow torow)
4630:                    throws DataStoreException {
4631:                for (int i = 0; i < dsTables.getRowCount(); i++) {
4632:                    if (dsTables.getInt(i,
4633:                            TablesRelationshipDescription.RELATIONSHIPTYPE) == RELATION_ONE_TO_MANY) {
4634:                        copyMasterDataValuesToRow(dsTables, fromrow, torow, i);
4635:                    }
4636:                }
4637:            }
4638:
4639:            //fc 06/11/04: Copies the master key values from one row to another. Used for one to many relationship models.
4640:            void copyMasterKeyValuesToRow(
4641:                    DataStoreBuffer.TablesRelationshipDescription dsTables,
4642:                    DataStoreRow fromrow, DataStoreRow torow, int iTableRow)
4643:                    throws DataStoreException {
4644:                String sMasterColumns = dsTables
4645:                        .getString(
4646:                                iTableRow,
4647:                                DataStoreBuffer.TablesRelationshipDescription.MASTERKEYCOLUMNS);
4648:                String[] saMasterColumns = Util.split(sMasterColumns, ",");
4649:                for (int i = 0; i < saMasterColumns.length; i++) {
4650:                    torow.setData(saMasterColumns[i], fromrow
4651:                            .getData(saMasterColumns[i]));
4652:                }
4653:            }
4654:
4655:            //fc 06/11/04: Copies the master data values from one row to another. Used for one to many relationship models.
4656:            void copyMasterDataValuesToRow(
4657:                    DataStoreBuffer.TablesRelationshipDescription dsTables,
4658:                    DataStoreRow fromrow, DataStoreRow torow, int iTableRow)
4659:                    throws DataStoreException {
4660:                String sTable = dsTables.getString(iTableRow,
4661:                        DataStoreBuffer.TablesRelationshipDescription.TABLE)
4662:                        + ".";
4663:                String[] saColumns = getColumnList();
4664:                for (int i = 0; i < saColumns.length; i++) {
4665:                    if (saColumns[i].startsWith(sTable)) {
4666:                        torow.setData(saColumns[i], fromrow
4667:                                .getData(saColumns[i]));
4668:                        //fc 10/11/04: set the status of the master columns to not modified.
4669:                        torow.getDSDataRow().setColumnStatus(i,
4670:                                STATUS_NOT_MODIFIED);
4671:                    }
4672:                }
4673:            }
4674:
4675:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.