From: <cel...@us...> - 2002-11-13 18:06:54
|
Update of /cvsroot/hibernate/Hibernate/cirrus/hibernate/tools/reverse In directory usw-pr-cvs1:/tmp/cvs-serv9096 Added Files: JDBCUtil.java MapGenerator.java MapGui.java ParamsPanel.java Log Message: --- NEW FILE: JDBCUtil.java --- /* * JDBCUtil.java * * Created on November 9, 2002, 4:27 PM */ package cirrus.hibernate.tools.reverse; import java.sql.*; import java.util.*; import cirrus.hibernate.Hibernate; import cirrus.hibernate.type.NullableType; import org.apache.log4j.*; /** * * @author Administrator */ public class JDBCUtil { private static Logger logger = Logger.getLogger(JDBCUtil.class); public static class Column { public String name; public int sqlType; public int sqlColumnLength; public int sqlDecimalLength; public boolean sqlNotNull; public boolean sqlReadOnly; public NullableType hibernateType; public Class javaType; public boolean equals(Object o) { boolean rv = false; if (o != null && o instanceof JDBCUtil.Column) { rv = (name.equals(((JDBCUtil.Column)o).name)); } return rv; } public int hashCode() { return (name != null) ? name.hashCode() : 0; } }; public static List getCatalogs(Connection c) throws SQLException { DatabaseMetaData dmd = c.getMetaData(); ResultSet rs = null; try { rs = dmd.getCatalogs(); List l = new LinkedList(); while (rs.next()) { l.add(rs.getString(1)); } return l; } finally { if (rs != null) rs.close(); } } public static Map getSchemas(Connection c) throws SQLException { DatabaseMetaData dmd = c.getMetaData(); ResultSet rs = null; try { rs = dmd.getSchemas(); Map map = new HashMap(); List l; while (rs.next()) { String schema = rs.getString(1); String catalog = null; if (rs.getMetaData().getColumnCount() > 1) { catalog = rs.getString(2); }; l = (List)map.get(catalog); if (l == null) { l = new LinkedList(); map.put(catalog, l); } l.add(schema); } return map; } finally { if (rs != null) rs.close(); } } public static List getTables(Connection c, String catalog, String schema, String tablePattern) throws SQLException { logger.debug("catalog='" + catalog + "'"); logger.debug("schema='" + schema + "'"); logger.debug("table='" + tablePattern + "'"); DatabaseMetaData dmd = c.getMetaData(); ResultSet rs = null; try { rs = dmd.getTables(catalog, schema, tablePattern, new String[] {"TABLE", "VIEW", "SYNONYM", "ALIAS"} ); Map map = new HashMap(); List l= new LinkedList(); while (rs.next()) { l.add(rs.getString(3)); } return l; } finally { if (rs != null) rs.close(); } } public static Set getForeignKeyColumns(Connection c, String catalog, String schema, String table) throws SQLException { logger.debug("catalog='" + catalog + "'"); logger.debug("schema='" + schema + "'"); logger.debug("table='" + table + "'"); DatabaseMetaData dmd = c.getMetaData(); ResultSet rs = null; try { rs = dmd.getImportedKeys(catalog, schema, table); HashSet columns = new HashSet(); while (rs.next()) { columns.add(rs.getString(8)); } return columns; } finally { if (rs != null) rs.close(); } } public static List getPrimaryKeyColumns(Connection c, String catalog, String schema, String table) throws SQLException { logger.debug("catalog='" + catalog + "'"); logger.debug("schema='" + schema + "'"); logger.debug("table='" + table + "'"); DatabaseMetaData dmd = c.getMetaData(); ResultSet rs = null; try { rs = dmd.getPrimaryKeys(catalog, schema, table); List pkColumns = new LinkedList();; while (rs.next()) { List tmp = getTableColumns(c, catalog, schema, table, rs.getString(4)); Column pkColumn = (Column)tmp.get(0); pkColumns.add(pkColumn); } return pkColumns; } finally { if (rs != null) rs.close(); } } public static List getTableColumns(Connection c, String catalog, String schema, String table) throws SQLException { return getTableColumns(c, catalog, schema, table, null); } public static List getTableColumns(Connection c, String catalog, String schema, String table, String columnPattern) throws SQLException { logger.debug("catalog='" + catalog + "'"); logger.debug("schema='" + schema + "'"); logger.debug("table='" + table + "'"); logger.debug("column='" + columnPattern+ "'"); DatabaseMetaData dmd = c.getMetaData(); ResultSet rs = null; try { rs = dmd.getColumns(catalog, schema, table, columnPattern); List columns = new LinkedList(); while (rs.next()) { JDBCUtil.Column aCol = new JDBCUtil.Column(); aCol.name = rs.getString(4); aCol.sqlType = rs.getShort(5); aCol.sqlColumnLength=rs.getInt(7); aCol.sqlDecimalLength=rs.getInt(9); aCol.sqlNotNull = ("NO".equals(rs.getString(18))); aCol.hibernateType = getHibernateType( aCol.sqlType, aCol.sqlColumnLength, aCol.sqlDecimalLength ); aCol.javaType = getJavaType( aCol.sqlType, aCol.sqlColumnLength, aCol.sqlDecimalLength ); columns.add(aCol); } return columns; } finally { if (rs != null) rs.close(); } } public static NullableType getHibernateType(int sqlType, int columnSize, int decimalDigits) { logger.debug("sqlType=" + sqlType); logger.debug("columnSize=" + columnSize); logger.debug("decimalDigits=" + decimalDigits); NullableType rv=Hibernate.SERIALIZABLE; if (sqlType == Types.CHAR || sqlType == Types.VARCHAR) { rv = Hibernate.STRING; } else if (sqlType == Types.FLOAT || sqlType == Types.REAL) { rv = Hibernate.FLOAT; } else if (sqlType == Types.INTEGER) { rv = Hibernate.INTEGER; } else if (sqlType == Types.DOUBLE) { rv = Hibernate.DOUBLE; } else if (sqlType == Types.DATE) { rv = Hibernate.DATE; } else if (sqlType == Types.TIMESTAMP) { rv = Hibernate.TIMESTAMP; } else if (sqlType == Types.TIME) { rv = Hibernate.TIME; } else if (sqlType == Types.BOOLEAN) { rv = Hibernate.BOOLEAN; } else if (sqlType == Types.SMALLINT) { rv = Hibernate.SHORT; } else if (sqlType == Types.BIT) { rv = Hibernate.BYTE; } else if (sqlType == Types.BIGINT) { rv = Hibernate.LONG; } else if (sqlType == Types.NUMERIC || sqlType == Types.DECIMAL) { if (decimalDigits == 0) { if (columnSize == 1) { rv = Hibernate.BYTE; } else if (columnSize < 5) { rv = Hibernate.SHORT; } else if (columnSize < 10) { rv = Hibernate.INTEGER; } else { rv = Hibernate.LONG; } } else { if (columnSize < 9) { rv = Hibernate.FLOAT; } else { rv = Hibernate.DOUBLE; } } } return rv; } public static Class getJavaType(int sqlType, int columnSize, int decimalDigits) { logger.debug("sqlType=" + sqlType); logger.debug("columnSize=" + columnSize); logger.debug("decimalDigits=" + decimalDigits); Class rv=String.class; if (sqlType == Types.CHAR || sqlType == Types.VARCHAR) { rv = String.class; } else if (sqlType == Types.FLOAT || sqlType == Types.REAL) { rv = Float.class; } else if (sqlType == Types.INTEGER) { rv = Integer.class; } else if (sqlType == Types.DOUBLE) { rv = Double.class; } else if (sqlType == Types.DATE) { rv = java.util.Date.class; } else if (sqlType == Types.TIMESTAMP) { rv = java.util.Date.class; } else if (sqlType == Types.TIME) { rv = java.util.Date.class; } else if (sqlType == Types.BOOLEAN) { rv = Boolean.class; } else if (sqlType == Types.SMALLINT) { rv = Short.class; } else if (sqlType == Types.BIT) { rv = Byte.class; } else if (sqlType == Types.BIGINT) { rv = Long.class; } else if (sqlType == Types.NUMERIC || sqlType == Types.DECIMAL) { if (decimalDigits == 0) { if (columnSize == 1) { rv = Byte.class; } else if (columnSize < 5) { rv = Short.class; } else if (columnSize < 10) { rv = Integer.class; } else { rv = Long.class; } } else { if (columnSize < 9) { rv = Float.class; } else { rv = Double.class; } } } return rv; } } --- NEW FILE: MapGenerator.java --- /* * MapGenerator.java * * Created on November 1, 2002, 1:50 PM */ package cirrus.hibernate.tools.reverse; import javax.sql.*; import java.sql.*; import org.w3c.dom.*; import javax.xml.parsers.*; import java.util.*; import java.io.*; import org.apache.log4j.*; import cirrus.hibernate.tools.codegen.*; import cirrus.hibernate.type.NullableType; import javax.xml.transform.*; import javax.xml.transform.dom.*; import javax.xml.transform.stream.*; /** * * @author Administrator */ public class MapGenerator { private static Logger logger = Logger.getLogger(MapGenerator.class); private String generator; private String[] generatorParameters; private String packageName; private String catalog; private String schemaPattern; private String idType; private String[] tableTypes=new String[] { "TABLE", "VIEW", "SYNONYM", "ALIAS"}; private File outputDirectory; private String idName; private DocumentBuilder docBuilder; private TransformerFactory tFactory; private boolean generateSource=true; private String baseClass; private org.jdom.input.DOMBuilder jdomBuilder; private boolean singleMapFile; private String[] tableNames; private String mappingFile; private boolean hibernateTypes; /** Creates a new instance of MapGenerator */ public MapGenerator() { try { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); docBuilder = dbf.newDocumentBuilder(); tFactory = TransformerFactory.newInstance(); jdomBuilder = new org.jdom.input.DOMBuilder(false); } catch (Exception e) { throw new RuntimeException(e.getMessage()); } } public void generate(Connection c) throws IOException, SQLException, Exception { Document d = getMap(c); writeMapping(d); generateCode(d); } public Document getMap(Connection c) throws IOException, SQLException { Document hbm = createMappingDoc(); logger.debug("reading tables from database"); String[] tableNames = getTableNames(); for (int i=0; tableNames != null && i < tableNames.length; i++) { addHibernateClass ( c, tableNames[i], hbm.getDocumentElement() ); } logger.debug("done reading tables from database"); return hbm; } public void generateCode(Document doc) throws Exception { Map map = new HashMap(); NodeList classes = doc.getElementsByTagName("class"); if (classes == null || classes.getLength() == 0) return; for (int i=0; i < classes.getLength(); i++) { Element classElement = (Element)classes.item(i); ClassMapping cmap=null; if (getBaseClass() != null) { ClassName cName = new ClassName(); cName.setFullyQualifiedName(getBaseClass()); cmap = new ClassMapping(cName, jdomBuilder.build(classElement)); } else cmap = new ClassMapping(jdomBuilder.build(classElement)); map.put(cmap.getCanonicalName(), cmap); } // generate source files Generator g = new Generator(); g.setBaseDirName(getOutputDirectory().getAbsolutePath()); g.generate(map); } protected void writeMapping(Document mapping) throws IOException { java.lang.String pkgName = packageName.replace('.', java.io.File.separatorChar) + File.separatorChar; File packageDir = new File(outputDirectory, pkgName); if (!packageDir.exists()) packageDir.mkdirs(); if (isSingleMapFile() ) { File mappingFile = new File(packageDir, getMappingFile()); FileOutputStream fos = new FileOutputStream(mappingFile); try { logger.debug("writing to file " + mappingFile); writeHbm(mapping, fos); } finally { fos.close(); } } else { NodeList classes = mapping.getElementsByTagName("class"); for (int i=0; i < classes.getLength();i++) { Element classElement = (Element)classes.item(i); Document hibDoc = createMappingDoc(); classElement = (Element)hibDoc.importNode(classElement, true); hibDoc.getDocumentElement().appendChild(classElement); String fname = makeEntityName(classElement.getAttribute("table")) + ".hbm.xml"; File mappingFile = new File(packageDir, fname); logger.debug("writing to file " + mappingFile); FileOutputStream fos = new FileOutputStream(mappingFile); try { writeHbm(hibDoc, fos); } finally { fos.close(); } } } } protected void writeHbm(Node node, OutputStream os) { try { // Use a Transformer for output Transformer transformer = tFactory.newTransformer(); transformer.setOutputProperty(OutputKeys.INDENT, "yes"); transformer.setOutputProperty(OutputKeys.METHOD, "xml"); transformer.setOutputProperty(OutputKeys.DOCTYPE_SYSTEM, "http://hibernate.sourceforge.net/hibernate-mapping-1.1.dtd"); transformer.setOutputProperty(OutputKeys.DOCTYPE_PUBLIC, "-//Hibernate/Hibernate Mapping DTD 1.1//EN"); DOMSource source = new DOMSource(node); StreamResult result = new StreamResult(os); transformer.transform(source, result); } catch (TransformerConfigurationException tce) { logger.error("Transformation configuration error", tce); throw new RuntimeException(tce.getMessage()); } catch (TransformerException te) { // Error generated by the parser logger.error("Transformation error", te); throw new RuntimeException(te.getMessage()); } } protected String getXml(Node node) { try { ByteArrayOutputStream baos = new ByteArrayOutputStream(); writeNode(node, baos); baos.close(); return baos.toString(); } catch (IOException ioe) { throw new RuntimeException(ioe.getMessage()); } } protected void writeNode(Node node, OutputStream os) { try { // Use a Transformer for output Transformer transformer = tFactory.newTransformer(); DOMSource source = new DOMSource(node); StreamResult result = new StreamResult(os); transformer.transform(source, result); } catch (TransformerConfigurationException tce) { logger.error("Transformation configuration error", tce); throw new RuntimeException(tce.getMessage()); } catch (TransformerException te) { // Error generated by the parser logger.error("Transformation error", te); throw new RuntimeException(te.getMessage()); } } protected Document createMappingDoc() { Document hbm = docBuilder.newDocument(); Element hibernate = hbm.createElement("hibernate-mapping"); hbm.appendChild(hibernate); //logger.debug(getXml(hbm)); return hbm; } protected void addHibernateClass(Connection c, String tableName, Element mappingElement) throws SQLException { logger.debug("adding hibernate class for table " + tableName); Document hbm = mappingElement.getOwnerDocument(); Element classElement = hbm.createElement("class"); String className = getPackageName() + "." + makeEntityName(tableName); classElement.setAttribute("name", className); classElement.setAttribute("table", tableName); if (getSchemaPattern() != null) { classElement.setAttribute("schema", getSchemaPattern()); } List pkColumns = JDBCUtil.getPrimaryKeyColumns(c, getCatalog(), getSchemaPattern(), tableName); Set fkColumns = JDBCUtil.getForeignKeyColumns(c, getCatalog(), getSchemaPattern(), tableName); List columns = JDBCUtil.getTableColumns(c, getCatalog(), getSchemaPattern(), tableName); if (pkColumns.size() == 1) { addId(classElement, (JDBCUtil.Column)pkColumns.iterator().next()); } else if (pkColumns.size() > 1) { addCompositeId(classElement, pkColumns, fkColumns); } addProperties(classElement, pkColumns, fkColumns, columns); logger.debug("class element: " + getXml(classElement)); mappingElement.appendChild(classElement); } protected void addId(Element classElement, JDBCUtil.Column pkColumn) { Document hbm = classElement.getOwnerDocument(); String tableName = classElement.getAttribute("table"); Element identifierElement = hbm.createElement("id"); String idName = getIdName(); if (idName == null) { idName = makeMemberName(pkColumn.name); } identifierElement.setAttribute("name", idName); identifierElement.setAttribute("column", pkColumn.name); if (getIdType() != null) { identifierElement.setAttribute("type", getIdType()); } else { String type = (isHibernateTypes()) ? pkColumn.hibernateType.getName() : pkColumn.javaType.getName(); identifierElement.setAttribute("type", type); if (pkColumn.sqlColumnLength > 0) { identifierElement.setAttribute("length", "" + pkColumn.sqlColumnLength); } } addGenerator(identifierElement); classElement.appendChild(identifierElement); } protected void addCompositeId(Element classElement, Collection primaryKeys, Collection foreignKeys) { Document hbm = classElement.getOwnerDocument(); String tableName = classElement.getAttribute("table"); Element identifierElement=hbm.createElement("composite-id"); // ciElement.setAttribute("class", getPackageName() + "." + makeEntityName(tableName) + "Key"); //String compositeId = this.getIdName(); //if (compositeId == null) compositeId = makeMemberName(tableName) + "Id"; // ciElement.setAttribute("name", compositeId); for (Iterator it = primaryKeys.iterator(); it.hasNext();) { JDBCUtil.Column pkColumn = (JDBCUtil.Column)it.next(); Element property = hbm.createElement("key-property"); property.setAttribute("name", makeMemberName(pkColumn.name)); if (getIdType() != null && foreignKeys.contains(pkColumn)) { // if the primary key column is also a foreign key, use the // specified keyType. property.setAttribute("type", getIdType()); } else { property.setAttribute("column", pkColumn.name); String type = (isHibernateTypes()) ? pkColumn.hibernateType.getName() : pkColumn.javaType.getName(); property.setAttribute("type", type); if (pkColumn.sqlColumnLength > 0) { property.setAttribute("length", "" + pkColumn.sqlColumnLength); } } identifierElement.appendChild(property); } classElement.appendChild(identifierElement); } protected void addProperties(Element classElement, Collection pkColumns, Collection fkColumns, Collection columns) { Document hbm = classElement.getOwnerDocument(); String tableName = classElement.getAttribute("table"); for (Iterator it = columns.iterator(); it.hasNext();) { JDBCUtil.Column column = (JDBCUtil.Column)it.next(); if (!pkColumns.contains(column)) { Element propertyElement = hbm.createElement("property"); propertyElement.setAttribute("name", makeMemberName(column.name)); propertyElement.setAttribute("column", column.name); if (getIdType() != null && fkColumns.contains(column)) { propertyElement.setAttribute("type", getIdType()); } else { String type = (isHibernateTypes()) ? column.hibernateType.getName() : column.javaType.getName(); propertyElement.setAttribute("type", type); if (column.sqlColumnLength > 0) { propertyElement.setAttribute("length", "" + column.sqlColumnLength); } } if (column.sqlNotNull) propertyElement.setAttribute("not-null", "" + column.sqlNotNull); logger.debug("column info: " + getXml(propertyElement)); classElement.appendChild(propertyElement); } } } protected void addGenerator(Element idElement) { Document hbm = idElement.getOwnerDocument(); Element generator = hbm.createElement("generator"); generator.setAttribute("class", getGenerator()); if (generatorParameters != null) { for (int i=0; i < generatorParameters.length;i++) { Element param = hbm.createElement("param"); param.appendChild(hbm.createTextNode(generatorParameters[i])); generator.appendChild(param); } } idElement.appendChild(generator); } protected String makeEntityName(String name) { String tmp = makeMemberName(name); tmp = tmp.substring(0,1).toUpperCase() + tmp.substring(1); return tmp; } protected String makeMemberName(String name) { String memberName = name.toLowerCase(); int i; while ((i = memberName.indexOf('_')) != -1) { java.lang.String tmp1 = memberName.substring(0, i); if (i+1 < memberName.length()) { tmp1 += memberName.substring(i+1, i+2).toUpperCase(); } if (i+2 < memberName.length()) { tmp1 += memberName.substring(i+2); } memberName = tmp1; } return memberName; } /** Getter for property schemaPattern. * @return Value of property schemaPattern. */ public java.lang.String getSchemaPattern() { return schemaPattern; } /** Setter for property schemaPattern. * @param schemaPattern New value of property schemaPattern. */ public void setSchemaPattern(java.lang.String schemaPattern) { this.schemaPattern = schemaPattern; } /** Getter for property tablePattern. * @return Value of property tablePattern. */ public java.lang.String[] getTableNames() { return tableNames; } /** Setter for property tablePattern. * @param tablePattern New value of property tablePattern. */ public void setTableNames(java.lang.String[] tableNames) { this.tableNames = tableNames; } /** Getter for property catalog. * @return Value of property catalog. */ public java.lang.String getCatalog() { return catalog; } /** Setter for property catalog. * @param catalog New value of property catalog. */ public void setCatalog(java.lang.String catalog) { this.catalog = catalog; } /** Getter for property tableTypes. * @return Value of property tableTypes. */ public java.lang.String[] getTableTypes() { return this.tableTypes; } /** Setter for property tableTypes. * @param tableTypes New value of property tableTypes. */ public void setTableTypes(java.lang.String[] tableTypes) { this.tableTypes = tableTypes; } /** Getter for property packageName. * @return Value of property packageName. */ public java.lang.String getPackageName() { return packageName; } /** Setter for property packageName. * @param packageName New value of property packageName. */ public void setPackageName(java.lang.String packageName) { this.packageName = packageName; } /** Getter for property outputDirectory. * @return Value of property outputDirectory. */ public java.io.File getOutputDirectory() { return outputDirectory; } /** Setter for property outputDirectory. * @param outputDirectory New value of property outputDirectory. */ public void setOutputDirectory(java.io.File outputDirectory) { this.outputDirectory = outputDirectory; if (!outputDirectory.exists() || !outputDirectory.isDirectory()) { throw new RuntimeException("Invalid directory " + outputDirectory); } } /** Getter for property idName. * @return Value of property idName. */ public java.lang.String getIdName() { return idName; } /** Setter for property idName. * @param idName New value of property idName. */ public void setIdName(java.lang.String idName) { this.idName = idName; } /** Getter for property generator. * @return Value of property generator. */ public java.lang.String getGenerator() { return generator; } /** Setter for property generator. * @param generator New value of property generator. */ public void setGenerator(java.lang.String generator) { this.generator = generator; } /** Getter for property generatorParameters. * @return Value of property generatorParameters. */ public java.lang.String[] getGeneratorParameters() { return this.generatorParameters; } /** Setter for property generatorParameters. * @param generatorParameters New value of property generatorParameters. */ public void setGeneratorParameters(java.lang.String[] generatorParameters) { this.generatorParameters = generatorParameters; } /** Getter for property mappingFile. * @return Value of property mappingFile. */ public java.lang.String getMappingFile() { return mappingFile; } /** Setter for property mappingFile. * @param mappingFile New value of property mappingFile. */ public void setMappingFile(java.lang.String mappingFile) { this.mappingFile = mappingFile; } /** Getter for property idType. * @return Value of property idType. */ public java.lang.String getIdType() { return idType; } /** Setter for property idType. * @param idType New value of property idType. */ public void setIdType(java.lang.String idType) { this.idType = idType; } /** Getter for property baseClass. * @return Value of property baseClass. */ public java.lang.String getBaseClass() { return baseClass; } /** Setter for property baseClass. * @param baseClass New value of property baseClass. */ public void setBaseClass(java.lang.String baseClass) { this.baseClass = baseClass; } /** Getter for property generateSource. * @return Value of property generateSource. */ public boolean isGenerateSource() { return generateSource; } /** Setter for property generateSource. * @param generateSource New value of property generateSource. */ public void setGenerateSource(boolean generateSource) { this.generateSource = generateSource; } /** Getter for property singleMapFile. * @return Value of property singleMapFile. */ public boolean isSingleMapFile() { return singleMapFile; } /** Setter for property singleMapFile. * @param singleMapFile New value of property singleMapFile. */ public void setSingleMapFile(boolean singleMapFile) { this.singleMapFile = singleMapFile; } /** * @param args the command line arguments */ public static void main(String[] args) throws Exception { MapGenerator mg = new MapGenerator(); mg.setPackageName("com.mtd"); mg.setSchemaPattern("postgres"); mg.setGenerator("sequence"); mg.setIdType("java.lang.Long"); mg.setGeneratorParameters(new String[] {"fooSequence" }); mg.setOutputDirectory(new File("c:\\temp")); mg.setMappingFile("test.hbm.xml"); //oracle.jdbc.OracleDriver.class.getName(); org.postgresql.Driver.class.getName(); Connection connection = DriverManager.getConnection("jdbc:postgresql:template1", "postgres", ""); mg.generate(connection); connection.close(); } /** Getter for property hibernateTypes. * @return Value of property hibernateTypes. */ public boolean isHibernateTypes() { return hibernateTypes; } /** Setter for property hibernateTypes. * @param hibernateTypes New value of property hibernateTypes. */ public void setHibernateTypes(boolean hibernateTypes) { this.hibernateTypes = hibernateTypes; } } --- NEW FILE: MapGui.java --- /* * MapGui.java * * Created on November 4, 2002, 11:01 AM */ package cirrus.hibernate.tools.reverse; import java.sql.*; import java.io.*; import javax.swing.*; import java.util.*; /** * * @author Administrator */ public class MapGui extends javax.swing.JApplet { final static Object[] javaKeyTypes= new String[] {"java.util.Date", "java.lang.Long", "java.lang.String", "java.sql.Timestamp"}; final static Object[] hibernateKeyTypes = new String[] {"date", "long", "string", "timestamp"}; final static int DATE_TYPE=0; final static int LONG_TYPE=1; final static int STRING_TYPE=2; final static int TIMESTAMP_TYPE=3; DefaultComboBoxModel javaTypesModel = new DefaultComboBoxModel(javaKeyTypes); DefaultComboBoxModel hibernateTypesModel = new DefaultComboBoxModel(hibernateKeyTypes); String[] generationParameters; Map schemas; /** Creates new form MapGui */ public MapGui() { initComponents(); keyFieldType.setModel(hibernateTypesModel); generatorNameItemStateChanged(null); readState(); Runtime.getRuntime().addShutdownHook(new Thread() { public void run() { saveState(); } } ); } /** This method is called from within the constructor to * initialize the form. * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the Form Editor. */ private void initComponents() {//GEN-BEGIN:initComponents java.awt.GridBagConstraints gridBagConstraints; mappingTypeGroup = new javax.swing.ButtonGroup(); buttonGroup1 = new javax.swing.ButtonGroup(); databasePanel = new javax.swing.JPanel(); jLabel1 = new javax.swing.JLabel(); catalogName = new javax.swing.JComboBox(); jLabel2 = new javax.swing.JLabel(); schemaName = new javax.swing.JComboBox(); jLabel3 = new javax.swing.JLabel(); tableName = new javax.swing.JTextField(); keyFieldTypeGroup = new javax.swing.ButtonGroup(); tabbedPanel = new javax.swing.JTabbedPane(); connectionPanel = new javax.swing.JPanel(); jLabel6 = new javax.swing.JLabel(); driverClass = new javax.swing.JTextField(); jLabel7 = new javax.swing.JLabel(); jLabel8 = new javax.swing.JLabel(); jLabel9 = new javax.swing.JLabel(); connectionUrl = new javax.swing.JTextField(); dbUser = new javax.swing.JTextField(); dbPassword = new javax.swing.JPasswordField(); jPanel5 = new javax.swing.JPanel(); tablesPanel = new javax.swing.JPanel(); tableListHolder = new javax.swing.JPanel(); cmdGetTables = new javax.swing.JButton(); tablesScroller = new javax.swing.JScrollPane(); selectedTables = new javax.swing.JList(); mappingPanel = new javax.swing.JPanel(); jLabel11 = new javax.swing.JLabel(); mappingTypePanel = new javax.swing.JPanel(); optionSingleMap = new javax.swing.JRadioButton(); optionTableMap = new javax.swing.JRadioButton(); mappingFile = new javax.swing.JTextField(); jLabel10 = new javax.swing.JLabel(); idFieldName = new javax.swing.JTextField(); Generator = new javax.swing.JLabel(); genPanel = new javax.swing.JPanel(); generatorName = new javax.swing.JComboBox(); cmdParams = new javax.swing.JButton(); jLabel12 = new javax.swing.JLabel(); jPanel1 = new javax.swing.JPanel(); optionHibernateTypes = new javax.swing.JRadioButton(); optionJavaTypes = new javax.swing.JRadioButton(); keyFieldType = new javax.swing.JComboBox(); jLabel14 = new javax.swing.JLabel(); codePanel = new javax.swing.JPanel(); jLabel4 = new javax.swing.JLabel(); packageName = new javax.swing.JTextField(); jLabel13 = new javax.swing.JLabel(); baseClass = new javax.swing.JTextField(); outputPanel = new javax.swing.JPanel(); jLabel5 = new javax.swing.JLabel(); outputDirectory = new javax.swing.JTextField(); cmdPickDir = new javax.swing.JButton(); cmdPanel = new javax.swing.JPanel(); cmdGenerate = new javax.swing.JButton(); databasePanel.setLayout(new java.awt.GridBagLayout()); databasePanel.setMinimumSize(new java.awt.Dimension(250, 70)); databasePanel.setPreferredSize(new java.awt.Dimension(250, 75)); jLabel1.setText("Catalog"); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST; gridBagConstraints.insets = new java.awt.Insets(0, 10, 0, 0); databasePanel.add(jLabel1, gridBagConstraints); catalogName.setMinimumSize(new java.awt.Dimension(31, 20)); catalogName.setNextFocusableComponent(schemaName); catalogName.setPreferredSize(new java.awt.Dimension(31, 20)); catalogName.addItemListener(new java.awt.event.ItemListener() { public void itemStateChanged(java.awt.event.ItemEvent evt) { catalogNameItemStateChanged(evt); } }); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; gridBagConstraints.insets = new java.awt.Insets(0, 10, 0, 10); databasePanel.add(catalogName, gridBagConstraints); jLabel2.setText("Schema"); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST; gridBagConstraints.insets = new java.awt.Insets(0, 10, 0, 0); databasePanel.add(jLabel2, gridBagConstraints); schemaName.setMinimumSize(new java.awt.Dimension(31, 20)); schemaName.setNextFocusableComponent(tableName); schemaName.setPreferredSize(new java.awt.Dimension(31, 20)); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; gridBagConstraints.insets = new java.awt.Insets(0, 10, 0, 10); databasePanel.add(schemaName, gridBagConstraints); jLabel3.setText("Table Filter"); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST; gridBagConstraints.insets = new java.awt.Insets(0, 10, 0, 0); databasePanel.add(jLabel3, gridBagConstraints); tableName.setText("%"); tableName.setNextFocusableComponent(catalogName); tableName.setPreferredSize(new java.awt.Dimension(200, 20)); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; gridBagConstraints.weightx = 1.0; gridBagConstraints.insets = new java.awt.Insets(0, 10, 0, 10); databasePanel.add(tableName, gridBagConstraints); tabbedPanel.setFont(new java.awt.Font("Dialog", 1, 11)); tabbedPanel.setPreferredSize(new java.awt.Dimension(430, 240)); connectionPanel.setLayout(new java.awt.GridBagLayout()); jLabel6.setText("Driver Class"); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST; connectionPanel.add(jLabel6, gridBagConstraints); driverClass.setText("oracle.jdbc.OracleDriver"); driverClass.setNextFocusableComponent(connectionUrl); driverClass.setPreferredSize(new java.awt.Dimension(200, 20)); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.insets = new java.awt.Insets(0, 10, 0, 0); connectionPanel.add(driverClass, gridBagConstraints); jLabel7.setText("Connection URL"); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST; connectionPanel.add(jLabel7, gridBagConstraints); jLabel8.setText("Username"); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST; connectionPanel.add(jLabel8, gridBagConstraints); jLabel9.setText("Password"); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST; connectionPanel.add(jLabel9, gridBagConstraints); connectionUrl.setText("jdbc:oracle:thin:@host:port:dbi"); connectionUrl.setNextFocusableComponent(dbUser); connectionUrl.setPreferredSize(new java.awt.Dimension(200, 20)); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.insets = new java.awt.Insets(0, 10, 0, 0); connectionPanel.add(connectionUrl, gridBagConstraints); dbUser.setNextFocusableComponent(dbPassword); dbUser.setPreferredSize(new java.awt.Dimension(200, 20)); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.insets = new java.awt.Insets(0, 10, 0, 0); connectionPanel.add(dbUser, gridBagConstraints); dbPassword.setNextFocusableComponent(driverClass); dbPassword.setPreferredSize(new java.awt.Dimension(200, 20)); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.insets = new java.awt.Insets(0, 10, 0, 0); connectionPanel.add(dbPassword, gridBagConstraints); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridwidth = 2; connectionPanel.add(jPanel5, gridBagConstraints); tabbedPanel.addTab("Connection", connectionPanel); tablesPanel.setLayout(new java.awt.BorderLayout()); tableListHolder.setLayout(new java.awt.GridBagLayout()); cmdGetTables.setFont(new java.awt.Font("Dialog", 0, 12)); cmdGetTables.setText("tables..."); cmdGetTables.setFocusPainted(false); cmdGetTables.setMaximumSize(new java.awt.Dimension(150, 26)); cmdGetTables.setMinimumSize(new java.awt.Dimension(80, 20)); cmdGetTables.setPreferredSize(new java.awt.Dimension(85, 20)); cmdGetTables.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { cmdGetTablesActionPerformed(evt); } }); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; gridBagConstraints.weightx = 1.0; gridBagConstraints.insets = new java.awt.Insets(5, 10, 0, 10); tableListHolder.add(cmdGetTables, gridBagConstraints); selectedTables.setFont(new java.awt.Font("Dialog", 0, 12)); selectedTables.setLayoutOrientation(JList.VERTICAL_WRAP); selectedTables.addListSelectionListener(new javax.swing.event.ListSelectionListener() { public void valueChanged(javax.swing.event.ListSelectionEvent evt) { selectedTablesValueChanged(evt); } }); tablesScroller.setViewportView(selectedTables); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; gridBagConstraints.weightx = 1.0; gridBagConstraints.weighty = 1.0; gridBagConstraints.insets = new java.awt.Insets(0, 10, 10, 10); tableListHolder.add(tablesScroller, gridBagConstraints); tablesPanel.add(tableListHolder, java.awt.BorderLayout.CENTER); tabbedPanel.addTab("Tables", tablesPanel); mappingPanel.setLayout(new java.awt.GridBagLayout()); jLabel11.setText("Mapping File"); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.fill = java.awt.GridBagConstraints.VERTICAL; gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST; mappingPanel.add(jLabel11, gridBagConstraints); mappingTypePanel.setLayout(new java.awt.GridBagLayout()); mappingTypePanel.setBorder(new javax.swing.border.EtchedBorder()); mappingTypePanel.setMinimumSize(new java.awt.Dimension(184, 55)); optionSingleMap.setFont(new java.awt.Font("Dialog", 0, 12)); optionSingleMap.setText("single map"); mappingTypeGroup.add(optionSingleMap); optionSingleMap.setMinimumSize(new java.awt.Dimension(87, 20)); optionSingleMap.setNextFocusableComponent(idFieldName); optionSingleMap.setPreferredSize(new java.awt.Dimension(87, 20)); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 1; gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; gridBagConstraints.insets = new java.awt.Insets(0, 2, 2, 0); mappingTypePanel.add(optionSingleMap, gridBagConstraints); optionTableMap.setFont(new java.awt.Font("Dialog", 0, 12)); optionTableMap.setSelected(true); optionTableMap.setText("one map per database table"); mappingTypeGroup.add(optionTableMap); optionTableMap.setNextFocusableComponent(optionSingleMap); optionTableMap.setPreferredSize(new java.awt.Dimension(183, 20)); optionTableMap.addItemListener(new java.awt.event.ItemListener() { public void itemStateChanged(java.awt.event.ItemEvent evt) { optionTableMapItemStateChanged(evt); } }); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.gridy = 0; gridBagConstraints.gridwidth = 2; gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints.weightx = 0.5; gridBagConstraints.insets = new java.awt.Insets(2, 2, 0, 2); mappingTypePanel.add(optionTableMap, gridBagConstraints); mappingFile.setText("mapping.hbm.xml"); mappingFile.setEnabled(false); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.gridy = 1; gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; gridBagConstraints.weightx = 0.5; gridBagConstraints.insets = new java.awt.Insets(0, 0, 2, 2); mappingTypePanel.add(mappingFile, gridBagConstraints); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints.insets = new java.awt.Insets(0, 10, 0, 0); mappingPanel.add(mappingTypePanel, gridBagConstraints); jLabel10.setText("Key Field Name"); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST; mappingPanel.add(jLabel10, gridBagConstraints); idFieldName.setText("id"); idFieldName.setMinimumSize(new java.awt.Dimension(220, 20)); idFieldName.setNextFocusableComponent(generatorName); idFieldName.setPreferredSize(new java.awt.Dimension(220, 20)); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; gridBagConstraints.insets = new java.awt.Insets(0, 10, 0, 0); mappingPanel.add(idFieldName, gridBagConstraints); Generator.setText("Generator"); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST; mappingPanel.add(Generator, gridBagConstraints); genPanel.setLayout(new java.awt.GridBagLayout()); genPanel.setPreferredSize(new java.awt.Dimension(250, 20)); generatorName.setEditable(true); generatorName.setFont(new java.awt.Font("Dialog", 0, 12)); generatorName.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "uuid.hex", "uuid.string", "vm.long", "vm.hex", "assigned", "native", "sequence", "hilo.long", "hilo.hex", "seqhilo.long" })); generatorName.setSelectedIndex(6); generatorName.setNextFocusableComponent(cmdParams); generatorName.setPreferredSize(new java.awt.Dimension(140, 20)); generatorName.addItemListener(new java.awt.event.ItemListener() { public void itemStateChanged(java.awt.event.ItemEvent evt) { generatorNameItemStateChanged(evt); } }); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; gridBagConstraints.weightx = 1.0; genPanel.add(generatorName, gridBagConstraints); cmdParams.setFont(new java.awt.Font("Dialog", 0, 12)); cmdParams.setText("params..."); cmdParams.setNextFocusableComponent(keyFieldType); cmdParams.setPreferredSize(new java.awt.Dimension(88, 20)); cmdParams.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { cmdParamsActionPerformed(evt); } }); genPanel.add(cmdParams, new java.awt.GridBagConstraints()); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; gridBagConstraints.insets = new java.awt.Insets(0, 10, 0, 0); mappingPanel.add(genPanel, gridBagConstraints); jLabel12.setText("Key Field Type"); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST; mappingPanel.add(jLabel12, gridBagConstraints); jPanel1.setLayout(new java.awt.GridBagLayout()); jPanel1.setBorder(new javax.swing.border.EtchedBorder()); optionHibernateTypes.setFont(new java.awt.Font("Dialog", 0, 12)); optionHibernateTypes.setSelected(true); optionHibernateTypes.setText("use Hibernate types"); keyFieldTypeGroup.add(optionHibernateTypes); optionHibernateTypes.addItemListener(new java.awt.event.ItemListener() { public void itemStateChanged(java.awt.event.ItemEvent evt) { optionHibernateTypesItemStateChanged(evt); } }); jPanel1.add(optionHibernateTypes, new java.awt.GridBagConstraints()); optionJavaTypes.setFont(new java.awt.Font("Dialog", 0, 12)); optionJavaTypes.setText("use Java types"); keyFieldTypeGroup.add(optionJavaTypes); jPanel1.add(optionJavaTypes, new java.awt.GridBagConstraints()); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints.insets = new java.awt.Insets(0, 10, 0, 0); mappingPanel.add(jPanel1, gridBagConstraints); keyFieldType.setFont(new java.awt.Font("Dialog", 0, 12)); keyFieldType.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "date", "integer", "long", "string", "timestamp" })); keyFieldType.setSelectedIndex(2); keyFieldType.setNextFocusableComponent(optionTableMap); keyFieldType.setPreferredSize(new java.awt.Dimension(31, 20)); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; gridBagConstraints.insets = new java.awt.Insets(0, 10, 0, 0); mappingPanel.add(keyFieldType, gridBagConstraints); jLabel14.setText("Key Field Class"); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST; mappingPanel.add(jLabel14, gridBagConstraints); tabbedPanel.addTab("Mapping", mappingPanel); codePanel.setLayout(new java.awt.GridBagLayout()); codePanel.setMinimumSize(new java.awt.Dimension(350, 112)); codePanel.setPreferredSize(new java.awt.Dimension(350, 150)); jLabel4.setText("Package Name"); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST; codePanel.add(jLabel4, gridBagConstraints); packageName.setNextFocusableComponent(baseClass); packageName.setPreferredSize(new java.awt.Dimension(220, 20)); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; gridBagConstraints.insets = new java.awt.Insets(0, 10, 0, 0); codePanel.add(packageName, gridBagConstraints); jLabel13.setText("Base Class Name"); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST; codePanel.add(jLabel13, gridBagConstraints); baseClass.setNextFocusableComponent(packageName); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; gridBagConstraints.insets = new java.awt.Insets(0, 10, 0, 0); codePanel.add(baseClass, gridBagConstraints); tabbedPanel.addTab("Code", codePanel); outputPanel.setLayout(new java.awt.GridBagLayout()); jLabel5.setText("Output Directory"); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; gridBagConstraints.weightx = 1.0; gridBagConstraints.insets = new java.awt.Insets(0, 10, 0, 0); outputPanel.add(jLabel5, gridBagConstraints); outputDirectory.setEditable(false); outputDirectory.setText("c:\\temp"); outputDirectory.setPreferredSize(new java.awt.Dimension(100, 20)); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 0; gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; gridBagConstraints.weightx = 0.1; gridBagConstraints.insets = new java.awt.Insets(0, 10, 0, 0); outputPanel.add(outputDirectory, gridBagConstraints); cmdPickDir.setFont(new java.awt.Font("Dialog", 0, 12)); cmdPickDir.setText("pick..."); cmdPickDir.setPreferredSize(new java.awt.Dimension(80, 20)); cmdPickDir.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { cmdPickDirActionPerformed(evt); } }); gridBagConstraints = new java.awt.GridBagConstraints(); gridBagConstraints.gridx = 1; gridBagConstraints.gridy = 1; gridBagConstraints.insets = new java.awt.Insets(0, 0, 0, 10); outputPanel.add(cmdPickDir, gridBagConstraints); tabbedPanel.addTab("Output", outputPanel); getContentPane().add(tabbedPanel, java.awt.BorderLayout.CENTER); cmdGenerate.setText("Generate"); cmdGenerate.setEnabled(false); cmdGenerate.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { cmdGenerateActionPerformed(evt); } }); cmdPanel.add(cmdGenerate); getContentPane().add(cmdPanel, java.awt.BorderLayout.SOUTH); }//GEN-END:initComponents private void optionHibernateTypesItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_optionHibernateTypesItemStateChanged // Add your handling code here: int selectedIndex = keyFieldType.getSelectedIndex(); if (optionHibernateTypes.isSelected()) { keyFieldType.setModel(hibernateTypesModel); } else { keyFieldType.setModel(javaTypesModel); } keyFieldType.setSelectedIndex(selectedIndex); // Add your handling code here: }//GEN-LAST:event_optionHibernateTypesItemStateChanged private void catalogNameItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_catalogNameItemStateChanged // Add your handling code here: List tmp = (List)schemas.get(catalogName.getSelectedItem()); Object[] schemaArr = (tmp != null) ? tmp.toArray() : new Object[0]; DefaultComboBoxModel dcbm = new DefaultComboBoxModel(schemaArr); schemaName.setModel(dcbm); schemaName.setSelectedItem(dbUser.getText()); }//GEN-LAST:event_catalogNameItemStateChanged private void cmdGetTablesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmdGetTablesActionPerformed // Add your handling code here: try { Connection c = null; try { c = getConnection(); DefaultComboBoxModel dcbm = new DefaultComboBoxModel(JDBCUtil.getCatalogs(c).toArray()); catalogName.setModel(dcbm); schemas = JDBCUtil.getSchemas(c); List tmp = (List)schemas.get(catalogName.getSelectedItem()); Object[] schemaArr = (tmp != null) ? tmp.toArray() : new Object[0]; dcbm = new DefaultComboBoxModel(schemaArr); Object prevItem = schemaName.getSelectedItem(); schemaName.setModel(dcbm); if (prevItem == null) schemaName.setSelectedItem(dbUser.getText()); JOptionPane.showMessageDialog(this, databasePanel, "Select Table Criteria", JOptionPane.QUESTION_MESSAGE); List tables = JDBCUtil.getTables( c, (String)catalogName.getSelectedItem(), (String)schemaName.getSelectedItem(), tableName.getText() ); dcbm = new DefaultComboBoxModel(tables.toArray()); selectedTables.setModel(dcbm); } finally { if (c != null) c.close(); } } catch (Exception e) { e.printStackTrace(); JOptionPane.showMessageDialog(this, e); } }//GEN-LAST:event_cmdGetTablesActionPerformed private void selectedTablesValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_selectedTablesValueChanged // Add your handling code here: int[] selected = selectedTables.getSelectedIndices(); cmdGenerate.setEnabled(!(selected == null || selected.length == 0)); }//GEN-LAST:event_selectedTablesValueChanged private void optionTableMapItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_optionTableMapItemStateChanged // Add your handling code here: mappingFile.setEnabled(!optionTableMap.isSelected()); }//GEN-LAST:event_optionTableMapItemStateChanged private void generatorNameItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_generatorNameItemStateChanged // Add your handling code here: if (generatorName.getSelectedIndex() != -1) { String gName = (String)generatorName.getSelectedItem(); if ( gName.equals("vm.long") || gName.equals("native") || gName.equals("sequence") || gName.equals("hilo.long") || gName.equals("seqhilo.long") ) { keyFieldType.setSelectedIndex(LONG_TYPE); } else if ( gName.equals("uuid.hex") || gName.equals("uuid.string") || gName.equals("vm.hex") || gName.equals("hilo.hex") ) { keyFieldType.setSelectedIndex(STRING_TYPE); } } }//GEN-LAST:event_generatorNameItemStateChanged private void cmdParamsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmdParamsActionPerformed // Add your handling code here: ParamsPanel paramsPanel = new ParamsPanel(); if (generationParameters != null) paramsPanel.setParameters(generationParameters); int choice =JOptionPane.showConfirmDialog(this, paramsPanel, "Generation Parameters", JOptionPane.OK_CANCEL_OPTION); if (choice == JOptionPane.OK_OPTION) { this.generationParameters = paramsPanel.getParameters(); } }//GEN-LAST:event_cmdParamsActionPerformed private void cmdGenerateActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cmdGenerateActionPerformed // Add your handling code here: Connection connection=null; try { MapGenerator mg = new MapGenerator(); String cat = (String)catalogName.getSelectedItem(); if (cat != null && cat.length() > 0) mg.setCatalog(cat); String schem = (String)schemaName.getSelectedItem(); if (schem != null && schem.length() > 0) mg.setSchemaPattern(schem); Object[] otables = selectedTables.getSelectedValues(); if (otables != null && otables.length > 0) { String[] tables = (String[])Arrays.asList(otables).toArray(new String[0]); mg.setTableNames(tables... [truncated message content] |