
com.landawn.abacus.EntityManager Maven / Gradle / Ivy
The newest version!
/*
* Copyright (C) 2015 HaiYang Li
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/
package com.landawn.abacus;
import java.util.Collection;
import java.util.List;
import java.util.Map;
// TODO: Auto-generated Javadoc
/**
*
* Main interface of entity manager.
*
EntityManager entityManager =
*
com.landawn.abacus.core.EntityManagerFactory.getInstance().getEntityManager(domainName);
*
*
Author author = new Author();
*
author.setFirstName("firstName");
*
author.setLastName("lastName");
*
EntityId entityId = entityManager.add(author);
*
*
Author dbAuthor = entityManager.get(entityId);
*
N.println(dbAuthor);
*
*
dbAuthor.setFirstName("updatedFirstName");
*
entityManager.update(dbAuthor);
*
dbAuthor = entityManager.get(entityId);
*
N.println(dbAuthor);
*
*
Condition cond = ConditionFactory.eq(Author.FIRST_NAME, "updatedFirstName");
*
ResultList resultList = entityManager.query(Author.__, null, cond);
*
N.println(resultList);
*
*
entityManager.delete(dbAuthor);
*
dbAuthor = entityManager.get(entityId);
*
N.println(dbAuthor);
*
*
*
*
* Design principles: 1, Simple (is beautiful) 2, Fast (is powerful) 3, Concepts (must be integral
* and consistent)
* These principles can't be broken by any change or reason. And basically programmable is > configurable. There is no
* extra support by configuration file or annotation.
*
* All the implementation should be multiple thread safety.
*
*
* {@code EntityManager} doesn't support the inline changes made by {@code add/remove} methods in {@code ActiveRecord}.
* these changes will be ignored. only the entity own property changes are committed if call {@code EntityManager}
* .update(...) or delete(...) APIs to update an {@code ActiveRecord}.
*
* @author Haiyang Li
* @param the entity type
* @since 0.8
*/
public interface EntityManager extends DBAccess {
/**
* Insert the specified {@code entity} into data store.
*
* @param entity
* @return EntityId
* @see #add(T[], Map)
*/
EntityId add(T entity);
/**
* Insert the specified {@code entity} into data store.
*
* @param entity
* @param options {@link com.landawn.abacus.util.Options}
* @return EntityId
* @see #add(T[], Map)
*/
EntityId add(T entity, Map options);
/**
* Insert the specified {@code entities} into data store. The entity in {@code entities} must be the same type
* entity.
*
* @param entities
* @return EntityId[]
* @see #add(T[], Map)
*/
List addAll(Collection extends T> entities);
/**
* Insert the specified {@code entities} into data store. The entity in {@code entities} must be the same type
* entity.
*
* @param entities
* @param options {@link com.landawn.abacus.util.Options}
* @return int
*/
List addAll(Collection extends T> entities, Map options);
/**
* Update the record in data store by the updated properties in the specified {@code entity}.
*
* @param entity
* @return int
* @see com.landawn.abacus.util.Options.Tran
*/
int update(T entity);
/**
* Update the record in data store by the updated properties in the specified {@code entity}.
*
* @param entity
* @param options {@link com.landawn.abacus.util.Options}
* @return int
*/
int update(T entity, Map options);
/**
* Update the records in data store by the updated properties in the specified {@code entities}. The entity in
* specified {@code entities} could be different type. The method will start a transaction to update.
*
* @param entities
* @return int
* @see com.landawn.abacus.util.Options.Tran
*/
int updateAll(Collection extends T> entities);
/**
* Update the records in data store by the updated properties in the specified {@code entities}. The entity in
* specified {@code entities} could be different type. The method will start a transaction to update.
*
* @param entities
* @param options {@link com.landawn.abacus.util.Options}
* @return int
*/
int updateAll(Collection extends T> entities, Map options);
/**
* Delete record from data store by the specified {@code entity}.
*
* @param entity
* @return int
* @see com.landawn.abacus.util.Options.Tran
*/
int delete(T entity);
/**
* Delete record from data store by the specified {@code entity}.
*
* @param entity
* @param options {@link com.landawn.abacus.util.Options}
* @return int
*/
int delete(T entity, Map options);
/**
* Delete record from data store by the specified {@code entities}.
*
* @param entities
* @return int
*/
int deleteAll(Collection extends T> entities);
/**
* Delete record from data store by the specified {@code entities}.
*
* @param entities
* @param options {@link com.landawn.abacus.util.Options}
* @return int
*/
int deleteAll(Collection extends T> entities, Map options);
/**
* Lock the record identified by the specified {@code entityId} on the specified level {@code lockMode}.
*
* @param entityId
* @param lockMode
* @param options {@link com.landawn.abacus.util.Options}
* @return lock code. Return null if record has lock by other.
* @deprecated
*/
@Deprecated
String lockRecord(EntityId entityId, LockMode lockMode, Map options);
/**
* Release the lock on the record identified by the specified {@code entityId}.
*
* @param entityId
* @param lockCode
* @param options {@link com.landawn.abacus.util.Options}
* @return true
if the record is locked by the specified {@code lockCode}.or already unlocked return
* {@code false} otherwise.
* @deprecated
*/
@Deprecated
boolean unlockRecord(EntityId entityId, String lockCode, Map options);
/**
* Return the version of the record identified by the specified {@code entityId}.
*
* @param entityId
* @param options {@link com.landawn.abacus.util.Options}
* @return long
* @deprecated
*/
@Deprecated
long getRecordVersion(EntityId entityId, Map options);
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy