Search in sources :

Example 1 with Dialect

use of com.github.drinkjava2.jdialects.Dialect in project jDialects by drinkjava2.

the class DialectTest method testPagination.

@Test
public void testPagination() {
    Dialect[] dialects = Dialect.values();
    for (Dialect dialect : dialects) {
        System.out.println("=========" + dialect + "==========");
        String result = "";
        try {
            System.out.println(dialect);
            result = dialect.paginate(1, 10, sql1);
            System.out.println(result);
        } catch (DialectException e) {
            System.out.println("Error:" + e.getMessage());
        }
        Assert.assertFalse(result.contains("$"));
        try {
            result = dialect.paginate(3, 10, sql1);
            System.out.println(result);
        } catch (DialectException e) {
            System.out.println("Error:" + e.getMessage());
        }
        Assert.assertFalse(result.contains("$"));
        try {
            result = dialect.paginate(1, 10, sql2);
            System.out.println(result);
        } catch (DialectException e) {
            System.out.println("Error:" + e.getMessage());
        }
        Assert.assertFalse(result.contains("$"));
        try {
            result = dialect.paginate(3, 10, sql2);
            System.out.println(result);
        } catch (DialectException e) {
            System.out.println("Error:" + e.getMessage());
        }
        Assert.assertFalse(result.contains("$"));
    }
}
Also used : DialectException(com.github.drinkjava2.jdialects.DialectException) DerbyDialect(com.github.drinkjava2.jdialects.Dialect.DerbyDialect) PostgresPlusDialect(com.github.drinkjava2.jdialects.Dialect.PostgresPlusDialect) DB2Dialect(com.github.drinkjava2.jdialects.Dialect.DB2Dialect) Dialect(com.github.drinkjava2.jdialects.Dialect) MySQLDialect(com.github.drinkjava2.jdialects.Dialect.MySQLDialect) PostgreSQL81Dialect(com.github.drinkjava2.jdialects.Dialect.PostgreSQL81Dialect) PostgreSQL9Dialect(com.github.drinkjava2.jdialects.Dialect.PostgreSQL9Dialect) Oracle10gDialect(com.github.drinkjava2.jdialects.Dialect.Oracle10gDialect) PostgreSQL82Dialect(com.github.drinkjava2.jdialects.Dialect.PostgreSQL82Dialect) SybaseASE15Dialect(com.github.drinkjava2.jdialects.Dialect.SybaseASE15Dialect) SybaseAnywhereDialect(com.github.drinkjava2.jdialects.Dialect.SybaseAnywhereDialect) DerbyTenSixDialect(com.github.drinkjava2.jdialects.Dialect.DerbyTenSixDialect) SQLServerDialect(com.github.drinkjava2.jdialects.Dialect.SQLServerDialect) HSQLDialect(com.github.drinkjava2.jdialects.Dialect.HSQLDialect) DerbyTenSevenDialect(com.github.drinkjava2.jdialects.Dialect.DerbyTenSevenDialect) H2Dialect(com.github.drinkjava2.jdialects.Dialect.H2Dialect) Oracle8iDialect(com.github.drinkjava2.jdialects.Dialect.Oracle8iDialect) Oracle9iDialect(com.github.drinkjava2.jdialects.Dialect.Oracle9iDialect) InformixDialect(com.github.drinkjava2.jdialects.Dialect.InformixDialect) SQLiteDialect(com.github.drinkjava2.jdialects.Dialect.SQLiteDialect) MySQL5Dialect(com.github.drinkjava2.jdialects.Dialect.MySQL5Dialect) DB2400Dialect(com.github.drinkjava2.jdialects.Dialect.DB2400Dialect) IngresDialect(com.github.drinkjava2.jdialects.Dialect.IngresDialect) DerbyTenFiveDialect(com.github.drinkjava2.jdialects.Dialect.DerbyTenFiveDialect) Test(org.junit.Test)

Example 2 with Dialect

use of com.github.drinkjava2.jdialects.Dialect in project jDialects by drinkjava2.

the class DialectTest method testDDLTypeMapping7.

