com.objectsql.BaseService Maven / Gradle / Ivy
Show all versions of object-sql Show documentation
/*
* Copyright 2017 @objectsql.com
*
* 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.objectsql;
import com.objectsql.exception.ORMException;
import com.objectsql.handler.ResultSetProcessHandler;
import com.objectsql.listener.*;
import com.objectsql.query.IQuery;
import com.objectsql.support.*;
import java.util.List;
public interface BaseService extends ServiceChangedListener, SQLService {
void setObjectSQLManager(ObjectSQLManager objectSQLManager);
void addDefaultListener(DefaultListener listener);
void removeDefaultListener(DefaultListener listener);
void addChangeListener(ChangeListener listener);
void removeChangeListener(ChangeListener listener);
void addChangedListener(ChangedListener listener);
void removeChangedListener(ChangedListener listener);
void addQueryListener(QueryListener listener);
void removeQueryListener(QueryListener listener);
List getDefaultListeners();
void setDefaultListeners(List defaultListeners);
List getChangeListeners();
void setChangeListeners(List changeListeners);
List getChangedListeners();
void setChangedListeners(List changedListeners);
List getQueryListeners();
void setQueryListeners(List queryListeners);
void copyAllListeners(BaseService service);
//触发默认值监听器
void triggerDefaultListener(ORMType type, T t);
//事务启用时,异常则回滚
void triggerChangeListener(ORMType ormType, final T original, final T t);
void triggerChangeListener(ORMType ormType, final T original, final T t, boolean updateNull, String [] nullColumns);
//立即触发
void triggerChangedListenerImmediately(ORMType ormType, final T original, final T current);
void triggerChangedListenerImmediately(ORMType ormType, final T original, final T current, boolean updateNull, String[] nullColumns);
//当事务结束时触发
void triggerChangedListenerWhenTransactionFinish(ServiceChangedListener serviceChangedListener, ORMType ormType, T original, T current);
void triggerChangedListenerWhenTransactionFinish(ServiceChangedListener serviceChangedListener, ORMType ormType, T original, T current, boolean updateNull, String[] nullColumns);
// Class getBaseClass();
/* 查询一个对象 方式一 : 取条件第一个值
Test tmp = new Test();
tmp.setId(1);//主键查询
tmp.setType(3);
Test test = baseDao.get(tmp);
查询一个对象(按主键) 方式二
Test test = baseDao.get(1);
Test test = baseDao.get(new Integer(1));
取第一个 方式三
Test tmp = new Test();
tmp.setType(3);
Test test = baseDao.get(tmp);
方式四 Query
BaseQuery query = BaseQuery.newQuery();
query.table(Test.class).createQuery();
test = testService.get(query);
MultiQuery multiQuery = MultiQuery.newQuery();
multiQuery.table("a", Test.class);
multiQuery.where(new Column("a", Test.T_ID), 3, ExpressionType.CDT_More);
multiQuery.createQuery(Test.class);
test = testService.get(multiQuery);
*/
S get(Object object);
/* 保存
testService.save(test);
*/
boolean insert(T t);
boolean insertWithoutListener(T t);
/* 更新(按主键), 若对象字段为空则不更新
testService.update(test);
*/
boolean update(T t);
boolean updateWithoutListener(T t);
/* 更新(按主键), 若对象字段为空也更新
testService.update(test, true);
*/
boolean update(T t, boolean updateNull);
boolean updateWithoutListener(T t, boolean updateNull);
boolean updateNull(T t, String ...forNullColumns);
boolean updateNullWithoutListener(T t, String ...forNullColumns);
boolean updateLambdaNull(T t, LambdaQuery
...forNullColumns);
boolean updateLambdaNullWithoutListener(T t, LambdaQuery
...forNullColumns);
boolean updates(T t, Expression... expressions);
boolean updatesWithoutListener(T t, Expression ... expressions);
boolean updatesNull(T t, Expression ... expressions);
boolean updatesNullWithoutListener(T t, Expression ... expressions);
boolean updatesNull(T t, String [] forNullColumns, Expression ... expressions);
boolean updatesNullWithoutListener(T t, String [] forNullColumns, Expression ... expressions);
boolean updatesLambdaNull(T t, LambdaQuery
[] forNullColumns, Expression ... expressions);
boolean updatesLambdaNullWithoutListener(T t, LambdaQuery
[] forNullColumns, Expression ... expressions);
boolean updates(T t, Condition condition);
boolean updatesWithoutListener(T t, Condition condition);
boolean updatesNull(T t, Condition condition);
boolean updatesNullWithoutListener(T t, Condition condition);
boolean updatesWithoutListener(Expression [] values, Expression [] conditions);
boolean updatesNull(T t, String [] forNullColumns, Condition condition);
boolean updatesNullWithoutListener(T t, String [] forNullColumns, Condition condition);
boolean updatesLambdaNull(T t, LambdaQuery
[] forNullColumns, Condition condition);
boolean updatesLambdaNullWithoutListener(T t, LambdaQuery
[] forNullColumns, Condition condition);
/* 删除, (限制条件删除,危险的动作)
testService.delete(test);
删除(按主键)
baseDao.delete(1, Test.class);
*/
boolean delete(Object object);
boolean deleteWithoutListener(Object object);
boolean deletes(Condition condition);
boolean deletesWithoutListener(Condition condition);
boolean deletes(Expression... expressions);
boolean deletesWithoutListener(Expression... expressions);
//查询该表总数据
int count(Expression ... expressions);
boolean exists(Condition condition);
boolean exists(Expression ... expressions);
//简单的查询(单表)
List listNames(String ...names);
List list();
List list(int start, int size);
List list(Expression ... expressions);
List list(Condition condition);
List list(Condition condition, MultiOrder multiOrder);
List list(Condition condition, MultiOrder multiOrder, Integer limit);
List list(Names names, Condition condition);
List list(Names names, Condition condition, MultiOrder multiOrder);
List list(Names names, Condition condition, MultiOrder multiOrder, Integer limit);
//复杂的查询(多表), 可以返回Bean,ExtBean,Map类型
List query(IQuery query);//queryDistinctString
List query(IQuery q, int size);
List query(IQuery q, int offset, int size);
void query(IQuery query, ResultSetProcessHandler resultSetHandler);
int queryCount(IQuery query);
Pageable queryPage(IQuery query, Pageable page);
String tableName() throws ORMException;
void createOrUpdate() throws ORMException;
}