/src/ru/adv/db/adapter/Postgres83.java
http://mozart.googlecode.com/ · Java · 115 lines · 54 code · 31 blank · 30 comment · 4 complexity · 998d3883a29badc4128873dcf1a0e9ed MD5 · raw file
- /* =================================================================
- Copyright (C) 2009 ADV/web-engineering All rights reserved.
- This file is part of Mozart.
- Mozart is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
- Mozart is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with Foobar. If not, see <http://www.gnu.org/licenses/>.
- Mozart
- http://www.mozartcms.ru
- ================================================================= */
- package ru.adv.db.adapter;
- import java.sql.SQLException;
- import java.util.ArrayList;
- import java.util.Collections;
- import java.util.List;
- import ru.adv.db.DBConnection;
- import ru.adv.db.config.ObjectAttr;
- public class Postgres83 extends Postgres80 {
-
- @Override
- public boolean isSupportConstraints() {
- return true;
- }
-
- @Override
- public List<String> getSetValueSequenceSql(String name, long value, int increment) {
- return Collections.singletonList(
- "ALTER SEQUENCE "+qi(name) + " INCREMENT BY " + increment + " RESTART WITH " + value
- );
- }
- @Override
- public String getCreateDatabaseSql(String name) {
- return "CREATE DATABASE " + qi(name) +" ENCODING='utf-8'";
- }
- @Override
- public List<String> getSystemStoredProcedureSql(String schema) {
- List<String> sqlList = new ArrayList<String>();
- for (String sql : super.getSystemStoredProcedureSql(schema)) {
- if ("text(bool)".equalsIgnoreCase( getStoredProcedureName(sql)) ) {
- // it's impossible change text(bool) function in this version
- // previous realisation casts boolean into '1'/'0'
- continue; //SKIP creation
- }
- if ("bool(text)".equalsIgnoreCase( getStoredProcedureName(sql)) ) {
- // there is perfect bool(text) funcation in this version
- continue; //SKIP creation
- }
- sqlList.add(sql);
- }
- return sqlList;
- }
- @Override
- protected void ceateNullabilityConstraint(DBConnection conn, ObjectAttr a) {
- conn.execute(String.format(
- "ALTER TABLE %1$s ALTER COLUMN %2$s %3$s NOT NULL",
- qi(a.getConfigObject().getRealName()), a.getSQLName(), ( a.isNullable() ? "DROP" : "SET" )
- ));
- }
- @Override
- public void dropConstraints(DBConnection conn, String schema, String tableName) throws SQLException {
- // select all constrain names for tabel
- List<Object[]> rows = conn.executeQuery(
- "SELECT pc.conname FROM pg_constraint pc, pg_class cl WHERE pc.conrelid = cl.oid AND pc.conname LIKE 'mz_%' AND cl.relname=?",
- new Object[]{registeredName(tableName)}
- );
- // drop all constrains
- for (Object[] row : rows) {
- conn.executeUpdate( String.format( "ALTER TABLE %1$s DROP CONSTRAINT %2$s", qi(tableName), qi(row[0].toString()) ));
- }
- }
- // @Override
- // public boolean isSupportForeignConstrain() {
- // return true;
- // }
-
-
-
- }