<commit_before>/*
 * Copyright 2007-2010 WorldWide Conferencing, LLC
 *
 * 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 net.liftweb {
package mapper {

import _root_.org.specs._
import _root_.org.specs.runner.JUnit3
import _root_.org.specs.runner.ConsoleRunner
import _root_.net.liftweb.common._
import _root_.net.liftweb.util._
import Helpers._
import _root_.net.liftweb.json._
import _root_.java.sql.{Connection, DriverManager}
//import _root_.net.liftweb.mapper.DBVendors.{MySqlRunner, DerbyRunner}

class MapperSpecsAsTest extends JUnit3(MapperSpecs)
object MapperSpecsRunner extends ConsoleRunner(MapperSpecs)

object MapperSpecs extends Specification {

  val doLog = false
  //def providers = DBProviders.H2MemoryProvider :: Nil
  def providers = DBProviders.asList

  /*
   private def logDBStuff(log: DBLog, len: Long) {
   println(" in log stuff "+log.getClass.getName)
   log match {
   case null =>
   case _ => println(log.allEntries)
   }
   }

   DB.addLogFunc(logDBStuff)
   */

  def dbSetup() {
    Schemifier.destroyTables_!!(ignoreLogger _, SampleModel, SampleTag,
                                Dog, User, Mixer, Dog2)
    Schemifier.schemify(true, ignoreLogger _, SampleModel, SampleTag,
                        User, Dog, Mixer, Dog2)
  }

  def snakify(connid: ConnectionIdentifier, name: String): String = {
    if (connid.jndiName == "snake")
      StringHelpers.snakify(name)
    else
      name.toLowerCase
  }

  if (!DB.loggingEnabled_? && doLog)
    DB.addLogFunc(logDBStuff)

  MapperRules.columnName = snakify
  MapperRules.tableName = snakify

  providers.foreach(provider => {
      def cleanup() {
        try { provider.setupDB } catch { case e if !provider.required_? => skip("Provider %s not available: %s".format(provider, e)) }
        Schemifier.destroyTables_!!(DefaultConnectionIdentifier, if (doLog) Log.infoF _ else ignoreLogger _,  SampleModel, SampleTag, User, Dog, Mixer, Dog2)
        Schemifier.destroyTables_!!(DBProviders.SnakeConnectionIdentifier, if (doLog) Log.infoF _ else ignoreLogger _,  SampleModelSnake)
        Schemifier.schemify(true, if (doLog) Log.infoF _ else ignoreLogger _, DefaultConnectionIdentifier, SampleModel, SampleTag, User, Dog, Mixer, Dog2)
        Schemifier.schemify(true, if (doLog) Log.infoF _ else ignoreLogger _, DBProviders.SnakeConnectionIdentifier, SampleModelSnake)
      }

      ("Mapper for " + provider.name) should {
        "schemify" in {
          cleanup()
          <commit_msg>fixed merge conflicts<commit_after>/*
 * Copyright 2007-2010 WorldWide Conferencing, LLC
 *
 * 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 net.liftweb {
package mapper {

import _root_.org.specs._
import _root_.org.specs.runner.JUnit3
import _root_.org.specs.runner.ConsoleRunner
import _root_.net.liftweb.common._
import _root_.net.liftweb.util._
import Helpers._
import _root_.net.liftweb.json._
import _root_.java.sql.{Connection, DriverManager}
//import _root_.net.liftweb.mapper.DBVendors.{MySqlRunner, DerbyRunner}

class MapperSpecsAsTest extends JUnit3(MapperSpecs)
object MapperSpecsRunner extends ConsoleRunner(MapperSpecs)

object MapperSpecs extends Specification {

  val doLog = false
  //def providers = DBProviders.H2MemoryProvider :: Nil
  def providers = DBProviders.asList

  /*
   private def logDBStuff(log: DBLog, len: Long) {
   println(" in log stuff "+log.getClass.getName)
   log match {
   case null =>
   case _ => println(log.allEntries)
   }
   }

   DB.addLogFunc(logDBStuff)
   */

  def dbSetup() {
    Schemifier.destroyTables_!!(ignoreLogger _, SampleModel, SampleTag,
                                Dog, User, Mixer, Dog2)
    Schemifier.schemify(true, ignoreLogger _, SampleModel, SampleTag,
                        User, Dog, Mixer, Dog2)
  }

  def snakify(connid: ConnectionIdentifier, name: String): String = {
    if (connid.jndiName == "snake")
      StringHelpers.snakify(name)
    else
      name.toLowerCase
  }

  /*
  if (!DB.loggingEnabled_? && doLog)
    DB.addLogFunc(logDBStuff)
*/

  MapperRules.columnName = snakify
  MapperRules.tableName = snakify

  providers.foreach(provider => {
      def cleanup() {
        try { provider.setupDB } catch { case e if !provider.required_? => skip("Provider %s not available: %s".format(provider, e)) }
        Schemifier.destroyTables_!!(DefaultConnectionIdentifier, if (doLog) Log.infoF _ else ignoreLogger _,  SampleModel, SampleTag, User, Dog, Mixer, Dog2)
        Schemifier.destroyTables_!!(DBProviders.SnakeConnectionIdentifier, if (doLog) Log.infoF _ else ignoreLogger _,  SampleModelSnake)
        Schemifier.schemify(true, if (doLog) Log.infoF _ else ignoreLogger _, DefaultConnectionIdentifier, SampleModel, SampleTag, User, Dog, Mixer, Dog2)
        Schemifier.schemify(true, if (doLog) Log.infoF _ else ignoreLogger _, DBProviders.SnakeConnectionIdentifier, SampleModelSnake)
      }

      ("Mapper for " + provider.name) should {
        "schemify" in {
          cleanup()
          
{'fraction_non_alphanumeric': 0.09514304723885562, 'fraction_numerical': 0.006320691949434464, 'mean_word_length': 3.5795887281035794, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1923544', 'n_tokens_mistral': 1848, 'n_tokens_neox': 1791, 'n_words': 498}