All Downloads are FREE. Search and download functionalities are using the official Maven repository.

br.com.objectos.way.sql.it.WaySqlModule Maven / Gradle / Ivy

The newest version!
/*
 * Copyright 2014 Objectos, Fábrica de Software LTDA.
 *
 * 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 br.com.objectos.way.sql.it;

import static br.com.objectos.way.sql.ForeignKeyAction.CASCADE;

import br.com.objectos.way.sql.IntegerColumnRef;
import br.com.objectos.way.sql.LocalDateColumnRef;
import br.com.objectos.way.sql.TableInfo;
import br.com.objectos.way.sql.WaySql;
import br.com.objectos.way.sql.annotation.Defines;
import br.com.objectos.way.sql.annotation.SqlModule;

/**
 * @author [email protected] (Marcio Endo)
 */
@SqlModule
class WaySqlModule {

  IntegerColumnRef EMPLOYEE_EMP_NO = WaySql.integerColumnRef();

  @Defines
  public TableInfo employee() {
    return WaySql
        .use("WAY_SQL_IT").createTable("EMPLOYEE")
        .column("EMP_NO").integer().notNull().bindTo(EMPLOYEE_EMP_NO)
        .column("BIRTH_DATE").date().notNull()
        .column("FIRST_NAME").varchar(14).notNull()
        .column("LAST_NAME").varchar(16).notNull()
        .column("HIRE_DATE").date().notNull()
        .primaryKey(EMPLOYEE_EMP_NO)
        .toTableInfo();
  }

  @Defines
  public TableInfo pair() {
    return WaySql
        .use("WAY_SQL_IT").createTable("PAIR")
        .column("ID").integer()
        .column("NAME").varchar(120).notNull()
        .toTableInfo();
  }

  @Defines
  public TableInfo revision() {
    IntegerColumnRef SEQ = WaySql.integerColumnRef();
    return WaySql
        .use("WAY_SQL_IT").createTable("REVISION")
        .column("SEQ").integer().notNull().autoIncrement().bindTo(SEQ)
        .column("DATE").date().notNull()
        .column("DESCRIPTION").varchar(140).notNull()
        .primaryKey(SEQ)
        .toTableInfo();
  }

  @Defines
  public TableInfo salary() {
    IntegerColumnRef EMP_NO = WaySql.integerColumnRef();
    LocalDateColumnRef FROM_DATE = WaySql.localDateColumnRef();
    return WaySql
        .use("WAY_SQL_IT").createTable("SALARY")
        .column("EMP_NO").integer().notNull().bindTo(EMP_NO)
        .column("SALARY").integer().notNull()
        .column("FROM_DATE").date().notNull().bindTo(FROM_DATE)
        .column("TO_DATE").date().notNull()
        .primaryKey(EMP_NO, FROM_DATE)
        .constraint("SALARY_EMP_NO_FK").foreignKey(EMP_NO).references(EMPLOYEE_EMP_NO).onDelete(CASCADE)
        .toTableInfo();
  }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy