/** * Requires that Table to be done. * * @param rSession the rets session * @param hSession the hibernate session * @exception HibernateException if an error occurs */ private void doValidationLookup(Session hSession) throws HibernateException { MetadataTable tValidationLookups = getMetadataTable(MetadataTable.VALIDATION_LOOKUP); Iterator i = mResources.values().iterator(); while (i.hasNext()) { Resource resource = (Resource) i.next(); Set hValidationLookups = new HashSet(); String resourcePath = resource.getPath(); List validationLookups = tValidationLookups.getDataRows(resourcePath); if (validationLookups != null) { Iterator j = validationLookups.iterator(); while (j.hasNext()) { Metadata md = (Metadata) j.next(); ValidationLookup hvl = new ValidationLookup(); hvl.setResource(resource); hvl.setValidationLookupName(md.getAttribute("ValidationLookupName")); hvl.setParent1Field(md.getAttribute("Parent1Field")); hvl.setParent2Field(md.getAttribute("Parent2Field")); hvl.updateLevel(); hSession.save(hvl); hValidationLookups.add(hvl); mValidationLookups.put(hvl.getPath(), hvl); } resource.setValidationLookups(hValidationLookups); hSession.saveOrUpdate(resource); } } }
private void doValidationLookupType(Session hSession) throws HibernateException { MetadataTable tValidationLookupTypes = getMetadataTable(MetadataTable.VALIDATION_LOOKUP_TYPE); Iterator i = mValidationLookups.values().iterator(); while (i.hasNext()) { ValidationLookup vl = (ValidationLookup) i.next(); Set hValdationLookupTypes = new HashSet(); List validationLookupTypes = tValidationLookupTypes.getDataRows(vl.getPath()); if (validationLookupTypes != null) { Iterator j = validationLookupTypes.iterator(); while (j.hasNext()) { Metadata md = (Metadata) j.next(); ValidationLookupType vlt = new ValidationLookupType(); vlt.setValidationLookup(vl); vlt.setValidText(md.getAttribute("ValidText")); vlt.setParent1Value(md.getAttribute("Parent1Value")); vlt.setParent2Value(md.getAttribute("Parent2Value")); vlt.updateLevel(); hSession.save(vlt); hValdationLookupTypes.add(vlt); } } vl.setValidationLookupTypes(hValdationLookupTypes); hSession.saveOrUpdate(vl); } }
private void doValidationExpression(Session hSession) throws HibernateException { MetadataTable tValidationExpressions = getMetadataTable(MetadataTable.VALIDATION_EXPRESSION); Iterator i = mResources.values().iterator(); while (i.hasNext()) { Resource resource = (Resource) i.next(); Set hValidationExpressions = new HashSet(); List validationExpressions = tValidationExpressions.getDataRows(resource.getPath()); if (validationExpressions != null) { Iterator j = validationExpressions.iterator(); while (j.hasNext()) { Metadata md = (Metadata) j.next(); ValidationExpression ve = new ValidationExpression(); ve.setResource(resource); ve.setValidationExpressionID(md.getAttribute("ValidationExpressionID")); ve.setValidationExpressionType( ValidationExpressionTypeEnum.fromString(md.getAttribute("ValidationExpressionType"))); ve.setValue(md.getAttribute("value")); ve.updateLevel(); hSession.save(ve); hValidationExpressions.add(ve); mValidationExpressions.put(ve.getPath(), ve); } } resource.setValidationExpressions(hValidationExpressions); hSession.saveOrUpdate(resource); } }
private void doValidationExternal(Session hSession) throws HibernateException { MetadataTable tValidationExternals = getMetadataTable(MetadataTable.VALIDATION_EXTERNAL); Iterator i = mResources.values().iterator(); while (i.hasNext()) { Resource resource = (Resource) i.next(); Set hValidationExternals = new HashSet(); List validationExternals = tValidationExternals.getDataRows(resource.getPath()); if (validationExternals != null) { Iterator j = validationExternals.iterator(); while (j.hasNext()) { Metadata md = (Metadata) j.next(); ValidationExternal hValidationExternal = new ValidationExternal(); hValidationExternal.setResource(resource); hValidationExternal.setValidationExternalName(md.getAttribute("ValidationExternalName")); // get the search class String path = md.getAttribute("SearchResource") + ":" + md.getAttribute("SearchClass"); MClass clazz = (MClass) mClasses.get(path); hValidationExternal.setSearchClass(clazz); hValidationExternal.updateLevel(); hSession.save(hValidationExternal); hValidationExternals.add(hValidationExternal); mValidationExternals.put(hValidationExternal.getPath(), hValidationExternal); } } resource.setValidationExternals(hValidationExternals); hSession.saveOrUpdate(resource); } }
private void doUpdateHelp(Session hSession) throws HibernateException { MetadataTable tUpdateHelps = getMetadataTable(MetadataTable.UPDATE_HELP); Iterator i = mResources.values().iterator(); while (i.hasNext()) { Resource resource = (Resource) i.next(); Set hUpdateHelps = new HashSet(); List updateHelps = tUpdateHelps.getDataRows(resource.getPath()); if (updateHelps != null) { Iterator j = updateHelps.iterator(); while (j.hasNext()) { Metadata md = (Metadata) j.next(); UpdateHelp hUpdateHelp = new UpdateHelp(); hUpdateHelp.setResource(resource); hUpdateHelp.setUpdateHelpID(md.getAttribute("UpdateHelpID")); hUpdateHelp.setValue(md.getAttribute("Value")); hUpdateHelp.updateLevel(); hSession.save(hUpdateHelp); hUpdateHelps.add(hUpdateHelp); mUpdateHelps.put(hUpdateHelp.getPath(), hUpdateHelp); } } resource.setUpdateHelps(hUpdateHelps); hSession.saveOrUpdate(resource); } }
private void doObjects(Session hSession) throws HibernateException { MetadataTable tObject = getMetadataTable(MetadataTable.OBJECT); Iterator i = mResources.values().iterator(); while (i.hasNext()) { Resource resource = (Resource) i.next(); Set hObjects = new HashSet(); List objects = tObject.getDataRows(resource.getPath()); if (objects != null) { Iterator j = objects.iterator(); while (j.hasNext()) { Metadata md = (Metadata) j.next(); MObject hObject = new MObject(); hObject.setResource(resource); hObject.setObjectType(ObjectTypeEnum.fromString(md.getAttribute("ObjectType"))); hObject.setMimeType(md.getAttribute("MimeType")); hObject.setVisibleName(md.getAttribute("VisibleName")); hObject.setDescription(StringUtils.substring(md.getAttribute("Description"), 0, 64)); // Should we have an updateLevel? hSession.save(hObject); hObjects.add(hObject); } } resource.setObjects(hObjects); hSession.saveOrUpdate(resource); } }
private void doUpdate(Session hSession) throws HibernateException { MetadataTable tUpdates = getMetadataTable(MetadataTable.UPDATE); Iterator i = mClasses.values().iterator(); while (i.hasNext()) { MClass clazz = (MClass) i.next(); Set hUpdates = new HashSet(); List updates = tUpdates.getDataRows(clazz.getPath()); if (updates != null) { Iterator j = updates.iterator(); while (j.hasNext()) { Metadata md = (Metadata) j.next(); Update hUpdate = new Update(); hUpdate.setMClass(clazz); hUpdate.setUpdateName(md.getAttribute("UpdateName")); hUpdate.setDescription(md.getAttribute("Description")); hUpdate.setKeyField(md.getAttribute("KeyField")); hUpdate.updateLevel(); hSession.save(hUpdate); hUpdates.add(hUpdate); mUpdates.put(hUpdate.getPath(), hUpdate); } } clazz.setUpdates(hUpdates); hSession.saveOrUpdate(clazz); } }
private void doResource(Session hSession, MSystem hSystem) throws HibernateException { MetadataTable tResource = getMetadataTable(MetadataTable.RESOURCE); Set hResources = new HashSet(); List resources = tResource.getDataRows(""); Iterator i = resources.iterator(); while (i.hasNext()) { Metadata md = (Metadata) i.next(); Resource hResource = new Resource(); hResource.setSystem(hSystem); String resourceID = md.getAttribute("ResourceID"); hResource.setResourceID(resourceID); hResource.setStandardName( ResourceStandardNameEnum.fromString(md.getAttribute("StandardName"))); hResource.setVisibleName(md.getAttribute("VisibleName")); hResource.setDescription(md.getAttribute("Description")); hResource.setKeyField(md.getAttribute("KeyField")); hResource.updateLevel(); hSession.save(hResource); hResources.add(hResource); mResources.put(hResource.getPath(), hResource); } hSystem.setResources(hResources); hSession.saveOrUpdate(hSystem); }
/** * Meant to be called only from do Lookup. * * @param rSession the rets session * @param hSession the hibernate session * @exception HibernateException if an error occurs */ private void doLookupTypes(Session hSession) throws HibernateException { MetadataTable tLookupTypes = getMetadataTable(MetadataTable.LOOKUP_TYPE); Iterator i = mLookups.values().iterator(); while (i.hasNext()) { Lookup lookup = (Lookup) i.next(); List lookupTypes = tLookupTypes.getDataRows(lookup.getPath()); Set hLookupTypes = new HashSet(); if (lookupTypes != null) { Iterator j = lookupTypes.iterator(); while (j.hasNext()) { Metadata md = (Metadata) j.next(); LookupType hLookupType = new LookupType(); hLookupType.setLookup(lookup); hLookupType.setLongValue(md.getAttribute("LongValue")); hLookupType.setShortValue(md.getAttribute("ShortValue")); hLookupType.setValue(md.getAttribute("Value")); hLookupType.updateLevel(); hSession.save(hLookupType); hLookupTypes.add(hLookupType); } } lookup.setLookupTypes(hLookupTypes); hSession.saveOrUpdate(lookup); } }
private void doLookup(Session hSession) throws HibernateException { MetadataTable tLookup = getMetadataTable(MetadataTable.LOOKUP); Iterator i = mResources.values().iterator(); while (i.hasNext()) { Resource resource = (Resource) i.next(); Set hLookups = new HashSet(); List lookups = tLookup.getDataRows(resource.getPath()); if (lookups != null) { Iterator j = lookups.iterator(); while (j.hasNext()) { Metadata md = (Metadata) j.next(); Lookup hLookup = new Lookup(); hLookup.setResource(resource); String lookupName = md.getAttribute("LookupName"); hLookup.setLookupName(lookupName); hLookup.setVisibleName(md.getAttribute("VisibleName")); hLookup.updateLevel(); hSession.save(hLookup); // doLookupTypes(hLookup, rSession, hSession); hLookups.add(hLookup); mLookups.put(hLookup.getPath(), hLookup); } } resource.setLookups(hLookups); hSession.saveOrUpdate(resource); } }
private void doEditMask(Session hSession) throws HibernateException { MetadataTable tEditMask = getMetadataTable(MetadataTable.EDITMASK); Iterator i = mResources.values().iterator(); while (i.hasNext()) { Resource resource = (Resource) i.next(); Set hEditMasks = new HashSet(); List editMasks = tEditMask.getDataRows(resource.getPath()); if (editMasks != null) { Iterator j = editMasks.iterator(); while (j.hasNext()) { Metadata md = (Metadata) j.next(); EditMask hEditMask = new EditMask(); hEditMask.setResource(resource); hEditMask.setEditMaskID(md.getAttribute("EditMaskID")); hEditMask.setValue(md.getAttribute("Value")); hEditMask.updateLevel(); hSession.save(hEditMask); hEditMasks.add(hEditMask); mEditMasks.put(hEditMask.getPath(), hEditMask); } } resource.setEditMasks(hEditMasks); hSession.saveOrUpdate(resource); } }
public void addAdmin(Admin admin) throws DBException { Session session; Transaction tx = null; try { session = HibernateSessionFactory.currentSession(); tx = session.beginTransaction(); session.saveOrUpdate(admin); tx.commit(); } catch (HibernateException e) { try { tx.rollback(); } catch (HibernateException e1) { e1.printStackTrace(); } e.printStackTrace(); throw new DBException("保存对象失败!"); } finally { try { HibernateSessionFactory.closeSession(); } catch (HibernateException e) { e.printStackTrace(); } } }
private void doForeignKey(Session hSession, MSystem hSystem) throws HibernateException { MetadataTable tForeignKeys = getMetadataTable(MetadataTable.FOREIGN_KEYS); Set hForeignKeys = new HashSet(); List foreignKeys = tForeignKeys.getDataRows(""); if (foreignKeys != null) { Iterator i = foreignKeys.iterator(); while (i.hasNext()) { Metadata md = (Metadata) i.next(); ForeignKey hFk = new ForeignKey(); hFk.setSystem(hSystem); hFk.setForeignKeyID(md.getAttribute("ForeignKeyID")); String path[] = new String[3]; path[0] = md.getAttribute("ParentResourceID"); path[1] = md.getAttribute("ParentClassID"); path[2] = md.getAttribute("ParentSystemName"); String tablePath = StringUtils.join(path, ":"); Table table = (Table) mTables.get(tablePath); hFk.setParentTable(table); path[0] = md.getAttribute("ChildResourceID"); path[1] = md.getAttribute("ChildClassID"); path[2] = md.getAttribute("ChildSystemName"); tablePath = StringUtils.join(path, ":"); table = (Table) mTables.get(tablePath); hFk.setChildTable(table); if (table == null) { LOG.error("table is null for path: " + tablePath); } hSession.save(hFk); hForeignKeys.add(hFk); } } hSystem.setForeignKeys(hForeignKeys); hSession.saveOrUpdate(hSystem); }
private void doClasses(Session hSession) throws HibernateException { MetadataTable tClass = getMetadataTable(MetadataTable.CLASS); Iterator i = mResources.values().iterator(); while (i.hasNext()) { Resource resource = (Resource) i.next(); Set hClasses = new HashSet(); List classes = tClass.getDataRows(resource.getPath()); Iterator j = classes.iterator(); while (j.hasNext()) { Metadata md = (Metadata) j.next(); MClass hClass = new MClass(); hClass.setResource(resource); String className = md.getAttribute("ClassName"); hClass.setClassName(className); hClass.setStandardName(ClassStandardNameEnum.fromString(md.getAttribute("StandardName"))); hClass.setVisibleName(md.getAttribute("VisibleName")); hClass.setDescription(md.getAttribute("Description")); StringBuffer tmp = new StringBuffer("rets_"); tmp.append(resource.getResourceID()).append("_"); tmp.append(hClass.getClassName()); hClass.setDbTable(tmp.toString()); hClass.updateLevel(); hSession.save(hClass); hClasses.add(hClass); mClasses.put(hClass.getPath(), hClass); } resource.setClasses(hClasses); hSession.saveOrUpdate(resource); } }
public void doUpdateType(Session hSession) throws HibernateException { MetadataTable tUpdateTypes = getMetadataTable(MetadataTable.UPDATE_TYPE); Iterator i = mUpdates.values().iterator(); while (i.hasNext()) { Update update = (Update) i.next(); Set hUpdateTypes = new HashSet(); List updateTypes = tUpdateTypes.getDataRows(update.getPath()); if (updateTypes != null) { Iterator j = updateTypes.iterator(); while (j.hasNext()) { Metadata md = (Metadata) j.next(); UpdateType updateType = new UpdateType(); updateType.setUpdate(update); String level = update.getLevel(); String systemName = md.getAttribute("SystemName"); String tablePath = level + ":" + systemName; Table table = (Table) mTables.get(tablePath); updateType.setTable(table); // Hack to get around metadata bug if (table == null) { LOG.error("null table for path: " + tablePath); System.exit(1); } updateType.setSequence(Integer.parseInt(md.getAttribute("Sequence"))); String joinedAttributes = md.getAttribute("Attributes"); String attributes[] = StringUtils.split(joinedAttributes, ","); Set attributeSet = new HashSet(); for (int c = 0; c < attributes.length; c++) { attributeSet.add(UpdateTypeAttributeEnum.fromInt(Integer.parseInt(attributes[c]))); } updateType.setAttributes(attributeSet); updateType.setDefault(md.getAttribute("Default")); String valExp[] = StringUtils.split(md.getAttribute("ValidationExpressionID"), ","); Set valExpSet = new HashSet(); String resourcePath = update.getMClass().getResource().getPath(); for (int c = 0; c < valExp.length; c++) { String vePath = resourcePath + ":" + valExp[c]; ValidationExpression ve = (ValidationExpression) mValidationExpressions.get(vePath); valExpSet.add(ve); } updateType.setValidationExpressions(valExpSet); String updateHelpPath = resourcePath + ":" + md.getAttribute("UpdateHelpID"); updateType.setUpdateHelp((UpdateHelp) mUpdateHelps.get(updateHelpPath)); String vlPath = resourcePath + ":" + md.getAttribute("ValdiationLookupName"); updateType.setValidationLookup((ValidationLookup) mValidationLookups.get(vlPath)); String vePath = resourcePath + ":" + md.getAttribute("ValdationExternalName"); updateType.setValidationExternal((ValidationExternal) mValidationExternals.get(vePath)); hSession.save(updateType); hUpdateTypes.add(updateType); } } update.setUpdateTypes(hUpdateTypes); hSession.saveOrUpdate(update); } }
private void doTable(Session hSession) throws HibernateException { MetadataTable tTables = getMetadataTable(MetadataTable.TABLE); Iterator i = mClasses.values().iterator(); while (i.hasNext()) { MClass hClass = (MClass) i.next(); Set hTables = new HashSet(); List tables = tTables.getDataRows(hClass.getPath()); if (tables != null) { Iterator j = tables.iterator(); while (j.hasNext()) { Metadata md = (Metadata) j.next(); Table hTable = new Table(); hTable.setMClass(hClass); hTable.setSystemName(md.getAttribute("SystemName")); String standardName = md.getAttribute("StandardName"); TableStandardName tsn = lookupTableStandardName(standardName); if (tsn == null) { if (!standardName.equals("")) { tsn = new TableStandardName(standardName); mTableStandardNames.put(standardName, tsn); hSession.save(tsn); } } hTable.setStandardName(tsn); hTable.setLongName(md.getAttribute("LongName")); String tmp = md.getAttribute("DbName"); if (tmp.startsWith("r_")) { hTable.setDbName(StringUtils.substring(tmp, 0, 10)); } else { hTable.setDbName(StringUtils.substring("r_" + tmp, 0, 10)); } hTable.setShortName(md.getAttribute("ShortName")); hTable.setMaximumLength(Integer.parseInt(md.getAttribute("MaximumLength"))); hTable.setDataType(DataTypeEnum.fromString(md.getAttribute("DataType"))); hTable.setPrecision(Integer.parseInt(md.getAttribute("Precision"))); hTable.setSearchable(boolValue(md.getAttribute("Searchable"))); hTable.setInterpretation( InterpretationEnum.fromString(md.getAttribute("Interpretation"))); hTable.setAlignment(AlignmentEnum.fromString(md.getAttribute("Alignment"))); hTable.setUseSeparator(boolValue(md.getAttribute("UseSeparator"))); String editMasksJoined = md.getAttribute("EditMaskID"); String resourcePath = hClass.getResource().getPath(); String path = null; Set hEditMasks = new HashSet(); if (editMasksJoined != null) { String editMasks[] = StringUtils.split(editMasksJoined, ","); for (int c = 0; c < editMasks.length; c++) { path = resourcePath + ":" + StringUtils.trimToEmpty(editMasks[c]); EditMask em = (EditMask) mEditMasks.get(path); hEditMasks.add(em); if (em == null) { LOG.error("edit mask null for path: " + path); } } } hTable.setEditMasks(hEditMasks); String lookupName = md.getAttribute("LookupName"); path = resourcePath + ":" + lookupName; Lookup lookup = (Lookup) mLookups.get(path); hTable.setLookup(lookup); hTable.setMaxSelect(Integer.parseInt(md.getAttribute("MaxSelect"))); hTable.setUnits(UnitEnum.fromString(md.getAttribute("Units"))); hTable.setIndex(Integer.parseInt(md.getAttribute("Index"))); hTable.setMinimum(Integer.parseInt(md.getAttribute("Minimum"))); hTable.setMaximum(Integer.parseInt(md.getAttribute("Maximum"))); hTable.setDefault(Integer.parseInt(md.getAttribute("Default"))); hTable.setRequired(Integer.parseInt(md.getAttribute("Required"))); String searchHelpID = md.getAttribute("SearchHelpID"); path = resourcePath + ":" + searchHelpID; SearchHelp searchHelp = (SearchHelp) mSearchHelps.get(path); hTable.setSearchHelp(searchHelp); // String = md.getAttribute("unique"); hTable.setUnique(boolValue(md.getAttribute("Unique"))); hTable.updateLevel(); hSession.save(hTable); hTables.add(hTable); mTables.put(hTable.getPath(), hTable); } hClass.setTables(hTables); hSession.saveOrUpdate(hClass); } } }