14 protected static $bulks = [
'insert' => [ ],
'update' => [ ],
'delete' => [ ] ];
16 protected static function getBulk($class, $operation =
'update') {
17 if (! isset ( self::$bulks [$operation] [$class] )) {
18 $bulkClass =
'\\Ubiquity\\orm\\bulk\\Bulk' . \ucfirst ( $operation ) .
's';
19 self::$bulks [$operation] [$class] =
new $bulkClass ( $class );
21 return self::$bulks [$operation] [$class];
24 protected static function toOperation($instance,
string $operation): void {
25 $class = \get_class ( $instance );
26 self::getBulk ( $class, $operation )->addInstance ( $instance );
29 protected static function toOperations(array $instances,
string $operation): void {
30 $instance = \current ( $instances );
31 if (isset ( $instance )) {
32 $class = \get_class ( $instance );
33 self::getBulk ( $class, $operation )->addInstances ( $instances );
43 public static function toInsert($instance): void {
44 self::toOperation ( $instance,
'insert' );
53 public static function toInserts(array $instances): void {
54 self::toOperations ( $instances,
'insert' );
61 $bulks = self::$bulks [
'insert'];
62 foreach ( $bulks as $bulk ) {
73 public static function toUpdate($instance): void {
74 self::toOperation ( $instance,
'update' );
83 public static function toUpdates(array $instances): void {
84 self::toOperations ( $instances,
'update' );
88 $bulks = self::$bulks [
'update'];
89 foreach ( $bulks as $bulk ) {
90 $bulk->groupOp ( $count );
95 $bulks = self::$bulks [
'insert'];
96 foreach ( $bulks as $bulk ) {
97 $bulk->groupOp ( $count );
102 $bulks = self::$bulks [
'delete'];
103 foreach ( $bulks as $bulk ) {
104 $bulk->groupOp ( $count );
112 $bulks = self::$bulks [
'update'];
113 foreach ( $bulks as $bulk ) {
125 self::toOperation ( $instance,
'delete' );
134 public static function toDeletes(array $instances): void {
135 self::toOperations ( $instances,
'delete' );
142 $bulks = self::$bulks [
'delete'];
143 foreach ( $bulks as $bulk ) {
151 public static function flush(): void {
152 foreach ( self::$bulks as $bulks ) {
153 foreach ( $bulks as $bulk ) {
165 public static function clearBulks(?array $operations =
null, ?array $classes =
null): void {
166 $operations ??= \array_keys ( self::$bulks );
167 foreach ( $operations as $op ) {
168 $thisClasses = $classes ?? \array_keys ( self::$bulks [$op] );
169 foreach ( $thisClasses as $class ) {
170 if (isset ( self::$bulks [$op] [$class] )) {
171 self::$bulks [$op] [$class]->clear ();
185 $bulk = self::$bulks [$operation] [$class] ?? null;
186 if (isset ( $bulk )) {
187 return $bulk->count ();
Ubiquity\orm\traits$DAOBulkUpdatesTrait This class is part of Ubiquity.
static flush()
Executes all waiting operations (inserts, updates, deletes)
static insertGroups($count=5)
static toUpdate($instance)
Adds an instance in the bulk list of objects to update.
static toUpdates(array $instances)
Adds an array of instances in the bulk list of objects to update.
static flushInserts()
Executes all waiting insert operations.
static flushDeletes()
Executes all waiting delete operations.
static flushUpdates()
Executes all waiting update operations.
static clearBulks(?array $operations=null, ?array $classes=null)
Clear bulk and clear instances waiting for operations.
static toInsert($instance)
Adds an instance in the bulk list of objects to insert.
static toOperation($instance, string $operation)
static toInserts(array $instances)
Adds an array of instances in the bulk list of objects to insert.
static deleteGroups($count=5)
static toDelete($instance)
Adds an instance in the bulk list of objects to delete.
static updateGroups($count=5)
static getBulk($class, $operation='update')
static toOperations(array $instances, string $operation)
static toDeletes(array $instances)
Adds an array of instances in the bulk list of objects to delete.
static countInstancesBulk(string $class, string $operation='update')
Return the count of instances waiting for flushing in a bulk.
Ubiquity\orm\traits This class is part of Ubiquity.