forked from geodmms/xdgnjobs

?? ?
2008-03-13 7f10d78b8971c812127b996fdb1d556a53fd378f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
package com.ximple.eofms.jobs;
 
import java.io.File;
import java.io.InputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.sql.SQLException;
 
import org.quartz.Job;
import org.quartz.JobDataMap;
import org.quartz.JobDetail;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
 
import com.vividsolutions.jts.util.Assert;
 
import oracle.sql.BLOB;
 
public abstract class AbstractOracleDatabaseJob implements Job
{
    private static final String SHPDATA_DIR = "SHPDATA_DIR";
    private static final String SPATAILSCHEMA = "ORGSCHEMA";
    private static final String ORAHOST = "ORAHOST";
    private static final String ORAINST = "ORAINST";
    private static final String ORAPORT = "ORAPORT";
    private static final String ORAUSER = "ORAUSER";
    private static final String ORAPASS = "ORAPASS";
 
    protected String _dataPath;
    protected String _oracleHost;
    protected String _oracleInstance;
    protected String _oraclePort;
    protected String _username;
    protected String _password;
    protected String _orgSchema;
 
    public abstract void execute(JobExecutionContext context) throws JobExecutionException;
 
    protected void extractJobConfiguration(JobDetail jobDetail) throws JobExecutionException
    {
        // The directory to scan is stored in the job map
        JobDataMap dataMap = jobDetail.getJobDataMap();
        _dataPath = dataMap.getString(SHPDATA_DIR);
        _oracleHost = dataMap.getString(ORAHOST);
        _oracleInstance = dataMap.getString(ORAINST);
        _oraclePort = dataMap.getString(ORAPORT);
        _username = dataMap.getString(ORAUSER);
        _password = dataMap.getString(ORAPASS);
        _orgSchema = dataMap.getString(SPATAILSCHEMA);
 
        // Validate the required input
        if (_dataPath == null)
        {
            throw new JobExecutionException("Directory not configured");
        }
 
        // Make sure the directory exists
        File dir = new File(_dataPath);
        if (!dir.exists())
        {
            throw new JobExecutionException("Invalid Dir " + _dataPath);
        }
    }
 
    protected OracleConvertJobContext prepareJobContext()
    {
        return new OracleConvertJobContext();
    }
 
    protected static byte[] getBytesFromBLOB(BLOB blob) throws SQLException
    {
        byte[] raw = null;
 
        // BLOB        blob        = (BLOB) rs.getBlob(1);
        int         optimalSize = blob.getChunkSize();
        byte[]      chunk       = new byte[optimalSize];
        InputStream is          = blob.getBinaryStream(0);
        ByteBuffer buffer      = null;    // ByteBuffer.allocate(optimalSize);
        int         len         = 0;
 
        try
        {
            while ((len = (is.read(chunk))) != -1)
            {
                if (buffer != null)
                {
                    buffer.limit(buffer.limit() + len);
                } else
                {
                    buffer = ByteBuffer.allocate(len);
                }
 
                buffer.put(chunk);
            }
 
            is.close();
            buffer.position(0);
            raw = buffer.array();
        } catch (IOException e)
        {
            e.printStackTrace();    // To change body of catch statement use File | Settings | File Templates.
            Assert.shouldNeverReachHere();
        }
 
        return raw;
    }
    
}