SQL - ALTER CLASS

Updates attributes on an existing class in the schema.

Syntax

  1. ALTER CLASS <class> <attribute-name> <attribute-value>
  • <class> Defines the class you want to change.
  • <attribute-name> Defines the attribute you want to change. For a list of supported attributes, see the table below.
  • <attribute-value> Defines the value you want to set.

Examples

  • Define a super-class:

    1. orientdb> ALTER CLASS Employee SUPERCLASS Person
  • Define multiple inheritances:

    1. orientdb> ALTER CLASS Employee SUPERCLASS Person, ORestricted

    This feature was introduced in version 2.1.

  • Add a super-class:

    1. orientdb> ALTER CLASS Employee SUPERCLASS +Person

    This feature was introduced in version 2.1.

  • Remove a super-class:

    1. orientdb> ALTER CLASS Employee SUPERCLASS -Person

    This feature was introduced in version 2.1.

  • Update the class name from Account to Seller:

    1. orientdb> ALTER CLASS Account NAME Seller
  • Update the oversize factor on the class Account:

    1. orientdb> ALTER CLASS Account OVERSIZE 2
  • Add a cluster to the class Account.

    1. orientdb> ALTER CLASS Account ADDCLUSTER account2

    In the event that the cluster does not exist, it automatically creates it.

  • Remove a cluster from the class Account with the ID 34:

    1. orientdb> ALTER CLASS Account REMOVECLUSTER 34
  • Add custom properties:

    1. orientdb> ALTER CLASS Post CUSTOM onCreate.fields=_allowRead,_allowUpdate
    2. orientdb> ALTER CLASS Post CUSTOM onCreate.identityType=role
  • Create a new cluster for the class Employee, then set the cluster selection strategy to balanced:

    1. orientdb> CREATE CLUSTER employee_1
    2. orientdb> ALTER CLASS Employee ADDCLUSTER employee_1
    3. orientdb> ALTER CLASS Employee CLUSTERSELECTION balanced
  • Convert the class TheClass to an abstract class:

    1. orientdb> ALTER CLASS TheClass ABSTRACT true

For more information see CREATE CLASS, DROP CLASS, ALTER CLUSTER commands. For more information on other commands, see Console and SQL commands.

Supported Attributes

Attribute Type Support Description
NAME String Changes the class name.
SHORTNAME String Defines a short name, (that is, an alias), for the class. Use NULL to remove a short name assignment.
SUPERCLASS String Defines a super-class for the class. Use NULL to remove a super-class assignment. Beginning with version 2.1, it supports multiple inheritances. To add a new class, you can use the syntax +<class>, to remove it use -<class>.
OVERSIZE Decimal number Defines the oversize factor.
ADDCLUSTER String Adds a cluster to the class. If the cluster doesn’t exist, it creates a physical cluster. Adding clusters to a class is also useful in storing records in distributed servers. For more information, see Distributed Sharding.
REMOVECLUSTER String Removes a cluster from a class. It does not delete the cluster, only removes it from the class.
STRICTMODE Enalbes or disables strict mode. When in strict mode, you work in schema-full mode and cannot add new properties to a record if they’re part of the class’ schema definition.
CLUSTERSELECTION 1.7 Defines the selection strategy in choosing which cluster it uses for new records. On class creation it inherits the setting from the database. For more information, see Cluster Selection.
CUSTOM Defines custom properties. Property names and values must follow the syntax <property-name>=<value> without spaces between the name and value.
ABSTRACT Boolean Converts class to an abstract class or the opposite.

Java API

In addition to updating a class through the console or SQL, you can also change it through the Java API, using either the Graph or Document API.

  • Graph API:

    1. // ADD A CLUSTER TO A VERTEX CLASS
    2. graph.getVertexType("Customer").addCluster("customer_usa");
    3. // ADD A CLUSTER TO AN EDGE CLASS
    4. graph.getEdgeType("WorksAt").addCluster("WorksAt_2015");
  • Document API

    1. db.getMetadata().getSchema().getClass("Customer").addCluster("customer_usa")

History

2.1

  • Added support for multiple inheritance.

1.7

  • Added support for CLUSTERSELECTION that sets the strategy used on selecting the cluster to use when creating new records.