@Test
public void testDDLTypeMapping7() {
    Dialect d = Dialect.MySQL5InnoDBDialect;
    String ddl = //
    "create table ddl_test(" + "f1 " + //
    d.BIGINT() + ",f2 " + //
    d.BINARY(5) + ",f3 " + //
    d.BIT() + ",f4 " + //
    d.BLOB() + ",f5 " + //
    d.BOOLEAN() + ",f6 " + //
    d.CHAR() + ",f7 " + //
    d.CLOB() + ",f8 " + //
    d.DATE() + // + ",f9 " + d.DECIMAL(3,5) //
    ",f10 " + //
    d.DOUBLE() + ",f11 " + //
    d.FLOAT() + ",f12 " + //
    d.INTEGER() + // + ",f13 " + d.JAVA_OBJECT() //
    ",f14 " + //
    d.LONGNVARCHAR(10) + ",f15 " + //
    d.LONGVARBINARY() + ",f16 " + //
    d.LONGVARCHAR() + ",f17 " + //
    d.NCHAR(5) + ",f18 " + //
    d.NCLOB() + ",f19 " + //
    d.NUMERIC(6, 4) + ",f20 " + //
    d.NVARCHAR(6) + // + ",f21 " + d.OTHER() //
    ",f22 " + //
    d.REAL() + ",f23 " + //
    d.SMALLINT() + ",f24 " + //
    d.TIME() + ",f25 " + //
    d.TIMESTAMP() + ",f26 " + //
    d.TINYINT() + ",f27 " + //
    d.VARBINARY() + ",f28 " + //
    d.VARCHAR(10) + ")" + d.engine(" DEFAULT CHARSET=utf8");
    System.out.println(ddl);
    d = Dialect.Oracle10gDialect;
    ddl = //
    "create table ddl_test(" + "f1 " + //
    d.BIGINT() + ",f2 " + //
    d.BINARY(5) + ",f3 " + //
    d.BIT() + ",f4 " + //
    d.BLOB() + ",f5 " + //
    d.BOOLEAN() + ",f6 " + //
    d.CHAR() + ",f7 " + //
    d.CLOB() + ",f8 " + //
    d.DATE() + ",f9 " + //
    d.DECIMAL(3, 5) + ",f10 " + //
    d.DOUBLE() + ",f11 " + //
    d.FLOAT() + ",f12 " + //
    d.INTEGER() + // + ",f13 " + d.JAVA_OBJECT() //
    ",f14 " + //
    d.LONGNVARCHAR(10) + ",f15 " + //
    d.LONGVARBINARY() + ",f16 " + //
    d.LONGVARCHAR() + ",f17 " + //
    d.NCHAR(5) + ",f18 " + //
    d.NCLOB() + ",f19 " + //
    d.NUMERIC(6, 4) + ",f20 " + //
    d.NVARCHAR(6) + // + ",f21 " + d.OTHER() //
    ",f22 " + //
    d.REAL() + ",f23 " + //
    d.SMALLINT() + ",f24 " + //
    d.TIME() + ",f25 " + //
    d.TIMESTAMP() + ",f26 " + //
    d.TINYINT() + ",f27 " + //
    d.VARBINARY() + ",f28 " + //
    d.VARCHAR(10) + ")" + d.engine();
    System.out.println(ddl);
}
Also used : DerbyDialect(com.github.drinkjava2.jdialects.Dialect.DerbyDialect) PostgresPlusDialect(com.github.drinkjava2.jdialects.Dialect.PostgresPlusDialect) DB2Dialect(com.github.drinkjava2.jdialects.Dialect.DB2Dialect) Dialect(com.github.drinkjava2.jdialects.Dialect) MySQLDialect(com.github.drinkjava2.jdialects.Dialect.MySQLDialect) PostgreSQL81Dialect(com.github.drinkjava2.jdialects.Dialect.PostgreSQL81Dialect) PostgreSQL9Dialect(com.github.drinkjava2.jdialects.Dialect.PostgreSQL9Dialect) Oracle10gDialect(com.github.drinkjava2.jdialects.Dialect.Oracle10gDialect) PostgreSQL82Dialect(com.github.drinkjava2.jdialects.Dialect.PostgreSQL82Dialect) SybaseASE15Dialect(com.github.drinkjava2.jdialects.Dialect.SybaseASE15Dialect) SybaseAnywhereDialect(com.github.drinkjava2.jdialects.Dialect.SybaseAnywhereDialect) DerbyTenSixDialect(com.github.drinkjava2.jdialects.Dialect.DerbyTenSixDialect) SQLServerDialect(com.github.drinkjava2.jdialects.Dialect.SQLServerDialect) HSQLDialect(com.github.drinkjava2.jdialects.Dialect.HSQLDialect) DerbyTenSevenDialect(com.github.drinkjava2.jdialects.Dialect.DerbyTenSevenDialect) H2Dialect(com.github.drinkjava2.jdialects.Dialect.H2Dialect) Oracle8iDialect(com.github.drinkjava2.jdialects.Dialect.Oracle8iDialect) Oracle9iDialect(com.github.drinkjava2.jdialects.Dialect.Oracle9iDialect) InformixDialect(com.github.drinkjava2.jdialects.Dialect.InformixDialect) SQLiteDialect(com.github.drinkjava2.jdialects.Dialect.SQLiteDialect) MySQL5Dialect(com.github.drinkjava2.jdialects.Dialect.MySQL5Dialect) DB2400Dialect(com.github.drinkjava2.jdialects.Dialect.DB2400Dialect) IngresDialect(com.github.drinkjava2.jdialects.Dialect.IngresDialect) DerbyTenFiveDialect(com.github.drinkjava2.jdialects.Dialect.DerbyTenFiveDialect) Test(org.junit.Test)

