home *** CD-ROM | disk | FTP | other *** search
Java Source | 1998-03-18 | 10.7 KB | 243 lines |
- /*
- * @(#RecordDefinitionBeanInfo.java
- *
- * Copyright (c) 1997 Symantec Corporation. All Rights Reserved.
- *
- */
-
- package symantec.itools.db.beans.jdbc;
-
- import java.beans.*;
- import symantec.itools.beans.SymantecBeanDescriptor;
-
-
- /**
- * BeanInfo for RecordDefinition
- *
- */
-
- public class RecordDefinitionBeanInfo extends SimpleBeanInfo {
-
- public BeanInfo[] getAdditionalBeanInfo() {
- try {
- java.util.Vector v = new java.util.Vector();
- BeanInfo[] rv;
- BeanInfo b;
- Class c = beanClass.getSuperclass();
-
- while (c.isAssignableFrom(Object.class) != true) {
- b = Introspector.getBeanInfo(c);
- v.addElement(b);
- c = c.getSuperclass();
- }
- rv = new BeanInfo[v.size()];
- v.copyInto(rv);
-
- return rv;
- }
- catch (IntrospectionException e) { throw new Error(e.toString());}
- }
-
- public BeanDescriptor getBeanDescriptor() {
- SymantecBeanDescriptor bd = new SymantecBeanDescriptor(beanClass);
- bd.setFolder("JDBC");
- bd.setToolbar("JDBC");
- bd.setRootTemplate(getTemplate());
- bd.setValue("VPO_Object", new Boolean(true));
- bd.setWinHelp("0x123D1");
-
- return (BeanDescriptor) bd;
- }
-
-
- public static String getTemplate()
- {
- StringBuffer template = new StringBuffer();
- String EOL = "\n";
- String TAB="\t";
-
- template.append("import symantec.itools.db.beans.jdbc.*;\n");
- template.append("import symantec.itools.db.beans.binding.*;\n");
- template.append("import java.util.*;\n");
- template.append("import java.sql.*;\n");
- template.append("\n");
- template.append("public class RecordDefinition1 extends RecordDefinition\n");
- template.append("{\n");
- template.append(" public static Statement m_InsertStatement=null;\n");
- template.append(" public Statement m_UpdateStatement=null;\n");
- template.append(" public Statement m_DeleteStatement=null;\n");
- template.append(" static DataModel m_DataModel = null;\n");
- template.append("\n");
- template.append(" private static int counter = 0;\n");
- template.append("\n");
- template.append(" public RecordDefinition1()\n");
- template.append(" {\n");
- template.append(" synchronized (getClass()) {\n");
- template.append(" if (counter == 0) {\n");
- template.append(" init();\n");
- template.append(" }\n");
- template.append(" counter++;\n");
- template.append(" }\n");
- template.append(" }\n");
- template.append("\n");
- template.append(" public void init()\n");
- template.append(" {\n");
- template.append(" //{{INIT_CONTROLS\n");
- template.append(" //}}\n");
- template.append(" }\n");
- template.append("\n");
- template.append(" public synchronized void setDataModel(PersistentObjectModel model)\n");
- template.append(" {\n");
- template.append(" m_DataModel = (DataModel)model;\n");
- template.append(" }\n");
- template.append("\n");
- template.append(" // getDataModel\n");
- template.append(" // Returns the data model for this class.\n");
- template.append(" // If the data model has not been generated call generateDataModel\n");
- template.append(" // generateDataModel executes a query and builds the data model from the result\n");
- template.append(" // If you want to customize the data model create it here instead of calling generate data model\n");
- template.append("\n");
- template.append(" public synchronized PersistentObjectModel getDataModel()\n");
- template.append(" {\n");
- template.append(" if (m_DataModel == null) {\n");
- template.append(" try {\n");
- template.append(" m_DataModel = generateDataModel();\n");
- template.append(" }\n");
- template.append(" catch (Exception ex) {\n");
- template.append(" throw new RuntimeException(ex.getMessage());\n");
- template.append(" }\n");
- template.append(" }\n");
- template.append(" return m_DataModel;\n");
- template.append(" }\n");
- template.append("\n");
- template.append(" // getInsertStatement\n");
- template.append(" // Returns a Statement object used to perform an INSERT operation.\n");
- template.append(" // If you want to customize the INSERT operation write your own code in this method.\n");
- template.append(" // If you bypass getStatement, you should also bypass setParameterValues,\n");
- template.append(" // since the parameters must be set in accordance with the Statement.\n");
- template.append("\n");
- template.append(" protected synchronized Statement getInsertStatement() throws SQLException\n");
- template.append(" {\n");
- template.append(" PreparedStatement psmd = (PreparedStatement)m_InsertStatement;\n");
- template.append(" if (psmd==null) {\n");
- template.append(" psmd = getStatement(psmd,INSERT_SQL);\n");
- template.append(" }\n");
- template.append(" setParameterValues(psmd);\n");
- template.append(" return psmd;\n");
- template.append(" }\n");
- template.append("\n");
- template.append(" // getUpdateStatement\n");
- template.append(" // Returns a Statement object used to perform an UPDATE operation.\n");
- template.append(" // If you want to customize the UPDATE operation write your own code in this method.\n");
- template.append(" // If you bypass getStatement, you should also bypass setParameterValues,\n");
- template.append(" // since the parameters must be set in accordance with the Statement.\n");
- template.append("\n");
- template.append(" protected synchronized Statement getUpdateStatement() throws SQLException\n");
- template.append(" {\n");
- template.append(" PreparedStatement psmd=(PreparedStatement)m_UpdateStatement;\n");
- template.append(" psmd = getStatement(psmd,UPDATE_SQL);\n");
- template.append(" setParameterValues(psmd);\n");
- template.append(" setParameters(psmd,ORIGINAL_VALUE,getColModif(),false);\n");
- template.append(" return psmd;\n");
- template.append(" }\n");
- template.append("\n");
- template.append(" // getDeleteStatement\n");
- template.append(" // Returns a Statement object used to perform an DELETE operation.\n");
- template.append(" // If you want to customize the DELETE operation write your own code in this method.\n");
- template.append(" // If you bypass getStatement, you should also bypass setParameterValues,\n");
- template.append(" // since the parameters must be set in accordance with the Statement.\n");
- template.append("\n");
- template.append(" protected synchronized Statement getDeleteStatement() throws SQLException\n");
- template.append(" {\n");
- template.append(" PreparedStatement psmd=(PreparedStatement)m_DeleteStatement;\n");
- template.append(" if (psmd==null) {\n");
- template.append(" psmd = getStatement(psmd,DELETE_SQL);\n");
- template.append(" }\n");
- template.append(" setParameters(psmd,ORIGINAL_VALUE,0,false);\n");
- template.append(" return psmd;\n");
- template.append(" }\n");
- template.append("\n");
- template.append(" // save\n");
- template.append(" // This is the top level method for performing a save.\n");
- template.append(" // If you want to customize DML you should write code in one of the above methods.\n");
- template.append(" // You should modify the code of this method if you want to add additional functionality.\n");
- template.append(" // For instance you may want to fire an event which indicates success or failure.\n");
- template.append("\n");
- template.append(" public synchronized int save()\n");
- template.append(" {\n");
- template.append(" return super.save();\n");
- template.append(" }\n");
- template.append("\n");
- template.append(" protected void finalize() throws Throwable\n");
- template.append(" {\n");
- template.append(" synchronized( getClass())\n");
- template.append(" {\n");
- template.append(" counter--;\n");
- template.append(" if (counter == 0) {\n");
- template.append(" releaseConnection();\n");
- template.append(" }\n");
- template.append(" }\n");
- template.append(" }\n");
- template.append("\n");
- template.append("//{{DECLARE_CONTROLS\n");
- template.append("//}}\n");
- template.append("}\n");
-
- return template.toString();
- }
-
-
- public java.awt.Image getIcon(int iconKind) {
- if (iconKind == BeanInfo.ICON_MONO_16x16 ||
- iconKind == BeanInfo.ICON_COLOR_16x16) {
- java.awt.Image img = loadImage("RecordDefinitionIconColor16.gif");
- return img;
- }
-
- if (iconKind == BeanInfo.ICON_MONO_32x32 ||
- iconKind == BeanInfo.ICON_COLOR_32x32) {
- java.awt.Image img = loadImage("RecordDefinitionIconColor32.gif");
- return img;
- }
-
- return null;
- }
-
- public MethodDescriptor[] getMethodDescriptors() {
- Class[] args;
- //ConnectionDescriptor connection;
- java.util.Vector connections;
- java.util.Vector md = new java.util.Vector();
-
- /*try{
- args = null;
- MethodDescriptor connect = new MethodDescriptor(beanClass.getMethod("connect", args));
-
- connections = new java.util.Vector();
- connection = new ConnectionDescriptor("input", "void", "",
- "%name%.connect();",
- "Connect");
- connections.addElement(connection);
-
- connect.setValue(ConnectionDescriptor.CONNECTIONS, connections);
- md.addElement(connect);
- } catch (Exception e) { throw new Error("connect:: " + e.toString()); }
-
- MethodDescriptor[] rv = new MethodDescriptor[md.size()];
- md.copyInto(rv);*/
-
- return null;
- }
-
- public PropertyDescriptor[] getPropertyDescriptors()
- {
- return new PropertyDescriptor[0];
- }
-
- public int getDefaultPropertyIndex() {
- return 0; // the index for our default property is always 0
- }
-
- private final static Class beanClass = RecordDefinition.class;
-
- } // end of class RecordDefinitionBeanInfo