Package org.objectstyle.wolips.eomodeler.core.sql

Source Code of org.objectstyle.wolips.eomodeler.core.sql.EOFSQLReverseEngineer56

package org.objectstyle.wolips.eomodeler.core.sql;

import java.io.File;
import java.io.IOException;
import java.util.List;
import java.util.Map;

import com.webobjects.eoaccess.EOAdaptor;
import com.webobjects.eoaccess.EOAdaptorChannel;
import com.webobjects.eoaccess.EOAdaptorContext;
import com.webobjects.foundation.NSArray;
import com.webobjects.foundation.NSDictionary;

public class EOFSQLReverseEngineer56 implements IEOSQLReverseEngineer {
  private String _adaptorName;

  private NSDictionary _connectionDictionary;

  private EOAdaptor _adaptor;

  private EOAdaptorContext _context;

  private EOAdaptorChannel _channel;

  public EOFSQLReverseEngineer56(String adaptorName, Map connectionDictionary) {
    _adaptorName = adaptorName;
    _connectionDictionary = (NSDictionary) EOFSQLUtils56.toWOCollections(connectionDictionary);
    _adaptor = EOAdaptor.adaptorWithName(_adaptorName);
    _adaptor.setConnectionDictionary(_connectionDictionary);
    _adaptor.assertConnectionDictionaryIsValid();
  }

  public void open() {
    _context = _adaptor.createAdaptorContext();
    _channel = _context.createAdaptorChannel();
    _channel.openChannel();
  }

  public void close() {
    if (_channel != null) {
      _channel.closeChannel();
      _channel = null;
    }
  }

  public List reverseEngineerTableNames() {
    open();
    try {
      NSArray tableNamesArray = _channel.describeTableNames();
      return (List) EOFSQLUtils56.toJavaCollections(tableNamesArray);
    } finally {
      close();
    }
  }

  public File reverseEngineerIntoModel() throws IOException {
    List tableNames = reverseEngineerTableNames();
    File eomodelFile = reverseEngineerWithTableNamesIntoModel(tableNames);
    return eomodelFile;
  }

  public File reverseEngineerWithTableNamesIntoModel(List tableNamesList) throws IOException {
    open();
    try {
      NSArray tableNamesArray = (NSArray) EOFSQLUtils56.toWOCollections(tableNamesList);
      com.webobjects.eoaccess.EOModel eofModel = _channel.describeModelWithTableNames(tableNamesArray);
      eofModel.beautifyNames();
      File tempFile = File.createTempFile("EntityModeler", "tmp");
      File eomodelFolder = new File(tempFile.getParentFile(), "EM" + System.currentTimeMillis() + ".eomodeld");
      tempFile.delete();
      eofModel.writeToFile(eomodelFolder.getAbsolutePath());
      return eomodelFolder;
    } finally {
      close();
    }
  }
}
TOP

Related Classes of org.objectstyle.wolips.eomodeler.core.sql.EOFSQLReverseEngineer56

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.