forked from datageartech/datagear
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a0a286a
commit 26ee794
Showing
4 changed files
with
138 additions
and
10 deletions.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
datagear-connection/src/main/java/org/datagear/connection/support/PostgresqlURLSensor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* Copyright (c) 2018 datagear.tech. All Rights Reserved. | ||
*/ | ||
|
||
package org.datagear.connection.support; | ||
|
||
import org.datagear.connection.PrefixURLSensor; | ||
import org.datagear.connection.URLSensor; | ||
|
||
/** | ||
* PostgreSQL {@linkplain URLSensor}。 | ||
* | ||
* @author [email protected] | ||
* | ||
*/ | ||
public class PostgresqlURLSensor extends PrefixURLSensor | ||
{ | ||
public static final String JDBC_PREFIX = "jdbc:postgresql"; | ||
|
||
public PostgresqlURLSensor() | ||
{ | ||
super(JDBC_PREFIX); | ||
} | ||
|
||
@Override | ||
public void setPrefix(String prefix) | ||
{ | ||
throw new UnsupportedOperationException(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
...persistence/src/main/java/org/datagear/persistence/support/dialect/PostgresqlDialect.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* Copyright 2018 datagear.tech. All Rights Reserved. | ||
*/ | ||
|
||
package org.datagear.persistence.support.dialect; | ||
|
||
import org.datagear.persistence.Order; | ||
import org.datagear.persistence.support.AbstractDialect; | ||
import org.datagear.util.Sql; | ||
|
||
/** | ||
* PostgreSQL方言。 | ||
* | ||
* @author [email protected] | ||
* | ||
*/ | ||
public class PostgresqlDialect extends AbstractDialect | ||
{ | ||
public PostgresqlDialect() | ||
{ | ||
super(); | ||
} | ||
|
||
public PostgresqlDialect(String identifierQuote) | ||
{ | ||
super(identifierQuote); | ||
} | ||
|
||
@Override | ||
public boolean supportsPagingSql() | ||
{ | ||
return true; | ||
} | ||
|
||
@Override | ||
public Sql toPagingQuerySql(Sql query, Order[] orders, long startRow, int count) | ||
{ | ||
Sql sql = Sql.valueOf(); | ||
|
||
Sql orderSql = toOrderSql(orders); | ||
|
||
if (isEmptySql(orderSql)) | ||
{ | ||
sql.sql(query); | ||
} | ||
else | ||
{ | ||
sql.sql("SELECT * FROM ("); | ||
sql.sql(query); | ||
sql.sql(") T "); | ||
sql.sql(" ORDER BY "); | ||
sql.sql(orderSql); | ||
} | ||
|
||
sql.sql(" LIMIT " + count + " OFFSET " + (startRow - 1)); | ||
|
||
return sql; | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
...ence/src/main/java/org/datagear/persistence/support/dialect/PostgresqlDialectBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* Copyright (c) 2018 datagear.tech. All Rights Reserved. | ||
*/ | ||
|
||
/** | ||
* | ||
*/ | ||
package org.datagear.persistence.support.dialect; | ||
|
||
import java.sql.Connection; | ||
|
||
import org.datagear.connection.URLSensor; | ||
import org.datagear.connection.support.PostgresqlURLSensor; | ||
import org.datagear.persistence.Dialect; | ||
import org.datagear.persistence.DialectBuilder; | ||
import org.datagear.persistence.support.AbstractURLSensedDialectBuilder; | ||
|
||
/** | ||
* PostgreSQL的{@linkplain DialectBuilder}。 | ||
* | ||
* @author [email protected] | ||
* | ||
*/ | ||
public class PostgresqlDialectBuilder extends AbstractURLSensedDialectBuilder | ||
{ | ||
public PostgresqlDialectBuilder() | ||
{ | ||
super(new PostgresqlURLSensor()); | ||
} | ||
|
||
@Override | ||
public void setUrlSensor(URLSensor urlSensor) | ||
{ | ||
throw new UnsupportedOperationException(); | ||
} | ||
|
||
@Override | ||
public Dialect build(Connection cn) | ||
{ | ||
return new PostgresqlDialect(getIdentifierQuote(cn)); | ||
} | ||
} |