aboutsummaryrefslogtreecommitdiffstats
path: root/src/com/iciql/dialect/DefaultSQLDialect.java
blob: 517ae103a79a1ad2af004149a906c671b48142e4 (plain)
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
package com.iciql.dialect;

import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.SQLException;

import com.iciql.IciqlException;
import com.iciql.SQLDialect;
import com.iciql.SQLStatement;
import com.iciql.TableDefinition.IndexDefinition;
import com.iciql.util.StringUtils;

/**
 * Default implementation of an SQL dialect. Does not support merge nor index
 * creation.
 */
public class DefaultSQLDialect implements SQLDialect {
	float databaseVersion;
	String productName;
	String productVersion;

	@Override
	public String toString() {
		return getClass().getName() + ": " + productName + " " + productVersion;
	}

	@Override
	public void configureDialect(Connection conn) {
		loadIdentity(conn);
	}

	protected void loadIdentity(Connection conn) {
		try {
			DatabaseMetaData data = conn.getMetaData();
			databaseVersion = Float.parseFloat(data.getDatabaseMajorVersion() + "."
					+ data.getDatabaseMinorVersion());
			productName = data.getDatabaseProductName();
			productVersion = data.getDatabaseProductVersion();
		} catch (SQLException e) {
			throw new IciqlException(e);
		}
	}

	@Override
	public boolean supportsMemoryTables() {
		return false;
	}

	@Override
	public boolean supportsMerge() {
		return false;
	}

	@Override
	public boolean supportsLimitOffset() {
		return true;
	}

	@Override
	public String prepareTableName(String schema, String table) {
		if (StringUtils.isNullOrEmpty(schema)) {
			return table;
		}
		return schema + "." + table;
	}

	@Override
	public String prepareColumnName(String name) {
		return name;
	}

	@Override
	public String prepareCreateIndex(String schema, String table, IndexDefinition index) {
		throw new IciqlException("Dialect does not support index creation!");
	}

	@Override
	public void appendLimit(SQLStatement stat, long limit) {
		stat.appendSQL(" LIMIT " + limit);
	}

	@Override
	public void appendOffset(SQLStatement stat, long offset) {
		stat.appendSQL(" OFFSET " + offset);
	}
}