/*
 * Copyright 2017 requery.io
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package io.requery.sql.platform;

import io.requery.query.Expression;
import io.requery.query.element.LimitedElement;
import io.requery.query.element.OrderByElement;
import io.requery.query.element.QueryElement;
import io.requery.sql.GeneratedColumnDefinition;
import io.requery.sql.IdentityColumnDefinition;
import io.requery.sql.Mapping;
import io.requery.sql.Platform;
import io.requery.sql.UserVersionColumnDefinition;
import io.requery.sql.VersionColumnDefinition;
import io.requery.sql.gen.Generator;
import io.requery.sql.gen.InsertGenerator;
import io.requery.sql.gen.LimitGenerator;
import io.requery.sql.gen.OffsetFetchGenerator;
import io.requery.sql.gen.OrderByGenerator;
import io.requery.sql.gen.UpdateGenerator;
import io.requery.sql.gen.UpsertMergeGenerator;

import java.util.Map;

/**
 * Base platform implementation assuming standard ANSI SQL support.
 */
public class Generic implements Platform {

    private final GeneratedColumnDefinition generatedColumnDefinition;
    private final LimitGenerator limitDefinition;
    private final VersionColumnDefinition versionColumnDefinition;
    private final Generator<QueryElement<?>> insertDefinition;
    private final Generator<Map<Expression<?>, Object>> updateDefinition;
    private final Generator<Map<Expression<?>, Object>> upsertDefinition;
    private final Generator<OrderByElement> orderByDefinition;

    public Generic() {
        generatedColumnDefinition = new IdentityColumnDefinition();
        limitDefinition = new OffsetFetchGenerator();
        versionColumnDefinition = new UserVersionColumnDefinition();
        insertDefinition = new InsertGenerator();
        updateDefinition = new UpdateGenerator();
        upsertDefinition = new UpsertMergeGenerator();
        orderByDefinition = new OrderByGenerator();
    }

    @Override
    public void addMappings(Mapping mapping) {
    }

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

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

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

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

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

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

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

    @Override
    public GeneratedColumnDefinition generatedColumnDefinition() {
        return generatedColumnDefinition;
    }

    @Override
    public Generator<LimitedElement> limitGenerator() {
        return limitDefinition;
    }

    @Override
    public VersionColumnDefinition versionColumnDefinition() {
        return versionColumnDefinition;
    }

    @Override
    public Generator<QueryElement<?>> insertGenerator() {
        return insertDefinition;
    }

    @Override
    public Generator<Map<Expression<?>, Object>> updateGenerator() {
        return updateDefinition;
    }

    @Override
    public Generator<Map<Expression<?>, Object>> upsertGenerator() {
        return upsertDefinition;
    }

    @Override
    public Generator<OrderByElement> orderByGenerator() {
        return orderByDefinition;
    }

    @Override
    public String toString() {
        return getClass().getSimpleName();
    }
}

@@ -16,9 +16,9 @@
  201
-7
+8
  req
@@ -1612,34 +1612,33 @@
 erator limit
-Definition
+Generator
 ;%0A    privat
@@ -1741,34 +1741,33 @@
 t%3C?%3E%3E insert
-Definition
+Generator
 ;%0A    privat
@@ -1814,34 +1814,33 @@
 ect%3E%3E update
-Definition
+Generator
 ;%0A    privat
@@ -1887,34 +1887,33 @@
 ect%3E%3E upsert
-Definition
+Generator
 ;%0A    privat
@@ -1953,26 +1953,25 @@
  orderBy
-Definition
+Generator
 ;%0A%0A    p
@@ -2069,26 +2069,25 @@
    limit
-Definition
+Generator
  = new O
@@ -2188,34 +2188,33 @@
       insert
-Definition
+Generator
  = new Inser
@@ -2241,26 +2241,25 @@
   update
-Definition
+Generator
  = new U
@@ -2290,26 +2290,25 @@
   upsert
-Definition
+Generator
  = new U
@@ -2345,26 +2345,25 @@
  orderBy
-Definition
+Generator
  = new O
@@ -3326,26 +3326,25 @@
 rn limit
-Definition
+Generator
 ;%0A    %7D%0A
@@ -3557,34 +3557,33 @@
 eturn insert
-Definition
+Generator
 ;%0A    %7D%0A%0A   
@@ -3683,26 +3683,25 @@
 n update
-Definition
+Generator
 ;%0A    %7D%0A
@@ -3805,26 +3805,25 @@
 n upsert
-Definition
+Generator
 ;%0A    %7D%0A
@@ -3917,26 +3917,25 @@
  orderBy
-Definition
+Generator
 ;%0A    %7D%0A

Update member names in Generic sql Platform