Source Code Cross Referenced for InsertStatement.java in  » Content-Management-System » harmonise » org » openharmonise » commons » dsi » dml » 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 » Content Management System » harmonise » org.openharmonise.commons.dsi.dml 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * The contents of this file are subject to the 
003:         * Mozilla Public License Version 1.1 (the "License"); 
004:         * you may not use this file except in compliance with the License. 
005:         * You may obtain a copy of the License at http://www.mozilla.org/MPL/
006:         *
007:         * Software distributed under the License is distributed on an "AS IS"
008:         * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. 
009:         * See the License for the specific language governing rights and 
010:         * limitations under the License.
011:         *
012:         * The Initial Developer of the Original Code is Simulacra Media Ltd.
013:         * Portions created by Simulacra Media Ltd are Copyright (C) Simulacra Media Ltd, 2004.
014:         *
015:         * All Rights Reserved.
016:         *
017:         * Contributor(s):
018:         */
019:        package org.openharmonise.commons.dsi.dml;
020:
021:        import java.util.*;
022:
023:        import org.openharmonise.commons.dsi.*;
024:
025:        /**
026:         * A DML insert statement .
027:         *
028:         * @author Michael Bell
029:         * @version $Revision: 1.2 $
030:         *
031:         */
032:        public class InsertStatement extends AbstractDMLStatement {
033:
034:            /**
035:             * The name of the table to receive the inserted data.
036:             */
037:            protected String m_sTable = null;
038:
039:            /**
040:             * Map of column references to values to be inserted.
041:             */
042:            protected HashMap m_ValuePairs = null;
043:
044:            /**
045:             * Flag which is true if insert columns and values are defined by .
046:             * a select statement
047:             */
048:            private boolean m_bIsValuesSelectDefined = false;
049:
050:            /**
051:             * Select statement which defines values for insert statement.
052:             */
053:            private SelectStatement m_select = null;
054:
055:            /**
056:             * Constructs insert statement
057:             *
058:             */
059:            public InsertStatement() {
060:            }
061:
062:            /**
063:             * Sets name of table to insert data into.
064:             * 
065:             * @param sTable name of table
066:             */
067:            public void setTable(String sTable) {
068:                m_sTable = sTable;
069:            }
070:
071:            /**
072:             * Returns the name of the table to insert data in.
073:             * 
074:             * @return the name of the table to insert data in
075:             */
076:            public String getTable() {
077:                if (m_sTable != null) {
078:                    return m_sTable;
079:                } else if (m_ValuePairs != null) {
080:                    String sRetr = null;
081:                    Set set = m_ValuePairs.keySet();
082:                    Iterator iter = set.iterator();
083:
084:                    if (iter.hasNext()) {
085:                        sRetr = ((ColumnRef) iter.next()).getTable();
086:                    }
087:
088:                    return sRetr;
089:                } else {
090:                    return null;
091:                }
092:            }
093:
094:            /**
095:             * Sets the select statement which determines column value pairs.
096:             * 
097:             * @param select the select statement
098:             */
099:            public void setColumnValuesBySelect(SelectStatement select) {
100:                m_select = select;
101:                m_bIsValuesSelectDefined = true;
102:            }
103:
104:            /**
105:             * Returns the select statement which determines the column value pairs.
106:             * 
107:             * @return the select statement which determines the column value pairs
108:             */
109:            public SelectStatement getColumnValuesSelect() {
110:                return m_select;
111:            }
112:
113:            /**
114:             * Returns <code>true</code> if column value pairs set by select.
115:             * 
116:             * @return
117:             */
118:            public boolean isColumnValuesBySelect() {
119:                return m_bIsValuesSelectDefined;
120:            }
121:
122:            /**
123:             * Returns a <code>Map</code> of column reference and value pairs
124:             * for inserting.
125:             * 
126:             * @return  column reference and value pairs in a <code>Map</code>
127:             */
128:            public Map getColumnValuePairs() {
129:                return m_ValuePairs;
130:            }
131:
132:            /**
133:             * Adds a column reference and associated value to this statement.
134:             * 
135:             * @param colref reference to column
136:             * @param i value to be inserted
137:             * @throws DataStoreException if column value pair are invalid
138:             */
139:            public void addColumnValue(ColumnRef colref, int i)
140:                    throws DataStoreException {
141:                addColumnValue(colref, new Integer(i));
142:            }
143:
144:            /**
145:             * Adds a column reference and associated value to this statement.
146:             * 
147:             * @param colref reference to column
148:             * @param val value to be inserted
149:             * @throws DataStoreException if column value pair are invalid
150:             */
151:            public void addColumnValue(ColumnRef colref, Object val)
152:                    throws DataStoreException {
153:                if (m_bIsValuesSelectDefined) {
154:                    throw new DataStoreException("Invalid data type");
155:                }
156:
157:                if (val != null) {
158:                    if ((val instanceof  String) == false
159:                            && (val instanceof  Integer) == false
160:                            && (val instanceof  Float) == false
161:                            && (val instanceof  Date) == false
162:                            && (val instanceof  SelectStatement) == false) {
163:                        throw new DataStoreException("Invalid class: "
164:                                + val.getClass().getName());
165:                    }
166:
167:                    if (val instanceof  SelectStatement) {
168:                        SelectStatement select = (SelectStatement) val;
169:
170:                        List selectcols = select.getSelectColumns();
171:
172:                        if ((selectcols.size() != 1)
173:                                || (colref.getDataType() != ((ColumnRef) selectcols
174:                                        .get(0)).getDataType())) {
175:                            throw new DataStoreException("Invalid type: "
176:                                    + colref.getDataType());
177:                        }
178:                    } else if ((colref.getDataType() == ColumnRef.NUMBER)
179:                            && !(val instanceof  Integer || val instanceof  Float)) {
180:                        throw new DataStoreException("Invalid type: "
181:                                + val.getClass().getName());
182:                    } else if ((colref.getDataType() == ColumnRef.TEXT || colref
183:                            .getDataType() == ColumnRef.LONG_TEXT)
184:                            && (val instanceof  String) == false) {
185:                        throw new DataStoreException("Invalid type: "
186:                                + val.getClass().getName());
187:                    } else if ((colref.getDataType() == ColumnRef.DATE)
188:                            && (val instanceof  Date) == false) {
189:                        throw new DataStoreException("Invalid type: "
190:                                + val.getClass().getName());
191:                    }
192:                }
193:
194:                if (m_ValuePairs == null) {
195:                    m_ValuePairs = new HashMap(11);
196:                }
197:
198:                m_ValuePairs.put(colref, val);
199:            }
200:
201:            /* (non-Javadoc)
202:             * @see org.openharmonise.commons.dsi.dml.AbstractDMLStatement#clear()
203:             */
204:            public void clear() {
205:                super.clear();
206:                m_sTable = null;
207:
208:                if (m_ValuePairs != null) {
209:                    m_ValuePairs.clear();
210:                }
211:            }
212:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.