public ICFSecurityTenantObj readTenantByUNameIdx( long ClusterId, String TenantName, boolean forceRead) { if (indexByUNameIdx == null) { indexByUNameIdx = new HashMap<CFSecurityTenantByUNameIdxKey, ICFSecurityTenantObj>(); } CFSecurityTenantByUNameIdxKey key = ((ICFSecuritySchema) schema.getBackingStore()).getFactoryTenant().newUNameIdxKey(); key.setRequiredClusterId(ClusterId); key.setRequiredTenantName(TenantName); ICFSecurityTenantObj obj = null; if ((!forceRead) && indexByUNameIdx.containsKey(key)) { obj = indexByUNameIdx.get(key); } else { CFSecurityTenantBuff buff = ((ICFSecuritySchema) schema.getBackingStore()) .getTableTenant() .readDerivedByUNameIdx(schema.getAuthorization(), ClusterId, TenantName); if (buff != null) { obj = schema.getTenantTableObj().newInstance(); obj.setPKey(((ICFSecuritySchema) schema.getBackingStore()).getFactoryTenant().newPKey()); obj.setBuff(buff); obj = (ICFSecurityTenantObj) obj.realize(); } else if (schema.getCacheMisses()) { indexByUNameIdx.put(key, null); } } return (obj); }
public void deleteTenant(ICFSecurityTenantObj Obj) { ICFSecurityTenantObj obj = Obj; ((ICFSecuritySchema) schema.getBackingStore()) .getTableTenant() .deleteTenant(schema.getAuthorization(), obj.getTenantBuff()); obj.forget(true); }
public void forgetTenantByClusterIdx(long ClusterId) { if (indexByClusterIdx == null) { return; } CFSecurityTenantByClusterIdxKey key = ((ICFSecuritySchema) schema.getBackingStore()).getFactoryTenant().newClusterIdxKey(); key.setRequiredClusterId(ClusterId); if (indexByClusterIdx.containsKey(key)) { Map<CFSecurityTenantPKey, ICFSecurityTenantObj> mapClusterIdx = indexByClusterIdx.get(key); if (mapClusterIdx != null) { List<ICFSecurityTenantObj> toForget = new LinkedList<ICFSecurityTenantObj>(); ICFSecurityTenantObj cur = null; Iterator<ICFSecurityTenantObj> iter = mapClusterIdx.values().iterator(); while (iter.hasNext()) { cur = iter.next(); toForget.add(cur); } iter = toForget.iterator(); while (iter.hasNext()) { cur = iter.next(); cur.forget(true); } } indexByClusterIdx.remove(key); } }
public void deleteTenantByIdIdx(long Id) { CFSecurityTenantPKey pkey = ((ICFSecuritySchema) schema.getBackingStore()).getFactoryTenant().newPKey(); pkey.setRequiredId(Id); ICFSecurityTenantObj obj = readTenant(pkey); if (obj != null) { ICFSecurityTenantEditObj editObj = (ICFSecurityTenantEditObj) obj.getEdit(); boolean editStarted; if (editObj == null) { editObj = (ICFSecurityTenantEditObj) obj.beginEdit(); if (editObj != null) { editStarted = true; } else { editStarted = false; } } else { editStarted = false; } if (editObj != null) { editObj.delete(); if (editStarted) { editObj.endEdit(); } } obj.forget(true); } }
public void deleteTenantByClusterIdx(long ClusterId) { CFSecurityTenantByClusterIdxKey key = ((ICFSecuritySchema) schema.getBackingStore()).getFactoryTenant().newClusterIdxKey(); key.setRequiredClusterId(ClusterId); if (indexByClusterIdx == null) { indexByClusterIdx = new HashMap< CFSecurityTenantByClusterIdxKey, Map<CFSecurityTenantPKey, ICFSecurityTenantObj>>(); } if (indexByClusterIdx.containsKey(key)) { Map<CFSecurityTenantPKey, ICFSecurityTenantObj> dict = indexByClusterIdx.get(key); ((ICFSecuritySchema) schema.getBackingStore()) .getTableTenant() .deleteTenantByClusterIdx(schema.getAuthorization(), ClusterId); Iterator<ICFSecurityTenantObj> iter = dict.values().iterator(); ICFSecurityTenantObj obj; List<ICFSecurityTenantObj> toForget = new LinkedList<ICFSecurityTenantObj>(); while (iter.hasNext()) { obj = iter.next(); toForget.add(obj); } iter = toForget.iterator(); while (iter.hasNext()) { obj = iter.next(); obj.forget(true); } indexByClusterIdx.remove(key); } else { ((ICFSecuritySchema) schema.getBackingStore()) .getTableTenant() .deleteTenantByClusterIdx(schema.getAuthorization(), ClusterId); } }
public ICFSecurityTenantObj getSystemTenant() { boolean transactionStarted = schema.beginTransaction(); ICFSecurityTenantObj tenantObj; try { schema.getAuditActionTableObj().bootstrapAuditActions(); ICFSecurityClusterObj clusterObj = schema.getClusterTableObj().getSystemCluster(); tenantObj = readTenantByUNameIdx(clusterObj.getRequiredId(), "system"); if (tenantObj == null) { tenantObj = newInstance(); ICFSecurityTenantEditObj tenantEdit = tenantObj.beginEdit(); tenantEdit.setRequiredContainerCluster(clusterObj); tenantEdit.setRequiredTenantName("system"); tenantObj = tenantEdit.create(); tenantEdit.endEdit(); } if (transactionStarted) { schema.commit(); } } catch (RuntimeException e) { if (transactionStarted) { try { schema.rollback(); } catch (Exception e2) { } } throw e; } return (tenantObj); }
public ICFSecurityTenantObj updateTenant(ICFSecurityTenantObj Obj) { ICFSecurityTenantObj obj = Obj; ((ICFSecuritySchema) schema.getBackingStore()) .getTableTenant() .updateTenant(schema.getAuthorization(), Obj.getTenantBuff()); obj = (ICFSecurityTenantObj) Obj.realize(); return (obj); }
public ICFSecurityTenantObj createTenant(ICFSecurityTenantObj Obj) { ICFSecurityTenantObj obj = Obj; CFSecurityTenantBuff buff = obj.getTenantBuff(); ((ICFSecuritySchema) schema.getBackingStore()) .getTableTenant() .createTenant(schema.getAuthorization(), buff); obj.copyBuffToPKey(); obj = obj.realize(); return (obj); }
public void setRequiredOwnerTenant(ICFSecurityTenantObj value) { if (buff == null) { getAttachmentDataBuff(); } requiredOwnerTenant = null; requiredContainerAttachment = null; if (value != null) { getPKey().setRequiredTenantId(value.getRequiredId()); getAttachmentDataBuff().setRequiredTenantId(value.getRequiredId()); } requiredOwnerTenant = value; }
public void forgetTenantByIdIdx(long Id) { if (members == null) { return; } CFSecurityTenantPKey key = ((ICFSecuritySchema) schema.getBackingStore()).getFactoryTenant().newPKey(); key.setRequiredId(Id); if (members.containsKey(key)) { ICFSecurityTenantObj probed = members.get(key); if (probed != null) { probed.forget(true); } } }
public void setRequiredOwnerCTenant(ICFSecurityTenantObj value) { if (buff == null) { getSchemaDefBuff(); } requiredContainerParentDomain = null; requiredOwnerCTenant = null; if (value != null) { getPKey().setRequiredTenantId(value.getRequiredId()); getSchemaDefBuff().setRequiredTenantId(value.getRequiredId()); } requiredOwnerCTenant = value; super.setRequiredOwnerTenant(value); }
public void forgetTenantByUNameIdx(long ClusterId, String TenantName) { if (indexByUNameIdx == null) { return; } CFSecurityTenantByUNameIdxKey key = ((ICFSecuritySchema) schema.getBackingStore()).getFactoryTenant().newUNameIdxKey(); key.setRequiredClusterId(ClusterId); key.setRequiredTenantName(TenantName); if (indexByUNameIdx.containsKey(key)) { ICFSecurityTenantObj probed = indexByUNameIdx.get(key); if (probed != null) { probed.forget(true); } indexByUNameIdx.remove(key); } }
public ICFSecurityTenantObj lockTenant(CFSecurityTenantPKey pkey) { ICFSecurityTenantObj locked = null; CFSecurityTenantBuff lockBuff = ((ICFSecuritySchema) schema.getBackingStore()) .getTableTenant() .lockDerived(schema.getAuthorization(), pkey); if (lockBuff != null) { locked = schema.getTenantTableObj().newInstance(); locked.setPKey(((ICFSecuritySchema) schema.getBackingStore()).getFactoryTenant().newPKey()); locked.setBuff(lockBuff); locked = (ICFSecurityTenantObj) locked.realize(); } else { throw CFLib.getDefaultExceptionFactory() .newCollisionDetectedException(getClass(), "lockTenant", pkey); } return (locked); }
public void minimizeMemory() { allTenant = null; indexByClusterIdx = null; indexByUNameIdx = null; List<ICFSecurityTenantObj> toForget = new LinkedList<ICFSecurityTenantObj>(); ICFSecurityTenantObj cur = null; Iterator<ICFSecurityTenantObj> iter = members.values().iterator(); while (iter.hasNext()) { cur = iter.next(); toForget.add(cur); } iter = toForget.iterator(); while (iter.hasNext()) { cur = iter.next(); cur.forget(); } }
public ICFSecurityTenantObj readTenant(CFSecurityTenantPKey pkey, boolean forceRead) { ICFSecurityTenantObj obj = null; if ((!forceRead) && members.containsKey(pkey)) { obj = members.get(pkey); } else { CFSecurityTenantBuff readBuff = ((ICFSecuritySchema) schema.getBackingStore()) .getTableTenant() .readDerivedByIdIdx(schema.getAuthorization(), pkey.getRequiredId()); if (readBuff != null) { obj = schema.getTenantTableObj().newInstance(); obj.setPKey(((ICFSecuritySchema) schema.getBackingStore()).getFactoryTenant().newPKey()); obj.setBuff(readBuff); obj = (ICFSecurityTenantObj) obj.realize(); } else if (schema.getCacheMisses()) { members.put(pkey, null); } } return (obj); }
public void deleteTenantByUNameIdx(long ClusterId, String TenantName) { if (indexByUNameIdx == null) { indexByUNameIdx = new HashMap<CFSecurityTenantByUNameIdxKey, ICFSecurityTenantObj>(); } CFSecurityTenantByUNameIdxKey key = ((ICFSecuritySchema) schema.getBackingStore()).getFactoryTenant().newUNameIdxKey(); key.setRequiredClusterId(ClusterId); key.setRequiredTenantName(TenantName); ICFSecurityTenantObj obj = null; if (indexByUNameIdx.containsKey(key)) { obj = indexByUNameIdx.get(key); ((ICFSecuritySchema) schema.getBackingStore()) .getTableTenant() .deleteTenantByUNameIdx(schema.getAuthorization(), ClusterId, TenantName); obj.forget(true); } else { ((ICFSecuritySchema) schema.getBackingStore()) .getTableTenant() .deleteTenantByUNameIdx(schema.getAuthorization(), ClusterId, TenantName); } }
public void forgetTenant(ICFSecurityTenantObj Obj, boolean forgetSubObjects) { ICFSecurityTenantObj obj = Obj; CFSecurityTenantPKey pkey = obj.getPKey(); if (members.containsKey(pkey)) { ICFSecurityTenantObj keepObj = members.get(pkey); // Detach object from alternate, duplicate, all and PKey indexes if (indexByClusterIdx != null) { CFSecurityTenantByClusterIdxKey keyClusterIdx = ((ICFSecuritySchema) schema.getBackingStore()).getFactoryTenant().newClusterIdxKey(); keyClusterIdx.setRequiredClusterId(keepObj.getRequiredClusterId()); Map<CFSecurityTenantPKey, ICFSecurityTenantObj> mapClusterIdx = indexByClusterIdx.get(keyClusterIdx); if (mapClusterIdx != null) { mapClusterIdx.remove(keepObj.getPKey()); } } if (indexByUNameIdx != null) { CFSecurityTenantByUNameIdxKey keyUNameIdx = ((ICFSecuritySchema) schema.getBackingStore()).getFactoryTenant().newUNameIdxKey(); keyUNameIdx.setRequiredClusterId(keepObj.getRequiredClusterId()); keyUNameIdx.setRequiredTenantName(keepObj.getRequiredTenantName()); indexByUNameIdx.remove(keyUNameIdx); } if (allTenant != null) { allTenant.remove(keepObj.getPKey()); } members.remove(pkey); if (forgetSubObjects) { ((ICFSecuritySchemaObj) schema) .getTSecGroupTableObj() .forgetTSecGroupByTenantIdx(keepObj.getRequiredId()); } } }
public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException { CFSecurityXMsgSchemaMessageFormatter schemaFormatter = null; try { // Common XML Attributes String attrId = null; String attrRevision = null; // Tenant Attributes String attrClusterId = null; String attrTenantName = null; String attrCreatedAt = null; String attrCreatedBy = null; String attrUpdatedAt = null; String attrUpdatedBy = null; // Attribute Extraction String attrLocalName; int numAttrs; int idxAttr; final String S_ProcName = "startElement"; final String S_LocalName = "LocalName"; assert qName.equals("RqstTenantCreate"); CFSecurityXMsgRqstHandler xmsgRqstHandler = (CFSecurityXMsgRqstHandler) getParser(); if (xmsgRqstHandler == null) { throw CFLib.getDefaultExceptionFactory() .newNullArgumentException(getClass(), S_ProcName, 0, "getParser()"); } schemaFormatter = xmsgRqstHandler.getSchemaMessageFormatter(); ICFSecuritySchemaObj schemaObj = xmsgRqstHandler.getSchemaObj(); if (schemaObj == null) { throw CFLib.getDefaultExceptionFactory() .newNullArgumentException(getClass(), S_ProcName, 0, "getParser().getSchemaObj()"); } // Instantiate an edit buffer for the parsed information ICFSecurityTenantEditObj editBuff = (ICFSecurityTenantEditObj) schemaObj.getTenantTableObj().newInstance().beginEdit(); CFSecurityTenantBuff dataBuff = (CFSecurityTenantBuff) editBuff.getTenantBuff(); // Extract Attributes numAttrs = attrs.getLength(); for (idxAttr = 0; idxAttr < numAttrs; idxAttr++) { attrLocalName = attrs.getLocalName(idxAttr); if (attrLocalName.equals("Id")) { if (attrId != null) { throw CFLib.getDefaultExceptionFactory() .newUniqueIndexViolationException( getClass(), S_ProcName, S_LocalName, attrLocalName); } attrId = attrs.getValue(idxAttr); } else if (attrLocalName.equals("schemaLocation")) { // ignored } else if (attrLocalName.equals("Revision")) { if (attrRevision != null) { throw CFLib.getDefaultExceptionFactory() .newUniqueIndexViolationException( getClass(), S_ProcName, S_LocalName, attrLocalName); } attrRevision = attrs.getValue(idxAttr); } else if (attrLocalName.equals("CreatedAt")) { if (attrCreatedAt != null) { throw CFLib.getDefaultExceptionFactory() .newUniqueIndexViolationException( getClass(), S_ProcName, S_LocalName, attrLocalName); } attrCreatedAt = attrs.getValue(idxAttr); } else if (attrLocalName.equals("CreatedBy")) { if (attrCreatedBy != null) { throw CFLib.getDefaultExceptionFactory() .newUniqueIndexViolationException( getClass(), S_ProcName, S_LocalName, attrLocalName); } attrCreatedBy = attrs.getValue(idxAttr); } else if (attrLocalName.equals("UpdatedAt")) { if (attrUpdatedAt != null) { throw CFLib.getDefaultExceptionFactory() .newUniqueIndexViolationException( getClass(), S_ProcName, S_LocalName, attrLocalName); } attrUpdatedAt = attrs.getValue(idxAttr); } else if (attrLocalName.equals("UpdatedBy")) { if (attrUpdatedBy != null) { throw CFLib.getDefaultExceptionFactory() .newUniqueIndexViolationException( getClass(), S_ProcName, S_LocalName, attrLocalName); } attrUpdatedBy = attrs.getValue(idxAttr); } else if (attrLocalName.equals("ClusterId")) { if (attrClusterId != null) { throw CFLib.getDefaultExceptionFactory() .newUniqueIndexViolationException( getClass(), S_ProcName, S_LocalName, attrLocalName); } attrClusterId = attrs.getValue(idxAttr); } else if (attrLocalName.equals("TenantName")) { if (attrTenantName != null) { throw CFLib.getDefaultExceptionFactory() .newUniqueIndexViolationException( getClass(), S_ProcName, S_LocalName, attrLocalName); } attrTenantName = attrs.getValue(idxAttr); } else { throw CFLib.getDefaultExceptionFactory() .newUnrecognizedAttributeException( getClass(), S_ProcName, getParser().getLocationInfo(), attrLocalName); } } // Ensure that required attributes have values if ((attrClusterId == null) || (attrClusterId.length() <= 0)) { throw CFLib.getDefaultExceptionFactory() .newNullArgumentException(getClass(), S_ProcName, 0, "ClusterId"); } if ((attrId == null) || (attrId.length() <= 0)) { throw CFLib.getDefaultExceptionFactory() .newNullArgumentException(getClass(), S_ProcName, 0, "Id"); } if (attrTenantName == null) { throw CFLib.getDefaultExceptionFactory() .newNullArgumentException(getClass(), S_ProcName, 0, "TenantName"); } // Save named attributes to context CFLibXmlCoreContext curContext = getParser().getCurContext(); // Convert string attributes to native Java types // and apply the converted attributes to the editBuff. long natClusterId = Long.parseLong(attrClusterId); dataBuff.setRequiredClusterId(natClusterId); String natTenantName = attrTenantName; dataBuff.setRequiredTenantName(natTenantName); UUID createdBy = null; if (attrCreatedBy != null) { createdBy = UUID.fromString(attrCreatedBy); } Calendar createdAt = null; if (attrCreatedAt != null) { createdAt = CFLibXmlUtil.parseTimestamp(attrCreatedAt); } UUID updatedBy = null; if (attrUpdatedBy != null) { updatedBy = UUID.fromString(attrUpdatedBy); } Calendar updatedAt = null; if (attrUpdatedAt != null) { updatedAt = CFLibXmlUtil.parseTimestamp(attrUpdatedAt); } if (createdBy != null) { dataBuff.setCreatedByUserId(createdBy); } if (createdAt != null) { dataBuff.setCreatedAt(createdAt); } if (updatedBy != null) { dataBuff.setUpdatedByUserId(updatedBy); } if (updatedAt != null) { dataBuff.setUpdatedAt(updatedAt); } // Attempt the create editBuff.copyBuffToPKey(); // Allow for predefined ids ICFSecurityTenantObj created = (ICFSecurityTenantObj) editBuff.create(); editBuff.endEdit(); String response = schemaFormatter.formatRspnXmlPreamble() + "\n" + "\t" + CFSecurityXMsgTenantMessageFormatter.formatTenantRspnCreated( "\n\t\t\t", created.getTenantBuff()) + "\n" + schemaFormatter.formatRspnXmlPostamble(); ((CFSecurityXMsgRqstHandler) getParser()).appendResponse(response); } catch (RuntimeException e) { CFSecurityXMsgRqstHandler xmsgRqstHandler = ((CFSecurityXMsgRqstHandler) getParser()); schemaFormatter = xmsgRqstHandler.getSchemaMessageFormatter(); String response = schemaFormatter.formatRspnXmlPreamble() + "\n" + "\t" + CFSecurityXMsgSchemaMessageFormatter.formatRspnException("\n\t\t\t", e) + "\n" + schemaFormatter.formatRspnXmlPostamble(); xmsgRqstHandler.resetResponse(); xmsgRqstHandler.appendResponse(response); xmsgRqstHandler.setCaughtException(true); } catch (Error e) { CFSecurityXMsgRqstHandler xmsgRqstHandler = ((CFSecurityXMsgRqstHandler) getParser()); schemaFormatter = xmsgRqstHandler.getSchemaMessageFormatter(); String response = schemaFormatter.formatRspnXmlPreamble() + "\n" + "\t" + CFSecurityXMsgSchemaMessageFormatter.formatRspnException("\n\t\t\t", e) + "\n" + schemaFormatter.formatRspnXmlPostamble(); xmsgRqstHandler.resetResponse(); xmsgRqstHandler.appendResponse(response); xmsgRqstHandler.setCaughtException(true); } }
public ICFSecurityTenantObj realizeTenant(ICFSecurityTenantObj Obj) { ICFSecurityTenantObj obj = Obj; CFSecurityTenantPKey pkey = obj.getPKey(); ICFSecurityTenantObj keepObj = null; if (members.containsKey(pkey) && (null != members.get(pkey))) { ICFSecurityTenantObj existingObj = members.get(pkey); keepObj = existingObj; /* * We always rebind the data because if we're being called, some index has * been updated and is refreshing it's data, which may or may not have changed */ // Detach object from alternate and duplicate indexes, leave PKey alone if (indexByClusterIdx != null) { CFSecurityTenantByClusterIdxKey keyClusterIdx = ((ICFSecuritySchema) schema.getBackingStore()).getFactoryTenant().newClusterIdxKey(); keyClusterIdx.setRequiredClusterId(keepObj.getRequiredClusterId()); Map<CFSecurityTenantPKey, ICFSecurityTenantObj> mapClusterIdx = indexByClusterIdx.get(keyClusterIdx); if (mapClusterIdx != null) { mapClusterIdx.remove(keepObj.getPKey()); } } if (indexByUNameIdx != null) { CFSecurityTenantByUNameIdxKey keyUNameIdx = ((ICFSecuritySchema) schema.getBackingStore()).getFactoryTenant().newUNameIdxKey(); keyUNameIdx.setRequiredClusterId(keepObj.getRequiredClusterId()); keyUNameIdx.setRequiredTenantName(keepObj.getRequiredTenantName()); indexByUNameIdx.remove(keyUNameIdx); } keepObj.setBuff(Obj.getBuff()); // Attach new object to alternate and duplicate indexes -- PKey stay stable if (indexByClusterIdx != null) { CFSecurityTenantByClusterIdxKey keyClusterIdx = ((ICFSecuritySchema) schema.getBackingStore()).getFactoryTenant().newClusterIdxKey(); keyClusterIdx.setRequiredClusterId(keepObj.getRequiredClusterId()); Map<CFSecurityTenantPKey, ICFSecurityTenantObj> mapClusterIdx = indexByClusterIdx.get(keyClusterIdx); if (mapClusterIdx != null) { mapClusterIdx.put(keepObj.getPKey(), keepObj); } } if (indexByUNameIdx != null) { CFSecurityTenantByUNameIdxKey keyUNameIdx = ((ICFSecuritySchema) schema.getBackingStore()).getFactoryTenant().newUNameIdxKey(); keyUNameIdx.setRequiredClusterId(keepObj.getRequiredClusterId()); keyUNameIdx.setRequiredTenantName(keepObj.getRequiredTenantName()); indexByUNameIdx.put(keyUNameIdx, keepObj); } if (allTenant != null) { allTenant.put(keepObj.getPKey(), keepObj); } } else { keepObj = obj; keepObj.setIsNew(false); // Attach new object to PKey, all, alternate, and duplicate indexes members.put(keepObj.getPKey(), keepObj); if (allTenant != null) { allTenant.put(keepObj.getPKey(), keepObj); } if (indexByClusterIdx != null) { CFSecurityTenantByClusterIdxKey keyClusterIdx = ((ICFSecuritySchema) schema.getBackingStore()).getFactoryTenant().newClusterIdxKey(); keyClusterIdx.setRequiredClusterId(keepObj.getRequiredClusterId()); Map<CFSecurityTenantPKey, ICFSecurityTenantObj> mapClusterIdx = indexByClusterIdx.get(keyClusterIdx); if (mapClusterIdx != null) { mapClusterIdx.put(keepObj.getPKey(), keepObj); } } if (indexByUNameIdx != null) { CFSecurityTenantByUNameIdxKey keyUNameIdx = ((ICFSecuritySchema) schema.getBackingStore()).getFactoryTenant().newUNameIdxKey(); keyUNameIdx.setRequiredClusterId(keepObj.getRequiredClusterId()); keyUNameIdx.setRequiredTenantName(keepObj.getRequiredTenantName()); indexByUNameIdx.put(keyUNameIdx, keepObj); } } return (keepObj); }
public List<ICFSecurityTenantObj> readTenantByClusterIdx(long ClusterId, boolean forceRead) { final String S_ProcName = "readTenantByClusterIdx"; CFSecurityTenantByClusterIdxKey key = ((ICFSecuritySchema) schema.getBackingStore()).getFactoryTenant().newClusterIdxKey(); key.setRequiredClusterId(ClusterId); Map<CFSecurityTenantPKey, ICFSecurityTenantObj> dict; if (indexByClusterIdx == null) { indexByClusterIdx = new HashMap< CFSecurityTenantByClusterIdxKey, Map<CFSecurityTenantPKey, ICFSecurityTenantObj>>(); } if ((!forceRead) && indexByClusterIdx.containsKey(key)) { dict = indexByClusterIdx.get(key); } else { dict = new HashMap<CFSecurityTenantPKey, ICFSecurityTenantObj>(); // Allow other threads to dirty-read while we're loading indexByClusterIdx.put(key, dict); ICFSecurityTenantObj obj; CFSecurityTenantBuff[] buffList = ((ICFSecuritySchema) schema.getBackingStore()) .getTableTenant() .readDerivedByClusterIdx(schema.getAuthorization(), ClusterId); CFSecurityTenantBuff buff; for (int idx = 0; idx < buffList.length; idx++) { buff = buffList[idx]; obj = schema.getTenantTableObj().newInstance(); obj.setPKey(((ICFSecuritySchema) schema.getBackingStore()).getFactoryTenant().newPKey()); obj.setBuff(buff); ICFSecurityTenantObj realized = (ICFSecurityTenantObj) obj.realize(); } } Comparator<ICFSecurityTenantObj> cmp = new Comparator<ICFSecurityTenantObj>() { public int compare(ICFSecurityTenantObj lhs, ICFSecurityTenantObj rhs) { if (lhs == null) { if (rhs == null) { return (0); } else { return (-1); } } else if (rhs == null) { return (1); } else { CFSecurityTenantPKey lhsPKey = lhs.getPKey(); CFSecurityTenantPKey rhsPKey = rhs.getPKey(); int ret = lhsPKey.compareTo(rhsPKey); return (ret); } } }; int len = dict.size(); ICFSecurityTenantObj arr[] = new ICFSecurityTenantObj[len]; Iterator<ICFSecurityTenantObj> valIter = dict.values().iterator(); int idx = 0; while ((idx < len) && valIter.hasNext()) { arr[idx++] = valIter.next(); } if (idx < len) { throw CFLib.getDefaultExceptionFactory() .newArgumentUnderflowException(getClass(), S_ProcName, 0, "idx", idx, len); } else if (valIter.hasNext()) { throw CFLib.getDefaultExceptionFactory() .newArgumentOverflowException(getClass(), S_ProcName, 0, "idx", idx, len); } Arrays.sort(arr, cmp); ArrayList<ICFSecurityTenantObj> arrayList = new ArrayList<ICFSecurityTenantObj>(len); for (idx = 0; idx < len; idx++) { arrayList.add(arr[idx]); } List<ICFSecurityTenantObj> sortedList = arrayList; return (sortedList); }
public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException { try { // Common XML Attributes String attrId = null; String attrRevision = null; // Tenant Attributes String attrClusterId = null; String attrTenantName = null; String attrCreatedAt = null; String attrCreatedBy = null; String attrUpdatedAt = null; String attrUpdatedBy = null; // Attribute Extraction String attrLocalName; int numAttrs; int idxAttr; final String S_ProcName = "startElement"; final String S_LocalName = "LocalName"; assert qName.equals("Tenant"); CFSecurityXMsgRspnHandler xmsgRspnHandler = (CFSecurityXMsgRspnHandler) getParser(); if (xmsgRspnHandler == null) { throw CFLib.getDefaultExceptionFactory() .newNullArgumentException(getClass(), S_ProcName, 0, "getParser()"); } ICFSecuritySchemaObj schemaObj = xmsgRspnHandler.getSchemaObj(); if (schemaObj == null) { throw CFLib.getDefaultExceptionFactory() .newNullArgumentException(getClass(), S_ProcName, 0, "getParser().getSchemaObj()"); } // Extract Attributes numAttrs = attrs.getLength(); for (idxAttr = 0; idxAttr < numAttrs; idxAttr++) { attrLocalName = attrs.getLocalName(idxAttr); if (attrLocalName.equals("Id")) { if (attrId != null) { throw CFLib.getDefaultExceptionFactory() .newUniqueIndexViolationException( getClass(), S_ProcName, S_LocalName, attrLocalName); } attrId = attrs.getValue(idxAttr); } else if (attrLocalName.equals("Revision")) { if (attrRevision != null) { throw CFLib.getDefaultExceptionFactory() .newUniqueIndexViolationException( getClass(), S_ProcName, S_LocalName, attrLocalName); } attrRevision = attrs.getValue(idxAttr); } else if (attrLocalName.equals("CreatedAt")) { if (attrCreatedAt != null) { throw CFLib.getDefaultExceptionFactory() .newUniqueIndexViolationException( getClass(), S_ProcName, S_LocalName, attrLocalName); } attrCreatedAt = attrs.getValue(idxAttr); } else if (attrLocalName.equals("CreatedBy")) { if (attrCreatedBy != null) { throw CFLib.getDefaultExceptionFactory() .newUniqueIndexViolationException( getClass(), S_ProcName, S_LocalName, attrLocalName); } attrCreatedBy = attrs.getValue(idxAttr); } else if (attrLocalName.equals("UpdatedAt")) { if (attrUpdatedAt != null) { throw CFLib.getDefaultExceptionFactory() .newUniqueIndexViolationException( getClass(), S_ProcName, S_LocalName, attrLocalName); } attrUpdatedAt = attrs.getValue(idxAttr); } else if (attrLocalName.equals("UpdatedBy")) { if (attrUpdatedBy != null) { throw CFLib.getDefaultExceptionFactory() .newUniqueIndexViolationException( getClass(), S_ProcName, S_LocalName, attrLocalName); } attrUpdatedBy = attrs.getValue(idxAttr); } else if (attrLocalName.equals("ClusterId")) { if (attrClusterId != null) { throw CFLib.getDefaultExceptionFactory() .newUniqueIndexViolationException( getClass(), S_ProcName, S_LocalName, attrLocalName); } attrClusterId = attrs.getValue(idxAttr); } else if (attrLocalName.equals("TenantName")) { if (attrTenantName != null) { throw CFLib.getDefaultExceptionFactory() .newUniqueIndexViolationException( getClass(), S_ProcName, S_LocalName, attrLocalName); } attrTenantName = attrs.getValue(idxAttr); } else if (attrLocalName.equals("schemaLocation")) { // ignored } else { throw CFLib.getDefaultExceptionFactory() .newUnrecognizedAttributeException( getClass(), S_ProcName, getParser().getLocationInfo(), attrLocalName); } } // Ensure that required attributes have values if ((attrClusterId == null) || (attrClusterId.length() <= 0)) { throw CFLib.getDefaultExceptionFactory() .newNullArgumentException(getClass(), S_ProcName, 0, "ClusterId"); } if ((attrId == null) || (attrId.length() <= 0)) { throw CFLib.getDefaultExceptionFactory() .newNullArgumentException(getClass(), S_ProcName, 0, "Id"); } if (attrTenantName == null) { throw CFLib.getDefaultExceptionFactory() .newNullArgumentException(getClass(), S_ProcName, 0, "TenantName"); } // Save named attributes to context CFLibXmlCoreContext curContext = xmsgRspnHandler.getCurContext(); // Convert string attributes to native Java types long natClusterId = Long.parseLong(attrClusterId); long natId = Long.parseLong(attrId); String natTenantName = attrTenantName; int natRevision = Integer.parseInt(attrRevision); UUID createdBy = null; if (attrCreatedBy != null) { createdBy = UUID.fromString(attrCreatedBy); } Calendar createdAt = null; if (attrCreatedAt != null) { createdAt = CFLibXmlUtil.parseTimestamp(attrCreatedAt); } UUID updatedBy = null; if (attrUpdatedBy != null) { updatedBy = UUID.fromString(attrUpdatedBy); } Calendar updatedAt = null; if (attrUpdatedAt != null) { updatedAt = CFLibXmlUtil.parseTimestamp(attrUpdatedAt); } // Get the parent context CFLibXmlCoreContext parentContext = curContext.getPrevContext(); // Instantiate a buffer for the parsed information ICFSecurityTenantObj obj = (ICFSecurityTenantObj) (schemaObj.getTenantTableObj().newInstance()); CFSecurityTenantBuff dataBuff = obj.getTenantBuff(); dataBuff.setRequiredClusterId(natClusterId); dataBuff.setRequiredId(natId); dataBuff.setRequiredTenantName(natTenantName); dataBuff.setRequiredRevision(natRevision); if (createdBy != null) { dataBuff.setCreatedByUserId(createdBy); } if (createdAt != null) { dataBuff.setCreatedAt(createdAt); } if (updatedBy != null) { dataBuff.setUpdatedByUserId(updatedBy); } if (updatedAt != null) { dataBuff.setUpdatedAt(updatedAt); } obj.copyBuffToPKey(); @SuppressWarnings("unchecked") List<ICFSecurityTenantObj> list = (List<ICFSecurityTenantObj>) xmsgRspnHandler.getListOfObjects(); ICFSecurityTenantObj realized = (ICFSecurityTenantObj) obj.realize(); xmsgRspnHandler.setLastObjectProcessed(realized); if (list != null) { list.add(realized); } } catch (RuntimeException e) { throw new RuntimeException( "Near " + getParser().getLocationInfo() + ": Caught and rethrew " + e.getClass().getName() + " - " + e.getMessage(), e); } catch (Error e) { throw new Error( "Near " + getParser().getLocationInfo() + ": Caught and rethrew " + e.getClass().getName() + " - " + e.getMessage(), e); } }
public List<ICFSecurityTenantObj> readAllTenant(boolean forceRead) { final String S_ProcName = "readAllTenant"; if ((allTenant == null) || forceRead) { Map<CFSecurityTenantPKey, ICFSecurityTenantObj> map = new HashMap<CFSecurityTenantPKey, ICFSecurityTenantObj>(); allTenant = map; CFSecurityTenantBuff[] buffList = ((ICFSecuritySchema) schema.getBackingStore()) .getTableTenant() .readAllDerived(schema.getAuthorization()); CFSecurityTenantBuff buff; ICFSecurityTenantObj obj; for (int idx = 0; idx < buffList.length; idx++) { buff = buffList[idx]; obj = newInstance(); obj.setPKey(((ICFSecuritySchema) schema.getBackingStore()).getFactoryTenant().newPKey()); obj.setBuff(buff); ICFSecurityTenantObj realized = (ICFSecurityTenantObj) obj.realize(); } } Comparator<ICFSecurityTenantObj> cmp = new Comparator<ICFSecurityTenantObj>() { public int compare(ICFSecurityTenantObj lhs, ICFSecurityTenantObj rhs) { if (lhs == null) { if (rhs == null) { return (0); } else { return (-1); } } else if (rhs == null) { return (1); } else { CFSecurityTenantPKey lhsPKey = lhs.getPKey(); CFSecurityTenantPKey rhsPKey = rhs.getPKey(); int ret = lhsPKey.compareTo(rhsPKey); return (ret); } } }; int len = allTenant.size(); ICFSecurityTenantObj arr[] = new ICFSecurityTenantObj[len]; Iterator<ICFSecurityTenantObj> valIter = allTenant.values().iterator(); int idx = 0; while ((idx < len) && valIter.hasNext()) { arr[idx++] = valIter.next(); } if (idx < len) { throw CFLib.getDefaultExceptionFactory() .newArgumentUnderflowException(getClass(), S_ProcName, 0, "idx", idx, len); } else if (valIter.hasNext()) { throw CFLib.getDefaultExceptionFactory() .newArgumentOverflowException(getClass(), S_ProcName, 0, "idx", idx, len); } Arrays.sort(arr, cmp); ArrayList<ICFSecurityTenantObj> arrayList = new ArrayList<ICFSecurityTenantObj>(len); for (idx = 0; idx < len; idx++) { arrayList.add(arr[idx]); } List<ICFSecurityTenantObj> sortedList = arrayList; return (sortedList); }