@Override
    protected DatabaseObject snapshotObject(DatabaseObject example, DatabaseSnapshot snapshot) throws DatabaseException {
        if (((View) example).getDefinition() != null) {
            return example;
        }
        Database database = snapshot.getDatabase();
        Schema schema = example.getSchema();

        List<CachedRow> viewsMetadataRs = null;
        try {
            viewsMetadataRs = ((JdbcDatabaseSnapshot) snapshot).getMetaDataFromCache().getViews(((AbstractJdbcDatabase) database).getJdbcCatalogName(schema), ((AbstractJdbcDatabase) database).getJdbcSchemaName(schema), example.getName());
            if (!viewsMetadataRs.isEmpty()) {
                CachedRow row = viewsMetadataRs.get(0);
                String rawViewName = row.getString("TABLE_NAME");
                String rawSchemaName = StringUtil.trimToNull(row.getString("TABLE_SCHEM"));
                String rawCatalogName = StringUtil.trimToNull(row.getString("TABLE_CAT"));
                String remarks = row.getString("REMARKS");
                if (remarks != null) {
                    remarks = remarks.replace("''", "'"); //come back escaped sometimes
                }

                View view = new View().setName(cleanNameFromDatabase(rawViewName, database));
                view.setRemarks(remarks);
                CatalogAndSchema schemaFromJdbcInfo = ((AbstractJdbcDatabase) database).getSchemaFromJdbcInfo(rawCatalogName, rawSchemaName);
                view.setSchema(new Schema(schemaFromJdbcInfo.getCatalogName(), schemaFromJdbcInfo.getSchemaName()));

                try {
                    String definition = database.getViewDefinition(schemaFromJdbcInfo, view.getName());

                    if (definition.startsWith("FULL_DEFINITION: ")) {
                        definition = definition.replaceFirst("^FULL_DEFINITION: ", "");
                        view.setContainsFullDefinition(true);
                    }

                    // remove strange zero-termination seen on some Oracle view definitions
                    int length = definition.length();
                    if (definition.charAt(length-1) == 0) {
                      definition = definition.substring(0, length-1);
                    }

                    if (database instanceof InformixDatabase) {
                        // Cleanup
                        definition = definition.trim();
                        definition = definition.replaceAll("\\s*,\\s*", ", ");
                        definition = definition.replaceAll("\\s*;", "");

                        // Strip the schema definition because it can optionally be included in the tag attribute
                        definition = definition.replaceAll("(?i)\""+view.getSchema().getName()+"\"\\.", "");
                    }

                    view.setDefinition(definition);
                } catch (DatabaseException e) {
                    throw new DatabaseException("Error getting " + database.getConnection().getURL() + " view with " + new GetViewDefinitionStatement(view.getSchema().getCatalogName(), view.getSchema().getName(), rawViewName), e);
                }

                return view;
            } else {
                return null;
            }
        } catch (SQLException e) {
            throw new DatabaseException(e);
        }
    }
@Override
    protected DatabaseObject snapshotObject(DatabaseObject example, DatabaseSnapshot snapshot) throws DatabaseException {
        if (((View) example).getDefinition() != null) {
            return example;
        }
        Database database = snapshot.getDatabase();
        Schema schema = example.getSchema();

        List<CachedRow> viewsMetadataRs = null;
        try {
            viewsMetadataRs = ((JdbcDatabaseSnapshot) snapshot).getMetaDataFromCache().getViews(((AbstractJdbcDatabase) database).getJdbcCatalogName(schema), ((AbstractJdbcDatabase) database).getJdbcSchemaName(schema), example.getName());
            if (!viewsMetadataRs.isEmpty()) {
                CachedRow row = viewsMetadataRs.get(0);
                String rawViewName = row.getString("TABLE_NAME");
                String rawSchemaName = StringUtil.trimToNull(row.getString("TABLE_SCHEM"));
                String rawCatalogName = StringUtil.trimToNull(row.getString("TABLE_CAT"));
                String remarks = row.getString("REMARKS");
                if (remarks != null) {
                    remarks = remarks.replace("''", "'"); 
                }

                View view = new View().setName(cleanNameFromDatabase(rawViewName, database));
                view.setRemarks(remarks);
                CatalogAndSchema schemaFromJdbcInfo = ((AbstractJdbcDatabase) database).getSchemaFromJdbcInfo(rawCatalogName, rawSchemaName);
                view.setSchema(new Schema(schemaFromJdbcInfo.getCatalogName(), schemaFromJdbcInfo.getSchemaName()));

                try {
                    String definition = database.getViewDefinition(schemaFromJdbcInfo, view.getName());

                    if (definition.startsWith("FULL_DEFINITION: ")) {
                        definition = definition.replaceFirst("^FULL_DEFINITION: ", "");
                        view.setContainsFullDefinition(true);
                    }

                    
                    int length = definition.length();
                    if (definition.charAt(length-1) == 0) {
                      definition = definition.substring(0, length-1);
                    }

                    if (database instanceof InformixDatabase) {
                        
                        definition = definition.trim();
                        definition = definition.replaceAll("\\s*,\\s*", ", ");
                        definition = definition.replaceAll("\\s*;", "");

                        
                        definition = definition.replaceAll("(?i)\""+view.getSchema().getName()+"\"\\.", "");
                    }

                    view.setDefinition(definition);
                } catch (DatabaseException e) {
                    throw new DatabaseException("Error getting " + database.getConnection().getURL() + " view with " + new GetViewDefinitionStatement(view.getSchema().getCatalogName(), view.getSchema().getName(), rawViewName), e);
                }

                return view;
            } else {
                return null;
            }
        } catch (SQLException e) {
            throw new DatabaseException(e);
        }
    }
