Here are the examples of the java api org.hibernate.Session taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
3313 Examples
19
Source : HibernateUtil.java
with MIT License
from zhangjikai
with MIT License
from zhangjikai
public static Session getSession() {
Session session = SESSIONMAP.get();
if (session == null) {
session = sessionFactory.openSession();
SESSIONMAP.set(session);
}
return session;
}
19
Source : OrderLineDAO.java
with Apache License 2.0
from yugabyte
with Apache License 2.0
from yugabyte
public List<OrderLine> findAllForOrder(final UUID orderId) {
try (Session session = openCurrentSession()) {
return session.createQuery("from OrderLine where orderId = '" + orderId + "'", OrderLine.clreplaced).list();
}
}
19
Source : OrderDAO.java
with Apache License 2.0
from yugabyte
with Apache License 2.0
from yugabyte
public List<Order> findOrdersForUser(final Integer userId) {
try (Session session = openCurrentSession()) {
return session.createQuery("from Order where user_id = " + userId, Order.clreplaced).list();
}
}
19
Source : ExecuteEndNodeCommand.java
with Apache License 2.0
from youseries
with Apache License 2.0
from youseries
private void removeProcessInstances(ProcessInstance pi, Session session) {
long pid = pi.getParentId();
if (pid > 0) {
ProcessInstance parent = (ProcessInstance) session.get(ProcessInstance.clreplaced, pid);
parent.setState(ProcessInstanceState.End);
session.delete(parent);
removeProcessInstances(parent, session);
}
}
19
Source : HibernateSessionFactory.java
with MIT License
from yangyueren
with MIT License
from yangyueren
/**
* Returns the ThreadLocal Session instance. Lazy initialize
* the <code>SessionFactory</code> if needed.
*
* @return Session
* @throws HibernateException
*/
public static Session getSession() throws HibernateException {
Session session = (Session) threadLocal.get();
if (session == null || !session.isOpen()) {
if (sessionFactory == null) {
rebuildSessionFactory();
}
session = (sessionFactory != null) ? sessionFactory.openSession() : null;
threadLocal.set(session);
}
return session;
}
19
Source : SchemaDAOTest.java
with Apache License 2.0
from yahoo
with Apache License 2.0
from yahoo
/**
* Test pipeline data access object.
*/
public clreplaced SchemaDAOTest {
private static Session session;
/**
* Setup database.
*/
@BeforeClreplaced
public static void initialize() throws Exception {
CLISettings.DB_CONFIG_FILE = "src/test/resources/database-configuration.properties";
App.prepareDatabase();
App.dropAllFields();
session = HibernateSessionFactoryManager.getSessionFactory().openSession();
}
/**
* Close database.
*/
@AfterClreplaced
public static void close() throws Exception {
if (session != null) {
session.close();
}
}
/**
* Check fetch schema by schema name.
*/
@Test
public void testFetchByName() {
Schema schema = DAOFactory.schemaDAO().fetchByName(session, "schema1");
replacedert.replacedertNotNull(schema);
}
}
19
Source : PipelineProjectionVMDAOTest.java
with Apache License 2.0
from yahoo
with Apache License 2.0
from yahoo
/**
* Test pipeline projection value mapping data access object.
*/
public clreplaced PipelineProjectionVMDAOTest {
private String schemaName = "schema1";
private static Session session;
/**
* Setup the database.
*/
@BeforeClreplaced
public static void initialize() throws Exception {
CLISettings.DB_CONFIG_FILE = "src/test/resources/database-configuration.properties";
App.prepareDatabase();
App.dropAllFields();
session = HibernateSessionFactoryManager.getSessionFactory().openSession();
}
/**
* Close the database.
*/
@AfterClreplaced
public static void close() throws Exception {
if (session != null) {
session.close();
}
}
/**
* Test pipeline projection value mappings.
*/
@Test
public void testAll() {
Field field1 = new Field();
field1.setFieldName("field1");
field1.setFieldType("string");
field1.setFieldId(1101);
field1.setSchemaName(schemaName);
Field field2 = new Field();
field2.setFieldName("field2");
field2.setFieldType("string");
field2.setFieldId(1102);
field2.setSchemaName(schemaName);
DAOFactory.fieldDAO().save(session, field1);
long fid1 = field1.getFieldId();
DAOFactory.fieldDAO().save(session, field2);
long fid2 = field2.getFieldId();
PipelineProjection projection1 = new PipelineProjection();
projection1.setField(field1);
projection1.setAlias("fieldAlias1");
projection1.setKey("key1");
PipelineProjection projection2 = new PipelineProjection();
projection2.setField(field2);
projection2.setAlias("fieldAlias2");
projection2.setKey("key2");
List<String> pair1 = new ArrayList<>(Arrays.asList("fieldValue1", "fieldValueMapping1"));
List<String> pair2 = new ArrayList<>(Arrays.asList("fieldValue2", "fieldValueMapping2"));
List<List<String>> vas1 = new ArrayList<>();
vas1.add(pair1);
vas1.add(pair2);
projection1.setProjectionVMs(vas1);
List<String> pair3 = new ArrayList<>(Arrays.asList("fieldValue3", "fieldValueMapping3"));
List<List<String>> vas2 = new ArrayList<>();
vas2.add(pair3);
projection2.setProjectionVMs(vas2);
List<PipelineProjection> projections12 = new ArrayList<>();
projections12.add(projection1);
projections12.add(projection2);
PipelineProjectionDAO pipelineProjectionDAO = DAOFactory.pipelineProjectionDAO();
// Triggers the pipelineProjectionVMDAO through pipelineProjectionDAO.save
pipelineProjectionDAO.save(session, projections12);
session.flush();
List<PipelineProjection> pplsit = pipelineProjectionDAO.fetchAll(session);
replacedert.replacedertEquals(pplsit.size(), 2);
for (PipelineProjection projection : pplsit) {
replacedert.replacedertTrue(projection.getField().getFieldId() == fid1 || projection.getField().getFieldId() == fid2);
List<PipelineProjectionVM> vas = projection.getProjectionVMs();
if (projection.getField().getFieldId() == fid1) {
replacedert.replacedertEquals(projection.getField().getFieldName(), field1.getFieldName());
replacedert.replacedertEquals(vas.size(), 2);
for (PipelineProjectionVM v : vas) {
replacedert.replacedertEquals(v.getPipelineProjectionId(), projection.getPipelineProjectionId());
if (v.getFieldValue() == "fieldValue1") {
replacedert.replacedertEquals(v.getFieldValueMapping(), "fieldValueMapping1");
} else if (v.getFieldValue() == "fieldValue2") {
replacedert.replacedertEquals(v.getFieldValueMapping(), "fieldValueMapping2");
}
}
}
if (projection.getField().getFieldId() == fid2) {
replacedert.replacedertEquals(projection.getField().getFieldName(), field2.getFieldName());
replacedert.replacedertEquals(vas.size(), 1);
for (PipelineProjectionVM v : vas) {
replacedert.replacedertEquals(v.getPipelineProjectionId(), projection.getPipelineProjectionId());
replacedert.replacedertEquals(v.getFieldValue(), "fieldValue3");
replacedert.replacedertEquals(v.getFieldValueMapping(), "fieldValueMapping3");
}
}
}
Field field3 = new Field();
field3.setFieldName("field3");
field3.setFieldType("string");
field3.setFieldId(1103);
field3.setSchemaName(schemaName);
Field field4 = new Field();
field4.setFieldName("field4");
field4.setFieldType("string");
field4.setFieldId(1104);
field4.setSchemaName(schemaName);
DAOFactory.fieldDAO().save(session, field3);
long fid3 = field3.getFieldId();
DAOFactory.fieldDAO().save(session, field4);
long fid4 = field4.getFieldId();
PipelineProjection projection3 = new PipelineProjection();
projection3.setField(field3);
projection3.setAlias("fieldAlias3");
projection3.setKey("key3");
PipelineProjection projection4 = new PipelineProjection();
projection4.setField(field4);
projection4.setAlias("fieldAlias4");
projection4.setKey("key4");
List<String> pair4 = new ArrayList<>(Arrays.asList("fieldValue4", "fieldValueMapping4"));
vas1.add(pair4);
List<String> pair5 = new ArrayList<>(Arrays.asList("fieldValue5", "fieldValueMapping5"));
List<String> pair6 = new ArrayList<>(Arrays.asList("fieldValue6", "fieldValueMapping6"));
vas2.add(pair5);
vas2.add(pair6);
projection3.setProjectionVMs(vas1);
projection4.setProjectionVMs(vas2);
List<PipelineProjection> projections34 = new ArrayList<>();
projections34.add(projection3);
projections34.add(projection4);
pipelineProjectionDAO.update(session, projections12, projections34);
session.flush();
pplsit = pipelineProjectionDAO.fetchAll(session);
replacedert.replacedertEquals(pplsit.size(), 2);
for (PipelineProjection projection : pplsit) {
replacedert.replacedertTrue(projection.getField().getFieldId() == fid3 || projection.getField().getFieldId() == fid4);
List<PipelineProjectionVM> vas = projection.getProjectionVMs();
if (projection.getField().getFieldId() == fid3) {
replacedert.replacedertEquals(projection.getField().getFieldName(), field3.getFieldName());
replacedert.replacedertEquals(vas.size(), 3);
for (PipelineProjectionVM v : vas) {
replacedert.replacedertEquals(v.getPipelineProjectionId(), projection.getPipelineProjectionId());
if (v.getFieldValue() == "fieldValue1") {
replacedert.replacedertEquals(v.getFieldValueMapping(), "fieldValueMapping1");
} else if (v.getFieldValue() == "fieldValue2") {
replacedert.replacedertEquals(v.getFieldValueMapping(), "fieldValueMapping2");
} else if (v.getFieldValue() == "fieldValue4") {
replacedert.replacedertEquals(v.getFieldValueMapping(), "fieldValueMapping4");
}
}
}
if (projection.getField().getFieldId() == fid4) {
replacedert.replacedertEquals(projection.getField().getFieldName(), field4.getFieldName());
replacedert.replacedertEquals(vas.size(), 3);
for (PipelineProjectionVM v : vas) {
replacedert.replacedertEquals(v.getPipelineProjectionId(), projection.getPipelineProjectionId());
if (v.getFieldValue() == "fieldValue3") {
replacedert.replacedertEquals(v.getFieldValueMapping(), "fieldValueMapping3");
} else if (v.getFieldValue() == "fieldValue5") {
replacedert.replacedertEquals(v.getFieldValueMapping(), "fieldValueMapping5");
} else if (v.getFieldValue() == "fieldValue6") {
replacedert.replacedertEquals(v.getFieldValueMapping(), "fieldValueMapping6");
}
}
}
}
pipelineProjectionDAO.delete(session, projections34);
DAOFactory.fieldDAO().delete(session, field1);
DAOFactory.fieldDAO().delete(session, field2);
DAOFactory.fieldDAO().delete(session, field3);
DAOFactory.fieldDAO().delete(session, field4);
session.flush();
replacedert.replacedertEquals(pipelineProjectionDAO.fetchAll(session).size(), 0);
PipelineProjectionVMDAO pipelineProjectionVMDAO = DAOFactory.pipelineProjectionVMDAO();
replacedert.replacedertEquals(pipelineProjectionVMDAO.fetchAll(session).size(), 0);
}
}
19
Source : PipelineProjectionDAOTest.java
with Apache License 2.0
from yahoo
with Apache License 2.0
from yahoo
/**
* Test pipeline projection data access object.
*/
public clreplaced PipelineProjectionDAOTest {
private final String schemaName = "schema1";
private static Session session;
/**
* Setup the database.
*/
@BeforeClreplaced
public static void initialize() throws Exception {
CLISettings.DB_CONFIG_FILE = "src/test/resources/database-configuration.properties";
App.prepareDatabase();
App.dropAllFields();
session = HibernateSessionFactoryManager.getSessionFactory().openSession();
}
/**
* Close the database.
*/
@AfterClreplaced
public static void close() throws Exception {
if (session != null) {
session.close();
}
}
/**
* Test pipeline projections.
*/
@Test
public void testAll() {
Field field1 = new Field();
field1.setFieldName("field1");
field1.setFieldType("string");
field1.setFieldId(1101);
field1.setSchemaName(schemaName);
Field field2 = new Field();
field2.setFieldName("field2");
field2.setFieldType("string");
field2.setFieldId(1102);
field2.setSchemaName(schemaName);
DAOFactory.fieldDAO().save(session, field1);
long fid1 = field1.getFieldId();
DAOFactory.fieldDAO().save(session, field2);
long fid2 = field2.getFieldId();
PipelineProjection projection1 = new PipelineProjection();
projection1.setField(field1);
projection1.setAlias("fieldAlias1");
projection1.setKey("key1");
projection1.setAggregation(Aggregation.COUNT);
PipelineProjection projection2 = new PipelineProjection();
projection2.setField(field2);
projection2.setAlias("fieldAlias2");
projection2.setKey("key2");
List<PipelineProjection> projections12 = new ArrayList<>();
projections12.add(projection1);
projections12.add(projection2);
PipelineProjectionDAO pipelineProjectionDAO = DAOFactory.pipelineProjectionDAO();
pipelineProjectionDAO.save(session, projections12);
session.flush();
replacedert.replacedertEquals(pipelineProjectionDAO.fetchAll(session).size(), 2);
for (PipelineProjection projection : pipelineProjectionDAO.fetchAll(session)) {
replacedert.replacedertTrue(projection.getField().getFieldId() == fid1 || projection.getField().getFieldId() == fid2);
if (projection.getField().getFieldId() == fid1) {
replacedert.replacedertEquals(projection.getField().getFieldName(), field1.getFieldName());
}
if (projection.getField().getFieldId() == fid2) {
replacedert.replacedertEquals(projection.getField().getFieldName(), field2.getFieldName());
}
}
Field field3 = new Field();
field3.setFieldName("field3");
field3.setFieldType("string");
field3.setFieldId(1103);
field3.setSchemaName(schemaName);
Field field4 = new Field();
field4.setFieldName("field4");
field4.setFieldType("string");
field4.setFieldId(1104);
field4.setSchemaName(schemaName);
Field field5 = new Field();
field5.setFieldName("field5");
field5.setFieldType("string");
field5.setFieldId(1105);
field5.setSchemaName(schemaName);
DAOFactory.fieldDAO().save(session, field3);
long fid3 = field3.getFieldId();
DAOFactory.fieldDAO().save(session, field4);
long fid4 = field4.getFieldId();
DAOFactory.fieldDAO().save(session, field5);
long fid5 = field5.getFieldId();
PipelineProjection projection3 = new PipelineProjection();
projection3.setField(field3);
projection3.setAlias("fieldAlias3");
projection3.setKey("key3");
projection3.setAggregation(Aggregation.COUNT_DISTINCT);
PipelineProjection projection4 = new PipelineProjection();
projection4.setField(field4);
projection4.setAlias("fieldAlias4");
PipelineProjection projection5 = new PipelineProjection();
projection5.setField(field5);
projection5.setAlias("fieldAlias5");
projection5.setKey("key5");
List<PipelineProjection> projections345 = new ArrayList<>();
projections345.add(projection3);
projections345.add(projection4);
projections345.add(projection5);
pipelineProjectionDAO.update(session, projections12, projections345);
session.flush();
replacedert.replacedertEquals(pipelineProjectionDAO.fetchAll(session).size(), 3);
replacedert.replacedertEquals(pipelineProjectionDAO.fetch(session, projection3.getPipelineProjectionId()).getAlias(), projection3.getAlias());
replacedert.replacedertEquals(pipelineProjectionDAO.fetch(session, projection4.getPipelineProjectionId()).getAlias(), projection4.getAlias());
replacedert.replacedertEquals(pipelineProjectionDAO.fetch(session, projection5.getPipelineProjectionId()).getAlias(), projection5.getAlias());
replacedert.replacedertEquals(pipelineProjectionDAO.fetch(session, projection3.getPipelineProjectionId()).getKey(), projection3.getKey());
replacedert.replacedertEquals(pipelineProjectionDAO.fetch(session, projection4.getPipelineProjectionId()).getKey(), projection4.getKey());
replacedert.replacedertEquals(pipelineProjectionDAO.fetch(session, projection5.getPipelineProjectionId()).getKey(), projection5.getKey());
replacedert.replacedertEquals(pipelineProjectionDAO.fetch(session, projection3.getPipelineProjectionId()).getAggregationName(), projection3.getAggregationName());
replacedert.replacedertEquals(pipelineProjectionDAO.fetch(session, projection4.getPipelineProjectionId()).getAggregationName(), projection4.getAggregationName());
replacedert.replacedertEquals(pipelineProjectionDAO.fetch(session, projection5.getPipelineProjectionId()).getAggregationName(), projection5.getAggregationName());
replacedert.replacedertEquals(pipelineProjectionDAO.fetch(session, projection3.getPipelineProjectionId()).getField().getFieldId(), fid3);
replacedert.replacedertEquals(pipelineProjectionDAO.fetch(session, projection4.getPipelineProjectionId()).getField().getFieldId(), fid4);
replacedert.replacedertEquals(pipelineProjectionDAO.fetch(session, projection5.getPipelineProjectionId()).getField().getFieldId(), fid5);
replacedert.replacedertEquals(pipelineProjectionDAO.fetch(session, projection3.getPipelineProjectionId()).getField().getFieldName(), field3.getFieldName());
replacedert.replacedertEquals(pipelineProjectionDAO.fetch(session, projection4.getPipelineProjectionId()).getField().getFieldName(), field4.getFieldName());
replacedert.replacedertEquals(pipelineProjectionDAO.fetch(session, projection5.getPipelineProjectionId()).getField().getFieldName(), field5.getFieldName());
pipelineProjectionDAO.delete(session, projections345);
DAOFactory.fieldDAO().delete(session, field1);
DAOFactory.fieldDAO().delete(session, field2);
DAOFactory.fieldDAO().delete(session, field3);
DAOFactory.fieldDAO().delete(session, field4);
DAOFactory.fieldDAO().delete(session, field5);
session.flush();
replacedert.replacedertEquals(pipelineProjectionDAO.fetchAll(session).size(), 0);
}
}
19
Source : PipelineDAOTest.java
with Apache License 2.0
from yahoo
with Apache License 2.0
from yahoo
/**
* Test pipeline data access object.
*/
public clreplaced PipelineDAOTest {
private final String schemaName = "schema1";
private static Session session;
/**
* Setup database.
*/
@BeforeClreplaced
public static void initialize() throws Exception {
CLISettings.DB_CONFIG_FILE = "src/test/resources/database-configuration.properties";
App.prepareDatabase();
App.dropAllFields();
session = HibernateSessionFactoryManager.getSessionFactory().openSession();
}
/**
* Close database.
*/
@AfterClreplaced
public static void close() throws Exception {
if (session != null) {
session.close();
}
}
/**
* Test pipeline setting of fields / filters / etc.
*/
@Test
public void testAll() throws IOException {
Field field1 = new Field();
field1.setFieldName("field1");
field1.setFieldType("string");
field1.setFieldId(1100);
field1.setSchemaName(schemaName);
Field field2 = new Field();
field2.setFieldName("field2");
field2.setFieldType("string");
field2.setFieldId(1101);
field2.setSchemaName(schemaName);
Field field3 = new Field();
field3.setFieldName("field3");
field3.setFieldType("string");
field3.setFieldId(1102);
field3.setSchemaName(schemaName);
DAOFactory.fieldDAO().save(session, field1);
DAOFactory.fieldDAO().save(session, field2);
DAOFactory.fieldDAO().save(session, field3);
PipelineProjection projection1 = new PipelineProjection();
projection1.setField(field1);
projection1.setAlias("fieldAlias1");
PipelineProjection projection2 = new PipelineProjection();
projection2.setField(field2);
projection2.setAlias("fieldAlias2");
List<PipelineProjection> projections12 = new ArrayList<>();
projections12.add(projection1);
projections12.add(projection2);
RelationalRule filter1 = new RelationalRule();
filter1.setId(String.valueOf(field1.getFieldId()));
filter1.setField(field1.getFieldName());
filter1.setType("string");
filter1.setOperator("operator1");
filter1.setValue("v1");
RelationalRule filter2 = new RelationalRule();
filter2.setId(String.valueOf(field2.getFieldId()));
filter2.setField(field2.getFieldName());
filter2.setType("string");
filter2.setOperator("operator2");
filter2.setValue("v2");
RelationalRule filter3 = new RelationalRule();
filter3.setId(String.valueOf(field3.getFieldId()));
filter3.setField(field3.getFieldName());
filter3.setType("string");
filter3.setOperator("operator3");
filter3.setValue("v3");
List<Filter> filters1 = new ArrayList<>();
filters1.add(filter1);
filters1.add(filter2);
LogicalRule filter4 = new LogicalRule();
filter4.setCondition("AND");
filter4.setRules(filters1);
List<Filter> filters2 = new ArrayList<>();
filters2.add(filter3);
filters2.add(filter4);
LogicalRule filter5 = new LogicalRule();
filter5.setCondition("OR");
filter4.setRules(filters2);
Pipeline pipeline1 = new Pipeline();
pipeline1.setPipelineName("pipeline1");
pipeline1.setPipelineDescription("pipelineDescription1");
pipeline1.setPipelineOwner("userName1");
pipeline1.setProjections(projections12);
pipeline1.setPipelineFilterJson(Filter.toJson(filter5));
pipeline1.setPipelineOozieJobId("ooziejobid-11111111");
pipeline1.setPipelineOozieJobStatus("RUNNING");
pipeline1.setPipelineSchemaName("schema1");
DAOFactory.pipelineDAO().save(session, pipeline1);
long id1 = pipeline1.getPrimaryIdx();
replacedert.replacedertFalse(id1 == 0);
Pipeline pipeline2 = DAOFactory.pipelineDAO().fetch(session, id1);
replacedert.replacedertEquals(pipeline2.getPipelineId(), pipeline1.getPipelineId());
replacedert.replacedertEquals(pipeline2.getPipelineName(), pipeline1.getPipelineName());
replacedert.replacedertEquals(pipeline2.getPipelineDescription(), pipeline1.getPipelineDescription());
replacedert.replacedertEquals(pipeline2.getPipelineOwner(), pipeline1.getPipelineOwner());
replacedert.replacedertEquals(pipeline2.getProjections().size(), pipeline1.getProjections().size());
replacedert.replacedertEquals(pipeline2.getPipelineOozieJobId(), pipeline1.getPipelineOozieJobId());
replacedert.replacedertEquals(pipeline2.getPipelineOozieJobStatus(), pipeline1.getPipelineOozieJobStatus());
ObjectMapper mapper = new ObjectMapper();
JsonNode node1 = mapper.readTree(pipeline2.getPipelineFilterJson());
JsonNode node2 = mapper.readTree(pipeline1.getPipelineFilterJson());
replacedert.replacedertEquals(node1.equals(node2), true);
for (PipelineProjection projection : pipeline2.getProjections()) {
replacedert.replacedertTrue(projection.getPipelineProjectionId() == projection1.getPipelineProjectionId() || projection.getPipelineProjectionId() == projection2.getPipelineProjectionId());
if (projection.getPipelineProjectionId() == projection1.getPipelineProjectionId()) {
replacedert.replacedertEquals(projection.getAlias(), projection1.getAlias());
}
if (projection.getPipelineProjectionId() == projection2.getPipelineProjectionId()) {
replacedert.replacedertEquals(projection.getAlias(), projection2.getAlias());
}
}
replacedert.replacedertEquals(DAOFactory.pipelineDAO().fetchByName(session, "pipeline1").getPipelineDescription(), pipeline1.getPipelineDescription());
PipelineProjection projection3 = new PipelineProjection();
projection3.setField(field1);
projection3.setAlias("fieldAlias3");
PipelineProjection projection4 = new PipelineProjection();
projection4.setField(field2);
projection4.setAlias("fieldAlias4");
PipelineProjection projection5 = new PipelineProjection();
projection5.setField(field3);
projection5.setAlias("fieldAlias5");
List<PipelineProjection> projections345 = new ArrayList<>();
projections345.add(projection3);
projections345.add(projection4);
projections345.add(projection5);
RelationalRule filter6 = new RelationalRule();
filter6.setId(String.valueOf(field3.getFieldId()));
filter6.setField(field3.getFieldName());
filter6.setType("string");
filter6.setOperator("operator6");
filter6.setValue("v6");
LogicalRule filter7 = new LogicalRule();
filter7.setCondition("AND");
List<Filter> filters3 = new ArrayList<>();
filters3.add(filter6);
filter7.setRules(filters3);
Pipeline pipeline3 = new Pipeline();
pipeline3.setPipelineId(id1);
pipeline3.setPipelineName("pipeline3");
pipeline3.setPipelineDescription("pipelineDescription3");
pipeline3.setPipelineOwner("userName3");
pipeline3.setProjections(projections345);
pipeline3.setPipelineFilterJson(Filter.toJson(filter7));
pipeline3.setPipelineOozieJobId("ooziejobid-333333333333");
pipeline3.setPipelineOozieJobStatus("KILLED");
pipeline3.setPipelineSchemaName("schema1");
DAOFactory.pipelineDAO().update(session, pipeline3);
List<Pipeline> pipelines = DAOFactory.pipelineDAO().fetchAll(session);
replacedert.replacedertEquals(pipelines.size(), 1);
Pipeline pipeline4 = DAOFactory.pipelineDAO().fetch(session, id1);
replacedert.replacedertEquals(pipeline4.getPipelineDescription(), pipeline3.getPipelineDescription());
replacedert.replacedertEquals(pipeline4.getProjections().size(), projections345.size());
replacedert.replacedertEquals(pipeline4.getPipelineOozieJobId(), pipeline3.getPipelineOozieJobId());
replacedert.replacedertEquals(pipeline4.getPipelineOozieJobStatus(), pipeline3.getPipelineOozieJobStatus());
JsonNode node3 = mapper.readTree(pipeline3.getPipelineFilterJson());
JsonNode node4 = mapper.readTree(pipeline4.getPipelineFilterJson());
replacedert.replacedertEquals(node3.equals(node4), true);
for (PipelineProjection projection : pipeline4.getProjections()) {
replacedert.replacedertTrue(projection.getPipelineProjectionId() == projection3.getPipelineProjectionId() || projection.getPipelineProjectionId() == projection4.getPipelineProjectionId() || projection.getPipelineProjectionId() == projection5.getPipelineProjectionId());
if (projection.getPipelineProjectionId() == projection3.getPipelineProjectionId()) {
replacedert.replacedertEquals(projection.getAlias(), projection3.getAlias());
}
if (projection.getPipelineProjectionId() == projection4.getPipelineProjectionId()) {
replacedert.replacedertEquals(projection.getAlias(), projection4.getAlias());
}
if (projection.getPipelineProjectionId() == projection5.getPipelineProjectionId()) {
replacedert.replacedertEquals(projection.getAlias(), projection5.getAlias());
}
}
replacedert.replacedertEquals(DAOFactory.pipelineDAO().fetchByName(session, "pipeline3").getPipelineDescription(), pipeline3.getPipelineDescription());
DAOFactory.pipelineDAO().delete(session, pipeline4);
replacedert.replacedertEquals(DAOFactory.pipelineDAO().fetchAll(session).size(), 0);
replacedert.replacedertEquals(DAOFactory.pipelineProjectionDAO().fetchAll(session).size(), 0);
DAOFactory.fieldDAO().delete(session, field1);
DAOFactory.fieldDAO().delete(session, field2);
DAOFactory.fieldDAO().delete(session, field3);
session.flush();
}
}
19
Source : FunnelGroupDAOTest.java
with Apache License 2.0
from yahoo
with Apache License 2.0
from yahoo
/**
* Test pipeline data access object.
*/
public clreplaced FunnelGroupDAOTest {
private static Session session;
/**
* Setup database.
*/
@BeforeClreplaced
public static void initialize() throws Exception {
CLISettings.DB_CONFIG_FILE = "src/test/resources/database-configuration.properties";
App.prepareDatabase();
App.dropAllFields();
session = HibernateSessionFactoryManager.getSessionFactory().openSession();
}
/**
* Close database.
*/
@AfterClreplaced
public static void close() throws Exception {
if (session != null) {
session.close();
}
}
/**
* Test funnel group setting of fields / filters / etc.
*/
@Test
public void testAll() throws IOException {
// Create fields and projections based on the fields.
Field[] fields = createThreeTestFields();
Field field1 = fields[0];
Field field2 = fields[1];
Field field3 = fields[2];
PipelineProjection projection1 = new PipelineProjection();
projection1.setField(field1);
projection1.setAlias("fieldAlias1");
PipelineProjection projection2 = new PipelineProjection();
projection2.setField(field2);
projection2.setAlias("fieldAlias2");
List<PipelineProjection> projections12 = new ArrayList<>();
projections12.add(projection1);
projections12.add(projection2);
// Create filters and filter groups.
RelationalRule[] filters = createThreeTestFilters(field1, field2, field3);
RelationalRule filter1 = filters[0];
RelationalRule filter2 = filters[1];
RelationalRule filter3 = filters[2];
List<Filter> filters1 = new ArrayList<>();
filters1.add(filter1);
filters1.add(filter2);
LogicalRule filter4 = new LogicalRule();
filter4.setCondition("AND");
filter4.setRules(filters1);
List<Filter> filters2 = new ArrayList<>();
filters2.add(filter3);
filters2.add(filter4);
LogicalRule filter5 = new LogicalRule();
filter5.setCondition("OR");
filter4.setRules(filters2);
// Create funnel groups.
FunnelGroup funnelGroup1 = new FunnelGroup();
funnelGroup1.setFunnelGroupName("funnelGroup1");
funnelGroup1.setFunnelGroupDescription("funnelGroupDescription1");
funnelGroup1.setFunnelGroupOwner("userName1");
funnelGroup1.setProjections(projections12);
funnelGroup1.setFunnelGroupFilterJson(Filter.toJson(filter5));
funnelGroup1.setFunnelGroupOozieJobId("ooziejobid-11111111");
funnelGroup1.setFunnelGroupOozieJobStatus("RUNNING");
funnelGroup1.setFunnelGroupSchemaName("schema1");
DAOFactory.funnelGroupDAO().save(session, funnelGroup1);
long id1 = funnelGroup1.getPrimaryIdx();
replacedert.replacedertNotEquals(id1, 0);
FunnelGroup funnelGroup2 = DAOFactory.funnelGroupDAO().fetch(session, id1);
replacedert.replacedertEquals(funnelGroup2.getFunnelGroupId(), funnelGroup1.getFunnelGroupId());
replacedert.replacedertEquals(funnelGroup2.getFunnelGroupName(), funnelGroup1.getFunnelGroupName());
replacedert.replacedertEquals(funnelGroup2.getFunnelGroupDescription(), funnelGroup1.getFunnelGroupDescription());
replacedert.replacedertEquals(funnelGroup2.getFunnelGroupOwner(), funnelGroup1.getFunnelGroupOwner());
replacedert.replacedertEquals(funnelGroup2.getProjections().size(), funnelGroup1.getProjections().size());
replacedert.replacedertEquals(funnelGroup2.getFunnelGroupOozieJobId(), funnelGroup1.getFunnelGroupOozieJobId());
replacedert.replacedertEquals(funnelGroup2.getFunnelGroupOozieJobStatus(), funnelGroup1.getFunnelGroupOozieJobStatus());
ObjectMapper mapper = new ObjectMapper();
JsonNode node1 = mapper.readTree(funnelGroup1.getFunnelGroupFilterJson());
JsonNode node2 = mapper.readTree(funnelGroup2.getFunnelGroupFilterJson());
replacedert.replacedertEquals(node1, node2);
for (PipelineProjection projection : funnelGroup2.getProjections()) {
replacedert.replacedertTrue(projection.getPipelineProjectionId() == projection1.getPipelineProjectionId() || projection.getPipelineProjectionId() == projection2.getPipelineProjectionId());
if (projection.getPipelineProjectionId() == projection1.getPipelineProjectionId()) {
replacedert.replacedertEquals(projection.getAlias(), projection1.getAlias());
}
if (projection.getPipelineProjectionId() == projection2.getPipelineProjectionId()) {
replacedert.replacedertEquals(projection.getAlias(), projection2.getAlias());
}
}
replacedert.replacedertEquals(DAOFactory.funnelGroupDAO().fetchByName(session, "funnelGroup1").getFunnelGroupDescription(), funnelGroup1.getFunnelGroupDescription());
PipelineProjection projection3 = new PipelineProjection();
projection3.setField(field1);
projection3.setAlias("fieldAlias3");
PipelineProjection projection4 = new PipelineProjection();
projection4.setField(field2);
projection4.setAlias("fieldAlias4");
PipelineProjection projection5 = new PipelineProjection();
projection5.setField(field3);
projection5.setAlias("fieldAlias5");
List<PipelineProjection> projections345 = new ArrayList<>();
projections345.add(projection3);
projections345.add(projection4);
projections345.add(projection5);
RelationalRule filter6 = new RelationalRule();
filter6.setId(String.valueOf(field3.getFieldId()));
filter6.setField(field3.getFieldName());
filter6.setType("string");
filter6.setOperator("operator6");
filter6.setValue("v6");
LogicalRule filter7 = new LogicalRule();
filter7.setCondition("AND");
List<Filter> filters3 = new ArrayList<>();
filters3.add(filter6);
filter7.setRules(filters3);
FunnelGroup funnelGroup3 = new FunnelGroup();
funnelGroup3.setFunnelGroupId(id1);
funnelGroup3.setFunnelGroupName("funnelGroup3");
funnelGroup3.setFunnelGroupDescription("pipelineDescription3");
funnelGroup3.setFunnelGroupOwner("userName3");
funnelGroup3.setProjections(projections345);
funnelGroup3.setFunnelGroupFilterJson(Filter.toJson(filter7));
funnelGroup3.setFunnelGroupOozieJobId("ooziejobid-333333333333");
funnelGroup3.setFunnelGroupOozieJobStatus("KILLED");
funnelGroup3.setFunnelGroupSchemaName("schema1");
DAOFactory.funnelGroupDAO().update(session, funnelGroup3);
List<FunnelGroup> groups = DAOFactory.funnelGroupDAO().fetchAll(session);
replacedert.replacedertEquals(groups.size(), 1);
FunnelGroup funnelGroup4 = DAOFactory.funnelGroupDAO().fetch(session, id1);
replacedert.replacedertEquals(funnelGroup4.getFunnelGroupDescription(), funnelGroup3.getFunnelGroupDescription());
replacedert.replacedertEquals(funnelGroup4.getProjections().size(), projections345.size());
replacedert.replacedertEquals(funnelGroup4.getFunnelGroupOozieJobId(), funnelGroup3.getFunnelGroupOozieJobId());
replacedert.replacedertEquals(funnelGroup4.getFunnelGroupOozieJobStatus(), funnelGroup3.getFunnelGroupOozieJobStatus());
JsonNode node3 = mapper.readTree(funnelGroup3.getFunnelGroupFilterJson());
JsonNode node4 = mapper.readTree(funnelGroup4.getFunnelGroupFilterJson());
replacedert.replacedertEquals(node3, node4);
for (PipelineProjection projection : funnelGroup4.getProjections()) {
replacedert.replacedertTrue(projection.getPipelineProjectionId() == projection3.getPipelineProjectionId() || projection.getPipelineProjectionId() == projection4.getPipelineProjectionId() || projection.getPipelineProjectionId() == projection5.getPipelineProjectionId());
if (projection.getPipelineProjectionId() == projection3.getPipelineProjectionId()) {
replacedert.replacedertEquals(projection.getAlias(), projection3.getAlias());
}
if (projection.getPipelineProjectionId() == projection4.getPipelineProjectionId()) {
replacedert.replacedertEquals(projection.getAlias(), projection4.getAlias());
}
if (projection.getPipelineProjectionId() == projection5.getPipelineProjectionId()) {
replacedert.replacedertEquals(projection.getAlias(), projection5.getAlias());
}
}
replacedert.replacedertEquals(DAOFactory.funnelGroupDAO().fetchByName(session, "funnelGroup3").getFunnelGroupDescription(), funnelGroup3.getFunnelGroupDescription());
DAOFactory.funnelGroupDAO().delete(session, funnelGroup4);
replacedert.replacedertEquals(DAOFactory.funnelGroupDAO().fetchAll(session).size(), 0);
replacedert.replacedertEquals(DAOFactory.pipelineProjectionDAO().fetchAll(session).size(), 0);
DAOFactory.fieldDAO().delete(session, field1);
DAOFactory.fieldDAO().delete(session, field2);
DAOFactory.fieldDAO().delete(session, field3);
session.flush();
}
/**
* Create 3 filters used for test.
*/
private RelationalRule[] createThreeTestFilters(Field field1, Field field2, Field field3) {
RelationalRule filter1 = new RelationalRule();
filter1.setId(String.valueOf(field1.getFieldId()));
filter1.setField(field1.getFieldName());
filter1.setType("string");
filter1.setOperator("operator1");
filter1.setValue("v1");
RelationalRule filter2 = new RelationalRule();
filter2.setId(String.valueOf(field2.getFieldId()));
filter2.setField(field2.getFieldName());
filter2.setType("string");
filter2.setOperator("operator2");
filter2.setValue("v2");
RelationalRule filter3 = new RelationalRule();
filter3.setId(String.valueOf(field3.getFieldId()));
filter3.setField(field3.getFieldName());
filter3.setType("string");
filter3.setOperator("operator3");
filter3.setValue("v3");
return new RelationalRule[] { filter1, filter2, filter3 };
}
/**
* Create 3 fields used for test.
*/
private Field[] createThreeTestFields() {
Field field1 = new Field();
field1.setFieldName("field1");
field1.setFieldType("string");
field1.setFieldId(1100);
field1.setSchemaName("schema1");
Field field2 = new Field();
field2.setFieldName("field2");
field2.setFieldType("string");
field2.setFieldId(1101);
field2.setSchemaName("schema1");
Field field3 = new Field();
field3.setFieldName("field3");
field3.setFieldType("string");
field3.setFieldId(1102);
field3.setSchemaName("schema1");
DAOFactory.fieldDAO().save(session, field1);
DAOFactory.fieldDAO().save(session, field2);
DAOFactory.fieldDAO().save(session, field3);
return new Field[] { field1, field2, field3 };
}
}
19
Source : AppTest.java
with Apache License 2.0
from yahoo
with Apache License 2.0
from yahoo
/**
* Unit test for simple App.
*/
public clreplaced AppTest {
private static Session session;
// all pre-defined data types
private static String[] dataTypes = { "integer", "boolean", "string" };
private static Set<String> allowedDataType = new HashSet<>(Arrays.asList(dataTypes));
/**
* Setup database.
*/
@BeforeClreplaced
public static void initialize() throws Exception {
CLISettings.DB_CONFIG_FILE = "src/test/resources/database-configuration.properties";
App.prepareDatabase();
App.dropAllFields();
session = HibernateSessionFactoryManager.getSessionFactory().openSession();
}
/**
* Test loading a custom schema.
*/
@Test
public void testLoadCustomSchema() throws Exception {
App.loadSchemas("src/test/resources/schemas/");
// Test read operational params.
SchemaDAO schemaDAO = DAOFactory.schemaDAO();
List<Schema> schemas = schemaDAO.fetchAll(session);
replacedert.replacedertEquals(schemas.size(), 4);
Schema schema = ServiceFactory.schemaService().fetchByName("schema1");
List<String> schemaUserIdFields = (new ObjectMapper()).readValue(schema.getSchemaUserIdFields(), List.clreplaced);
replacedert.replacedertEquals(schemaUserIdFields.size(), 2);
replacedert.replacedertEquals(schema.getSchemaTargetTable(), "daily_data");
// Check that there are the correct number of fields in the database
List<Field> allFields = schema.getFields();
int fieldNum = allFields.size();
replacedert.replacedertEquals(fieldNum, 17);
schema = ServiceFactory.schemaService().fetchByName("schema3");
schemaUserIdFields = (new ObjectMapper()).readValue(schema.getSchemaUserIdFields(), List.clreplaced);
replacedert.replacedertNull(schemaUserIdFields);
replacedert.replacedertEquals(schema.getSchemaDisableBullet().booleanValue(), true);
replacedert.replacedertEquals(schema.getSchemaDisableFunnel().booleanValue(), true);
replacedert.replacedertEquals(schema.getFields().size(), 3);
}
/**
* Test updating a schema's operational params.
* @throws Exception
*/
@Test
public void testUpdateSchemaOperationalParams() throws Exception {
// Load original info
App.loadSchemas("src/test/resources/schemas/");
Schema schema1 = ServiceFactory.schemaService().fetchByName("schema1");
Schema schema2 = ServiceFactory.schemaService().fetchByName("schema2");
Schema schema3 = ServiceFactory.schemaService().fetchByName("schema3");
replacedert.replacedertEquals(schema1.getSchemaDefaultFilters(), "[{\"id\":\"user_logged_in\",\"operator\":\"equal\",\"value\":\"1\"},{\"id\":\"browser\",\"operator\":\"equal\",\"value\":\"browser1\"},{\"id\":\"debug_tag\",\"operator\":\"is_null\"}]");
replacedert.replacedertEquals(schema2.getSchemaDefaultFilters(), "[{\"id\":\"filter\",\"operator\":\"is_null\"}]");
replacedert.replacedertFalse(schema1.getIsSchemaDeleted());
replacedert.replacedertFalse(schema2.getIsSchemaDeleted());
replacedert.replacedertFalse(schema3.getIsSchemaDeleted());
// Update
App.loadSchemas("src/test/resources/updated_schemas/");
schema1 = ServiceFactory.schemaService().fetchByName("schema1");
schema2 = ServiceFactory.schemaService().fetchByName("schema2");
schema3 = ServiceFactory.schemaService().fetchByName("schema3");
replacedert.replacedertEquals(schema1.getSchemaDefaultFilters(), "[{\"id\":\"user_logged_in\",\"operator\":\"equal\",\"value\":\"1\"},{\"id\":\"browser\",\"operator\":\"equal\",\"value\":\"browser1\"}]");
replacedert.replacedertEquals(schema2.getSchemaDefaultFilters(), "[{\"id\":\"filter\",\"operator\":\"is_null\"},{\"id\":\"cookie_version\",\"operator\":\"equal\",\"value\":\"1\"}]");
replacedert.replacedertFalse(schema1.getIsSchemaDeleted());
replacedert.replacedertFalse(schema2.getIsSchemaDeleted());
replacedert.replacedertTrue(schema3.getIsSchemaDeleted());
}
/**
* Test loading a file rather than directory.
*/
@Test(expectedExceptions = { IllegalArgumentException.clreplaced })
public void testLoadCustomSchemaWithIllegalPath() throws Exception {
// The argument is the path for a file
App.loadSchemas("src/test/resources/schemas/testfile");
}
/**
* Test run the app.
*/
@Test
public void mainTest() throws Exception {
String[] args = { "--version", "0.0.0", "--schema-files-dir", "src/test/resources/schemas/", "--db-config-file", "src/test/resources/database-configuration.properties" };
File templateOutputFolder = new File("/tmp/funnelmart_test");
if (!templateOutputFolder.exists()) {
templateOutputFolder.mkdir();
} else {
FileUtils.deleteDirectory(templateOutputFolder);
templateOutputFolder.mkdir();
}
try {
App.main(args);
} catch (Exception e) {
replacedert.fail(e.getMessage());
}
}
/**
* Check if the field type is one of the pre-defined types.
*/
private String fieldTypeValidityCheck(String fieldType) throws Exception {
if (!fieldType.equals("") && !allowedDataType.contains(fieldType)) {
return "Type " + fieldType + " is not valid; ";
}
return "";
}
/**
* Check if the field type meets expectation.
*/
private String fieldDataTypeCheck(String actualFieldType, String expectedFieldType) throws Exception {
if (!expectedFieldType.equals("") && !actualFieldType.equals(expectedFieldType)) {
return "Expected " + expectedFieldType + " type, but get " + actualFieldType + " type; ";
}
return "";
}
/**
* Check if the number of subfields meets expectation.
*/
private String subfieldNumCheck(int actualSubfieldNum, int expectedSubfieldNum) throws Exception {
if (expectedSubfieldNum > 0 && actualSubfieldNum != expectedSubfieldNum) {
return "Expected " + expectedSubfieldNum + " subfields, but get " + actualSubfieldNum + " subfields; ";
}
return "";
}
/**
* Check if certain subfields exist under their parent fields.
*/
private String subfieldMemberCheck(String[] actualFields, List<String> expectedFields) throws Exception {
if (!expectedFields.equals("")) {
StringBuilder invalidFields = new StringBuilder();
Set<String> expectedFieldNames = new HashSet<>(expectedFields);
for (String f : actualFields) {
if (!expectedFieldNames.contains(f)) {
invalidFields.append(f + ", ");
}
}
if (invalidFields.length() != 0) {
return "Subfields not exist: " + invalidFields.toString() + "; ";
}
}
return "";
}
/**
* Check if the field exists.
*/
private String fieldExistCheck(String fieldName) throws Exception {
if (!fieldName.equals("")) {
return "Field not exist; ";
}
return "";
}
}
19
Source : SchemaServiceImpl.java
with Apache License 2.0
from yahoo
with Apache License 2.0
from yahoo
/**
* Delete enreplacedy.
*/
public void delete(String name) throws DataValidatorException, DatabaseException {
Session session = this.createSession();
Schema model = this.preDeleteCheck(session, name);
try {
this.getDAO().delete(session, model);
} catch (RuntimeException e) {
throw new DatabaseException("Database exception: delete " + this.getDAO().getEnreplacedyClreplaced().getSimpleName() + " failed.", e);
} finally {
this.reclaimSession(session);
}
}
19
Source : SchemaServiceImpl.java
with Apache License 2.0
from yahoo
with Apache License 2.0
from yahoo
/**
* Fetch enreplacedy by name.
*/
public Schema fetch(String name) throws DataValidatorException, DatabaseException {
Session session = this.createSession();
Schema model = null;
try {
model = this.getDAO().fetchByName(session, name);
} catch (RuntimeException e) {
throw new DatabaseException("Database exception: cannot query " + this.getDAO().getEnreplacedyClreplaced().getSimpleName() + " with name [" + name + "].", e);
} finally {
this.reclaimSession(session);
}
if (model == null) {
throw new DataValidatorException("Cannot find " + this.getDAO().getEnreplacedyClreplaced().getSimpleName() + " with name [" + name + "].");
}
return model;
}
19
Source : SchemaServiceImpl.java
with Apache License 2.0
from yahoo
with Apache License 2.0
from yahoo
/**
* Model check before model delete.
*/
protected Schema preDeleteCheck(Session session, String schemaName) throws DataValidatorException {
// check if name exists
Schema oldModel = this.getDAO().fetchByName(session, schemaName);
if (oldModel == null) {
throw new DataValidatorException("The " + this.getDAO().getEnreplacedyClreplaced().getSimpleName() + " with name [" + schemaName + "] does not exist.");
}
return oldModel;
}
19
Source : PipelineServiceImpl.java
with Apache License 2.0
from yahoo
with Apache License 2.0
from yahoo
/**
* Fetch enreplacedy by Id.
*/
public Pipeline fetch(long id) throws DataValidatorException, DatabaseException {
Session session = this.createSession();
Pipeline model = null;
try {
model = this.getDAO().fetch(session, id);
} catch (RuntimeException e) {
throw new DatabaseException("Database exception: cannot query " + this.getDAO().getEnreplacedyClreplaced().getSimpleName() + " with id [" + id + "].", e);
} finally {
this.reclaimSession(session);
}
if (model == null) {
throw new DataValidatorException("Cannot find " + this.getDAO().getEnreplacedyClreplaced().getSimpleName() + " with id [" + id + "].");
}
return model;
}
19
Source : PipelineServiceImpl.java
with Apache License 2.0
from yahoo
with Apache License 2.0
from yahoo
/**
* Delete enreplacedy.
*/
public void delete(long id) throws DataValidatorException, DatabaseException {
Session session = this.createSession();
Pipeline model = this.preDeleteCheck(session, id);
try {
this.getDAO().delete(session, model);
} catch (RuntimeException e) {
throw new DatabaseException("Database exception: delete " + this.getDAO().getEnreplacedyClreplaced().getSimpleName() + " failed.", e);
} finally {
this.reclaimSession(session);
}
}
19
Source : PipelineServiceImpl.java
with Apache License 2.0
from yahoo
with Apache License 2.0
from yahoo
/**
* Check relational rules.
*/
protected void checkRelationalRule(Session session, PipelineRelationalRule rule) throws DataValidatorException {
this.validateField(session, rule.getField());
if (rule.getOperator() == null) {
throw new DataValidatorException("A pipeline relational rule should contain an operator.");
}
if (rule.getValue() == null) {
throw new DataValidatorException("A pipeline relational rule should contain a value.");
}
}
19
Source : PipelineServiceImpl.java
with Apache License 2.0
from yahoo
with Apache License 2.0
from yahoo
/**
* Check filter.
*/
protected void checkFilter(Session session, PipelineFilter rule) throws DataValidatorException {
if (rule instanceof PipelineLogicalRule) {
checkLogicalRule(session, (PipelineLogicalRule) rule);
} else if (rule instanceof PipelineRelationalRule) {
checkRelationalRule(session, (PipelineRelationalRule) rule);
}
}
19
Source : AbstractServiceImpl.java
with Apache License 2.0
from yahoo
with Apache License 2.0
from yahoo
/**
* Check before saving model.
*/
protected void preSaveCheck(Session session, T model) throws DataValidatorException {
String modelName = this.getDAO().getEnreplacedyClreplaced().getSimpleName();
// check model is not null
if (model == null) {
throw new DataValidatorException(modelName + " model is not provided.");
}
// check name is set
if (model.getPrimaryName() == null) {
throw new DataValidatorException("The name of the " + modelName + " is not provided.");
}
// check name is valid
if (!this.isNameValid(model.getPrimaryName())) {
throw new DataValidatorException("The name of the " + modelName + " should start with an English letter. It should contain only English letters and underscores.");
}
// check name is unique
if (this.getDAO().fetchByName(session, model.getPrimaryName()) != null) {
throw new DataValidatorException("Data mart name '" + model.getPrimaryName() + "' already exists.");
}
}
19
Source : AbstractServiceImpl.java
with Apache License 2.0
from yahoo
with Apache License 2.0
from yahoo
/**
* Check model before update.
*/
protected T preUpdateCheck(Session session, T newModel) throws DataValidatorException {
String modelName = this.getDAO().getEnreplacedyClreplaced().getSimpleName();
// check model is not null
if (newModel == null) {
throw new DataValidatorException(modelName + " is not provided.");
}
// check name is set
if (newModel.getPrimaryName() == null) {
throw new DataValidatorException("The name of the " + modelName + " is not provided.");
}
// check name is valid
if (!this.isNameValid(newModel.getPrimaryName())) {
throw new DataValidatorException("The name of the " + modelName + " should start with an English letter. It should contain only English letters and underscores.");
}
return null;
}
19
Source : AbstractServiceImpl.java
with Apache License 2.0
from yahoo
with Apache License 2.0
from yahoo
/**
* Model check before model delete.
*/
protected T preDeleteCheck(Session session, long id) throws DataValidatorException {
// check if id valid
if (id <= 0) {
throw new DataValidatorException("The id of the field model is not provided.");
}
// check if id exists
T oldModel = this.getDAO().fetch(session, id);
if (oldModel == null) {
throw new DataValidatorException("The " + this.getDAO().getEnreplacedyClreplaced().getSimpleName() + " with id [" + id + "] does not exist.");
}
return oldModel;
}
19
Source : PipelineDAOImpl.java
with Apache License 2.0
from yahoo
with Apache License 2.0
from yahoo
/**
* Update pipeline enreplacedy (core implementation).
*/
@Override
protected void updateKernel(Session session, Pipeline oldModel, Pipeline newModel) {
DAOFactory.pipelineProjectionDAO().update(session, oldModel.getProjections(), newModel.getProjections());
super.updateKernel(session, oldModel, newModel);
}
19
Source : PipelineDAOImpl.java
with Apache License 2.0
from yahoo
with Apache License 2.0
from yahoo
/**
* Delete pipeline enreplacedy (core implementation).
*/
@Override
public void deleteKernel(Session session, Pipeline model) {
List<PipelineProjection> projections = model.getProjections();
super.deleteKernel(session, model);
if (projections != null) {
PipelineProjection.setPipelineId(projections, model.getPrimaryIdx());
DAOFactory.pipelineProjectionDAO().delete(session, projections);
}
}
19
Source : PipelineDAOImpl.java
with Apache License 2.0
from yahoo
with Apache License 2.0
from yahoo
/**
* Performs lazy fetch.
*/
@Override
public List<Pipeline> fetchAll(Session session) {
return this.fetchAll(session, FetchMode.LAZY);
}
19
Source : PipelineDAOImpl.java
with Apache License 2.0
from yahoo
with Apache License 2.0
from yahoo
/**
* Update pipeline enreplacedy (method overloading).
*/
@Override
public void update(Session session, Pipeline newModel) {
Pipeline oldModel = this.fetch(session, newModel.getPipelineId());
if (oldModel == null) {
return;
}
super.update(session, oldModel, newModel);
}
19
Source : PipelineDAOImpl.java
with Apache License 2.0
from yahoo
with Apache License 2.0
from yahoo
/**
* Performs eager fetch.
*/
@Override
public Pipeline fetch(Session session, long id) {
Pipeline pipeline = super.fetch(session, id);
if (pipeline != null) {
Hibernate.initialize(pipeline.getProjections());
}
return pipeline;
}
19
Source : PipelineDAOImpl.java
with Apache License 2.0
from yahoo
with Apache License 2.0
from yahoo
/**
* Save pipeline enreplacedy (core implementation).
*/
@Override
protected void saveKernel(Session session, Pipeline model) {
super.saveKernel(session, model);
PipelineProjection.setPipelineId(model.getProjections(), model.getPrimaryIdx());
DAOFactory.pipelineProjectionDAO().save(session, model.getProjections());
}
19
Source : PipelineDAOImpl.java
with Apache License 2.0
from yahoo
with Apache License 2.0
from yahoo
/**
* Fetch all the pipelines.
* If fetch mode is eager, it will fetch the projections for each pipeline.
* If fetch mode is lazy, projections will not be fetched.
*/
@Override
public List<Pipeline> fetchAll(Session session, FetchMode mode) {
List<Pipeline> pipelines = super.fetchAll(session);
if (mode == FetchMode.EAGER) {
if (pipelines != null) {
for (Pipeline pipeline : pipelines) {
Hibernate.initialize(pipeline.getProjections());
}
}
return pipelines;
} else {
// default is LAZY
return Pipeline.simplifyPipelineList(pipelines);
}
}
19
Source : PipelineDAOImpl.java
with Apache License 2.0
from yahoo
with Apache License 2.0
from yahoo
/**
* Update a list of pipelines.
*/
@Override
public void updateAll(Session session, List<Pipeline> oldPipelines, List<Pipeline> newPipelines) {
this.deleteAll(session, oldPipelines);
this.saveAll(session, newPipelines);
}
19
Source : FunnelGroupDAOImpl.java
with Apache License 2.0
from yahoo
with Apache License 2.0
from yahoo
/**
* Performs lazy fetch.
*/
@Override
public List<FunnelGroup> fetchAll(Session session) {
return this.fetchAll(session, FetchMode.LAZY);
}
19
Source : FieldDAOImpl.java
with Apache License 2.0
from yahoo
with Apache License 2.0
from yahoo
/**
* Get all field enreplacedies.
*/
@Override
public List<Field> fetchAll(Session session, FetchMode mode) {
return super.fetchAll(session);
}
19
Source : AbstractEntityDAOImpl.java
with Apache License 2.0
from yahoo
with Apache License 2.0
from yahoo
/**
* Update method overloading.
*/
@Override
public void update(Session session, T newModel) {
this.update(session, null, newModel);
}
19
Source : AbstractEntityDAOImpl.java
with Apache License 2.0
from yahoo
with Apache License 2.0
from yahoo
/**
* Update model. It is transaction. Will roll back if it fails.
*/
@Override
public void update(Session session, T oldModel, T newModel) {
Transaction tx = null;
try {
tx = session.beginTransaction();
this.updateKernel(session, oldModel, newModel);
tx.commit();
} catch (RuntimeException e) {
if (tx != null) {
tx.rollback();
}
throw e;
}
}
19
Source : AbstractEntityDAOImpl.java
with Apache License 2.0
from yahoo
with Apache License 2.0
from yahoo
/**
* Delete model. It is transaction. Will roll back if it fails.
*/
@Override
public void delete(Session session, T model) {
Transaction tx = null;
try {
tx = session.beginTransaction();
this.deleteKernel(session, model);
tx.commit();
} catch (RuntimeException e) {
if (tx != null) {
tx.rollback();
}
throw e;
}
}
19
Source : AbstractEntityDAOImpl.java
with Apache License 2.0
from yahoo
with Apache License 2.0
from yahoo
/**
* Save model. It is transaction. Will roll back if it fails.
*/
@Override
public void save(Session session, T model) {
Transaction tx = null;
try {
tx = session.beginTransaction();
this.saveKernel(session, model);
tx.commit();
} catch (RuntimeException e) {
if (tx != null) {
tx.rollback();
}
throw e;
}
}
19
Source : BaseServiceImpl.java
with GNU General Public License v3.0
from xenv
with GNU General Public License v3.0
from xenv
@Override
public Integer add(Object object) {
Session session = getSession();
return (Integer) session.save(object);
}
19
Source : BaseServiceImpl.java
with GNU General Public License v3.0
from xenv
with GNU General Public License v3.0
from xenv
@Override
public void update(Object object) {
Session session = getSession();
session.update(object);
}
19
Source : BaseServiceImpl.java
with GNU General Public License v3.0
from xenv
with GNU General Public License v3.0
from xenv
@Override
public Object get(int id) {
Session session = getSession();
return session.get(clazz, id);
}
19
Source : BaseServiceImpl.java
with GNU General Public License v3.0
from xenv
with GNU General Public License v3.0
from xenv
/**
* @see BaseService
*/
@Override
public void delete(Object object) {
Session session = getSession();
try {
// 获取对象的setDeleteAt方法,插入一个时间
Method setDeleteAt = object.getClreplaced().getMethod("setDeleteAt", Date.clreplaced);
setDeleteAt.invoke(object, new Date());
} catch (Exception e) {
e.printStackTrace();
}
session.update(object);
}
19
Source : BaseServiceImpl.java
with GNU General Public License v3.0
from xenv
with GNU General Public License v3.0
from xenv
@Override
public Object get(Clreplaced clazz, int id) {
Session session = getSession();
return session.get(clazz, id);
}
19
Source : QuestionDaoImpl.java
with GNU Affero General Public License v3.0
from wkeyuan
with GNU Affero General Public License v3.0
from wkeyuan
private void saveQuChenScore(Question enreplacedy, Session session, boolean isnew) {
// 保存相关选项信息
saveRows(enreplacedy, session);
saveColumns(enreplacedy, session);
}
19
Source : QuestionDaoImpl.java
with GNU Affero General Public License v3.0
from wkeyuan
with GNU Affero General Public License v3.0
from wkeyuan
/**
* 矩阵单选题保存
* @param enreplacedy
* @param session
*/
private void saveQuChenRadio(Question enreplacedy, Session session, boolean isnew) {
// 保存相关选项信息
saveRows(enreplacedy, session);
saveColumns(enreplacedy, session);
}
19
Source : QuestionDaoImpl.java
with GNU Affero General Public License v3.0
from wkeyuan
with GNU Affero General Public License v3.0
from wkeyuan
/**
* 矩阵多选题保存
* @param enreplacedy
* @param session
*/
private void saveQuChenCheckbox(Question enreplacedy, Session session, boolean isnew) {
// 保存相关选项信息
saveRows(enreplacedy, session);
saveColumns(enreplacedy, session);
}
19
Source : QuestionDaoImpl.java
with GNU Affero General Public License v3.0
from wkeyuan
with GNU Affero General Public License v3.0
from wkeyuan
/**
* 保存题目DAO入口
*/
@Override
public void save(Question enreplacedy) {
Session session = getSession();
saveQuestion(enreplacedy, session);
}
19
Source : QuestionDaoImpl.java
with GNU Affero General Public License v3.0
from wkeyuan
with GNU Affero General Public License v3.0
from wkeyuan
/**
* 复合矩阵单选题保存
* @param enreplacedy
* @param session
*/
private void saveQuCompChenRadio(Question enreplacedy, Session session, boolean isnew) {
// 保存相关选项信息
saveRows(enreplacedy, session);
saveColumns(enreplacedy, session);
saveOptions(enreplacedy, session);
}
19
Source : QuestionDaoImpl.java
with GNU Affero General Public License v3.0
from wkeyuan
with GNU Affero General Public License v3.0
from wkeyuan
/**
* 矩阵填空题保存
* @param enreplacedy
* @param session
*/
private void saveQuChenFbk(Question enreplacedy, Session session, boolean isnew) {
// 保存相关选项信息
saveRows(enreplacedy, session);
saveColumns(enreplacedy, session);
}
19
Source : StudentDaoImpl.java
with Apache License 2.0
from weijieqiu
with Apache License 2.0
from weijieqiu
@Override
public int studentCount(Student s_student) throws Exception {
Session session = getSessionFactory().getCurrentSession();
StringBuffer sql = new StringBuffer("select count(*) from t_student");
if (StringUtil.isNotEmpty(s_student.getId())) {
sql.append(" and id like '%" + s_student.getId() + "%'");
}
if (StringUtil.isNotEmpty(s_student.getName())) {
sql.append(" and name like '%" + s_student.getName() + "%'");
}
Query query = session.createSQLQuery(sql.toString().replaceFirst("and", "where"));
int count = ((BigInteger) query.uniqueResult()).intValue();
return count;
}
19
Source : AbstractTest.java
with Apache License 2.0
from vladmihalcea
with Apache License 2.0
from vladmihalcea
protected <T> T doInJDBC(final ConnectionCallable<T> callable) {
final AtomicReference<T> result = new AtomicReference<T>();
Session session = null;
Transaction txn = null;
try {
session = sessionFactory().openSession();
txn = session.beginTransaction();
session.doWork(new Work() {
@Override
public void execute(Connection connection) throws SQLException {
result.set(callable.execute(connection));
}
});
if (txn.getLocalStatus() == LocalStatus.ACTIVE) {
txn.commit();
} else {
try {
txn.rollback();
} catch (Exception e) {
LOGGER.error("Rollback failure", e);
}
}
} catch (Throwable t) {
if (txn != null && txn.getLocalStatus() == LocalStatus.ACTIVE) {
try {
txn.rollback();
} catch (Exception e) {
LOGGER.error("Rollback failure", e);
}
}
throw new RuntimeException(t);
} finally {
if (session != null) {
session.close();
}
}
return result.get();
}
19
Source : AbstractTest.java
with Apache License 2.0
from vladmihalcea
with Apache License 2.0
from vladmihalcea
protected <T> T doInHibernate(HibernateTransactionFunction<T> callable) {
T result = null;
Session session = null;
Transaction txn = null;
try {
session = sessionFactory().openSession();
callable.beforeTransactionCompletion();
txn = session.beginTransaction();
result = callable.apply(session);
if (txn.getLocalStatus() == LocalStatus.ACTIVE) {
txn.commit();
} else {
try {
txn.rollback();
} catch (Exception e) {
LOGGER.error("Rollback failure", e);
}
}
} catch (Throwable t) {
if (txn != null && txn.getLocalStatus() == LocalStatus.ACTIVE) {
try {
txn.rollback();
} catch (Exception e) {
LOGGER.error("Rollback failure", e);
}
}
throw new RuntimeException(t);
} finally {
callable.afterTransactionCompletion();
if (session != null) {
session.close();
}
}
return result;
}
19
Source : AbstractTest.java
with Apache License 2.0
from vladmihalcea
with Apache License 2.0
from vladmihalcea
protected void doInJDBC(final ConnectionVoidCallable callable) {
Session session = null;
Transaction txn = null;
try {
session = sessionFactory().openSession();
txn = session.beginTransaction();
session.doWork(new Work() {
@Override
public void execute(Connection connection) throws SQLException {
callable.execute(connection);
}
});
if (txn.getLocalStatus() == LocalStatus.ACTIVE) {
txn.commit();
} else {
try {
txn.rollback();
} catch (Exception e) {
LOGGER.error("Rollback failure", e);
}
}
} catch (Throwable t) {
if (txn != null && txn.getLocalStatus() == LocalStatus.ACTIVE) {
try {
txn.rollback();
} catch (Exception e) {
LOGGER.error("Rollback failure", e);
}
}
throw new RuntimeException(t);
} finally {
if (session != null) {
session.close();
}
}
}
See More Examples