private MSystem doSystem(Session hSession) throws HibernateException { MSystem hSystem = new MSystem(); hSystem.setVersion(101001); hSystem.setDate(Calendar.getInstance().getTime()); hSession.save(hSystem); return hSystem; }
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); }
private void loadMetadata() throws RetsServerException { MetadataLoader loader = new MetadataLoader(); MSystem system = loader.parseMetadataDirectory(); Iterator j = system.getResources().iterator(); while (j.hasNext()) { Resource res = (Resource) j.next(); Iterator k = res.getClasses().iterator(); while (k.hasNext()) { MClass clazz = (MClass) k.next(); mClasses.put(clazz.getPath(), clazz); Iterator l = clazz.getTables().iterator(); while (l.hasNext()) { Table table = (Table) l.next(); mTables.put(table.getPath(), table); } } } }
public MetadataSegment fetchMetadataOld(String type, String[] levels) throws RetsReplyException { // Always need system to get version and date MSystem system = findSystemFromHibernate(); MetadataFinder finder = (MetadataFinder) sMetadataFinders.get(type); if (finder != null) { StopWatch stopWatch = new StopWatch(); LOG.debug("Using finder for type: " + type); stopWatch.start(); List metadata = finder.findMetadata(levels, mSessions); stopWatch.stop(); LOG.debug("End finder: " + stopWatch.getTime()); return new MetadataSegment(metadata, levels, system.getVersionString(), system.getDate()); } else { LOG.warn( "Recieved query for unknown metadataResults type: " + type + ", level=" + StringUtils.join(levels, ":")); throw new RetsReplyException(ReplyCode.INVALID_TYPE, type); } }
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); }