Skip to content
Permalink
Browse files
refactor: rename dmlcommand -> sqlcommand
see #563
  • Loading branch information
vlsi committed Jul 11, 2016
1 parent 28c0c22 commit 79db1273cce04174999f46981aea26905ae5a189
@@ -19,19 +19,19 @@

public final String nativeSql;
public final int[] bindPositions;
public final DMLCommand command;
public final SqlCommand command;

static {
for (int i = 1; i < BIND_NAMES.length; i++) {
BIND_NAMES[i] = "$" + i;
}
}

public NativeQuery(String nativeSql, DMLCommand dml) {
public NativeQuery(String nativeSql, SqlCommand dml) {
this(nativeSql, NO_BINDS, dml);
}

public NativeQuery(String nativeSql, int[] bindPositions, DMLCommand dml) {
public NativeQuery(String nativeSql, int[] bindPositions, SqlCommand dml) {
this.nativeSql = nativeSql;
this.bindPositions =
bindPositions == null || bindPositions.length == 0 ? NO_BINDS : bindPositions;
@@ -111,7 +111,7 @@ public static int calculateBindLength(int bindCount) {
return res;
}

public DMLCommand getCommand() {
public SqlCommand getCommand() {
return command;
}
}
@@ -44,7 +44,7 @@
boolean isBatchedReWriteConfigured) {
if (!withParameters && !splitStatements) {
return Collections.singletonList(new NativeQuery(query,
DMLCommand.createStatementTypeInfo(DMLCommandType.BLANK)));
SqlCommand.createStatementTypeInfo(SqlCommandType.BLANK)));
}

int fragmentStart = 0;
@@ -61,7 +61,7 @@
int valuesBraceClosePosition = -1;
boolean isInsertPresent = false;
boolean isReturningPresent = false;
DMLCommandType currentCommandType = DMLCommandType.BLANK;
SqlCommandType currentCommandType = SqlCommandType.BLANK;

boolean whitespaceOnly = true;
int keyWordCount = 0;
@@ -136,7 +136,7 @@
}

