Package org.exoplatform.services.database.annotation

Examples of org.exoplatform.services.database.annotation.Table


      exoDatasource = datasource;
   }

   public <T extends DBObject> void createTable(Class<T> type, boolean dropIfExist) throws Exception
   {
      Table table = type.getAnnotation(Table.class);
      if (table == null)
      {
         throw new Exception("Cannot find the annotation for class " + type.getClass().getName());
      }
      StringBuilder builder = new StringBuilder(1000);
      builder.append("CREATE TABLE ").append(table.name()).append(" (");
      appendId(builder);
      TableField[] fields = table.field();
      for (int i = 0; i < fields.length; i++)
      {
         TableField field = fields[i];
         String fieldType = field.type();
         if ("string".equals(fieldType))
         {
            appendStringField(field, builder);
         }
         else if ("int".equals(fieldType))
         {
            appendIntegerField(field, builder);
         }
         else if ("long".equals(fieldType))
         {
            appendLongField(field, builder);
         }
         else if ("float".equals(fieldType))
         {
            appendFloatField(field, builder);
         }
         else if ("double".equals(fieldType))
         {
            appendDoubleField(field, builder);
         }
         else if ("boolean".equals(fieldType))
         {
            appendBooleanField(field, builder);
         }
         else if ("date".equals(fieldType))
         {
            appendDateField(field, builder);
         }
         else if ("binary".equals(fieldType))
         {
            appendBinaryField(field, builder);
         }
         if (i != fields.length - 1)
            builder.append(", ");
      }
      builder.append(")");

      // print out the sql string
      Connection conn = exoDatasource.getConnection();
      conn.setAutoCommit(false);
      Statement statement = conn.createStatement();
      LOG.debug("QUERY: \n  " + builder + "\n");
      if (dropIfExist && hasTable(type))
         statement.execute("DROP TABLE IF EXISTS " + table.name());
      statement.execute(builder.toString());
      statement.close();
      conn.commit();
      exoDatasource.closeConnection(conn);
   }
View Full Code Here


      exoDatasource.closeConnection(conn);
   }

   public <T extends DBObject> void dropTable(Class<T> type) throws Exception
   {
      Table table = type.getAnnotation(Table.class);
      if (table == null)
      {
         throw new Exception("Can not find the annotation for class " + type.getClass().getName());
      }
      Connection conn = exoDatasource.getConnection();
      Statement s = conn.createStatement();
      s.execute("DROP TABLE " + table.name());
      s.close();
      conn.commit();
      exoDatasource.closeConnection(conn);
   }
View Full Code Here

      exoDatasource.closeConnection(conn);
   }

   public <T extends DBObject> boolean hasTable(Class<T> type) throws Exception
   {
      Table table = type.getAnnotation(Table.class);
      if (table == null)
      {
         throw new Exception("Can not find the annotation for class " + type.getClass().getName());
      }
      Connection connection = exoDatasource.getConnection();
      Statement statement = connection.createStatement();
      try
      {
         if (statement.execute("SELECT 1 FROM " + table.name()) == true)
            return true;
      }
      catch (SQLException ex)
      {
         return false;
View Full Code Here

      tableManager.createTable(ExoLongID.class, true);
   }

   public ExoLongID loadObjectByName(String name) throws Exception
   {
      Table table = ExoLongID.class.getAnnotation(Table.class);
      StringBuilder builder = new StringBuilder("SELECT EXO_NAME, EXO_START FROM ");
      builder.append(table.name()).append(" WHERE EXO_NAME = '").append(name).append('\'');
      return loadUnique(builder.toString());
   }
View Full Code Here

      exoDatasource = datasource;
   }

   public <T extends DBObject> void createTable(Class<T> type, boolean dropIfExist) throws Exception
   {
      Table table = type.getAnnotation(Table.class);
      if (table == null)
      {
         throw new Exception("Cannot find the annotation for class " + type.getClass().getName());
      }
      StringBuilder builder = new StringBuilder(1000);
      builder.append("CREATE TABLE ").append(table.name()).append(" (");
      appendId(builder);
      TableField[] fields = table.field();
      for (int i = 0; i < fields.length; i++)
      {
         TableField field = fields[i];
         String fieldType = field.type();
         if ("string".equals(fieldType))
         {
            appendStringField(field, builder);
         }
         else if ("int".equals(fieldType))
         {
            appendIntegerField(field, builder);
         }
         else if ("long".equals(fieldType))
         {
            appendLongField(field, builder);
         }
         else if ("float".equals(fieldType))
         {
            appendFloatField(field, builder);
         }
         else if ("double".equals(fieldType))
         {
            appendDoubleField(field, builder);
         }
         else if ("boolean".equals(fieldType))
         {
            appendBooleanField(field, builder);
         }
         else if ("date".equals(fieldType))
         {
            appendDateField(field, builder);
         }
         else if ("binary".equals(fieldType))
         {
            appendBinaryField(field, builder);
         }
         if (i != fields.length - 1)
            builder.append(", ");
      }
      builder.append(")");

      // print out the sql string
      Connection conn = exoDatasource.getConnection();
      conn.setAutoCommit(false);
      Statement statement = conn.createStatement();
      LOG.info("QUERY: \n  " + builder + "\n");
      if (dropIfExist && hasTable(type))
         statement.execute("DROP TABLE IF EXISTS " + table.name());
      statement.execute(builder.toString());
      statement.close();
      conn.commit();
      exoDatasource.closeConnection(conn);
   }
View Full Code Here

      exoDatasource.closeConnection(conn);
   }

   public <T extends DBObject> void dropTable(Class<T> type) throws Exception
   {
      Table table = type.getAnnotation(Table.class);
      if (table == null)
      {
         throw new Exception("Can not find the annotation for class " + type.getClass().getName());
      }
      Connection conn = exoDatasource.getConnection();
      Statement s = conn.createStatement();
      s.execute("DROP TABLE " + table.name());
      s.close();
      conn.commit();
      exoDatasource.closeConnection(conn);
   }
View Full Code Here

      exoDatasource.closeConnection(conn);
   }

   public <T extends DBObject> boolean hasTable(Class<T> type) throws Exception
   {
      Table table = type.getAnnotation(Table.class);
      if (table == null)
      {
         throw new Exception("Can not find the annotation for class " + type.getClass().getName());
      }
      Connection connection = exoDatasource.getConnection();
      Statement statement = connection.createStatement();
      try
      {
         if (statement.execute("SELECT 1 FROM " + table.name()) == true)
            return true;
      }
      catch (SQLException ex)
      {
         return false;
View Full Code Here

   }

   public void mapResultSet(ResultSet resultSet, T bean) throws Exception
   {
      Class<? extends DBObject> clazz = bean.getClass();
      Table table = clazz.getAnnotation(Table.class);
      TableField[] tableFields = table.field();

      ResultSetMetaData rsmd = resultSet.getMetaData();
      int numberOfColumns = rsmd.getColumnCount();
      for (int i = 1; i <= numberOfColumns; i++)
      {
View Full Code Here

   }

   public void mapUpdate(T bean, PreparedStatement statement) throws Exception
   {
      Class<? extends DBObject> clazz = bean.getClass();
      Table table = clazz.getAnnotation(Table.class);
      TableField[] tableFields = table.field();

      int i = 1;
      for (TableField tableField : tableFields)
      {
         String fieldName = tableField.field().length() == 0 ? tableField.name() : tableField.field();
View Full Code Here

      exoDatasource = datasource;
   }

   public <T extends DBObject> void createTable(Class<T> type, boolean dropIfExist) throws Exception
   {
      Table table = type.getAnnotation(Table.class);
      if (table == null)
      {
         throw new Exception("Cannot find the annotation for class " + type.getClass().getName());
      }
      StringBuilder builder = new StringBuilder(1000);
      builder.append("CREATE TABLE ").append(table.name()).append(" (");
      appendId(builder);
      TableField[] fields = table.field();
      for (int i = 0; i < fields.length; i++)
      {
         TableField field = fields[i];
         String fieldType = field.type();
         if ("string".equals(fieldType))
         {
            appendStringField(field, builder);
         }
         else if ("int".equals(fieldType))
         {
            appendIntegerField(field, builder);
         }
         else if ("long".equals(fieldType))
         {
            appendLongField(field, builder);
         }
         else if ("float".equals(fieldType))
         {
            appendFloatField(field, builder);
         }
         else if ("double".equals(fieldType))
         {
            appendDoubleField(field, builder);
         }
         else if ("boolean".equals(fieldType))
         {
            appendBooleanField(field, builder);
         }
         else if ("date".equals(fieldType))
         {
            appendDateField(field, builder);
         }
         else if ("binary".equals(fieldType))
         {
            appendBinaryField(field, builder);
         }
         if (i != fields.length - 1)
            builder.append(", ");
      }
      builder.append(")");

      // print out the sql string
      Connection conn = exoDatasource.getConnection();
      conn.setAutoCommit(false);
      Statement statement = conn.createStatement();
      LOG.info("QUERY: \n  " + builder + "\n");
      if (dropIfExist && hasTable(type))
         statement.execute("DROP TABLE IF EXISTS " + table.name());
      statement.execute(builder.toString());
      statement.close();
      conn.commit();
      exoDatasource.closeConnection(conn);
   }
View Full Code Here

TOP

Related Classes of org.exoplatform.services.database.annotation.Table

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.