@Override protected DatabaseObject snapshotObject(DatabaseObject example, DatabaseSnapshot snapshot) throws DatabaseException, InvalidExampleException { if (example.getSnapshotId() != null) { return example; } org.hibernate.mapping.Table hibernateTable = findHibernateTable(example, snapshot); if (hibernateTable == null) { return example; } Table table = new Table().setName(hibernateTable.getName()); LOG.info("Found table " + table.getName()); // table.setSnapshotId(SnapshotIdService.getInstance().generateId()); table.setSchema(example.getSchema()); return table; }
@Override protected DatabaseObject snapshotObject(DatabaseObject example, DatabaseSnapshot snapshot) throws DatabaseException, InvalidExampleException { if (example.getSnapshotId() != null) { return example; } Table table = ((Index) example).getTable(); org.hibernate.mapping.Table hibernateTable = findHibernateTable(table, snapshot); if (hibernateTable == null) { return example; } Iterator indexIterator = hibernateTable.getIndexIterator(); while (indexIterator.hasNext()) { org.hibernate.mapping.Index hibernateIndex = (org.hibernate.mapping.Index) indexIterator.next(); Index index = new Index(); index.setTable(table); index.setName(hibernateIndex.getName()); Iterator columnIterator = hibernateIndex.getColumnIterator(); while (columnIterator.hasNext()) { org.hibernate.mapping.Column hibernateColumn = (org.hibernate.mapping.Column) columnIterator.next(); index.getColumns().add(new Column(hibernateColumn.getName()).setRelation(table)); } if (index.getColumnNames().equalsIgnoreCase(((Index) example).getColumnNames())) { LOG.info("Found index " + index.getName()); table.getIndexes().add(index); return index; } } return example; }
protected org.hibernate.mapping.Table findHibernateTable(DatabaseObject example, DatabaseSnapshot snapshot) throws DatabaseException { HibernateDatabase database = (HibernateDatabase) snapshot.getDatabase(); MetadataImplementor metadata = (MetadataImplementor) database.getMetadata(); Collection<Table> tmapp = metadata.collectTableMappings(); Iterator<Table> tableMappings = tmapp.iterator(); while (tableMappings.hasNext()) { org.hibernate.mapping.Table hibernateTable = tableMappings.next(); if (hibernateTable.getName().equalsIgnoreCase(example.getName())) { return hibernateTable; } } return null; } }
Table table = new Table().setName(hibernateTable.getName()); PrimaryKey primaryKey = null; int pkColumnPosition = 0; LOG.info("Found table " + table.getName()); table.setSchema(example.getSchema()); Column column = new Column(); column.setName(hibernateColumn.getName()); column.setType(dataType); LOG.info("Found column " + column.getName() + " " + column.getType().toString()); column.setRemarks(hibernateColumn.getComment()); column.setDefaultValue(hibernateColumn.getDefaultValue()); column.setNullable(hibernateColumn.isNullable()); column.setCertainDataType(false); primaryKey = new PrimaryKey(); primaryKey.setName(hibernatePrimaryKey.getName()); primaryKey.addColumnName(pkColumnPosition++, column.getName()); if (("native".equals(identifierGeneratorStrategy) || "identity".equals(identifierGeneratorStrategy)) && dialect.getNativeIdentifierGeneratorClass().equals(IdentityGenerator.class)) { column.setAutoIncrementInformation(new Column.AutoIncrementInformation()); column.setRelation(table);