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


001:        package simpleorm.data;
002:
003:        import java.util.*;
004:
005:        /**
006:         * Contains the list of field meta data within a record.
007:         * (This meta data could just be stored with each instance.
008:         * However we need separate meta data objects so that we can
009:         * issue queries etc.  Also so that we can display a list of instances etc.
010:         * But it does )
011:         */
012:        public class DRecordMeta {
013:            Class clazz; // of the DRecordInstance
014:            String tableName;
015:            Map<String, DFieldMeta> fields = Collections
016:                    .synchronizedMap(new LinkedHashMap(16));
017:            List<DForeignKeyMeta> refingFKeys = new ArrayList(5);
018:            List<DForeignKeyMeta> refedFKeys = new ArrayList(5);
019:
020:            Object recordImplementation; // eg. ddl utils Table
021:
022:            public DRecordMeta(Class clazz, String name) {
023:                this .clazz = clazz;
024:                this .tableName = name;
025:            }
026:
027:            public DFieldMeta addField(DFieldMeta field) {
028:                if (field.recordMeta != null)
029:                    throw new DException("DFieldMeta " + field
030:                            + " already in record " + field.recordMeta);
031:                field.recordMeta = this ;
032:                fields.put(field.name, field);
033:                return field;
034:            }
035:
036:            /** Adds Foreign key to both the refing (field.record) and refed (this) DRecordMetas.
037:             * Ie. generates
038:             * CREATE TABLE  field.table(...) FOREIGN KEY (field) references this.
039:             * (obviously all field.record must be the same.)
040:             */
041:            public DForeignKeyMeta addRefingFKey(DFieldMeta... fields) {
042:                DForeignKeyMeta fkey = new DForeignKeyMeta(this , fields);
043:                fkey.refingRecord.refingFKeys.add(fkey);
044:                fkey.refedRecord.refedFKeys.add(fkey);
045:                fkey.name = fkey.refingRecord.getTableName() + "_"
046:                        + fkey.refingRecord.refingFKeys.size();
047:                return fkey;
048:            }
049:
050:            public DFieldMeta getField(String name) {
051:                return fields.get(name);
052:            }
053:
054:            public Collection<DFieldMeta> getFields() {
055:                return Collections.unmodifiableCollection(fields.values());
056:            }
057:
058:            public Collection<DForeignKeyMeta> getRefingFKeys() {
059:                return Collections.unmodifiableCollection(refingFKeys);
060:            }
061:
062:            public Collection<DForeignKeyMeta> getRefedFKeys() {
063:                return Collections.unmodifiableCollection(refedFKeys);
064:            }
065:
066:            /** Called by DConnections, not directly by user. */
067:            DRecordInstance newInstance() { // not SORM, in find/query record.
068:                try {
069:                    return (DRecordInstance) clazz.newInstance();
070:                } catch (Exception ex) {
071:                    throw new DException("While newing " + this , ex);
072:                }
073:            }
074:
075:            /** nth primarykey, first is 0.
076:             * Linear search, but nth is almost always 0. */
077:            DFieldMeta primaryKeyField(int nth) {
078:                int n0 = nth;
079:                for (DFieldMeta field : fields.values()) {
080:                    if (field.isPrimaryKey() && nth-- == 0)
081:                        return field;
082:                }
083:                throw new DException("Not enough primary keys " + n0 + this );
084:            }
085:
086:            ////////
087:
088:            public String getTableName() { // SORM
089:                return tableName;
090:            }
091:
092:            public Class getClazz() { // sorm userClass, not public
093:                return clazz;
094:            }
095:
096:            public Object getRecordImplementation() {
097:                return recordImplementation;
098:            }
099:
100:            public void setRecordImplementation(Object recordImplementation) {
101:                this.recordImplementation = recordImplementation;
102:            }
103:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.