@ Override protected DatabaseObject snapshotObject ( DatabaseObject example , DatabaseSnapshot snapshot ) throws DatabaseException { if ( ( ( View ) example ) . getDefinition ( ) != null ) { return example ; } Database database = snapshot . getDatabase ( ) ; Schema schema = example . getSchema ( ) ; List < CachedRow > viewsMetadataRs = null ; try { viewsMetadataRs = ( ( JdbcDatabaseSnapshot ) snapshot ) . getMetaDataFromCache ( ) . getViews ( ( ( AbstractJdbcDatabase ) database ) . getJdbcCatalogName ( schema ) , ( ( AbstractJdbcDatabase ) database ) . getJdbcSchemaName ( schema ) , example . getName ( ) ) ; if ( ! viewsMetadataRs . isEmpty ( ) ) { CachedRow row = viewsMetadataRs . get ( 0 ) ; String rawViewName = row . getString ( "TABLE_NAME" ) ; String rawSchemaName = StringUtil . trimToNull ( row . getString ( "TABLE_SCHEM" ) ) ; String rawCatalogName = StringUtil . trimToNull ( row . getString ( "TABLE_CAT" ) ) ; String remarks = row . getString ( "REMARKS" ) ; if ( remarks != null ) { remarks = remarks . replace ( "''" , "'" ) ; //come back escaped sometimes } View view = new View ( ) . setName ( cleanNameFromDatabase ( rawViewName , database ) ) ; view . setRemarks ( remarks ) ; CatalogAndSchema schemaFromJdbcInfo = ( ( AbstractJdbcDatabase ) database ) . getSchemaFromJdbcInfo ( rawCatalogName , rawSchemaName ) ; view . setSchema ( new Schema ( schemaFromJdbcInfo . getCatalogName ( ) , schemaFromJdbcInfo . getSchemaName ( ) ) ) ; try { String definition = database . getViewDefinition ( schemaFromJdbcInfo , view . getName ( ) ) ; if ( definition . startsWith ( "FULL_DEFINITION: " ) ) { definition = definition . replaceFirst ( "^FULL_DEFINITION: " , "" ) ; view . setContainsFullDefinition ( true ) ; } // remove strange zero-termination seen on some Oracle view definitions int length = definition . length ( ) ; if ( definition . charAt ( length - 1 ) == 0 ) { definition = definition . substring ( 0 , length - 1 ) ; } if ( database instanceof InformixDatabase ) { // Cleanup definition = definition . trim ( ) ; definition = definition . replaceAll ( "\\s*,\\s*" , ", " ) ; definition = definition . replaceAll ( "\\s*;" , "" ) ; // Strip the schema definition because it can optionally be included in the tag attribute definition = definition . replaceAll ( "(?i)\"" + view . getSchema ( ) . getName ( ) + "\"\\." , "" ) ; } view . setDefinition ( definition ) ; } catch ( DatabaseException e ) { throw new DatabaseException ( "Error getting " + database . getConnection ( ) . getURL ( ) + " view with " + new GetViewDefinitionStatement ( view . getSchema ( ) . getCatalogName ( ) , view . getSchema ( ) . getName ( ) , rawViewName ) , e ) ; } return view ; } else { return null ; } } catch ( SQLException e ) { throw new DatabaseException ( e ) ; } }
}
}