Source Code Cross Referenced for WGenericCrudPagelet.java in  » Database-ORM » SimpleORM » simpleorm » simplewebapp » dbute » 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 » Database ORM » SimpleORM » simpleorm.simplewebapp.dbute 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package simpleorm.simplewebapp.dbute;
002:
003:        import simpleorm.simplewebapp.core.*;
004:        import simpleorm.simplewebapp.scalarFields.WFieldString;
005:        import simpleorm.simplewebapp.scalarFields.WFieldInteger;
006:        import simpleorm.simplewebapp.scalarFields.WFieldBoolean;
007:        import simpleorm.core.*;
008:
009:        /**
010:         * Does basic crud operations based on meta data.
011:         * A transaction must have been begun.
012:         */
013:        public abstract class WGenericCrudPagelet extends WPagelet {
014:
015:            public WButton update = addNewButton("Update");
016:            public WButton delete = addNewButton("Delete");
017:            public WButton add = addNewButton("Add");
018:
019:            SRecordMeta meta;
020:            WField key;
021:
022:            WFieldGroup identityGroup = addGroup(this , new WFieldGroup(
023:                    "identity"));
024:            WFieldGroup bodyGroup = addGroup(this , new WFieldGroup("body"));
025:
026:            public WGenericCrudPagelet(WPage wpage, SRecordMeta meta) {
027:                super (wpage, "crud");
028:                this .meta = meta;
029:            }
030:
031:            /**
032:             * Very auto way to generate all Crud WPageStructure.
033:             */
034:            public void generateCrudFields() {
035:                for (Object fname : meta.getFieldNames()) {
036:                    SFieldMeta sfield = meta.getField((String) fname);
037:                    WField wfield = addGeneratedCrudField(sfield);
038:                }
039:            }
040:
041:            public WField addGeneratedCrudField(SFieldMeta sfield) {
042:                WFieldGroup grp = sfield.getBoolean(SCon.SPRIMARY_KEY) ? identityGroup
043:                        : bodyGroup;
044:                WField wfield = addField(grp, generateField(sfield));
045:                String[] options = (String[]) sfield
046:                        .getProperty(WRecordInstance.SELECT_OPTIONS);
047:                if (options != null) {
048:                    wfield.getOptions().add("");
049:                    for (String opt : options)
050:                        wfield.getOptions().add(opt);
051:                    wfield.setWidget(WField.SELECT);
052:                }
053:                return wfield;
054:            }
055:
056:            /** Create a new SimpleWebApp WField that corresponds to the given SimpleORM SFieldMeta.
057:             * Copies meta attributes across such as required and size.
058:             */
059:            public WField generateField(SFieldMeta sfield) {
060:                String name = sfield.getString(SCon.SFIELD_NAME);
061:                WField wfield;
062:                if (sfield instanceof  SFieldString) {
063:                    wfield = new WFieldString(name);
064:                    int size = (Integer) sfield.getProperty(SCon.SBYTE_SIZE);
065:                    wfield.setMaxLength(size);
066:                    wfield.setDisplayLength(size < 60 ? size : 60);
067:                } else if (sfield instanceof  SFieldInteger)
068:                    wfield = new WFieldInteger(name);
069:                else if (sfield instanceof  SFieldBoolean) {
070:                    wfield = new WFieldBoolean(name);
071:                } else
072:                    throw new WException("Cann't create WField for " + sfield);
073:                wfield.setDataField(sfield);
074:                if (sfield.getBoolean(SCon.SPRIMARY_KEY)) {
075:                    if (key != null)
076:                        throw new WException("Only one key supported for now "
077:                                + key + sfield);
078:                    else
079:                        key = wfield;
080:                    wfield.setReadOnly(true);
081:                }
082:                if (sfield.getBoolean(SCon.SMANDATORY))
083:                    wfield.setRequired(true);
084:                return wfield;
085:            }
086:
087:            protected @Override
088:            void onPreValidate() throws Exception {
089:                String theKey = key.getText();
090:                if (theKey == null) {
091:                    update.setDisabled(true);
092:                    delete.setDisabled(true);
093:                } else
094:                    add.setDisabled(true);
095:            }
096:
097:            protected @Override
098:            void onNotSubmitted() {
099:                //SRecordInstance rec = meta.findOrCreate();
100:                Object theKey = key.getValue();
101:                if (theKey != null) {
102:                    SRecordInstance rec = meta.findOrCreate(theKey);
103:                    for (WField wfield : getAllFieldValues()) {
104:                        SFieldMeta sfield = (SFieldMeta) wfield.getDataField(); //WUser.meta.getFieldStrict(wfield.getDataName());
105:                        Object value = rec.getObject(sfield);
106:                        if (logger().isDebug())
107:                            logger().debug(
108:                                    "onNotSubmitted  " + sfield + " == "
109:                                            + value);
110:                        wfield.setValue(value);
111:                    }
112:                }
113:            }
114:
115:            protected @Override
116:            void onWasSubmitted() {
117:                Object theKey = key.getValue();
118:                SRecordInstance rec;
119:                if (theKey != null)
120:                    rec = meta.findOrCreate(theKey);
121:                else if (getSubmitButton() == add) {
122:                    rec = meta.createWithGeneratedKey();
123:                } else
124:                    throw new WException("Bad button with null key "
125:                            + getSubmitButton());
126:
127:                if (getSubmitButton() == update || getSubmitButton() == add) {
128:                    for (WField wfield : getAllFieldValues()) {
129:                        if (wfield != key) {
130:                            SFieldMeta sfield = (SFieldMeta) wfield
131:                                    .getDataField(); //WUser.meta.getFieldStrict(wfield.getDataName());
132:                            Object value = wfield.getValue();
133:                            if (logger().isDebug())
134:                                logger().debug(
135:                                        "onWasSubmitted  " + sfield + " := "
136:                                                + value);
137:                            try {
138:                                rec.setObject(sfield, value);
139:                            } catch (WValidationException ve) {
140:                                ve.setField(wfield);
141:                                throw ve;
142:                            }
143:                        }
144:                    }
145:                } else if (getSubmitButton() == delete) {
146:                    rec.deleteRecord();
147:                    nullAllFields();
148:                } else
149:                    throw new WException("Bad button " + getSubmitButton());
150:                SConnection.commit(); // Ensure subsequent Selects do not access deleted record.
151:                SConnection.begin();
152:                getPageStructure().setActualRedirectUrl(
153:                        getPotentialSuccessUrl());
154:            }
155:
156:            protected @Override
157:            void onMaybeErroneous() {
158:                if (isErroneous()) { // && SConnection.getConnection().hasBegun() -- must be in a transaction
159:                    SConnection.rollback(); // ensure that any partial updates are ignored
160:                    SConnection.begin();
161:                }
162:            }
163:
164:            //////////////////
165:
166:            public WButton getUpdate() {
167:                return update;
168:            }
169:
170:            public WButton getDelete() {
171:                return delete;
172:            }
173:
174:            public WButton getAdd() {
175:                return add;
176:            }
177:
178:            public SRecordMeta getMeta() {
179:                return meta;
180:            }
181:
182:            public WField getKey() {
183:                return key;
184:            }
185:
186:            public WFieldGroup getBodyGroup() {
187:                return bodyGroup;
188:            }
189:
190:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.