blob: d39289ae33cec2084b7d97393b2ad4d79fe2dc20 (
plain) (
blame)
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
|
/*
* Copyright (c) 2012, 2013 Eike Stepper (Berlin, Germany) and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Eike Stepper - initial API and implementation
* Erdal Karaca - copied from mysql impl to adapt to oracle db
*/
package org.eclipse.net4j.db.oracle;
import org.eclipse.net4j.db.DBType;
import org.eclipse.net4j.db.ddl.IDBField;
import org.eclipse.net4j.spi.db.DBAdapter;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class OracleAdapter extends DBAdapter
{
public static final String NAME = "oracle"; //$NON-NLS-1$
public static final String VERSION = "11.1.0.7"; //$NON-NLS-1$
public OracleAdapter()
{
super(NAME, VERSION);
}
public String[] getReservedWords()
{
List<String> list = new ArrayList<String>(Arrays.asList(getSQL92ReservedWords()));
list.add("INDEX");
list.add("COMMENT");
list.add("ACCESS");
return list.toArray(new String[list.size()]);
}
@Override
public boolean isTypeIndexable(DBType type)
{
switch (type)
{
case VARCHAR:
return false;
default:
return super.isTypeIndexable(type);
}
}
@Override
protected String getTypeName(IDBField field)
{
DBType type = field.getType();
switch (type)
{
case NUMERIC:
case DECIMAL:
case FLOAT:
case REAL:
case DOUBLE:
case BIGINT:
return "NUMBER";
case TINYINT:
return "NUMBER(5)";
case SMALLINT:
case BOOLEAN:
return "NUMBER(7)";
case INTEGER:
return "NUMBER(12)";
case DATE:
case TIME:
return "DATE";
case CHAR:
case VARCHAR:
return "VARCHAR2(" + field.getPrecision() + ")";
default:
return super.getTypeName(field);
}
}
@Override
public int getFieldLength(DBType type)
{
if (type == DBType.VARCHAR)
{
return 4000; // Oracle only supports 4000 for VARCHAR
}
return super.getFieldLength(type);
}
@Override
public DBType adaptType(DBType type)
{
if (type == DBType.BOOLEAN)
{
return DBType.SMALLINT;
}
return super.adaptType(type);
}
@Override
public int getMaxTableNameLength()
{
return 30;
}
@Override
public int getMaxFieldNameLength()
{
return 30;
}
@Override
public boolean isTableNotFoundException(SQLException ex)
{
String message = ex.getMessage();
return message != null && message.toLowerCase().contains("ora-00942") && "42000".equals(ex.getSQLState());
}
@Override
public boolean isColumnNotFoundException(SQLException ex)
{
String message = ex.getMessage();
return message != null && message.toLowerCase().contains("ora-00904") && "42000".equals(ex.getSQLState());
}
@Override
public boolean isDuplicateKeyException(SQLException ex)
{
String message = ex.getMessage();
return message != null && message.toLowerCase().contains("ora-00001") && "23000".equals(ex.getSQLState());
}
@Override
protected String sqlModifyField(String tableName, String fieldName, String definition)
{
return "ALTER TABLE " + tableName + " MODIFY " + fieldName + " " + definition;
}
}
|