~ubuntu-branches/ubuntu/utopic/gridengine/utopic

« back to all changes in this revision

Viewing changes to source/libs/jgdi/cullconv/src/com/sun/grid/cull/AbstractGDIGenerator.java

  • Committer: Bazaar Package Importer
  • Author(s): Mark Hymers
  • Date: 2008-06-25 22:36:13 UTC
  • Revision ID: james.westby@ubuntu.com-20080625223613-tvd9xlhuoct9kyhm
Tags: upstream-6.2~beta2
ImportĀ upstreamĀ versionĀ 6.2~beta2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * AbstractGDIGenerator.java
 
3
 *
 
4
 * Created on April 4, 2006, 9:23 AM
 
5
 *
 
6
 * To change this template, choose Tools | Template Manager
 
7
 * and open the template in the editor.
 
8
 */
 
9
 
 
10
package com.sun.grid.cull;
 
11
 
 
12
import java.util.logging.Level;
 
13
import java.util.logging.Logger;
 
14
 
 
15
/**
 
16
 * Abstract helper class for generating code which performs GDI actions
 
17
 */
 
18
public abstract class AbstractGDIGenerator {
 
19
   
 
20
   protected Logger logger = Logger.getLogger("cullconv");
 
21
   
 
22
   /* classname of the cull object without packagename */
 
23
   protected String classname;
 
24
   
 
25
   protected String name;
 
26
   
 
27
   /* key is the name of the primary key field, value is the java type */
 
28
   protected java.util.Map<String,String> primaryKeys = new java.util.HashMap<String,String>();
 
29
   
 
30
   protected com.sun.grid.cull.CullObject cullObject;
 
31
   
 
32
   public AbstractGDIGenerator(String name, String classname,
 
33
           com.sun.grid.cull.CullObject cullObject) {
 
34
      this.name = name;
 
35
      this.classname = classname;
 
36
      this.cullObject = cullObject;
 
37
   }
 
38
   
 
39
   public void addPrimaryKey(String name, String type) {
 
40
      primaryKeys.put(name, type);
 
41
   }
 
42
   
 
43
   public void addPrimaryKeys(CullObject cullObj, JavaHelper jh) {
 
44
      
 
45
      for(int i = 0; i < cullObj.getPrimaryKeyCount(); i++ ) {
 
46
         CullAttr attr = cullObj.getPrimaryKeyAttr(i);
 
47
         addPrimaryKey(attr.getName(), jh.getClassName(attr.getType()));
 
48
      }
 
49
   }
 
50
   
 
51
   public int getPrimaryKeyCount() {
 
52
      return primaryKeys.size();
 
53
   }
 
54
   public CullObject getCullObject() {
 
55
      return cullObject;
 
56
   }
 
57
   
 
58
   
 
59
   public void genMethods() {
 
60
      
 
61
      if (cullObject.hasModifyOperation()) {
 
62
         if(logger.isLoggable(Level.FINE)) {
 
63
            logger.fine("generate update method for " + cullObject.getName());
 
64
         }
 
65
         genUpdateMethod();
 
66
      }
 
67
      if (cullObject.hasDeleteOperation()) {
 
68
         if(logger.isLoggable(Level.FINE)) {
 
69
            logger.fine("generate delete method for " + cullObject.getName());
 
70
         }
 
71
         genDeleteMethod();
 
72
         genDeleteByPrimaryKeyMethod();
 
73
      }
 
74
      if (cullObject.hasAddOperation()) {
 
75
         if(logger.isLoggable(Level.FINE)) {
 
76
            logger.fine("generate add method for " + cullObject.getName());
 
77
         }
 
78
         genAddMethod();
 
79
      }
 
80
      if (cullObject.hasGetListOperation()) {
 
81
         if(logger.isLoggable(Level.FINE)) {
 
82
            logger.fine("generate get list method for " + cullObject.getName());
 
83
         }
 
84
         genGetListMethod();
 
85
      }
 
86
      if (cullObject.hasGetOperation() ) {
 
87
         
 
88
         if(cullObject.getPrimaryKeyCount() > 0) {
 
89
            if(logger.isLoggable(Level.FINE)) {
 
90
               logger.fine("generate get by primary key method for " + cullObject.getName());
 
91
            }
 
92
            genGetByPrimaryKeyMethod();
 
93
         } else {
 
94
            if(logger.isLoggable(Level.FINE)) {
 
95
               logger.fine("generate gen get method for " + cullObject.getName());
 
96
            }
 
97
            genGetMethod();
 
98
         }
 
99
      }
 
100
   }
 
101
   
 
102
   protected abstract void genUpdateMethod();
 
103
   protected abstract void genGetMethod();
 
104
   protected abstract void genGetListMethod();
 
105
   protected abstract void genGetByPrimaryKeyMethod();
 
106
   protected abstract void genAddMethod();
 
107
   protected abstract void genDeleteMethod();
 
108
   protected abstract void genDeleteByPrimaryKeyMethod();
 
109
   public abstract void genImport();
 
110
   
 
111
   
 
112
}