ambermappedcomponent.java
来自「RESIN 3.2 最新源码」· Java 代码 · 共 1,961 行 · 第 1/4 页
JAVA
1,961 行
out.println("return true;"); out.popDepth(); out.println("}"); out.popDepth(); out.println("}"); return; } out.println("try {"); out.pushDepth(); id.generateMatch(out, id.generateCastFromObject("key")); out.popDepth(); out.println("} catch (ClassCastException e) {"); out.println(" throw new IllegalArgumentException(\"Primary key type is incorrect: '\"+key.getClass().getName()+\"'\");"); out.println("}"); out.popDepth(); out.println("}"); out.popDepth(); out.println("}"); } /** * Generates the prologue. */ void generatePrologue(JavaWriter out, HashSet<Object> completedSet) throws IOException { if (_entityType.getColumns() != null) { for (AmberColumn column : _entityType.getColumns()) column.generatePrologue(out); } Id id = _entityType.getId(); boolean isAbstractParent = (_entityType.getParentType() == null || ! _entityType.getParentType().isEntity()); // jpa/0m02 if (id != null) // && isAbstractParent) id.generatePrologue(out, completedSet); ArrayList<AmberField> fields = _entityType.getFields(); for (int i = 0; i < fields.size(); i++) { AmberField prop = fields.get(i); prop.generatePrologue(out, completedSet); } } /** * Generates the __caucho_getCacheEntity() */ void generateGetCacheEntity(JavaWriter out) throws IOException { out.println(); out.println("public com.caucho.amber.entity.Entity __caucho_getCacheEntity()"); out.println("{"); out.pushDepth(); out.println("if (__caucho_cacheItem != null)"); out.println(" return __caucho_cacheItem.getEntity();"); out.println("else"); out.println(" return null;"); out.popDepth(); out.println("}"); out.println(); out.println("public com.caucho.amber.entity.EntityItem __caucho_getCacheItem()"); out.println("{"); out.pushDepth(); out.println("return __caucho_cacheItem;"); out.popDepth(); out.println("}"); out.println(); out.println("public void __caucho_setCacheItem(com.caucho.amber.entity.EntityItem cacheItem)"); out.println("{"); out.pushDepth(); out.println("__caucho_cacheItem = cacheItem;"); out.popDepth(); out.println("}"); } /** * Generates the entity type */ void generateGetEntityType(JavaWriter out) throws IOException { out.println(); out.println("public com.caucho.amber.type.EntityType __caucho_getEntityType()"); out.println("{"); out.pushDepth(); out.println("return __caucho_home;"); out.popDepth(); out.println("}"); } /** * Generates the get entity state */ void generateGetEntityState(JavaWriter out) throws IOException { out.println(); out.println("public com.caucho.amber.entity.EntityState __caucho_getEntityState()"); out.println("{"); out.pushDepth(); out.println("return __caucho_state;"); out.popDepth(); out.println("}"); out.println(); out.println("public void __caucho_setEntityState(com.caucho.amber.entity.EntityState state)"); out.println("{"); out.pushDepth(); out.println("__caucho_state = state;"); out.popDepth(); out.println("}"); } /** * Generates the fields. */ void generateFields(JavaWriter out) throws IOException { if (_entityType.getId() != null) { for (AmberField key : _entityType.getId().getKeys()) { if (_entityType == key.getSourceType()) { key.generateSuperGetterMethod(out); key.generateSuperSetterMethod(out); } } } for (AmberField prop : _entityType.getFields()) { if (_entityType == prop.getSourceType()) { prop.generateSuperGetterMethod(out); prop.generateSuperSetterMethod(out); if (! (prop instanceof IdField)) { prop.generateGetterMethod(out); prop.generateSetterMethod(out); } } } } /** * Generates the stub methods (needed for EJB) */ void generateMethods(JavaWriter out) throws IOException { for (StubMethod method : _entityType.getMethods()) { method.generate(out); } } /** * Generates the load */ void generateLoad(JavaWriter out, boolean isEntityParent) throws IOException { // commented out: jpa/0l03 // if (_entityType.getParentType() != null) // return; if (! isEntityParent) { out.println(); out.println("public boolean __caucho_makePersistent(com.caucho.amber.manager.AmberConnection aConn, com.caucho.amber.type.EntityType home)"); out.println(" throws java.sql.SQLException"); out.println("{"); out.pushDepth(); out.println("__caucho_session = aConn;"); out.println("if (home != null)"); out.println(" __caucho_home = home;"); // XXX: makePersistent is called in contexts other than the P_NON_TRANSACTIONAL one, so this setting is inappropriate // out.println("__caucho_state = com.caucho.amber.entity.EntityState.P_NON_TRANSACTIONAL;"); int loadCount = _entityType.getLoadGroupIndex(); for (int i = 0; i <= loadCount / 64; i++) { out.println("__caucho_loadMask_" + i + " = 0L;"); } int dirtyCount = _entityType.getDirtyIndex(); for (int i = 0; i <= dirtyCount / 64; i++) { out.println("__caucho_dirtyMask_" + i + " = 0L;"); out.println("__caucho_updateMask_" + i + " = 0L;"); } out.println(); out.println("return true;"); out.popDepth(); out.println("}"); } int index = _entityType.getLoadGroupIndex(); boolean hasLoad = (_entityType.getFields().size() > 0); if (! isEntityParent) { index = 0; hasLoad = hasLoad || (_entityType.getId() != null); } // jpa/0l20 if (true || hasLoad || ! isEntityParent) { out.println(); out.println("public void __caucho_retrieve_eager(com.caucho.amber.manager.AmberConnection aConn)"); out.println("{"); out.pushDepth(); generateRetrieveEager(out, _entityType); out.popDepth(); out.println("}"); out.println(); out.println("public void __caucho_retrieve_self(com.caucho.amber.manager.AmberConnection aConn)"); out.println("{"); out.pushDepth(); generateRetrieveSelf(out, _entityType); out.popDepth(); out.println("}"); } } private void generateRetrieveEager(JavaWriter out, EntityType entityType) throws IOException { if (entityType == null || ! entityType.isEntity()) return; int index = entityType.getLoadGroupIndex(); boolean hasLoad = (entityType.getFields().size() > 0); EntityType parentType = entityType.getParentType(); if (parentType == null || ! parentType.isEntity()) { index = 0; hasLoad = true; } generateRetrieveEager(out, parentType); if (hasLoad) out.println("__caucho_load_" + index + "(aConn);"); } private void generateRetrieveSelf(JavaWriter out, EntityType entityType) throws IOException { if (entityType == null || ! entityType.isEntity()) return; int index = entityType.getLoadGroupIndex(); boolean hasLoad = (entityType.getFields().size() > 0); EntityType parentType = entityType.getParentType(); if (parentType != null && parentType.isEntity()) { generateRetrieveSelf(out, parentType); } else { index = 0; hasLoad = true; } if (hasLoad) { int group = index / 64; long mask = (1L << (index % 64)); out.println("if ((__caucho_loadMask_" + group + " & " + mask + "L) == 0)"); out.println(" __caucho_load_select_" + index + "(aConn);"); } } /** * Generates the detach */ void generateDetach(JavaWriter out, boolean isEntityParent) throws IOException { if (isEntityParent) return; out.println(); out.println("public void __caucho_detach()"); out.println("{"); out.pushDepth(); generateLogFinest(out, " amber detach"); out.println(); out.println("__caucho_session = null;"); for (AmberField field : _entityType.getFields()) field.generateDetach(out); // jpa/0x00 // out.println("__caucho_home = null;"); out.println("__caucho_state = com.caucho.amber.entity.EntityState.TRANSIENT;"); out.popDepth(); out.println("}"); } /** * Generates the load group. */ void generateLoadGroup(JavaWriter out, int groupIndex) throws IOException { if (_entityType.hasLoadGroup(groupIndex)) { new LoadGroupGenerator(_extClassName, _entityType, groupIndex).generate(out); } } /** * Generates the load */ void generateResultSetLoad(JavaWriter out, boolean isEntityParent) throws IOException { if (isEntityParent) return; out.println(); out.println("public int __caucho_load(com.caucho.amber.manager.AmberConnection aConn, java.sql.ResultSet rs, int index)"); out.println(" throws java.sql.SQLException"); out.println("{"); out.pushDepth(); int index = _entityType.generateLoad(out, "rs", "index", 0, 0); out.println("__caucho_loadMask_0 |= 1L;"); int dirtyCount = _entityType.getDirtyIndex(); for (int i = 0; i <= dirtyCount / 64; i++) { out.println("__caucho_dirtyMask_" + i + " = 0;"); // ejb/0645 // out.println("__caucho_updateMask_" + i + " = 0;"); } out.println(); /* jpa/0g43 - XA doesn't have a cache item out.println("if (__caucho_cacheItem == null) {"); // the cache item does not have its state changed out.println("}"); out.println("else "); */ out.println("if (__caucho_state.isTransactional()) {"); out.println("}"); out.println("else if (__caucho_session == null"); out.println(" || ! __caucho_session.isActiveTransaction()) {"); out.println(" __caucho_state = com.caucho.amber.entity.EntityState.P_NON_TRANSACTIONAL;"); out.println(" if (__caucho_cacheItem != null)"); out.println(" __caucho_cacheItem.save((com.caucho.amber.entity.Entity) this);"); out.println("}"); out.println("else {"); out.println(" __caucho_state = com.caucho.amber.entity.EntityState.P_TRANSACTIONAL;"); out.println("}"); if (_entityType.getHasLoadCallback()) { out.println(); out.println("__caucho_load_callback();"); } out.println("return " + index + ";"); out.popDepth(); out.println("}"); } /** * Generates the load */ void generateSetQuery(JavaWriter out, boolean isEntityParent) throws IOException { if (isEntityParent) return; out.println(); out.println("public void __caucho_setKey(java.sql.PreparedStatement pstmt, int index)"); out.println(" throws java.sql.SQLException"); out.println("{"); out.pushDepth(); // jpa/0gg0 vs jpa/06c5 if (! _entityType.isAbstractClass()) _entityType.generateSet(out, "pstmt", "index", "super"); out.popDepth(); out.println("}"); } /** * Generates the increment version */ void generateIncrementVersion(JavaWriter out) throws IOException { out.println(); out.println("public void __caucho_increment_version()"); out.println("{"); out.pushDepth(); VersionField version = _entityType.getVersionField(); if (version != null) { out.println("if (__caucho_inc_version)"); out.println(" return;"); out.println(); out.println("__caucho_inc_version = true;"); version.generateIncrementVersion(out); } out.popDepth(); out.println("}"); } /** * Generates the flush */ void generateFlush(JavaWriter out) throws IOException { } /** * Generates the update */ void generateFlushUpdate(JavaWriter out, boolean isEntityParent) throws IOException { out.println(); out.println("protected void __caucho_flushUpdate(long mask, com.caucho.amber.type.EntityType home)"); out.println(" throws java.sql.SQLException"); out.println("{"); out.pushDepth(); if (isEntityParent) { out.println("super.__caucho_flushUpdate(mask, home.getParentType());"); } out.println("String sql = home.generateUpdateSQL(mask);"); out.println("if (sql != null) {"); out.pushDepth();
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?