Example 3 with Dialect

use of com.github.drinkjava2.jdialects.Dialect in project jDialects by drinkjava2.

the class DialectTest method testPagination2.

@Test
public void testPagination2() {
    Dialect[] dialects = Dialect.values();
    for (Dialect dialect : dialects) {
        System.out.println("=========" + dialect + "==========");
        String result = "";
        try {
            result = dialect.paginate(1, 10, sql3);
            System.out.println(result);
        } catch (DialectException e) {
            System.out.println("Error:" + e.getMessage());
        }
        Assert.assertFalse(result.contains("$"));
        Assert.assertTrue(StrUtils.isEmpty(result) || 1 == StrUtils.countMatches(result, '?'));
        try {
            result = dialect.paginate(3, 10, sql4);
            System.out.println(result);
        } catch (DialectException e) {
            System.out.println("Error:" + e.getMessage());
        }
        Assert.assertFalse(result.contains("$"));
        Assert.assertTrue(StrUtils.isEmpty(result) || 1 == StrUtils.countMatches(result, '?'));
        try {
            result = dialect.paginate(1, 10, sql3);
            System.out.println(result);
        } catch (DialectException e) {
            System.out.println("Error:" + e.getMessage());
        }
        Assert.assertFalse(result.contains("$"));
        Assert.assertTrue(StrUtils.isEmpty(result) || 1 == StrUtils.countMatches(result, '?'));
        try {
            result = dialect.paginate(3, 10, sql4);
            System.out.println(result);
        } catch (DialectException e) {
            System.out.println("Error:" + e.getMessage());
        }
        Assert.assertFalse(result.contains("$"));
        Assert.assertTrue(StrUtils.isEmpty(result) || 1 == StrUtils.countMatches(result, '?'));
    }
}
Also used : DialectException(com.github.drinkjava2.jdialects.DialectException) DerbyDialect(com.github.drinkjava2.jdialects.Dialect.DerbyDialect) PostgresPlusDialect(com.github.drinkjava2.jdialects.Dialect.PostgresPlusDialect) DB2Dialect(com.github.drinkjava2.jdialects.Dialect.DB2Dialect) Dialect(com.github.drinkjava2.jdialects.Dialect) MySQLDialect(com.github.drinkjava2.jdialects.Dialect.MySQLDialect) PostgreSQL81Dialect(com.github.drinkjava2.jdialects.Dialect.PostgreSQL81Dialect) PostgreSQL9Dialect(com.github.drinkjava2.jdialects.Dialect.PostgreSQL9Dialect) Oracle10gDialect(com.github.drinkjava2.jdialects.Dialect.Oracle10gDialect) PostgreSQL82Dialect(com.github.drinkjava2.jdialects.Dialect.PostgreSQL82Dialect) SybaseASE15Dialect(com.github.drinkjava2.jdialects.Dialect.SybaseASE15Dialect) SybaseAnywhereDialect(com.github.drinkjava2.jdialects.Dialect.SybaseAnywhereDialect) DerbyTenSixDialect(com.github.drinkjava2.jdialects.Dialect.DerbyTenSixDialect) SQLServerDialect(com.github.drinkjava2.jdialects.Dialect.SQLServerDialect) HSQLDialect(com.github.drinkjava2.jdialects.Dialect.HSQLDialect) DerbyTenSevenDialect(com.github.drinkjava2.jdialects.Dialect.DerbyTenSevenDialect) H2Dialect(com.github.drinkjava2.jdialects.Dialect.H2Dialect) Oracle8iDialect(com.github.drinkjava2.jdialects.Dialect.Oracle8iDialect) Oracle9iDialect(com.github.drinkjava2.jdialects.Dialect.Oracle9iDialect) InformixDialect(com.github.drinkjava2.jdialects.Dialect.InformixDialect) SQLiteDialect(com.github.drinkjava2.jdialects.Dialect.SQLiteDialect) MySQL5Dialect(com.github.drinkjava2.jdialects.Dialect.MySQL5Dialect) DB2400Dialect(com.github.drinkjava2.jdialects.Dialect.DB2400Dialect) IngresDialect(com.github.drinkjava2.jdialects.Dialect.IngresDialect) DerbyTenFiveDialect(com.github.drinkjava2.jdialects.Dialect.DerbyTenFiveDialect) Test(org.junit.Test)

