Unverified 提交 dccd19ef authored 作者: Noel Grandin's avatar Noel Grandin 提交者: GitHub

Merge pull request #1185 from grandinj/objectid_in_prepared

Improve naming of the object id field in Prepared
...@@ -59,7 +59,7 @@ public abstract class Prepared { ...@@ -59,7 +59,7 @@ public abstract class Prepared {
* object is not stored, {@code -1} if object is stored and its ID is * object is not stored, {@code -1} if object is stored and its ID is
* already read, {@code >0} if object is stored and its id is not yet read. * already read, {@code >0} if object is stored and its id is not yet read.
*/ */
private int objectId; private int persistedObjectId;
private int currentRowNumber; private int currentRowNumber;
private int rowScanCount; private int rowScanCount;
/** /**
...@@ -244,13 +244,13 @@ public abstract class Prepared { ...@@ -244,13 +244,13 @@ public abstract class Prepared {
/** /**
* Get the object id to use for the database object that is created in this * Get the object id to use for the database object that is created in this
* statement. This id is only set when the object is persistent. * statement. This id is only set when the object is already persisted.
* If not set, this method returns 0. * If not set, this method returns 0.
* *
* @return the object id or 0 if not set * @return the object id or 0 if not set
*/ */
protected int getCurrentObjectId() { protected int getPersistedObjectId() {
int id = objectId; int id = persistedObjectId;
return id >= 0 ? id : 0; return id >= 0 ? id : 0;
} }
...@@ -262,13 +262,13 @@ public abstract class Prepared { ...@@ -262,13 +262,13 @@ public abstract class Prepared {
* @return the object id * @return the object id
*/ */
protected int getObjectId() { protected int getObjectId() {
int id = objectId; int id = persistedObjectId;
if (id == 0) { if (id == 0) {
id = session.getDatabase().allocateObjectId(); id = session.getDatabase().allocateObjectId();
} else if (id < 0) { } else if (id < 0) {
throw DbException.throwInternalError("Prepared.getObjectId() was called before"); throw DbException.throwInternalError("Prepared.getObjectId() was called before");
} }
objectId = -1; persistedObjectId = -1;
return id; return id;
} }
...@@ -295,12 +295,12 @@ public abstract class Prepared { ...@@ -295,12 +295,12 @@ public abstract class Prepared {
} }
/** /**
* Set the object id for this statement. * Set the persisted object id for this statement.
* *
* @param i the object id * @param i the object id
*/ */
public void setObjectId(int i) { public void setPersistedObjectId(int i) {
this.objectId = i; this.persistedObjectId = i;
this.create = false; this.create = false;
} }
......
...@@ -418,7 +418,7 @@ public class Set extends Prepared { ...@@ -418,7 +418,7 @@ public class Set extends Prepared {
} }
case SetTypes.TRACE_LEVEL_FILE: case SetTypes.TRACE_LEVEL_FILE:
session.getUser().checkAdmin(); session.getUser().checkAdmin();
if (getCurrentObjectId() == 0) { if (getPersistedObjectId() == 0) {
// don't set the property when opening the database // don't set the property when opening the database
// this is for compatibility with older versions, because // this is for compatibility with older versions, because
// this setting was persistent // this setting was persistent
...@@ -427,7 +427,7 @@ public class Set extends Prepared { ...@@ -427,7 +427,7 @@ public class Set extends Prepared {
break; break;
case SetTypes.TRACE_LEVEL_SYSTEM_OUT: case SetTypes.TRACE_LEVEL_SYSTEM_OUT:
session.getUser().checkAdmin(); session.getUser().checkAdmin();
if (getCurrentObjectId() == 0) { if (getPersistedObjectId() == 0) {
// don't set the property when opening the database // don't set the property when opening the database
// this is for compatibility with older versions, because // this is for compatibility with older versions, because
// this setting was persistent // this setting was persistent
...@@ -552,7 +552,7 @@ public class Set extends Prepared { ...@@ -552,7 +552,7 @@ public class Set extends Prepared {
} }
addOrUpdateSetting(name,expression.getValue(session).getString(),0); addOrUpdateSetting(name,expression.getValue(session).getString(),0);
} catch (Exception e) { } catch (Exception e) {
//Errors during start are ignored to allow to open the database //Errors during start are ignored to allow to open the database
if (database.isStarting()) { if (database.isStarting()) {
database.getTrace(Trace.DATABASE).error(e, "{0}: failed to set authenticator during database start ",expression.toString()); database.getTrace(Trace.DATABASE).error(e, "{0}: failed to set authenticator during database start ",expression.toString());
} else { } else {
......
...@@ -54,7 +54,7 @@ public class MetaRecord implements Comparable<MetaRecord> { ...@@ -54,7 +54,7 @@ public class MetaRecord implements Comparable<MetaRecord> {
DatabaseEventListener listener) { DatabaseEventListener listener) {
try { try {
Prepared command = systemSession.prepare(sql); Prepared command = systemSession.prepare(sql);
command.setObjectId(id); command.setPersistedObjectId(id);
command.update(); command.update();
} catch (DbException e) { } catch (DbException e) {
e = e.addSQL(sql); e = e.addSQL(sql);
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论