home *** CD-ROM | disk | FTP | other *** search
/ Symantec Visual Cafe for Java 2.5 / symantec-visual-cafe-2.5-database-dev-edition.iso / VCafe / prosrc.bin / RecordDefinitionBeanInfo.java < prev    next >
Encoding:
Java Source  |  1998-03-18  |  10.7 KB  |  243 lines

  1. /*
  2.  * @(#RecordDefinitionBeanInfo.java
  3.  *
  4.  * Copyright (c) 1997 Symantec Corporation. All Rights Reserved.
  5.  *
  6.  */
  7.  
  8. package symantec.itools.db.beans.jdbc;
  9.  
  10. import java.beans.*;
  11. import symantec.itools.beans.SymantecBeanDescriptor;
  12.  
  13.  
  14. /**
  15.  * BeanInfo for RecordDefinition
  16.  *
  17.  */
  18.  
  19. public class RecordDefinitionBeanInfo extends SimpleBeanInfo {
  20.  
  21.     public BeanInfo[] getAdditionalBeanInfo() {
  22.         try {
  23.             java.util.Vector v = new java.util.Vector();
  24.             BeanInfo[] rv;
  25.             BeanInfo b;
  26.             Class c = beanClass.getSuperclass();
  27.  
  28.             while (c.isAssignableFrom(Object.class) != true) {
  29.                 b = Introspector.getBeanInfo(c);
  30.                 v.addElement(b);
  31.                 c = c.getSuperclass();
  32.             }
  33.             rv = new BeanInfo[v.size()];
  34.             v.copyInto(rv);
  35.  
  36.             return rv;
  37.         }
  38.         catch (IntrospectionException e) { throw new Error(e.toString());}
  39.     }
  40.  
  41.     public BeanDescriptor getBeanDescriptor() {
  42.         SymantecBeanDescriptor bd = new SymantecBeanDescriptor(beanClass);
  43.         bd.setFolder("JDBC");
  44.         bd.setToolbar("JDBC");
  45.         bd.setRootTemplate(getTemplate());
  46.         bd.setValue("VPO_Object", new Boolean(true));
  47.         bd.setWinHelp("0x123D1");
  48.  
  49.         return (BeanDescriptor) bd;
  50.     }
  51.  
  52.  
  53.     public static String getTemplate()
  54.     {
  55.         StringBuffer template = new StringBuffer();
  56.         String EOL = "\n";
  57.         String TAB="\t";
  58.  
  59.         template.append("import symantec.itools.db.beans.jdbc.*;\n");
  60.         template.append("import symantec.itools.db.beans.binding.*;\n");
  61.         template.append("import java.util.*;\n");
  62.         template.append("import java.sql.*;\n");
  63.         template.append("\n");
  64.         template.append("public class RecordDefinition1 extends RecordDefinition\n");
  65.         template.append("{\n");
  66.         template.append("    public static   Statement m_InsertStatement=null;\n");
  67.         template.append("    public          Statement m_UpdateStatement=null;\n");
  68.         template.append("    public          Statement m_DeleteStatement=null;\n");
  69.         template.append("    static          DataModel m_DataModel = null;\n");
  70.         template.append("\n");
  71.         template.append("    private static int counter = 0;\n");
  72.         template.append("\n");
  73.         template.append("    public RecordDefinition1()\n");
  74.         template.append("    {\n");
  75.         template.append("        synchronized (getClass()) {\n");
  76.         template.append("            if (counter == 0) {\n");
  77.         template.append("                init();\n");
  78.         template.append("            }\n");
  79.         template.append("            counter++;\n");
  80.         template.append("        }\n");
  81.         template.append("    }\n");
  82.         template.append("\n");
  83.         template.append("    public void init()\n");
  84.         template.append("    {\n");
  85.         template.append("        //{{INIT_CONTROLS\n");
  86.         template.append("        //}}\n");
  87.         template.append("    }\n");
  88.         template.append("\n");
  89.         template.append("    public synchronized void setDataModel(PersistentObjectModel model)\n");
  90.         template.append("    {\n");
  91.         template.append("        m_DataModel = (DataModel)model;\n");
  92.         template.append("    }\n");
  93.         template.append("\n");
  94.         template.append("   // getDataModel\n");
  95.         template.append("   // Returns the data model for this class.\n");
  96.         template.append("   // If the data model has not been generated call generateDataModel\n");
  97.         template.append("   // generateDataModel executes a query and builds the data model from the result\n");
  98.         template.append("   // If you want to customize the data model create it here instead of calling generate data model\n");
  99.         template.append("\n");
  100.         template.append("    public synchronized PersistentObjectModel getDataModel()\n");
  101.         template.append("    {\n");
  102.         template.append("        if (m_DataModel == null) {\n");
  103.         template.append("            try {\n");
  104.         template.append("                m_DataModel = generateDataModel();\n");
  105.         template.append("            }\n");
  106.         template.append("            catch (Exception ex) {\n");
  107.         template.append("                throw new RuntimeException(ex.getMessage());\n");
  108.         template.append("            }\n");
  109.         template.append("        }\n");
  110.         template.append("        return m_DataModel;\n");
  111.         template.append("    }\n");
  112.         template.append("\n");
  113.         template.append("   // getInsertStatement\n");
  114.         template.append("   // Returns a Statement object used to perform an INSERT operation.\n");
  115.         template.append("   // If you want to customize the INSERT operation write your own code in this method.\n");
  116.         template.append("   // If you bypass getStatement, you should also bypass setParameterValues,\n");
  117.         template.append("   // since the parameters must be set in accordance with the Statement.\n");
  118.         template.append("\n");
  119.         template.append("    protected synchronized Statement getInsertStatement() throws SQLException\n");
  120.         template.append("    {\n");
  121.         template.append("        PreparedStatement psmd = (PreparedStatement)m_InsertStatement;\n");
  122.         template.append("        if (psmd==null) {\n");
  123.         template.append("            psmd = getStatement(psmd,INSERT_SQL);\n");
  124.         template.append("        }\n");
  125.         template.append("        setParameterValues(psmd);\n");
  126.         template.append("        return psmd;\n");
  127.         template.append("    }\n");
  128.         template.append("\n");
  129.         template.append("   // getUpdateStatement\n");
  130.         template.append("   // Returns a Statement object used to perform an UPDATE operation.\n");
  131.         template.append("   // If you want to customize the UPDATE operation write your own code in this method.\n");
  132.         template.append("   // If you bypass getStatement, you should also bypass setParameterValues,\n");
  133.         template.append("   // since the parameters must be set in accordance with the Statement.\n");
  134.         template.append("\n");
  135.         template.append("    protected synchronized Statement getUpdateStatement() throws SQLException\n");
  136.         template.append("    {\n");
  137.         template.append("        PreparedStatement psmd=(PreparedStatement)m_UpdateStatement;\n");
  138.         template.append("        psmd = getStatement(psmd,UPDATE_SQL);\n");
  139.         template.append("        setParameterValues(psmd);\n");
  140.         template.append("        setParameters(psmd,ORIGINAL_VALUE,getColModif(),false);\n");
  141.         template.append("        return psmd;\n");
  142.         template.append("    }\n");
  143.         template.append("\n");
  144.         template.append("   // getDeleteStatement\n");
  145.         template.append("   // Returns a Statement object used to perform an DELETE operation.\n");
  146.         template.append("   // If you want to customize the DELETE operation write your own code in this method.\n");
  147.         template.append("   // If you bypass getStatement, you should also bypass setParameterValues,\n");
  148.         template.append("   // since the parameters must be set in accordance with the Statement.\n");
  149.         template.append("\n");
  150.         template.append("    protected synchronized Statement getDeleteStatement() throws SQLException\n");
  151.         template.append("    {\n");
  152.         template.append("        PreparedStatement psmd=(PreparedStatement)m_DeleteStatement;\n");
  153.         template.append("        if (psmd==null) {\n");
  154.         template.append("            psmd = getStatement(psmd,DELETE_SQL);\n");
  155.         template.append("        }\n");
  156.         template.append("        setParameters(psmd,ORIGINAL_VALUE,0,false);\n");
  157.         template.append("        return psmd;\n");
  158.         template.append("    }\n");
  159.         template.append("\n");
  160.         template.append("   // save\n");
  161.         template.append("   // This is the top level method for performing a save.\n");
  162.         template.append("   // If you want to customize DML you should write code in one of the above methods.\n");
  163.         template.append("   // You should modify the code of this method if you want to add additional functionality.\n");
  164.         template.append("   // For instance you may want to fire an event which indicates success or failure.\n");
  165.         template.append("\n");
  166.         template.append("    public synchronized int save()\n");
  167.         template.append("    {\n");
  168.         template.append("        return super.save();\n");
  169.         template.append("    }\n");
  170.         template.append("\n");
  171.         template.append("    protected  void finalize() throws Throwable\n");
  172.         template.append("    {\n");
  173.         template.append("       synchronized( getClass())\n");
  174.         template.append("       {\n");
  175.         template.append("           counter--;\n");
  176.         template.append("           if (counter == 0) {\n");
  177.         template.append("               releaseConnection();\n");
  178.         template.append("           }\n");
  179.         template.append("       }\n");
  180.         template.append("    }\n");
  181.         template.append("\n");
  182.         template.append("//{{DECLARE_CONTROLS\n");
  183.         template.append("//}}\n");
  184.         template.append("}\n");
  185.  
  186.         return template.toString();
  187.     }
  188.  
  189.  
  190.     public java.awt.Image getIcon(int iconKind) {
  191.         if (iconKind == BeanInfo.ICON_MONO_16x16 ||
  192.             iconKind == BeanInfo.ICON_COLOR_16x16) {
  193.             java.awt.Image img = loadImage("RecordDefinitionIconColor16.gif");
  194.             return img;
  195.         }
  196.  
  197.         if (iconKind == BeanInfo.ICON_MONO_32x32 ||
  198.             iconKind == BeanInfo.ICON_COLOR_32x32) {
  199.             java.awt.Image img = loadImage("RecordDefinitionIconColor32.gif");
  200.             return img;
  201.         }
  202.  
  203.         return null;
  204.     }
  205.  
  206.     public MethodDescriptor[] getMethodDescriptors() {
  207.         Class[] args;
  208.         //ConnectionDescriptor connection;
  209.         java.util.Vector connections;
  210.         java.util.Vector md = new java.util.Vector();
  211.  
  212.         /*try{
  213.             args = null;
  214.             MethodDescriptor connect = new MethodDescriptor(beanClass.getMethod("connect", args));
  215.  
  216.             connections = new java.util.Vector();
  217.             connection = new ConnectionDescriptor("input", "void", "",
  218.                                     "%name%.connect();",
  219.                                     "Connect");
  220.             connections.addElement(connection);
  221.  
  222.             connect.setValue(ConnectionDescriptor.CONNECTIONS, connections);
  223.             md.addElement(connect);
  224.         } catch (Exception e) { throw new Error("connect:: " + e.toString()); }
  225.  
  226.         MethodDescriptor[] rv = new MethodDescriptor[md.size()];
  227.         md.copyInto(rv);*/
  228.  
  229.         return null;
  230.     }
  231.  
  232.     public PropertyDescriptor[] getPropertyDescriptors()
  233.     {
  234.         return new PropertyDescriptor[0];
  235.     }
  236.  
  237.     public int getDefaultPropertyIndex() {
  238.         return 0;    //  the index for our default property is always 0
  239.     }
  240.  
  241.     private final static Class beanClass = RecordDefinition.class;
  242.  
  243. }    //  end of class RecordDefinitionBeanInfo