Example 4 with Dialect

use of com.github.drinkjava2.jdialects.Dialect in project jDialects by drinkjava2.

the class TableTest method printAllDialectsDDLs.

private static void printAllDialectsDDLs(Table... tables) {
    Dialect[] diaList = Dialect.values();
    for (Dialect dialect : diaList) {
        System.out.println("======" + dialect + "=====");
        try {
            String[] ddl = dialect.toCreateDDL(tables);
            printDDLs(ddl);
        } catch (Exception e) {
            e.printStackTrace();
            System.out.println("Exception found: " + e.getMessage());
        }
    }
}
Also used : Dialect(com.github.drinkjava2.jdialects.Dialect)

Example 5 with Dialect

use of com.github.drinkjava2.jdialects.Dialect in project jDialects by drinkjava2.

the class SortedUUIDGenerator method getNextID.

@Override
public Object getNextID(NormalJdbcTool jdbc, Dialect dialect, Type dataType) {
    String s = "" + AutoIdGenerator.INSTANCE.getNextID(jdbc, dialect, dataType);
    if (s.length() > (sortedLength - 1))
        throw new DialectException("SortedLength should set bigger than auto generated ID length");
    StringBuilder sb = new StringBuilder("1");
    for (int i = 1; i < sortedLength - s.length(); i++) sb.append("0");
    sb.append(s);
    sb.append(UUIDAnyGenerator.getAnyLengthRadix36UUID(uuidLength));
    return sb.toString();
}
Also used : DialectException(com.github.drinkjava2.jdialects.DialectException)

Aggregations

Dialect (com.github.drinkjava2.jdialects.Dialect)12 Test (org.junit.Test)10 DB2400Dialect (com.github.drinkjava2.jdialects.Dialect.DB2400Dialect)9 DB2Dialect (com.github.drinkjava2.jdialects.Dialect.DB2Dialect)9 DerbyDialect (com.github.drinkjava2.jdialects.Dialect.DerbyDialect)9 DerbyTenFiveDialect (com.github.drinkjava2.jdialects.Dialect.DerbyTenFiveDialect)9 DerbyTenSevenDialect (com.github.drinkjava2.jdialects.Dialect.DerbyTenSevenDialect)9 DerbyTenSixDialect (com.github.drinkjava2.jdialects.Dialect.DerbyTenSixDialect)9 H2Dialect (com.github.drinkjava2.jdialects.Dialect.H2Dialect)9 HSQLDialect (com.github.drinkjava2.jdialects.Dialect.HSQLDialect)9 InformixDialect (com.github.drinkjava2.jdialects.Dialect.InformixDialect)9 IngresDialect (com.github.drinkjava2.jdialects.Dialect.IngresDialect)9 Oracle10gDialect (com.github.drinkjava2.jdialects.Dialect.Oracle10gDialect)9 Oracle8iDialect (com.github.drinkjava2.jdialects.Dialect.Oracle8iDialect)9 Oracle9iDialect (com.github.drinkjava2.jdialects.Dialect.Oracle9iDialect)9 PostgreSQL81Dialect (com.github.drinkjava2.jdialects.Dialect.PostgreSQL81Dialect)9 PostgreSQL82Dialect (com.github.drinkjava2.jdialects.Dialect.PostgreSQL82Dialect)9 PostgreSQL9Dialect (com.github.drinkjava2.jdialects.Dialect.PostgreSQL9Dialect)9 PostgresPlusDialect (com.github.drinkjava2.jdialects.Dialect.PostgresPlusDialect)9 SQLServerDialect (com.github.drinkjava2.jdialects.Dialect.SQLServerDialect)9