mirror of
https://github.com/Rogiel/l2jserver2
synced 2025-12-05 23:22:47 +00:00
Implements OrientDB artificial primary key generations
Generated primary keys use the document ReferenceID in order to provide the generated ID. Differently from SQL based databases, IDs generated by this system are 0 indexed
This commit is contained in:
@@ -383,9 +383,15 @@ public abstract class AbstractOrientDatabaseService extends AbstractService
|
||||
property.setType(OType.getTypeByClass(path.getType()));
|
||||
}
|
||||
final boolean nullable = QPathUtils.isNullable(path);
|
||||
if (property.isNotNull() != !nullable)
|
||||
final boolean autoIncrement = QPathUtils
|
||||
.isAutoIncrementable(path);
|
||||
if (property.isNotNull() && autoIncrement)
|
||||
property.setNotNull(false);
|
||||
else if (property.isNotNull() != !nullable && !autoIncrement)
|
||||
property.setNotNull(!nullable);
|
||||
if (property.isMandatory() != !nullable)
|
||||
if (property.isMandatory() && autoIncrement)
|
||||
property.setMandatory(false);
|
||||
else if (property.isMandatory() != !nullable && !autoIncrement)
|
||||
property.setMandatory(!nullable);
|
||||
}
|
||||
for (final ForeignKey<?> fk : table.getForeignKeys()) {
|
||||
@@ -578,8 +584,13 @@ public abstract class AbstractOrientDatabaseService extends AbstractService
|
||||
if (primaryKey != null && object instanceof Model) {
|
||||
final Long rawID = row.getDocument().getIdentity()
|
||||
.getClusterPosition();
|
||||
row.getDocument()
|
||||
.field(primaryKey.getMetadata().getExpression()
|
||||
.toString(), rawID.intValue());
|
||||
row.getDocument().save(); // save, again!
|
||||
|
||||
final ID<? super RI> id = mapper.getPrimaryKeyMapper()
|
||||
.createID((RI) rawID);
|
||||
.createID((RI) (Integer) rawID.intValue());
|
||||
((Model<ID<? super RI>>) object).setID(id);
|
||||
}
|
||||
rows++;
|
||||
|
||||
Reference in New Issue
Block a user