nativeQueries.add(new NativeQuery(nativeSql.toString(),
toIntArray(bindPositions), DMLCommand.createStatementTypeInfo(
toIntArray(bindPositions), SqlCommand.createStatementTypeInfo(
currentCommandType, isBatchedReWriteConfigured, valuesBraceOpenPosition,
valuesBraceClosePosition,
isReturningPresent, nativeQueries.size())));
@@ -146,7 +146,7 @@
bindPositions.clear();
}
nativeSql.setLength(0);
currentCommandType = DMLCommandType.BLANK;
currentCommandType = SqlCommandType.BLANK;
isReturningPresent = false;
valuesBraceOpenPosition = -1;
valuesBraceClosePosition = -1;
@@ -164,18 +164,18 @@
if (keywordStart >= 0 && (i == aChars.length - 1 || !isKeyWordChar)) {
int wordLength = (isKeyWordChar ? i + 1 : i) - keywordStart;
if (wordLength == 6 && parseUpdateKeyword(aChars, keywordStart)) {
currentCommandType = DMLCommandType.UPDATE;
currentCommandType = SqlCommandType.UPDATE;
} else if (wordLength == 6 && parseDeleteKeyword(aChars, keywordStart)) {
currentCommandType = DMLCommandType.DELETE;
currentCommandType = SqlCommandType.DELETE;
} else if (wordLength == 4 && parseMoveKeyword(aChars, keywordStart)) {
currentCommandType = DMLCommandType.MOVE;
currentCommandType = SqlCommandType.MOVE;
} else if (wordLength == 6 && parseInsertKeyword(aChars, keywordStart)) {
if (!isInsertPresent && (nativeQueries == null || nativeQueries.isEmpty())) {
// Only allow rewrite for insert command starting with the insert keyword.
// Else, too many risks of wrong interpretation.
isCurrentReWriteCompatible = keyWordCount == 0;
isInsertPresent = true;
currentCommandType = DMLCommandType.INSERT;
currentCommandType = SqlCommandType.INSERT;
} else {
isCurrentReWriteCompatible = false;
}
@@ -211,7 +211,7 @@
}

NativeQuery lastQuery = new NativeQuery(nativeSql.toString(),
toIntArray(bindPositions), DMLCommand.createStatementTypeInfo(currentCommandType,
toIntArray(bindPositions), SqlCommand.createStatementTypeInfo(currentCommandType,
isBatchedReWriteConfigured, valuesBraceOpenPosition, valuesBraceClosePosition,
isReturningPresent, (nativeQueries == null ? 0 : nativeQueries.size())));

@@ -8,7 +8,7 @@

package org.postgresql.core;

import static org.postgresql.core.DMLCommandType.INSERT;
import static org.postgresql.core.SqlCommandType.INSERT;

/**
* Data Modification Language inspection support.
@@ -17,7 +17,7 @@
* @author Christopher Deckers (chrriis@gmail.com)
*
*/
public class DMLCommand {
public class SqlCommand {

public boolean isBatchedReWriteCompatible() {
return valuesBraceOpenPosition >= 0;
@@ -31,33 +31,33 @@ public int getBatchRewriteValuesBraceClosePosition() {
return valuesBraceClosePosition;
}

public DMLCommandType getType() {
public SqlCommandType getType() {
return commandType;
}

public boolean isReturningKeywordPresent() {
return parsedSQLhasRETURNINGKeyword;
}

public static DMLCommand createStatementTypeInfo(DMLCommandType type,
public static SqlCommand createStatementTypeInfo(SqlCommandType type,
boolean isBatchedReWritePropertyConfigured,
int valuesBraceOpenPosition, int valuesBraceClosePosition, boolean isRETURNINGkeywordPresent,
int priorQueryCount) {
return new DMLCommand(type, isBatchedReWritePropertyConfigured,
return new SqlCommand(type, isBatchedReWritePropertyConfigured,
valuesBraceOpenPosition, valuesBraceClosePosition, isRETURNINGkeywordPresent,
priorQueryCount);
}

public static DMLCommand createStatementTypeInfo(DMLCommandType type) {
return new DMLCommand(type, false, -1, -1, false, 0);
public static SqlCommand createStatementTypeInfo(SqlCommandType type) {
return new SqlCommand(type, false, -1, -1, false, 0);
}

public static DMLCommand createStatementTypeInfo(DMLCommandType type,
public static SqlCommand createStatementTypeInfo(SqlCommandType type,
boolean isRETURNINGkeywordPresent) {
return new DMLCommand(type, false, -1, -1, isRETURNINGkeywordPresent, 0);
return new SqlCommand(type, false, -1, -1, isRETURNINGkeywordPresent, 0);
}

private DMLCommand(DMLCommandType type, boolean isBatchedReWriteConfigured,
private SqlCommand(SqlCommandType type, boolean isBatchedReWriteConfigured,
int valuesBraceOpenPosition, int valuesBraceClosePosition, boolean isPresent,
int priorQueryCount) {
commandType = type;
@@ -69,7 +69,7 @@ private DMLCommand(DMLCommandType type, boolean isBatchedReWriteConfigured,
this.valuesBraceClosePosition = batchedReWriteCompatible ? valuesBraceClosePosition : -1;
}

private final DMLCommandType commandType;
private final SqlCommandType commandType;
private final boolean parsedSQLhasRETURNINGKeyword;
private final int valuesBraceOpenPosition;
private final int valuesBraceClosePosition;
@@ -14,7 +14,7 @@
*
*/

public enum DMLCommandType {
public enum SqlCommandType {

INSERT(true),
/**
@@ -35,7 +35,7 @@ public boolean canSupportBatchedReWrite() {

private final boolean canSupportBatchedReWrite;

private DMLCommandType(boolean reWriteSupport) {
private SqlCommandType(boolean reWriteSupport) {
canSupportBatchedReWrite = reWriteSupport;
}

@@ -9,8 +9,8 @@

package org.postgresql.core.v2;

import org.postgresql.core.DMLCommand;
import org.postgresql.core.DMLCommandType;
import org.postgresql.core.SqlCommand;
import org.postgresql.core.SqlCommandType;
import org.postgresql.core.NativeQuery;
import org.postgresql.core.ParameterList;
import org.postgresql.core.Parser;
@@ -32,7 +32,8 @@
assert queries.size() <= 1 : "Exactly one query expected in V2. " + queries.size()
+ " queries given.";

nativeQuery = queries.isEmpty() ? new NativeQuery("", DMLCommand.createStatementTypeInfo(DMLCommandType.BLANK)) : queries.get(0);
nativeQuery = queries.isEmpty() ? new NativeQuery("", SqlCommand.createStatementTypeInfo(
SqlCommandType.BLANK)) : queries.get(0);
}

public ParameterList createParameterList() {
@@ -11,8 +11,8 @@

import org.postgresql.PGProperty;
import org.postgresql.copy.CopyOperation;
import org.postgresql.core.DMLCommand;
import org.postgresql.core.DMLCommandType;
import org.postgresql.core.SqlCommand;
import org.postgresql.core.SqlCommandType;
import org.postgresql.core.Field;
import org.postgresql.core.Logger;
import org.postgresql.core.NativeQuery;
@@ -2421,7 +2421,9 @@ private void receiveRFQ() throws IOException {
private int estimatedReceiveBufferBytes = 0;

private final SimpleQuery beginTransactionQuery =
new SimpleQuery(new NativeQuery("BEGIN", new int[0], DMLCommand.createStatementTypeInfo(DMLCommandType.BLANK)), null);
new SimpleQuery(new NativeQuery("BEGIN", new int[0], SqlCommand.createStatementTypeInfo(
SqlCommandType.BLANK)), null);

private final SimpleQuery EMPTY_QUERY = new SimpleQuery(new NativeQuery("", new int[0], DMLCommand.createStatementTypeInfo(DMLCommandType.BLANK)), null);
private final SimpleQuery EMPTY_QUERY = new SimpleQuery(new NativeQuery("", new int[0], SqlCommand
.createStatementTypeInfo(SqlCommandType.BLANK)), null);
}
@@ -1,6 +1,6 @@
package org.postgresql.test.jdbc3;

import org.postgresql.core.DMLCommandType;
import org.postgresql.core.SqlCommandType;
import org.postgresql.core.NativeQuery;
import org.postgresql.core.Parser;

@@ -84,19 +84,19 @@ public void testHasReturning() {

queries = Parser.parseJdbcSql("select 1 as returning", true, true, false, true, true);
query = queries.get(0);
assertFalse("This is not an insert command", query.command.getType() == DMLCommandType.INSERT);
assertFalse("This is not an insert command", query.command.getType() == SqlCommandType.INSERT);
assertTrue("Returning is OK here as it is not an insert command ", query.command.isReturningKeywordPresent());

}

public void testHasDelete() {
List<NativeQuery> queries = Parser.parseJdbcSql("DeLeTe from foo where a=1", true, true, false, true, true);
NativeQuery query = queries.get(0);
assertTrue("This is a delete command", query.command.getType() == DMLCommandType.DELETE);
assertTrue("This is a delete command", query.command.getType() == SqlCommandType.DELETE);

queries = Parser.parseJdbcSql("update foo set (a=?,b=?,c=?)", true, true, false, true, true);
query = queries.get(0);
assertFalse("This is not a delete command", query.command.getType() == DMLCommandType.DELETE);
assertFalse("This is not a delete command", query.command.getType() == SqlCommandType.DELETE);

}

@@ -105,27 +105,27 @@ public void testisMove() {

List<NativeQuery> queries = Parser.parseJdbcSql("MoVe NEXT FROM FOO", true, true, false, true, true);
NativeQuery query = queries.get(0);
assertTrue("This is a move command", query.command.getType() == DMLCommandType.MOVE);
assertTrue("This is a move command", query.command.getType() == SqlCommandType.MOVE);

queries = Parser.parseJdbcSql("update foo set (a=?,b=?,c=?)", true, true, false, true, true);
query = queries.get(0);
assertFalse("This is not a move command", query.command.getType() == DMLCommandType.MOVE);
assertFalse("This is not a move command", query.command.getType() == SqlCommandType.MOVE);

}

public void testIsInsert() {

List<NativeQuery> queries = Parser.parseJdbcSql("InSeRt into foo (a,b,c) values (?,?,?) returning a", true, true, false, true, true);
NativeQuery query = queries.get(0);
assertTrue("This is an insert command", query.command.getType() == DMLCommandType.INSERT);
assertTrue("This is an insert command", query.command.getType() == SqlCommandType.INSERT);

queries = Parser.parseJdbcSql("update foo set (a=?,b=?,c=?)", true, true, false, true, true);
query = queries.get(0);
assertFalse("This is not an insert command", query.command.getType() == DMLCommandType.INSERT);
assertFalse("This is not an insert command", query.command.getType() == SqlCommandType.INSERT);

queries = Parser.parseJdbcSql("select 1 as insert", true, true, false, true, true);
query = queries.get(0);
assertFalse("This is not insert command", query.command.getType() == DMLCommandType.INSERT);
assertFalse("This is not insert command", query.command.getType() == SqlCommandType.INSERT);
}

public void testMultipleEmptyQueries() {

0 comments on commit 79db127

Please sign in to comment.